userspace. For both mount options, if the option is given, then
the respective open flag is set, otherwise the open flag is left
unmodified (so the filesystem can set it).
+
+ * Add ACCESS operation. This is called from the access() system
+ call if 'default_permissions' mount option is not given
2005-07-28 Miklos Szeredi <miklos@szeredi.hu>
* Introduced in version 2.3
*/
void (*destroy) (void *);
+
+ /**
+ * Check file access permissions
+ *
+ * Need not be implemented. Will only be called for the access()
+ * system call, and only if 'default_permissions' mount option is
+ * not given.
+ *
+ * Introduced in version 2.4
+ */
+ int (*access) (const char *, int);
};
/** Extra context that may be needed by some filesystems
writepage */
int writepage;
- /** Can be filled in by open, to use direct I/O on this file */
+ /** Can be filled in by open, to use direct I/O on this file.
+ Introduced in version 2.4 */
unsigned int direct_io : 1;
/** Can be filled in by open, to indicate, that cached file data
- need not be invalidated */
+ need not be invalidated. Introduced in version 2.4 */
unsigned int keep_cache : 1;
};
void (*getattr)(fuse_req_t req, fuse_ino_t ino);
void (*setattr)(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
int to_set);
+ void (*access) (fuse_req_t req, fuse_ino_t ino, int mask);
void (*readlink)(fuse_req_t req, fuse_ino_t ino);
void (*mknod) (fuse_req_t req, fuse_ino_t parent, const char *name,
mode_t mode, dev_t rdev);
return fuse_do_getattr(inode);
}
+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;
+}
+
static int fuse_permission(struct inode *inode, int mask, struct nameidata *nd)
{
struct fuse_conn *fc = get_fuse_conn(inode);
+ int err;
if (!fuse_allow_task(fc, current))
return -EACCES;
else if (fc->flags & FUSE_DEFAULT_PERMISSIONS) {
#ifdef KERNEL_2_6_10_PLUS
- int err = generic_permission(inode, mask, NULL);
+ err = generic_permission(inode, mask, NULL);
#else
- int err = vfs_permission(inode, mask);
+ err = vfs_permission(inode, mask);
#endif
/* If permission is denied, try to refresh file
This is actually not so grave, since the user can
simply keep access to the file/directory anyway by
keeping it open... */
-
- return err;
} else {
int mode = inode->i_mode;
if ((mask & MAY_WRITE) && IS_RDONLY(inode) &&
return -EROFS;
if ((mask & MAY_EXEC) && !S_ISDIR(mode) && !(mode & S_IXUGO))
return -EACCES;
- return 0;
+
+ err = 0;
+ if (nd->flags & LOOKUP_ACCESS)
+ err = fuse_access(inode, mask);
}
+ return err;
}
static int parse_dirfile(char *buf, size_t nbytes, struct file *file,
/** Is removexattr not implemented by fs? */
unsigned no_removexattr : 1;
- /** Are file locking primitives implemented by fs? */
+ /** Are file locking primitives not implemented by fs? */
unsigned no_lk : 1;
+ /** Is access not implemented by fs */
+ unsigned no_access : 1;
+
#ifdef KERNEL_2_6
/** Backing dev info */
struct backing_dev_info bdi;
FUSE_FSYNCDIR = 30,
FUSE_GETLK = 31,
FUSE_SETLK = 32,
- FUSE_SETLKW = 33
+ FUSE_SETLKW = 33,
+ FUSE_ACCESS = 34
};
/* Conservative buffer size for the client */
struct fuse_file_lock lk;
};
+struct fuse_access_in {
+ __u32 mask;
+ __u32 padding;
+};
+
struct fuse_init_in_out {
__u32 major;
__u32 minor;
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) {
+ 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);
.forget = fuse_forget,
.getattr = fuse_getattr,
.setattr = fuse_setattr,
+ .access = fuse_access,
.readlink = fuse_readlink,
.mknod = fuse_mknod,
.mkdir = fuse_mkdir,
case FUSE_GETLK: return "GETLK";
case FUSE_SETLK: return "SETLK";
case FUSE_SETLKW: return "SETLKW";
+ case FUSE_ACCESS: return "ACCESS";
default: return "???";
}
}
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)
case FUSE_SETLKW:
do_setlk(req, in->nodeid, 1, (struct fuse_lk_in_out *) inarg);
break;
+
+ case FUSE_ACCESS:
+ do_access(req, in->nodeid, (struct fuse_access_in *) inarg);
+ break;
default:
fuse_reply_err(req, ENOSYS);