diff options
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | configure.ac | 8 | ||||
-rw-r--r-- | fdi/30-ifuse.fdi | 46 | ||||
-rw-r--r-- | fdi/Makefile.am | 4 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/ifuse.c | 125 |
6 files changed, 103 insertions, 84 deletions
diff --git a/Makefile.am b/Makefile.am index 70e1c93..e015eec 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ AUTOMAKE_OPTIONS = foreign -SUBDIRS = src fdi +SUBDIRS = src DISTCHECK_CONFIGURE_FLAGS = --disable-root-sbin diff --git a/configure.ac b/configure.ac index 3d013be..f9fdc8e 100644 --- a/configure.ac +++ b/configure.ac @@ -34,10 +34,4 @@ AC_FUNC_MALLOC AC_FUNC_REALLOC AC_CHECK_FUNCS([strcasecmp strdup strerror strndup]) -AC_ARG_ENABLE([root-sbin], - AS_HELP_STRING([--disable-root-sbin], - [Don't install mount helper in /sbin]), - [without_root_sbin=yes],[without_root_sbin=no]) -AM_CONDITIONAL([WITHOUT_ROOT_SBIN], test "x$without_root_sbin" = "xyes") - -AC_OUTPUT(Makefile src/Makefile fdi/Makefile) +AC_OUTPUT(Makefile src/Makefile) diff --git a/fdi/30-ifuse.fdi b/fdi/30-ifuse.fdi deleted file mode 100644 index 5a47d15..0000000 --- a/fdi/30-ifuse.fdi +++ /dev/null @@ -1,46 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<deviceinfo version="0.2"> - <device> - <match key="info.subsystem" string="usb_device"> - <match key="usb_device.vendor_id" int="0x5ac"> - <match key="usb_device.product_id" compare_ge="0x1290"> - <match key="usb_device.product_id" compare_le="0x1294"> - <append key="info.capabilities" type="strlist">block</append> - <append key="info.capabilities" type="strlist">storage</append> - <merge key="storage.hotpluggable" type="bool">false</merge> - <merge key="storage.removable" type="bool">true</merge> - <merge key="storage.requires_eject" type="bool">false</merge> - <merge key="storage.automount_enabled_hint" type="bool">true</merge> - <!-- This also applies to the iPhone as it has the same filesystem structure --> - <merge key="storage.model" type="string">iPod</merge> - <merge key="storage.vendor" type="copy_property">usb_device.vendor</merge> - <merge key="storage.serial" type="copy_property">usb_device.serial</merge> - <merge key="storage.orginating_device" type="copy_property">/org/freedesktop/Hal/devices/computer</merge> - <append key="block.device" type="copy_property">linux.device_file</append> - <merge key="block.storage_device" type="copy_property">info.udi</merge> - </match> - </match> - </match> - </match> - <match key="info.subsystem" string="usb"> - <match key="usb.vendor_id" int="0x5ac"> - <match key="usb.product_id" compare_ge="0x1290"> - <match key="usb.product_id" compare_le="0x1294"> - <match key="usb.interface.number" int="0x1"> - <append key="info.capabilities" type="strlist">block</append> - <append key="info.capabilities" type="strlist">volume</append> - <merge key="info.category" type="string">volume</merge> - <append key="block.device" type="copy_property">@info.parent:linux.device_file</append> - <merge key="block.storage_device" type="copy_property">@info.parent:info.udi</merge> - <merge key="volume.mount.valid_options" type="strlist">allow_other</merge> - <append key="volume.fstype" type="string">fuse.ifuse</append> - <append key="volume.fsusage" type="string">filesystem</append> - <append key="volume.label" type="copy_property">@info.parent:usb_device.product</append> - <append key="volume.uuid" type="copy_property">@info.parent:usb_device.serial</append> - </match> - </match> - </match> - </match> - </match> - </device> -</deviceinfo> diff --git a/fdi/Makefile.am b/fdi/Makefile.am deleted file mode 100644 index adfa88c..0000000 --- a/fdi/Makefile.am +++ /dev/null @@ -1,4 +0,0 @@ -freedesktopfdidir=$(prefix)/share/hal/fdi/information/20thirdparty -freedesktopfdi_DATA=30-ifuse.fdi - -EXTRA_DIST=$(freedesktopfdi_DATA) diff --git a/src/Makefile.am b/src/Makefile.am index 59cb4ba..63988d4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ AM_CFLAGS = $(libglib2_CFLAGS) $(libfuse_CFLAGS) $(libiphone_CFLAGS) -g AM_LDFLAGS = $(libglib2_LIBS) $(libfuse_LIBS) $(libiphone_LIBS) -bin_PROGRAMS = ifuse +bin_PROGRAMS = ifuse ifuse_SOURCES = ifuse.c diff --git a/src/ifuse.c b/src/ifuse.c index bf5f9aa..7c510e2 100644 --- a/src/ifuse.c +++ b/src/ifuse.c @@ -21,6 +21,10 @@ #define FUSE_USE_VERSION 26 +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif /* HAVE_CONFIG_H */ + #include <fuse.h> #include <stdio.h> #include <string.h> @@ -45,6 +49,30 @@ lockdownd_client_t control = NULL; int debug = 0; +static struct { + char *mount_point; + char *device_uuid; +} opts; + +enum { + KEY_HELP = 1, + KEY_VERSION, + KEY_ROOT, + KEY_UUID, + KEY_DEBUG +}; + +static struct fuse_opt ifuse_opts[] = { + FUSE_OPT_KEY("-V", KEY_VERSION), + FUSE_OPT_KEY("--version", KEY_VERSION), + FUSE_OPT_KEY("-h", KEY_HELP), + FUSE_OPT_KEY("--help", KEY_HELP), + FUSE_OPT_KEY("--uuid=", KEY_UUID), + FUSE_OPT_KEY("--root", KEY_ROOT), + FUSE_OPT_KEY("--debug", KEY_DEBUG), + FUSE_OPT_END +}; + static void free_dictionary(char **dictionary) { int i = 0; @@ -543,57 +571,104 @@ static struct fuse_operations ifuse_oper = { .destroy = ifuse_cleanup }; +static void print_usage() +{ + fprintf(stderr, "Usage: ifuse <mount_point> [OPTIONS]\n"); + fprintf(stderr, "Mount filesystem of an iPhone/iPod Touch.\n\n"); + fprintf(stderr, " -o opt,[opt...]\tmount options\n"); + fprintf(stderr, " -u, --uuid UUID\tmount specific device by its 40-digit device UUID\n"); + fprintf(stderr, " -h, --help\t\tprint usage information\n"); + fprintf(stderr, " -V, --version\t\tprint version\n"); + fprintf(stderr, " --root\t\tmount root file system (jailbroken device required)\n"); + fprintf(stderr, " --debug\t\tenable libiphone communication debugging\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "Example:\n\n"); + fprintf(stderr, " $ ifuse /media/iPhone --root\n\n"); + fprintf(stderr, " This mounts the root filesystem of the first attached device on\n"); + fprintf(stderr, " this computer in the directory /media/iPhone.\n"); + fprintf(stderr, "\n"); +} + static int ifuse_opt_proc(void *data, const char *arg, int key, struct fuse_args *outargs) { char *tmp; static int option_num = 0; - (void) data; + int res = 1; switch (key) { + case KEY_UUID: + opts.device_uuid = strdup(arg+7); + res = 0; + break; + case KEY_DEBUG: + iphone_set_debug_mask(DBGMASK_ALL); + iphone_set_debug_level(1); + res = 0; + break; + case KEY_ROOT: + ifuse_oper.init = ifuse_init_jailbroken; + res = 0; + break; + case KEY_HELP: + print_usage(); + exit(1); + case KEY_VERSION: + fprintf(stderr, "%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION); + exit(0); case FUSE_OPT_KEY_OPT: - if (strcmp(arg, "allow_other") == 0 || strcmp(arg, "-d") == 0 || strcmp(arg, "-s") == 0) - return 1; - else if (strcmp(arg, "--root") == 0) { - ifuse_oper.init = ifuse_init_jailbroken; - return 0; - } else if (strcmp(arg, "--debug") == 0) { - iphone_set_debug_mask(DBGMASK_ALL); - iphone_set_debug_level(1); - return 0; - } else - return 0; + /* ignore other options and pass them to fuse_main later */ break; case FUSE_OPT_KEY_NONOPT: + if(option_num == 0) { + opts.mount_point = strdup(arg); + } + if(option_num == 1) { + /* compatibility to older style which passed a device file option first */ + free(opts.mount_point); + opts.mount_point = strdup(arg); + } option_num++; - - // Throw the first nameless option away (the mountpoint) - if (option_num == 1) - return 0; - else - return 1; + break; } - return 1; + return res; } int main(int argc, char *argv[]) { char **ammended_argv; - int i, j; struct fuse_args args = FUSE_ARGS_INIT(argc, argv); + struct stat mst; - if (fuse_opt_parse(&args, NULL, NULL, ifuse_opt_proc) == -1) { + memset(&opts, 0, sizeof(opts)); + + if (fuse_opt_parse(&args, NULL, ifuse_opts, ifuse_opt_proc) == -1) { return -1; } fuse_opt_add_arg(&args, "-oallow_other"); - if (argc < 2) { - fprintf(stderr, "A path to the USB device must be specified\n"); + if (!opts.mount_point) { + fprintf(stderr, "ERROR: No mount point specified\n"); + return -1; + } + + if (opts.device_uuid && strlen(opts.device_uuid) != 40) { + fprintf(stderr, "Invalid device UUID specified, length needs to be 40 characters\n"); + return -1; + } + + if (stat(opts.mount_point, &mst) < 0) { + if (errno == ENOENT) { + fprintf(stderr, "ERROR: the mount point specified does not exist\n"); + return -1; + } + + fprintf(stderr, "There was an error accessing the mount point: %s\n", strerror(errno)); return -1; } - iphone_get_device(&phone); + iphone_device_new(&phone, opts.device_uuid ? opts.device_uuid : NULL); if (!phone) { - fprintf(stderr, "No iPhone found, is it connected?\n"); + fprintf(stderr, "No device found, is it connected?\n"); fprintf(stderr, "If it is make sure that your user has permissions to access the raw usb device.\n"); fprintf(stderr, "If you're still having issues try unplugging the device and reconnecting it.\n"); return 0; |