diff options
| author | 2008-07-30 09:42:15 -0700 | |
|---|---|---|
| committer | 2008-07-30 09:42:15 -0700 | |
| commit | ed6e6e57a819c78b888b1b71056ccc4ebb40434f (patch) | |
| tree | 68ce222301295e9768939e5bf018daf51b741c28 /src | |
| parent | 3dc130f3049e250b2d5c0b48af1995fda2fad3d4 (diff) | |
| download | libimobiledevice-ed6e6e57a819c78b888b1b71056ccc4ebb40434f.tar.gz libimobiledevice-ed6e6e57a819c78b888b1b71056ccc4ebb40434f.tar.bz2 | |
Added beginnings of a fuse fs, right now it's read only and terribly fragile.
Diffstat (limited to 'src')
| -rw-r--r-- | src/AFC.h | 5 | ||||
| -rw-r--r-- | src/Makefile.am | 7 | ||||
| -rw-r--r-- | src/ifuse.c | 135 |
3 files changed, 140 insertions, 7 deletions
| @@ -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 | ||
| 14 | typedef struct { | 15 | typedef 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 | ||
| 41 | enum { | ||
| 42 | S_IFREG = 0, | ||
| 43 | S_IFDIR = 1 | ||
| 44 | }; | ||
| 45 | 42 | ||
| 46 | enum { | 43 | enum { |
| 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 @@ | |||
| 1 | AM_CFLAGS = `xml2-config --cflags` | 1 | AM_CFLAGS = `xml2-config --cflags` `pkg-config fuse --cflags` `pkg-config glib-2.0 --cflags` -g |
| 2 | AM_LDFLAGS = `xml2-config --libs` -lusb -lgnutls | 2 | AM_LDFLAGS = `xml2-config --libs` `pkg-config fuse --libs` `pkg-config glib-2.0 --libs` -lusb -lgnutls |
| 3 | 3 | ||
| 4 | bin_PROGRAMS = iphoneclient | 4 | bin_PROGRAMS = iphoneclient ifuse |
| 5 | iphoneclient_SOURCES = usbmux.c main.c iphone.c plist.c lockdown.c AFC.c | 5 | iphoneclient_SOURCES = usbmux.c main.c iphone.c plist.c lockdown.c AFC.c |
| 6 | ifuse_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 | |||
| 20 | AFClient *afc; | ||
| 21 | GHashTable *file_handles; | ||
| 22 | int fh_index = 0; | ||
| 23 | |||
| 24 | int debug = 0; | ||
| 25 | |||
| 26 | static 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 | |||
| 43 | static 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 | |||
| 58 | static 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 | |||
| 73 | static 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 | |||
| 88 | void 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 | |||
| 120 | void ifuse_cleanup() { | ||
| 121 | afc_disconnect(afc); | ||
| 122 | } | ||
| 123 | |||
| 124 | static 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 | |||
| 133 | int main(int argc, char *argv[]) { | ||
| 134 | return fuse_main(argc, argv, &ifuse_oper, NULL); | ||
| 135 | } | ||
