add access operation
diff --git a/ChangeLog b/ChangeLog
index b0192d7..e2e1b8c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-10-26 Miklos Szeredi <miklos@szeredi.hu>
+
+ * Add ACCESS operation. This is called from the access() system
+ call if 'default_permissions' mount option is not given
+
2005-10-18 Miklos Szeredi <miklos@szeredi.hu>
* lib: optimize buffer reallocation in fill_dir.
diff --git a/configure.in b/configure.in
index 8cc5c65..5a8c8b5 100644
--- a/configure.in
+++ b/configure.in
@@ -1,4 +1,4 @@
-AC_INIT(fuse, 2.4.1)
+AC_INIT(fuse, 2.5.0-pre0)
AM_INIT_AUTOMAKE
AM_CONFIG_HEADER(include/config.h)
diff --git a/example/fusexmp.c b/example/fusexmp.c
index 1ef0ac3..1732556 100644
--- a/example/fusexmp.c
+++ b/example/fusexmp.c
@@ -36,6 +36,17 @@
return 0;
}
+static int xmp_access(const char *path, int mask)
+{
+ int res;
+
+ res = access(path, mask);
+ if(res == -1)
+ return -errno;
+
+ return 0;
+}
+
static int xmp_readlink(const char *path, char *buf, size_t size)
{
int res;
@@ -319,6 +330,7 @@
static struct fuse_operations xmp_oper = {
.getattr = xmp_getattr,
+ .access = xmp_access,
.readlink = xmp_readlink,
.readdir = xmp_readdir,
.mknod = xmp_mknod,
diff --git a/example/fusexmp_fh.c b/example/fusexmp_fh.c
index f1c08f8..d17699e 100644
--- a/example/fusexmp_fh.c
+++ b/example/fusexmp_fh.c
@@ -33,6 +33,17 @@
return 0;
}
+static int xmp_access(const char *path, int mask)
+{
+ int res;
+
+ res = access(path, mask);
+ if(res == -1)
+ return -errno;
+
+ return 0;
+}
+
static int xmp_readlink(const char *path, char *buf, size_t size)
{
int res;
@@ -317,6 +328,7 @@
static struct fuse_operations xmp_oper = {
.getattr = xmp_getattr,
+ .access = xmp_access,
.readlink = xmp_readlink,
.opendir = xmp_opendir,
.readdir = xmp_readdir,
diff --git a/include/fuse.h b/include/fuse.h
index 9739f26..4a099bc 100644
--- a/include/fuse.h
+++ b/include/fuse.h
@@ -63,8 +63,9 @@
*
* All methods are optional, but some are essential for a useful
* filesystem (e.g. getattr). Open, flush, release, fsync, opendir,
- * releasedir, fsyncdir, init and destroy are special purpose methods,
- * without which a full featured filesystem can still be implemented.
+ * releasedir, fsyncdir, access, init and destroy are special purpose
+ * methods, without which a full featured filesystem can still be
+ * implemented.
*/
struct fuse_operations {
/** Get file attributes.
@@ -296,6 +297,17 @@
* Introduced in version 2.3
*/
void (*destroy) (void *);
+
+ /**
+ * Check file access permissions
+ *
+ * Need not be implemented. This will be called for the access()
+ * system call. If the 'default_permissions' mount option is
+ * given, this method is not called.
+ *
+ * Introduced in version 2.5
+ */
+ int (*access) (const char *, int);
};
/** Extra context that may be needed by some filesystems
diff --git a/include/fuse_common.h b/include/fuse_common.h
index ef7e85a..a59aea6 100644
--- a/include/fuse_common.h
+++ b/include/fuse_common.h
@@ -21,7 +21,7 @@
#define FUSE_MAJOR_VERSION 2
/** Minor version of FUSE library interface */
-#define FUSE_MINOR_VERSION 4
+#define FUSE_MINOR_VERSION 5
#define FUSE_MAKE_VERSION(maj, min) ((maj) * 10 + (min))
#define FUSE_VERSION FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION)
diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h
index dee4325..73f57f0 100644
--- a/include/fuse_lowlevel.h
+++ b/include/fuse_lowlevel.h
@@ -642,6 +642,8 @@
* @param name of the extended attribute
*/
void (*removexattr) (fuse_req_t req, fuse_ino_t ino, const char *name);
+
+ void (*access) (fuse_req_t req, fuse_ino_t ino, int mask);
};
/**
diff --git a/kernel/configure.ac b/kernel/configure.ac
index 5f31daa..04483e3 100644
--- a/kernel/configure.ac
+++ b/kernel/configure.ac
@@ -1,4 +1,4 @@
-AC_INIT(fuse-kernel, 2.4.1)
+AC_INIT(fuse-kernel, 2.5.0-pre0)
AC_CONFIG_HEADERS([config.h])
AC_PROG_INSTALL
diff --git a/kernel/dir.c b/kernel/dir.c
index 6753636..20a6aae 100644
--- a/kernel/dir.c
+++ b/kernel/dir.c
@@ -482,6 +482,40 @@
return fuse_do_getattr(inode);
}
+#ifdef KERNEL_2_6
+static int fuse_access(struct inode *inode, int mask)
+{
+ struct fuse_conn *fc = get_fuse_conn(inode);
+ struct fuse_req *req;
+ struct fuse_access_in inarg;
+ int err;
+
+ if (fc->no_access)
+ return 0;
+
+ req = fuse_get_request(fc);
+ if (!req)
+ return -EINTR;
+
+ memset(&inarg, 0, sizeof(inarg));
+ inarg.mask = mask;
+ req->in.h.opcode = FUSE_ACCESS;
+ req->in.h.nodeid = get_node_id(inode);
+ req->inode = inode;
+ req->in.numargs = 1;
+ req->in.args[0].size = sizeof(inarg);
+ req->in.args[0].value = &inarg;
+ request_send(fc, req);
+ err = req->out.h.error;
+ fuse_put_request(fc, req);
+ if (err == -ENOSYS) {
+ fc->no_access = 1;
+ err = 0;
+ }
+ return err;
+}
+#endif
+
static int fuse_permission(struct inode *inode, int mask, struct nameidata *nd)
{
struct fuse_conn *fc = get_fuse_conn(inode);
@@ -525,6 +559,11 @@
return -EROFS;
if ((mask & MAY_EXEC) && !S_ISDIR(mode) && !(mode & S_IXUGO))
return -EACCES;
+
+#ifdef KERNEL_2_6
+ if (nd && (nd->flags & LOOKUP_ACCESS))
+ return fuse_access(inode, mask);
+#endif
return 0;
}
}
diff --git a/kernel/fuse_i.h b/kernel/fuse_i.h
index b8270ce..af9457d 100644
--- a/kernel/fuse_i.h
+++ b/kernel/fuse_i.h
@@ -340,6 +340,9 @@
/** Is removexattr not implemented by fs? */
unsigned no_removexattr : 1;
+ /** Is access not implemented by fs? */
+ unsigned no_access : 1;
+
#ifdef KERNEL_2_6
/** Backing dev info */
struct backing_dev_info bdi;
diff --git a/kernel/fuse_kernel.h b/kernel/fuse_kernel.h
index 1dc9e06..7710201 100644
--- a/kernel/fuse_kernel.h
+++ b/kernel/fuse_kernel.h
@@ -127,7 +127,8 @@
FUSE_OPENDIR = 27,
FUSE_READDIR = 28,
FUSE_RELEASEDIR = 29,
- FUSE_FSYNCDIR = 30
+ FUSE_FSYNCDIR = 30,
+ FUSE_ACCESS = 34
};
/* Conservative buffer size for the client */
@@ -250,6 +251,11 @@
__u32 padding;
};
+struct fuse_access_in {
+ __u32 mask;
+ __u32 padding;
+};
+
struct fuse_init_in_out {
__u32 major;
__u32 minor;
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 2d81fb0..8d340f9 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -14,7 +14,7 @@
helper.c \
mount.c
-libfuse_la_LDFLAGS = -lpthread -version-number 2:4:1 \
+libfuse_la_LDFLAGS = -lpthread -version-number 2:5:0 \
-Wl,--version-script,fuse_versionscript
EXTRA_DIST = fuse_versionscript
diff --git a/lib/fuse.c b/lib/fuse.c
index b0cf553..6b3b6ae 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -736,6 +736,29 @@
reply_err(req, err);
}
+static void fuse_access(fuse_req_t req, fuse_ino_t ino, int mask)
+{
+ struct fuse *f = req_fuse_prepare(req);
+ char *path;
+ int err;
+
+ err = -ENOENT;
+ pthread_rwlock_rdlock(&f->tree_lock);
+ path = get_path(f, ino);
+ if (path != NULL) {
+ if (f->flags & FUSE_DEBUG) {
+ printf("ACCESS %s 0%o\n", path, mask);
+ fflush(stdout);
+ }
+ err = -ENOSYS;
+ if (f->op.access)
+ err = f->op.access(path, mask);
+ free(path);
+ }
+ pthread_rwlock_unlock(&f->tree_lock);
+ reply_err(req, err);
+}
+
static void fuse_readlink(fuse_req_t req, fuse_ino_t ino)
{
struct fuse *f = req_fuse_prepare(req);
@@ -1622,6 +1645,7 @@
.forget = fuse_forget,
.getattr = fuse_getattr,
.setattr = fuse_setattr,
+ .access = fuse_access,
.readlink = fuse_readlink,
.mknod = fuse_mknod,
.mkdir = fuse_mkdir,
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index 95882ed..22dc41d 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -69,6 +69,7 @@
case FUSE_READDIR: return "READDIR";
case FUSE_RELEASEDIR: return "RELEASEDIR";
case FUSE_FSYNCDIR: return "FSYNCDIR";
+ case FUSE_ACCESS: return "ACCESS";
default: return "???";
}
}
@@ -361,6 +362,15 @@
fuse_reply_err(req, ENOSYS);
}
+static void do_access(fuse_req_t req, fuse_ino_t nodeid,
+ struct fuse_access_in *arg)
+{
+ if (req->f->op.access)
+ req->f->op.access(req, nodeid, arg->mask);
+ else
+ fuse_reply_err(req, ENOSYS);
+}
+
static void do_readlink(fuse_req_t req, fuse_ino_t nodeid)
{
if (req->f->op.readlink)
@@ -811,6 +821,10 @@
do_fsyncdir(req, in->nodeid, (struct fuse_fsync_in *) inarg);
break;
+ case FUSE_ACCESS:
+ do_access(req, in->nodeid, (struct fuse_access_in *) inarg);
+ break;
+
default:
fuse_reply_err(req, ENOSYS);
}