aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Miklos Szeredi <miklos@szeredi.hu>2001-11-20 19:12:28 +0000
committerGravatar Miklos Szeredi <miklos@szeredi.hu>2001-11-20 19:12:28 +0000
commitfe428120937e4c267c392e23164770377f9dfa1d (patch)
tree65f39fe747eaeb2e67252894d7ba6c9966a2f63f
parent33232032423dcc06716537204f1995afa5a73940 (diff)
fusermount changes
-rw-r--r--example/fusexmp.c32
-rw-r--r--example/null.c32
-rw-r--r--lib/fuse.c54
-rw-r--r--util/fusermount.c25
4 files changed, 75 insertions, 68 deletions
diff --git a/example/fusexmp.c b/example/fusexmp.c
index 1f1f2a3..dc2a569 100644
--- a/example/fusexmp.c
+++ b/example/fusexmp.c
@@ -24,8 +24,6 @@
#include <utime.h>
#include <fcntl.h>
-static char *unmount_cmd;
-
static int xmp_getattr(const char *path, struct stat *stbuf)
{
int res;
@@ -260,11 +258,14 @@ static struct fuse_operations xmp_oper = {
write: xmp_write,
};
+static void cleanup()
+{
+ close(0);
+ system(getenv("FUSE_UNMOUNT_CMD"));
+}
static void exit_handler()
{
- close(0);
- system(unmount_cmd);
exit(0);
}
@@ -299,19 +300,9 @@ int main(int argc, char *argv[])
int multithreaded;
struct fuse *fuse;
- if(argc < 2) {
- fprintf(stderr,
- "usage: %s unmount_cmd [options] \n"
- "Options:\n"
- " -d enable debug output\n"
- " -s disable multithreaded operation\n",
- argv[0]);
- exit(1);
- }
-
argctr = 1;
- unmount_cmd = argv[argctr++];
+ atexit(cleanup);
set_signal_handlers();
flags = 0;
@@ -326,6 +317,17 @@ int main(int argc, char *argv[])
multithreaded = 0;
break;
+ case 'h':
+ fprintf(stderr,
+ "usage: %s [options] \n"
+ "Options:\n"
+ " -d enable debug output\n"
+ " -s disable multithreaded operation\n"
+ " -h print help\n",
+ argv[0]);
+ exit(1);
+ break;
+
default:
fprintf(stderr, "invalid option: %s\n", argv[argctr]);
exit(1);
diff --git a/example/null.c b/example/null.c
index 379ba7a..c9816f1 100644
--- a/example/null.c
+++ b/example/null.c
@@ -17,8 +17,6 @@
#define UNUSED __attribute__((unused))
-static char *unmount_cmd;
-
static int null_getattr(const char *path, struct stat *stbuf)
{
if(strcmp(path, "/") != 0)
@@ -90,11 +88,14 @@ static struct fuse_operations null_oper = {
write: null_write,
};
+static void cleanup()
+{
+ close(0);
+ system(getenv("FUSE_UNMOUNT_CMD"));
+}
static void exit_handler()
{
- close(0);
- system(unmount_cmd);
exit(0);
}
@@ -129,19 +130,9 @@ int main(int argc, char *argv[])
int multithreaded;
struct fuse *fuse;
- if(argc < 2) {
- fprintf(stderr,
- "usage: %s unmount_cmd [options] \n"
- "Options:\n"
- " -d enable debug output\n"
- " -s disable multithreaded operation\n",
- argv[0]);
- exit(1);
- }
-
argctr = 1;
- unmount_cmd = argv[argctr++];
+ atexit(cleanup);
set_signal_handlers();
flags = 0;
@@ -156,6 +147,17 @@ int main(int argc, char *argv[])
multithreaded = 0;
break;
+ case 'h':
+ fprintf(stderr,
+ "usage: %s [options] \n"
+ "Options:\n"
+ " -d enable debug output\n"
+ " -s disable multithreaded operation\n"
+ " -h print help\n",
+ argv[0]);
+ exit(1);
+ break;
+
default:
fprintf(stderr, "invalid option: %s\n", argv[argctr]);
exit(1);
diff --git a/lib/fuse.c b/lib/fuse.c
index b1b0749..35a02ad 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -783,6 +783,10 @@ void __fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd)
do_lookup(f, in, (char *) inarg);
break;
+ case FUSE_FORGET:
+ do_forget(f, in, (struct fuse_forget_in *) inarg);
+ break;
+
case FUSE_GETATTR:
do_getattr(f, in);
break;
@@ -854,31 +858,20 @@ struct fuse_cmd *__fuse_read_cmd(struct fuse *f)
cmd = (struct fuse_cmd *) malloc(sizeof(struct fuse_cmd));
cmd->buf = (char *) malloc(FUSE_MAX_IN);
- do {
- res = read(f->fd, cmd->buf, FUSE_MAX_IN);
- if(res == -1) {
- perror("reading fuse device");
- /* BAD... This will happen again */
- free_cmd(cmd);
- return NULL;
- }
- if((size_t) res < sizeof(struct fuse_in_header)) {
- fprintf(stderr, "short read on fuse device\n");
- /* Cannot happen */
- free_cmd(cmd);
- return NULL;
- }
- cmd->buflen = res;
-
- /* FORGET is special: it can be done without calling filesystem
- methods. */
- in = (struct fuse_in_header *) cmd->buf;
- if(in->opcode == FUSE_FORGET) {
- void *inarg = cmd->buf + sizeof(struct fuse_in_header);
- do_forget(f, in, (struct fuse_forget_in *) inarg);
- }
- } while(in->opcode == FUSE_FORGET);
-
+ res = read(f->fd, cmd->buf, FUSE_MAX_IN);
+ if(res == -1) {
+ perror("reading fuse device");
+ /* BAD... This will happen again */
+ free_cmd(cmd);
+ return NULL;
+ }
+ if((size_t) res < sizeof(struct fuse_in_header)) {
+ fprintf(stderr, "short read on fuse device\n");
+ /* Cannot happen */
+ free_cmd(cmd);
+ return NULL;
+ }
+ cmd->buflen = res;
return cmd;
}
@@ -898,6 +891,17 @@ struct fuse *fuse_new(int fd, int flags)
{
struct fuse *f;
struct node *root;
+ char verstr[128];
+ char *realver = getenv("FUSE_KERNEL_VERSION");
+
+ if(realver != NULL) {
+ sprintf(verstr, "%i", FUSE_KERNEL_VERSION);
+ if(strcmp(verstr, realver) != 0) {
+ fprintf(stderr,
+ "Warning: FUSE version mismatch: using %s, kernel is %s\n",
+ realver, verstr);
+ }
+ }
f = (struct fuse *) calloc(1, sizeof(struct fuse));
diff --git a/util/fusermount.c b/util/fusermount.c
index ac30c65..0e256e5 100644
--- a/util/fusermount.c
+++ b/util/fusermount.c
@@ -11,10 +11,9 @@
* NOTE: This program should be part of (or be called from) /bin/mount
*
* Unless that is done, operations on /etc/mtab are not under lock, and so
- * data in it may be lost. (I will _not_ reimplement that locking, and
- * anyway that should be done in libc, if possible. But probably it is
- * not).
- *
+ * data in this file may be lost. (I will _not_ reimplement that locking,
+ * and anyway that should be done in libc, if possible. But probably it
+ * isn't).
*/
#include <stdio.h>
@@ -186,6 +185,10 @@ static int remove_mount(const char *mnt)
return 0;
}
+/* Until there is a nice interface for capabilities in _libc_, this will
+remain here. I don't think it is fair to expect users to compile libcap
+for this program. And anyway what's all this fuss about versioning the
+kernel interface? It is quite good as is. */
#define _LINUX_CAPABILITY_VERSION 0x19980330
typedef struct __user_cap_header_struct {
@@ -409,9 +412,9 @@ int main(int argc, char *argv[])
int unmount = 0;
char **userprog;
int numargs;
- char **newargv;
char mypath[PATH_MAX];
char *unmount_cmd;
+ char verstr[128];
progname = argv[0];
@@ -494,15 +497,11 @@ int main(int argc, char *argv[])
unmount_cmd = (char *) malloc(strlen(mypath) + strlen(mnt) + 64);
sprintf(unmount_cmd, "%s -u %s", mypath, mnt);
+ setenv("FUSE_UNMOUNT_CMD", unmount_cmd, 1);
+ sprintf(verstr, "%i", FUSE_KERNEL_VERSION);
+ setenv("FUSE_KERNEL_VERSION", verstr, 1);
- newargv = (char **) malloc(sizeof(char *) * (numargs + 2));
- newargv[0] = userprog[0];
- newargv[1] = unmount_cmd;
- for(a = 1; a < numargs; a++)
- newargv[a+1] = userprog[a];
- newargv[numargs+1] = NULL;
-
- execvp(userprog[0], newargv);
+ execvp(userprog[0], userprog);
fprintf(stderr, "%s: failed to exec %s: %s\n", progname, userprog[0],
strerror(errno));