From 1b7d2b886265daa5527f487c1b6e86d006574ac4 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Fri, 8 Mar 2019 14:24:50 -0700 Subject: [PATCH] Document fuse_fsync_in.fsync_flags and remove magic numbers (#375) --- example/hello_ll.c | 2 +- example/notify_inval_inode.c | 6 +----- example/notify_store_retrieve.c | 6 +----- example/poll.c | 2 +- include/fuse_kernel.h | 7 +++++++ lib/fuse_lowlevel.c | 14 ++++++++------ test/test_syscalls.c | 14 ++++++++------ 7 files changed, 27 insertions(+), 24 deletions(-) diff --git a/example/hello_ll.c b/example/hello_ll.c index 97f3c50..51b452c 100644 --- a/example/hello_ll.c +++ b/example/hello_ll.c @@ -138,7 +138,7 @@ static void hello_ll_open(fuse_req_t req, fuse_ino_t ino, { if (ino != 2) fuse_reply_err(req, EISDIR); - else if ((fi->flags & 3) != O_RDONLY) + else if ((fi->flags & O_ACCMODE) != O_RDONLY) fuse_reply_err(req, EACCES); else fuse_reply_open(req, fi); diff --git a/example/notify_inval_inode.c b/example/notify_inval_inode.c index 0cee6e6..cdea82d 100644 --- a/example/notify_inval_inode.c +++ b/example/notify_inval_inode.c @@ -76,10 +76,6 @@ timeout, so we just send a big value */ #define NO_TIMEOUT 500000 -/* We cannot check directly if e.g. O_RDONLY is set, since this is not - * an individual bit (cf. open(2)) */ -#define ACCESS_MASK (O_RDONLY | O_WRONLY | O_RDWR) - #define MAX_STR_LEN 128 #define FILE_INO 2 #define FILE_NAME "current_time" @@ -224,7 +220,7 @@ static void tfs_open(fuse_req_t req, fuse_ino_t ino, if (ino == FUSE_ROOT_ID) fuse_reply_err(req, EISDIR); - else if ((fi->flags & ACCESS_MASK) != O_RDONLY) + else if ((fi->flags & O_ACCMODE) != O_RDONLY) fuse_reply_err(req, EACCES); else if (ino == FILE_INO) fuse_reply_open(req, fi); diff --git a/example/notify_store_retrieve.c b/example/notify_store_retrieve.c index 8fd81ff..56cb8b7 100644 --- a/example/notify_store_retrieve.c +++ b/example/notify_store_retrieve.c @@ -75,10 +75,6 @@ timeout, so we just send a big value */ #define NO_TIMEOUT 500000 -/* We cannot check directly if e.g. O_RDONLY is set, since this is not - * an individual bit (cf. open(2)) */ -#define ACCESS_MASK (O_RDONLY | O_WRONLY | O_RDWR) - #define MAX_STR_LEN 128 #define FILE_INO 2 #define FILE_NAME "current_time" @@ -227,7 +223,7 @@ static void tfs_open(fuse_req_t req, fuse_ino_t ino, if (ino == FUSE_ROOT_ID) fuse_reply_err(req, EISDIR); - else if ((fi->flags & ACCESS_MASK) != O_RDONLY) + else if ((fi->flags & O_ACCMODE) != O_RDONLY) fuse_reply_err(req, EACCES); else if (ino == FILE_INO) fuse_reply_open(req, fi); diff --git a/example/poll.c b/example/poll.c index 8abca07..64917cc 100644 --- a/example/poll.c +++ b/example/poll.c @@ -115,7 +115,7 @@ static int fsel_open(const char *path, struct fuse_file_info *fi) if (idx < 0) return -ENOENT; - if ((fi->flags & 3) != O_RDONLY) + if ((fi->flags & O_ACCMODE) != O_RDONLY) return -EACCES; if (fsel_open_mask & (1 << idx)) return -EBUSY; diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h index c806a17..6079b7f 100644 --- a/include/fuse_kernel.h +++ b/include/fuse_kernel.h @@ -339,6 +339,13 @@ struct fuse_file_lock { */ #define FUSE_POLL_SCHEDULE_NOTIFY (1 << 0) +/** + * Fsync flags + * + * FUSE_FSYNC_FDATASYNC: Sync data only, not metadata + */ +#define FUSE_FSYNC_FDATASYNC (1 << 0) + enum fuse_opcode { FUSE_LOOKUP = 1, FUSE_FORGET = 2, /* no reply */ diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c index cd59ec0..f5542cc 100644 --- a/lib/fuse_lowlevel.c +++ b/lib/fuse_lowlevel.c @@ -284,7 +284,7 @@ size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize, dirent->ino = stbuf->st_ino; dirent->off = off; dirent->namelen = namelen; - dirent->type = (stbuf->st_mode & 0170000) >> 12; + dirent->type = (stbuf->st_mode & S_IFMT) >> 12; strncpy(dirent->name, name, namelen); memset(dirent->name + namelen, 0, entlen_padded - entlen); @@ -377,7 +377,7 @@ size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize, dirent->ino = e->attr.st_ino; dirent->off = off; dirent->namelen = namelen; - dirent->type = (e->attr.st_mode & 0170000) >> 12; + dirent->type = (e->attr.st_mode & S_IFMT) >> 12; strncpy(dirent->name, name, namelen); memset(dirent->name + namelen, 0, entlen_padded - entlen); @@ -1315,7 +1315,7 @@ static void do_write(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; - fi.writepage = (arg->write_flags & 1) != 0; + fi.writepage = (arg->write_flags & FUSE_WRITE_CACHE) != 0; if (req->se->conn.proto_minor < 9) { param = ((char *) arg) + FUSE_COMPAT_WRITE_IN_SIZE; @@ -1345,7 +1345,7 @@ static void do_write_buf(fuse_req_t req, fuse_ino_t nodeid, const void *inarg, memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; - fi.writepage = arg->write_flags & 1; + fi.writepage = arg->write_flags & FUSE_WRITE_CACHE; if (se->conn.proto_minor < 9) { bufv.buf[0].mem = ((char *) arg) + FUSE_COMPAT_WRITE_IN_SIZE; @@ -1420,12 +1420,13 @@ static void do_fsync(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) { struct fuse_fsync_in *arg = (struct fuse_fsync_in *) inarg; struct fuse_file_info fi; + int datasync = arg->fsync_flags & FUSE_FSYNC_FDATASYNC; memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; if (req->se->op.fsync) - req->se->op.fsync(req, nodeid, arg->fsync_flags & 1, &fi); + req->se->op.fsync(req, nodeid, datasync, &fi); else fuse_reply_err(req, ENOSYS); } @@ -1491,12 +1492,13 @@ static void do_fsyncdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) { struct fuse_fsync_in *arg = (struct fuse_fsync_in *) inarg; struct fuse_file_info fi; + int datasync = arg->fsync_flags & FUSE_FSYNC_FDATASYNC; memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; if (req->se->op.fsyncdir) - req->se->op.fsyncdir(req, nodeid, arg->fsync_flags & 1, &fi); + req->se->op.fsyncdir(req, nodeid, datasync, &fi); else fuse_reply_err(req, ENOSYS); } diff --git a/test/test_syscalls.c b/test/test_syscalls.c index a281ae3..cdf17d7 100644 --- a/test/test_syscalls.c +++ b/test/test_syscalls.c @@ -163,8 +163,9 @@ static int check_mode(const char *path, mode_t mode) PERROR("lstat"); return -1; } - if ((stbuf.st_mode & 07777) != mode) { - ERROR("mode 0%o instead of 0%o", stbuf.st_mode & 07777, mode); + if ((stbuf.st_mode & ALLPERMS) != mode) { + ERROR("mode 0%o instead of 0%o", stbuf.st_mode & ALLPERMS, + mode); return -1; } return 0; @@ -178,8 +179,9 @@ static int fcheck_mode(int fd, mode_t mode) PERROR("fstat"); return -1; } - if ((stbuf.st_mode & 07777) != mode) { - ERROR("mode 0%o instead of 0%o", stbuf.st_mode & 07777, mode); + if ((stbuf.st_mode & ALLPERMS) != mode) { + ERROR("mode 0%o instead of 0%o", stbuf.st_mode & ALLPERMS, + mode); return -1; } return 0; @@ -1040,7 +1042,7 @@ static int do_test_open(int exist, int flags, const char *flags_str, int mode) err += check_mode(testfile, mode); err += check_nlink(testfile, 1); err += check_size(testfile, currlen); - if (exist && !(flags & O_TRUNC) && (mode & 0400)) + if (exist && !(flags & O_TRUNC) && (mode & S_IRUSR)) err += check_data(testfile, testdata2, 0, testdata2len); res = write(fd, data, datalen); @@ -1057,7 +1059,7 @@ static int do_test_open(int exist, int flags, const char *flags_str, int mode) err += check_size(testfile, currlen); - if (mode & 0400) { + if (mode & S_IRUSR) { err += check_data(testfile, data, 0, datalen); if (exist && !(flags & O_TRUNC) && testdata2len > datalen) -- 2.30.2