From 2b05e48cb4a90dfc94ff584124f08e431398bb1a Mon Sep 17 00:00:00 2001 From: Matt Colyer Date: Mon, 1 Sep 2008 15:04:31 -0700 Subject: Enforce a modified kr style. Use "make indent" from now on before committing. --- src/ifuse.c | 187 ++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 107 insertions(+), 80 deletions(-) (limited to 'src/ifuse.c') diff --git a/src/ifuse.c b/src/ifuse.c index c266879..ad34eb5 100644 --- a/src/ifuse.c +++ b/src/ifuse.c @@ -42,7 +42,8 @@ iphone_lckd_client_t control = NULL; int debug = 0; -static int ifuse_getattr(const char *path, struct stat *stbuf) { +static int ifuse_getattr(const char *path, struct stat *stbuf) +{ int res = 0; iphone_afc_client_t afc = fuse_get_context()->private_data; @@ -54,31 +55,32 @@ static int ifuse_getattr(const char *path, struct stat *stbuf) { return res; } -static int ifuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, - off_t offset, struct fuse_file_info *fi) { +static int ifuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) +{ int i; char **dirs = NULL; iphone_afc_client_t afc = fuse_get_context()->private_data; iphone_afc_get_dir_list(afc, path, &dirs); - if(!dirs) + if (!dirs) return -ENOENT; for (i = 0; dirs[i]; i++) { filler(buf, dirs[i], NULL, 0); } - + free_dictionary(dirs); return 0; } -static int ifuse_create(const char *path, mode_t mode, struct fuse_file_info *fi) { +static int ifuse_create(const char *path, mode_t mode, struct fuse_file_info *fi) +{ // exactly the same as open but using a different mode iphone_afc_file_t file = NULL; iphone_afc_client_t afc = fuse_get_context()->private_data; - + iphone_afc_open_file(afc, path, IPHONE_AFC_FILE_WRITE, &file); fh_index++; fi->fh = fh_index; @@ -86,11 +88,12 @@ static int ifuse_create(const char *path, mode_t mode, struct fuse_file_info *fi return 0; } -static int ifuse_open(const char *path, struct fuse_file_info *fi) { +static int ifuse_open(const char *path, struct fuse_file_info *fi) +{ iphone_afc_file_t file = NULL; iphone_afc_client_t afc = fuse_get_context()->private_data; uint32_t mode = 0; - + if ((fi->flags & 3) == O_RDWR || (fi->flags & 3) == O_WRONLY) { mode = IPHONE_AFC_FILE_READ; } else if ((fi->flags & 3) == O_RDONLY) { @@ -98,9 +101,9 @@ static int ifuse_open(const char *path, struct fuse_file_info *fi) { } else { mode = IPHONE_AFC_FILE_READ; } - + iphone_afc_open_file(afc, path, mode, &file); - + fh_index++; fi->fh = fh_index; g_hash_table_insert(file_handles, &fh_index, file); @@ -108,8 +111,8 @@ static int ifuse_open(const char *path, struct fuse_file_info *fi) { return 0; } -static int ifuse_read(const char *path, char *buf, size_t size, off_t offset, - struct fuse_file_info *fi) { +static int ifuse_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) +{ int bytes = 0; iphone_afc_file_t file; iphone_afc_client_t afc = fuse_get_context()->private_data; @@ -118,7 +121,7 @@ static int ifuse_read(const char *path, char *buf, size_t size, off_t offset, return 0; file = g_hash_table_lookup(file_handles, &(fi->fh)); - if (!file){ + if (!file) { return -ENOENT; } @@ -127,171 +130,195 @@ static int ifuse_read(const char *path, char *buf, size_t size, off_t offset, return bytes; } -static int ifuse_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { +static int ifuse_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) +{ int bytes = 0; iphone_afc_file_t file = NULL; iphone_afc_client_t afc = fuse_get_context()->private_data; - - if (size == 0) return 0; - + + if (size == 0) + return 0; + file = g_hash_table_lookup(file_handles, &(fi->fh)); - if (!file) return -ENOENT; - + if (!file) + return -ENOENT; + if (IPHONE_E_SUCCESS == iphone_afc_seek_file(afc, file, offset)) iphone_afc_write_file(afc, file, buf, size, &bytes); return bytes; } -static int ifuse_fsync(const char *path, int datasync, struct fuse_file_info *fi) { +static int ifuse_fsync(const char *path, int datasync, struct fuse_file_info *fi) +{ return 0; } -static int ifuse_release(const char *path, struct fuse_file_info *fi){ +static int ifuse_release(const char *path, struct fuse_file_info *fi) +{ iphone_afc_file_t file = NULL; iphone_afc_client_t afc = fuse_get_context()->private_data; - + file = g_hash_table_lookup(file_handles, &(fi->fh)); - if (!file){ + if (!file) { return -ENOENT; } iphone_afc_close_file(afc, file); - + g_hash_table_remove(file_handles, &(fi->fh)); return 0; } -void *ifuse_init(struct fuse_conn_info *conn) { +void *ifuse_init(struct fuse_conn_info *conn) +{ int port = 0; iphone_afc_client_t afc = NULL; - + conn->async_read = 0; file_handles = g_hash_table_new(g_int_hash, g_int_equal); iphone_get_device(&phone); - if (!phone){ + if (!phone) { fprintf(stderr, "No iPhone found, is it connected?\n"); return NULL; } - + if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { iphone_free_device(phone); fprintf(stderr, "Something went wrong in the lockdownd client.\n"); return NULL; } - + if (IPHONE_E_SUCCESS == iphone_lckd_start_service(control, "com.apple.afc", &port) && !port) { iphone_lckd_free_client(control); iphone_free_device(phone); fprintf(stderr, "Something went wrong when starting AFC."); - return NULL; + return NULL; } iphone_afc_new_client(phone, 3432, port, &afc); - return afc; + return afc; } -void ifuse_cleanup(void *data) { - iphone_afc_client_t afc = (iphone_afc_client_t )data; +void ifuse_cleanup(void *data) +{ + iphone_afc_client_t afc = (iphone_afc_client_t) data; iphone_afc_free_client(afc); iphone_lckd_free_client(control); iphone_free_device(phone); } -int ifuse_flush(const char *path, struct fuse_file_info *fi) { +int ifuse_flush(const char *path, struct fuse_file_info *fi) +{ return 0; } -int ifuse_statfs(const char *path, struct statvfs *stats) { +int ifuse_statfs(const char *path, struct statvfs *stats) +{ iphone_afc_client_t afc = fuse_get_context()->private_data; char **info_raw = NULL; uint32_t totalspace = 0, freespace = 0, blocksize = 0, i = 0; - + iphone_afc_get_devinfo(afc, &info_raw); - if (!info_raw) return -ENOENT; - + if (!info_raw) + return -ENOENT; + for (i = 0; info_raw[i]; i++) { if (!strcmp(info_raw[i], "FSTotalBytes")) { - totalspace = atoi(info_raw[i+1]); + totalspace = atoi(info_raw[i + 1]); } else if (!strcmp(info_raw[i], "FSFreeBytes")) { - freespace = atoi(info_raw[i+1]); + freespace = atoi(info_raw[i + 1]); } else if (!strcmp(info_raw[i], "FSBlockSize")) { - blocksize = atoi(info_raw[i+1]); + blocksize = atoi(info_raw[i + 1]); } } free_dictionary(info_raw); - + // Now to fill the struct. stats->f_bsize = stats->f_frsize = blocksize; - stats->f_blocks = totalspace / blocksize; // gets the blocks by dividing bytes by blocksize - stats->f_bfree = stats->f_bavail = freespace / blocksize; // all bytes are free to everyone, I guess. - stats->f_namemax = 255; // blah - stats->f_files = stats->f_ffree = 1000000000; // make up any old thing, I guess + stats->f_blocks = totalspace / blocksize; // gets the blocks by dividing bytes by blocksize + stats->f_bfree = stats->f_bavail = freespace / blocksize; // all bytes are free to everyone, I guess. + stats->f_namemax = 255; // blah + stats->f_files = stats->f_ffree = 1000000000; // make up any old thing, I guess return 0; } -int ifuse_truncate(const char *path, off_t size) { +int ifuse_truncate(const char *path, off_t size) +{ int result = 0; iphone_afc_client_t afc = fuse_get_context()->private_data; iphone_afc_file_t tfile = NULL; iphone_afc_open_file(afc, path, IPHONE_AFC_FILE_READ, &tfile); - if (!tfile) return -1; - + if (!tfile) + return -1; + result = iphone_afc_truncate_file(afc, tfile, size); iphone_afc_close_file(afc, tfile); return result; } -int ifuse_ftruncate(const char *path, off_t size, struct fuse_file_info *fi) { +int ifuse_ftruncate(const char *path, off_t size, struct fuse_file_info *fi) +{ iphone_afc_client_t afc = fuse_get_context()->private_data; iphone_afc_file_t file = g_hash_table_lookup(file_handles, &fi->fh); - if (!file) return -ENOENT; - + if (!file) + return -ENOENT; + return iphone_afc_truncate_file(afc, file, size); } -int ifuse_unlink(const char *path) { +int ifuse_unlink(const char *path) +{ iphone_afc_client_t afc = fuse_get_context()->private_data; - if (IPHONE_E_SUCCESS == iphone_afc_delete_file(afc, path)) return 0; - else return -1; + if (IPHONE_E_SUCCESS == iphone_afc_delete_file(afc, path)) + return 0; + else + return -1; } -int ifuse_rename(const char *from, const char *to) { +int ifuse_rename(const char *from, const char *to) +{ iphone_afc_client_t afc = fuse_get_context()->private_data; - if (IPHONE_E_SUCCESS == iphone_afc_rename_file(afc, from, to)) return 0; - else return -1; + if (IPHONE_E_SUCCESS == iphone_afc_rename_file(afc, from, to)) + return 0; + else + return -1; } -int ifuse_mkdir(const char *dir, mode_t ignored) { +int ifuse_mkdir(const char *dir, mode_t ignored) +{ iphone_afc_client_t afc = fuse_get_context()->private_data; - if (IPHONE_E_SUCCESS == iphone_afc_mkdir(afc, dir)) return 0; - else return -1; + if (IPHONE_E_SUCCESS == iphone_afc_mkdir(afc, dir)) + return 0; + else + return -1; } static struct fuse_operations ifuse_oper = { - .getattr = ifuse_getattr, - .statfs = ifuse_statfs, - .readdir = ifuse_readdir, - .mkdir = ifuse_mkdir, - .rmdir = ifuse_unlink, // AFC uses the same op for both. - .create = ifuse_create, - .open = ifuse_open, - .read = ifuse_read, - .write = ifuse_write, - .truncate = ifuse_truncate, - .ftruncate = ifuse_ftruncate, - .unlink = ifuse_unlink, - .rename = ifuse_rename, - .fsync = ifuse_fsync, - .release = ifuse_release, - .init = ifuse_init, - .destroy = ifuse_cleanup + .getattr = ifuse_getattr, + .statfs = ifuse_statfs, + .readdir = ifuse_readdir, + .mkdir = ifuse_mkdir, + .rmdir = ifuse_unlink, // AFC uses the same op for both. + .create = ifuse_create, + .open = ifuse_open, + .read = ifuse_read, + .write = ifuse_write, + .truncate = ifuse_truncate, + .ftruncate = ifuse_ftruncate, + .unlink = ifuse_unlink, + .rename = ifuse_rename, + .fsync = ifuse_fsync, + .release = ifuse_release, + .init = ifuse_init, + .destroy = ifuse_cleanup }; -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ return fuse_main(argc, argv, &ifuse_oper, NULL); } -- cgit v1.1-32-gdbae