Репозиторий ALT Linux backports/2.4
Последнее обновление: 9 июля 2008 | Пакетов: 497 | Посещений: 1576927
 поиск   регистрация   авторизация 
 
Группа :: Коммуникации
Пакет: SieFS

 Главная   Изменения   Спек   Патчи   Загрузить   Bugs and FR 

Патч: siefs-0.4-fuse22.patch


--- siefs-0.4/siefs/siefs.c.fuse22	2004-08-13 10:13:06 +0400
+++ siefs-0.4/siefs/siefs.c	2005-02-13 21:53:13 +0300
@@ -7,6 +7,15 @@
     See the file COPYING.
 */
 
+/* Using the FUSE 1.1 library interface for now. */
+#define FUSE_USE_VERSION	11
+
+/*
+ * In older FUSE versions _FILE_OFFSET_BITS was set by fuse.h; newer versions
+ * require this flag to be specified explicitly.
+ */
+#define _FILE_OFFSET_BITS	64
+
 #include <fuse.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -29,8 +38,6 @@
 #define SIEFS_GET 1
 #define SIEFS_PUT 2
 
-#define MOUNTPROG			FUSEINST "/bin/fusermount"
-
 static obexsession *g_os;
 static char *comm_device;
 static int g_baudrate;
@@ -515,17 +522,61 @@ static struct fuse_operations siefs_oper
     release:	siefs_close,
 };
 
-void usage() {
-
-	fprintf(stderr, "Usage: mount -t siefs [-o options] comm_device mountpoint\n\n");
-	fprintf(stderr, "Options:\n");
-	fprintf(stderr, "\tuid=<value>\t\towner id\n");
-	fprintf(stderr, "\tgid=<value>\t\tgroup id\n");
-	fprintf(stderr, "\tumask=<value>\t\tumask value (octal)\n");
-	fprintf(stderr, "\tbaudrate=<value>\t\tcommunication speed\n");
-	fprintf(stderr, "\tdevice=<device>\t\tcommunication device (for use in fstab)\n");
-	fprintf(stderr, "\tnohide\t\t\tdon't hide `telecom' directory\n");
-	exit(1);
+void usage()
+{
+	fprintf(stderr,
+		"Usage: siefs [options...] device mountpoint [-- FUSE_options...]\n"
+		"       mount -t siefs [-o mount_options] device mountpoint\n"
+		"\n"
+		"Options:\n"
+		"    -o opt,opt...    mount options\n"
+		"    -n               do not update mtab (not supported)\n"
+		"    -v               verbose mode (not supported, ignored)\n"
+		"    -h               show this help text\n"
+		"    -H               show help on FUSE options\n"
+		"\n"
+		"Mount options (see also 'siefs -H' for FUSE mount options):\n"
+		"    uid=<value>         owner id\n"
+		"    gid=<value>         group id\n"
+		"    umask=<value>       umask value (octal)\n"
+		"    baudrate=<value>    communication speed\n"
+		"    device=<device>     communication device (for use in fstab)\n"
+		"    nohide              don't hide 'telecom' directory\n"
+		);
+	exit(0);
+}
+
+void show_fuse_options()
+{
+	static char *help_argv[] = { "...", "-h", NULL };
+
+	fprintf(stderr,
+		"Usage: siefs [options...] device mountpoint [-- FUSE_options...]\n"
+		"Valid FUSE options follow:\n"
+		);
+	fuse_main(2, help_argv, NULL);
+	exit(0);
+}
+
+void add_option(char **options, const char *new_option)
+{
+	if (*options) {
+		size_t old_len = strlen(*options);
+		size_t added_len = strlen(new_option);
+		char *new_options = malloc(old_len + added_len + 2);
+
+		if (!new_options) {
+			perror("siefs: out of memory");
+			exit(1);
+		}
+		memcpy(new_options, *options, old_len);
+		new_options[old_len] = ',';
+		memcpy(new_options + old_len + 1, new_option, added_len + 1);
+		free(*options);
+		*options = new_options;
+	} else {
+		*options = strdup(new_option);
+	}
 }
 
 void cleanup() {
@@ -534,42 +585,58 @@ void cleanup() {
 
 int main(int argc, char *argv[])
 {
-	char *mountprog = MOUNTPROG;
-    char **fuse_argv = (char **) malloc(3 + argc + 1);
-	char *p, *pp;
-	int i, j;
-	pid_t pid;
-
-	p = strrchr(argv[0], '/');
-	p = (p == NULL) ? argv[0] : p+1;
-	if (strncmp(p, "mount", 5) == 0) {
-
-		/* original call, "mount.siefs /dev/ttyS0 /mnt/mobile -o ..." */
-		if (argc < 3)
-			usage();
-
-		i = 0;
-		fuse_argv[i++] = mountprog;
-		if (getuid() == 0) fuse_argv[i++] = "-x";
-		fuse_argv[i++] = argv[2];
-		fuse_argv[i++] = PREFIX "/bin/siefs";
-		fuse_argv[i++] = argv[1];
-		for (j=4; j<argc; j++)
-			fuse_argv[i++] = argv[j];
-		fuse_argv[i++] = NULL;
-
-		execvp(mountprog, fuse_argv);
-		fprintf(stderr, "fuse: failed to exec %s: %s\n", mountprog,
-				strerror(errno));
-		return -1;
-	}
+	int fuse_argc;
+	char **fuse_argv;
+	char *options = NULL;
+	char *fuse_options = NULL;
+	char *mountpoint;
+	char *p;
+	int c;
+
+	while ((c = getopt(argc, argv, "hHnvo:")) != -1) {
+		switch (c) {
+			case 'h':
+				usage();
+				break;
+
+			case 'H':
+				show_fuse_options();
+				break;
+
+			case 'n':
+				fprintf(stderr, "siefs: disabling mtab update is not supported\n");
+				return 1;
 
-	/* recall from fusermount, "mount.siefs /dev/ttyS0 ..." */
+			case 'v':
+				/* option '-v' is ignored */
+				break;
+
+			case 'o':
+				if (options) {
+					fprintf(stderr, "siefs: duplicate '-o ...' option\n");
+					return 1;
+				}
+				options = optarg;
+				break;
 
-	if (argc < 2)
-		usage();
+			case '?':
+				/* getopt has already printed an error message */
+				fprintf(stderr, "Try 'siefs -h' for more information.\n");
+				return 1;
 
-	comm_device = argv[1];
+			default:
+				abort();
+		}
+	}
+
+	if (argc < optind + 2) {
+		fprintf(stderr, "siefs: required parameter missing\n");
+		fprintf(stderr, "Try 'siefs -h' for more information.\n");
+		return 1;
+	}
+
+	comm_device = argv[optind++];
+	mountpoint = argv[optind++];
 	g_baudrate = -1;
 	g_uid = getuid();
 	g_gid = getgid();
@@ -577,8 +644,8 @@ int main(int argc, char *argv[])
 	g_hidetc = 1;
 	umask(g_umask);
 	
-	if (argc >= 3) {
-		p = argv[2];
+	if (options) {
+		p = strtok(options, ",");
 		while (p && *p) {
 			if (strncmp(p, "baudrate=", 9) == 0) {
 				g_baudrate = atoi(p+9);
@@ -592,11 +659,11 @@ int main(int argc, char *argv[])
 				g_hidetc = 0;
 			} else if (strncmp(p, "device=", 7) == 0) {
 				comm_device = strdup(p+7);
-				*(comm_device + strcspn(comm_device, ",")) = '\0';
+			} else {
+				/* unknown options are passed to FUSE */
+				add_option(&fuse_options, p);
 			}
-				
-			p = strchr(p, ',');
-			if (p) p++;
+			p = strtok(NULL, ",");
 		}
 	}
 
@@ -616,27 +683,21 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
-	pid = fork();
-	if (pid < 0) {
-
-		perror("fork");
-		exit(1);
-
-	} else if (pid != 0) {
-
-		/* parent process */
-		usleep(200000);
-		return 0;
-
-	}
-
-	/* child process */
-	setsid();
-
 	atexit(cleanup);
 
-	fuse_argv[0] = argv[0];
-	fuse_main(1, fuse_argv, &siefs_oper);
+	fuse_argc = 0;
+	fuse_argv = malloc(sizeof(char *) * (argc - optind + 5));
+	fuse_argv[fuse_argc++] = argv[0];
+	fuse_argv[fuse_argc++] = mountpoint;
+	if (fuse_options) {
+		fuse_argv[fuse_argc++] = "-o";
+		fuse_argv[fuse_argc++] = fuse_options;
+	}
+	while (optind < argc) {
+		fuse_argv[fuse_argc++] = argv[optind++];
+	}
+	fuse_argv[fuse_argc] = NULL;
+	fuse_main(fuse_argc, fuse_argv, &siefs_oper);
 
 	return 0;
 
 
design & coding: Vladimir Lettiev aka crux © 2004-2005