diff options
| author | 2008-08-25 23:50:22 +0200 | |
|---|---|---|
| committer | 2008-08-31 19:33:18 +0200 | |
| commit | e52da6fe75008174a254254ec83394766afb624b (patch) | |
| tree | 9ad8cd860525a3340dd49e2dbc8cd685dcf1ca7e /src/ifuse.c | |
| parent | 6ac4ceb4c6ee63c279f4841381a3eb09598f3517 (diff) | |
| download | libimobiledevice-e52da6fe75008174a254254ec83394766afb624b.tar.gz libimobiledevice-e52da6fe75008174a254254ec83394766afb624b.tar.bz2 | |
make it compile
Diffstat (limited to 'src/ifuse.c')
| -rw-r--r-- | src/ifuse.c | 106 |
1 files changed, 51 insertions, 55 deletions
diff --git a/src/ifuse.c b/src/ifuse.c index cc2072f..1c184a2 100644 --- a/src/ifuse.c +++ b/src/ifuse.c | |||
| @@ -49,8 +49,9 @@ int debug = 0; | |||
| 49 | 49 | ||
| 50 | static int ifuse_getattr(const char *path, struct stat *stbuf) { | 50 | static int ifuse_getattr(const char *path, struct stat *stbuf) { |
| 51 | int res = 0; | 51 | int res = 0; |
| 52 | AFCFile *file; | 52 | |
| 53 | AFClient *afc = fuse_get_context()->private_data; | 53 | iphone_afc_client_t afc = fuse_get_context()->private_data; |
| 54 | res = iphone_afc_get_file_attr(afc, path, stbuf); | ||
| 54 | 55 | ||
| 55 | return res; | 56 | return res; |
| 56 | } | 57 | } |
| @@ -59,9 +60,9 @@ static int ifuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, | |||
| 59 | off_t offset, struct fuse_file_info *fi) { | 60 | off_t offset, struct fuse_file_info *fi) { |
| 60 | int i; | 61 | int i; |
| 61 | char **dirs; | 62 | char **dirs; |
| 62 | AFClient *afc = fuse_get_context()->private_data; | 63 | iphone_afc_client_t afc = fuse_get_context()->private_data; |
| 63 | 64 | ||
| 64 | dirs = afc_get_dir_list(afc, path); | 65 | dirs = iphone_afc_get_dir_list(afc, path); |
| 65 | 66 | ||
| 66 | if(!dirs) | 67 | if(!dirs) |
| 67 | return -ENOENT; | 68 | return -ENOENT; |
| @@ -77,10 +78,10 @@ static int ifuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, | |||
| 77 | 78 | ||
| 78 | static int ifuse_create(const char *path, mode_t mode, struct fuse_file_info *fi) { | 79 | static int ifuse_create(const char *path, mode_t mode, struct fuse_file_info *fi) { |
| 79 | // exactly the same as open but using a different mode | 80 | // exactly the same as open but using a different mode |
| 80 | AFCFile *file; | 81 | iphone_afc_file_t file; |
| 81 | AFClient *afc = fuse_get_context()->private_data; | 82 | iphone_afc_client_t afc = fuse_get_context()->private_data; |
| 82 | 83 | ||
| 83 | file = afc_open_file(afc, path, AFC_FILE_WRITE); | 84 | iphone_afc_open_file(afc, path, AFC_FILE_WRITE, &file); |
| 84 | fh_index++; | 85 | fh_index++; |
| 85 | fi->fh = fh_index; | 86 | fi->fh = fh_index; |
| 86 | g_hash_table_insert(file_handles, &fh_index, file); | 87 | g_hash_table_insert(file_handles, &fh_index, file); |
| @@ -88,8 +89,8 @@ static int ifuse_create(const char *path, mode_t mode, struct fuse_file_info *fi | |||
| 88 | } | 89 | } |
| 89 | 90 | ||
| 90 | static int ifuse_open(const char *path, struct fuse_file_info *fi) { | 91 | static int ifuse_open(const char *path, struct fuse_file_info *fi) { |
| 91 | AFCFile *file; | 92 | iphone_afc_file_t file; |
| 92 | AFClient *afc = fuse_get_context()->private_data; | 93 | iphone_afc_client_t afc = fuse_get_context()->private_data; |
| 93 | uint32 mode = 0; | 94 | uint32 mode = 0; |
| 94 | 95 | ||
| 95 | if ((fi->flags & 3) == O_RDWR || (fi->flags & 3) == O_WRONLY) { | 96 | if ((fi->flags & 3) == O_RDWR || (fi->flags & 3) == O_WRONLY) { |
| @@ -100,7 +101,7 @@ static int ifuse_open(const char *path, struct fuse_file_info *fi) { | |||
| 100 | mode = AFC_FILE_READ; | 101 | mode = AFC_FILE_READ; |
| 101 | } | 102 | } |
| 102 | 103 | ||
| 103 | file = afc_open_file(afc, path, mode); | 104 | iphone_afc_open_file(afc, path, mode, &file); |
| 104 | 105 | ||
| 105 | fh_index++; | 106 | fh_index++; |
| 106 | fi->fh = fh_index; | 107 | fi->fh = fh_index; |
| @@ -112,8 +113,8 @@ static int ifuse_open(const char *path, struct fuse_file_info *fi) { | |||
| 112 | static int ifuse_read(const char *path, char *buf, size_t size, off_t offset, | 113 | static int ifuse_read(const char *path, char *buf, size_t size, off_t offset, |
| 113 | struct fuse_file_info *fi) { | 114 | struct fuse_file_info *fi) { |
| 114 | int bytes; | 115 | int bytes; |
| 115 | AFCFile *file; | 116 | iphone_afc_file_t file; |
| 116 | AFClient *afc = fuse_get_context()->private_data; | 117 | iphone_afc_client_t afc = fuse_get_context()->private_data; |
| 117 | 118 | ||
| 118 | if (size == 0) | 119 | if (size == 0) |
| 119 | return 0; | 120 | return 0; |
| @@ -123,23 +124,23 @@ static int ifuse_read(const char *path, char *buf, size_t size, off_t offset, | |||
| 123 | return -ENOENT; | 124 | return -ENOENT; |
| 124 | } | 125 | } |
| 125 | 126 | ||
| 126 | bytes = afc_seek_file(afc, file, offset); | 127 | bytes = iphone_afc_seek_file(afc, file, offset); |
| 127 | bytes = afc_read_file(afc, file, buf, size); | 128 | bytes = iphone_afc_read_file(afc, file, buf, size); |
| 128 | return bytes; | 129 | return bytes; |
| 129 | } | 130 | } |
| 130 | 131 | ||
| 131 | static int ifuse_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { | 132 | static int ifuse_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { |
| 132 | int bytes = 0; | 133 | int bytes = 0; |
| 133 | AFCFile *file = NULL; | 134 | iphone_afc_file_t file = NULL; |
| 134 | AFClient *afc = fuse_get_context()->private_data; | 135 | iphone_afc_client_t afc = fuse_get_context()->private_data; |
| 135 | 136 | ||
| 136 | if (size == 0) return 0; | 137 | if (size == 0) return 0; |
| 137 | 138 | ||
| 138 | file = g_hash_table_lookup(file_handles, &(fi->fh)); | 139 | file = g_hash_table_lookup(file_handles, &(fi->fh)); |
| 139 | if (!file) return -ENOENT; | 140 | if (!file) return -ENOENT; |
| 140 | 141 | ||
| 141 | bytes = afc_seek_file(afc, file, offset); | 142 | bytes = iphone_afc_seek_file(afc, file, offset); |
| 142 | bytes = afc_write_file(afc, file, buf, size); | 143 | bytes = iphone_afc_write_file(afc, file, buf, size); |
| 143 | return bytes; | 144 | return bytes; |
| 144 | } | 145 | } |
| 145 | 146 | ||
| @@ -148,16 +149,15 @@ static int ifuse_fsync(const char *path, int datasync, struct fuse_file_info *fi | |||
| 148 | } | 149 | } |
| 149 | 150 | ||
| 150 | static int ifuse_release(const char *path, struct fuse_file_info *fi){ | 151 | static int ifuse_release(const char *path, struct fuse_file_info *fi){ |
| 151 | AFCFile *file; | 152 | iphone_afc_file_t file; |
| 152 | AFClient *afc = fuse_get_context()->private_data; | 153 | iphone_afc_client_t afc = fuse_get_context()->private_data; |
| 153 | 154 | ||
| 154 | file = g_hash_table_lookup(file_handles, &(fi->fh)); | 155 | file = g_hash_table_lookup(file_handles, &(fi->fh)); |
| 155 | if (!file){ | 156 | if (!file){ |
| 156 | return -ENOENT; | 157 | return -ENOENT; |
| 157 | } | 158 | } |
| 158 | afc_close_file(afc, file); | 159 | iphone_afc_close_file(afc, file); |
| 159 | 160 | ||
| 160 | free(file); | ||
| 161 | g_hash_table_remove(file_handles, &(fi->fh)); | 161 | g_hash_table_remove(file_handles, &(fi->fh)); |
| 162 | 162 | ||
| 163 | return 0; | 163 | return 0; |
| @@ -165,49 +165,44 @@ static int ifuse_release(const char *path, struct fuse_file_info *fi){ | |||
| 165 | 165 | ||
| 166 | void *ifuse_init(struct fuse_conn_info *conn) { | 166 | void *ifuse_init(struct fuse_conn_info *conn) { |
| 167 | int port = 0; | 167 | int port = 0; |
| 168 | AFClient *afc = NULL; | 168 | iphone_afc_client_t afc = NULL; |
| 169 | 169 | ||
| 170 | conn->async_read = 0; | 170 | conn->async_read = 0; |
| 171 | 171 | ||
| 172 | file_handles = g_hash_table_new(g_int_hash, g_int_equal); | 172 | file_handles = g_hash_table_new(g_int_hash, g_int_equal); |
| 173 | 173 | ||
| 174 | phone = get_iPhone(); | 174 | iphone_get_device(&phone); |
| 175 | if (!phone){ | 175 | if (!phone){ |
| 176 | fprintf(stderr, "No iPhone found, is it connected?\n"); | 176 | fprintf(stderr, "No iPhone found, is it connected?\n"); |
| 177 | return NULL; | ||
| 178 | } | ||
| 179 | |||
| 180 | lockdownd_client *control = new_lockdownd_client(phone); | ||
| 181 | if (!lockdownd_hello(control)) { | ||
| 182 | fprintf(stderr, "Something went wrong in the lockdownd client.\n"); | ||
| 183 | return NULL; | 177 | return NULL; |
| 184 | } | 178 | } |
| 179 | |||
| 185 | 180 | ||
| 186 | if (!lockdownd_init(phone, &control)) { | 181 | if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { |
| 187 | free_iPhone(phone); | 182 | iphone_free_device(phone); |
| 188 | fprintf(stderr, "Something went wrong in the lockdownd client.\n"); | 183 | fprintf(stderr, "Something went wrong in the lockdownd client.\n"); |
| 189 | return NULL; | 184 | return NULL; |
| 190 | } | 185 | } |
| 191 | 186 | ||
| 192 | port = lockdownd_start_service(control, "com.apple.afc"); | 187 | port = iphone_lckd_start_service(control, "com.apple.afc"); |
| 193 | if (!port) { | 188 | if (!port) { |
| 194 | lockdownd_close(control); | 189 | iphone_lckd_free_client(control); |
| 195 | free_iPhone(phone); | 190 | iphone_free_device(phone); |
| 196 | fprintf(stderr, "Something went wrong when starting AFC."); | 191 | fprintf(stderr, "Something went wrong when starting AFC."); |
| 197 | return NULL; | 192 | return NULL; |
| 198 | } | 193 | } |
| 199 | 194 | ||
| 200 | afc = afc_connect(phone, 3432, port); | 195 | iphone_afc_new_client(phone, 3432, port, &afc); |
| 201 | 196 | ||
| 202 | return afc; | 197 | return afc; |
| 203 | } | 198 | } |
| 204 | 199 | ||
| 205 | void ifuse_cleanup(void *data) { | 200 | void ifuse_cleanup(void *data) { |
| 206 | AFClient *afc = (AFClient *)data; | 201 | iphone_afc_client_t afc = (iphone_afc_client_t )data; |
| 207 | 202 | ||
| 208 | afc_disconnect(afc); | 203 | iphone_afc_free_client(afc); |
| 209 | lockdownd_close(control); | 204 | iphone_lckd_free_client(control); |
| 210 | free_iPhone(phone); | 205 | iphone_free_device(phone); |
| 211 | } | 206 | } |
| 212 | 207 | ||
| 213 | int ifuse_flush(const char *path, struct fuse_file_info *fi) { | 208 | int ifuse_flush(const char *path, struct fuse_file_info *fi) { |
| @@ -215,8 +210,8 @@ int ifuse_flush(const char *path, struct fuse_file_info *fi) { | |||
| 215 | } | 210 | } |
| 216 | 211 | ||
| 217 | int ifuse_statfs(const char *path, struct statvfs *stats) { | 212 | int ifuse_statfs(const char *path, struct statvfs *stats) { |
| 218 | AFClient *afc = fuse_get_context()->private_data; | 213 | iphone_afc_client_t afc = fuse_get_context()->private_data; |
| 219 | char **info_raw = afc_get_devinfo(afc); | 214 | char **info_raw = iphone_afc_get_devinfo(afc); |
| 220 | uint32 totalspace = 0, freespace = 0, blocksize = 0, i = 0; | 215 | uint32 totalspace = 0, freespace = 0, blocksize = 0, i = 0; |
| 221 | 216 | ||
| 222 | if (!info_raw) return -ENOENT; | 217 | if (!info_raw) return -ENOENT; |
| @@ -243,38 +238,39 @@ int ifuse_statfs(const char *path, struct statvfs *stats) { | |||
| 243 | 238 | ||
| 244 | int ifuse_truncate(const char *path, off_t size) { | 239 | int ifuse_truncate(const char *path, off_t size) { |
| 245 | int result = 0; | 240 | int result = 0; |
| 246 | AFClient *afc = fuse_get_context()->private_data; | 241 | iphone_afc_client_t afc = fuse_get_context()->private_data; |
| 247 | AFCFile *tfile = afc_open_file(afc, path, AFC_FILE_READ); | 242 | iphone_afc_file_t tfile = NULL; |
| 243 | iphone_afc_open_file(afc, path, AFC_FILE_READ, &tfile); | ||
| 248 | if (!tfile) return -1; | 244 | if (!tfile) return -1; |
| 249 | 245 | ||
| 250 | result = afc_truncate_file(afc, tfile, size); | 246 | result = iphone_afc_truncate_file(afc, tfile, size); |
| 251 | afc_close_file(afc, tfile); | 247 | iphone_afc_close_file(afc, tfile); |
| 252 | return result; | 248 | return result; |
| 253 | } | 249 | } |
| 254 | 250 | ||
| 255 | int ifuse_ftruncate(const char *path, off_t size, struct fuse_file_info *fi) { | 251 | int ifuse_ftruncate(const char *path, off_t size, struct fuse_file_info *fi) { |
| 256 | AFClient *afc = fuse_get_context()->private_data; | 252 | iphone_afc_client_t afc = fuse_get_context()->private_data; |
| 257 | AFCFile *file = g_hash_table_lookup(file_handles, &fi->fh); | 253 | iphone_afc_file_t file = g_hash_table_lookup(file_handles, &fi->fh); |
| 258 | if (!file) return -ENOENT; | 254 | if (!file) return -ENOENT; |
| 259 | 255 | ||
| 260 | return afc_truncate_file(afc, file, size); | 256 | return iphone_afc_truncate_file(afc, file, size); |
| 261 | } | 257 | } |
| 262 | 258 | ||
| 263 | int ifuse_unlink(const char *path) { | 259 | int ifuse_unlink(const char *path) { |
| 264 | AFClient *afc = fuse_get_context()->private_data; | 260 | iphone_afc_client_t afc = fuse_get_context()->private_data; |
| 265 | if (afc_delete_file(afc, path)) return 0; | 261 | if (iphone_afc_delete_file(afc, path)) return 0; |
| 266 | else return -1; | 262 | else return -1; |
| 267 | } | 263 | } |
| 268 | 264 | ||
| 269 | int ifuse_rename(const char *from, const char *to) { | 265 | int ifuse_rename(const char *from, const char *to) { |
| 270 | AFClient *afc = fuse_get_context()->private_data; | 266 | iphone_afc_client_t afc = fuse_get_context()->private_data; |
| 271 | if (afc_rename_file(afc, from, to)) return 0; | 267 | if (iphone_afc_rename_file(afc, from, to)) return 0; |
| 272 | else return -1; | 268 | else return -1; |
| 273 | } | 269 | } |
| 274 | 270 | ||
| 275 | int ifuse_mkdir(const char *dir, mode_t ignored) { | 271 | int ifuse_mkdir(const char *dir, mode_t ignored) { |
| 276 | AFClient *afc = fuse_get_context()->private_data; | 272 | iphone_afc_client_t afc = fuse_get_context()->private_data; |
| 277 | if (afc_mkdir(afc, dir)) return 0; | 273 | if (iphone_afc_mkdir(afc, dir)) return 0; |
| 278 | else return -1; | 274 | else return -1; |
| 279 | } | 275 | } |
| 280 | 276 | ||
