summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Matt Colyer2008-07-30 09:42:15 -0700
committerGravatar Matt Colyer2008-07-30 09:42:15 -0700
commited6e6e57a819c78b888b1b71056ccc4ebb40434f (patch)
tree68ce222301295e9768939e5bf018daf51b741c28
parent3dc130f3049e250b2d5c0b48af1995fda2fad3d4 (diff)
downloadlibimobiledevice-ed6e6e57a819c78b888b1b71056ccc4ebb40434f.tar.gz
libimobiledevice-ed6e6e57a819c78b888b1b71056ccc4ebb40434f.tar.bz2
Added beginnings of a fuse fs, right now it's read only and terribly fragile.
-rw-r--r--src/AFC.h5
-rw-r--r--src/Makefile.am7
-rw-r--r--src/ifuse.c135
3 files changed, 140 insertions, 7 deletions
diff --git a/src/AFC.h b/src/AFC.h
index 787b9fe..6e1bf77 100644
--- a/src/AFC.h
+++ b/src/AFC.h
@@ -10,6 +10,7 @@
10#include <string.h> 10#include <string.h>
11#include <stdio.h> 11#include <stdio.h>
12#include <stdlib.h> 12#include <stdlib.h>
13#include <sys/stat.h>
13 14
14typedef struct { 15typedef struct {
15 //const uint32 header1 = 0x36414643; // '6AFC' or 'CFA6' when sent ;) 16 //const uint32 header1 = 0x36414643; // '6AFC' or 'CFA6' when sent ;)
@@ -38,10 +39,6 @@ typedef struct __AFCToken {
38 char *token; 39 char *token;
39} AFCToken; 40} AFCToken;
40 41
41enum {
42 S_IFREG = 0,
43 S_IFDIR = 1
44};
45 42
46enum { 43enum {
47 AFC_FILE_READ = 0x00000002, 44 AFC_FILE_READ = 0x00000002,
diff --git a/src/Makefile.am b/src/Makefile.am
index cb05d95..ed1ae59 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,5 +1,6 @@
1AM_CFLAGS = `xml2-config --cflags` 1AM_CFLAGS = `xml2-config --cflags` `pkg-config fuse --cflags` `pkg-config glib-2.0 --cflags` -g
2AM_LDFLAGS = `xml2-config --libs` -lusb -lgnutls 2AM_LDFLAGS = `xml2-config --libs` `pkg-config fuse --libs` `pkg-config glib-2.0 --libs` -lusb -lgnutls
3 3
4bin_PROGRAMS = iphoneclient 4bin_PROGRAMS = iphoneclient ifuse
5iphoneclient_SOURCES = usbmux.c main.c iphone.c plist.c lockdown.c AFC.c 5iphoneclient_SOURCES = usbmux.c main.c iphone.c plist.c lockdown.c AFC.c
6ifuse_SOURCES = ifuse.c usbmux.c iphone.c plist.c lockdown.c AFC.c
diff --git a/src/ifuse.c b/src/ifuse.c
new file mode 100644
index 0000000..eb124af
--- /dev/null
+++ b/src/ifuse.c
@@ -0,0 +1,135 @@
1#define FUSE_USE_VERSION 26
2
3#include <fuse.h>
4#include <stdio.h>
5#include <string.h>
6#include <errno.h>
7#include <fcntl.h>
8#include <usb.h>
9#include <libxml/parser.h>
10#include <libxml/tree.h>
11#include <glib.h>
12
13#include "usbmux.h"
14#include "iphone.h"
15#include "plist.h"
16#include "lockdown.h"
17#include "AFC.h"
18
19
20AFClient *afc;
21GHashTable *file_handles;
22int fh_index = 0;
23
24int debug = 0;
25
26static int ifuse_getattr(const char *path, struct stat *stbuf) {
27 int res = 0;
28 AFCFile *file;
29
30 memset(stbuf, 0, sizeof(struct stat));
31 file = afc_get_file_info(afc, path);
32 if (!file){
33 res = -ENOENT;
34 }
35
36 stbuf->st_mode = file->type | 0444;
37 stbuf->st_size = file->size;
38 //stbuf->st_nlink = 2;
39
40 return res;
41}
42
43static int ifuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
44 off_t offset, struct fuse_file_info *fi) {
45 int i;
46 char **dirs, **filename;
47
48 dirs = afc_get_dir_list(afc, path);
49 for (i = 0; strcmp(dirs[i], ""); i++) {
50 filler(buf, dirs[i], NULL, 0);
51 }
52
53 free_dictionary(dirs);
54
55 return 0;
56}
57
58static int ifuse_open(const char *path, struct fuse_file_info *fi) {
59 AFCFile *file;
60
61 if((fi->flags & 3) != O_RDONLY)
62 return -EACCES;
63
64 file = afc_open_file(afc, path, AFC_FILE_READ);
65
66 fh_index++;
67 fi->fh = fh_index;
68 g_hash_table_insert(file_handles, &fh_index, file);
69
70 return 0;
71}
72
73static int ifuse_read(const char *path, char *buf, size_t size, off_t offset,
74 struct fuse_file_info *fi) {
75 int bytes;
76 AFCFile *file;
77
78 file = g_hash_table_lookup(file_handles, &(fi->fh));
79 if (!file){
80 return -ENOENT;
81 }
82
83 bytes = afc_read_file(afc, file, buf, size);
84
85 return bytes;
86}
87
88void ifuse_init(struct fuse_conn_info *conn) {
89 char *response = (char*)malloc(sizeof(char) * 2048);
90 int bytes = 0, port = 0, i = 0;
91
92 file_handles = g_hash_table_new(g_int_hash, g_int_equal);
93
94 iPhone *phone = get_iPhone();
95 if (!phone){
96 fprintf(stderr, "No iPhone found, is it connected?\n");
97 return -1;
98 }
99
100 lockdownd_client *control = new_lockdownd_client(phone);
101 if (!lockdownd_hello(control)) {
102 fprintf(stderr, "Something went wrong in the lockdownd client.\n");
103 return -1;
104 }
105
106 //if (!lockdownd_start_SSL_session(control, "29942970-207913891623273984")) {
107 fprintf(stderr, "Something went wrong in GnuTLS.\n");
108 return -1;
109 }
110
111 port = lockdownd_start_service(control, "com.apple.afc");
112 if (!port) {
113 fprintf(stderr, "Something went wrong when starting AFC.");
114 }
115
116 afc = afc_connect(phone, 3432, port);
117
118}
119
120void ifuse_cleanup() {
121 afc_disconnect(afc);
122}
123
124static struct fuse_operations ifuse_oper = {
125 .getattr = ifuse_getattr,
126 .readdir = ifuse_readdir,
127 .open = ifuse_open,
128 .read = ifuse_read,
129 .init = ifuse_init,
130 .destroy = ifuse_cleanup
131};
132
133int main(int argc, char *argv[]) {
134 return fuse_main(argc, argv, &ifuse_oper, NULL);
135}