aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/sharefs/fuse-helper.c41
-rw-r--r--cmd/sharefs/fuse-helper.h5
2 files changed, 15 insertions, 31 deletions
diff --git a/cmd/sharefs/fuse-helper.c b/cmd/sharefs/fuse-helper.c
index 2c62c260..a1c511b4 100644
--- a/cmd/sharefs/fuse-helper.c
+++ b/cmd/sharefs/fuse-helper.c
@@ -10,31 +10,17 @@
#include <sys/syscall.h>
#include "fuse-helper.h"
-#define SHAREFS_MEDIA_RW_ID (1 << 10) - 1 /* owning gid presented to userspace */
-#define SHAREFS_PERM_DIR 0700 /* permission bits for directories presented to userspace */
-#define SHAREFS_PERM_REG 0600 /* permission bits for regular files presented to userspace */
-#define SHAREFS_FORBIDDEN_FLAGS O_DIRECT /* these open flags are cleared unconditionally */
-/* translate_pathname translates a userspace pathname to a relative pathname;
- * the returned address is a constant string or part of pathname, it is never heap allocated. */
-static inline const char *translate_pathname(const char *pathname) {
- if (pathname == NULL) {
- errno = EINVAL;
- return NULL;
- }
-
- while (*pathname == '/')
- pathname++;
- if (*pathname == '\0')
- pathname = ".";
- return pathname;
-}
-
-#define MUST_TRANSLATE_PATHNAME(pathname) \
- do { \
- pathname = translate_pathname(pathname); \
- if (pathname == NULL) \
- return -errno; \
+/* MUST_TRANSLATE_PATHNAME translates a userspace pathname to a relative pathname;
+ * the resulting address points to a constant string or part of pathname, it is never heap allocated. */
+#define MUST_TRANSLATE_PATHNAME(pathname) \
+ do { \
+ if (pathname == NULL) \
+ return -EINVAL; \
+ while (*pathname == '/') \
+ pathname++; \
+ if (*pathname == '\0') \
+ pathname = "."; \
} while (0)
/* GET_CONTEXT_PRIV obtains fuse context and private data for the calling thread. */
@@ -170,8 +156,6 @@ int sharefs_rmdir(const char *pathname) {
}
int sharefs_rename(const char *oldpath, const char *newpath, unsigned int flags) {
- int res;
-
struct fuse_context *ctx;
struct sharefs_private *priv;
GET_CONTEXT_PRIV(ctx, priv);
@@ -204,8 +188,6 @@ int sharefs_truncate(const char *pathname, off_t length, struct fuse_file_info *
}
int sharefs_utimens(const char *pathname, const struct timespec times[2], struct fuse_file_info *fi) {
- int res;
-
struct fuse_context *ctx;
struct sharefs_private *priv;
GET_CONTEXT_PRIV(ctx, priv);
@@ -227,7 +209,6 @@ int sharefs_create(const char *pathname, mode_t mode, struct fuse_file_info *fi)
MUST_TRANSLATE_PATHNAME(pathname);
(void)mode;
- (void)fi;
if ((fd = openat(priv->dirfd, pathname, fi->flags & ~SHAREFS_FORBIDDEN_FLAGS, SHAREFS_PERM_REG)) == -1)
return -errno;
@@ -293,8 +274,6 @@ int sharefs_release(const char *pathname, struct fuse_file_info *fi) {
}
int sharefs_fsync(const char *pathname, int datasync, struct fuse_file_info *fi) {
- int res;
-
(void)pathname;
if (datasync ? fdatasync(fi->fh) : fsync(fi->fh) == -1)
diff --git a/cmd/sharefs/fuse-helper.h b/cmd/sharefs/fuse-helper.h
index 869df6bb..34f388b3 100644
--- a/cmd/sharefs/fuse-helper.h
+++ b/cmd/sharefs/fuse-helper.h
@@ -6,6 +6,11 @@
#error This package requires libfuse >= v3.4
#endif
+#define SHAREFS_MEDIA_RW_ID (1 << 10) - 1 /* owning gid presented to userspace */
+#define SHAREFS_PERM_DIR 0700 /* permission bits for directories presented to userspace */
+#define SHAREFS_PERM_REG 0600 /* permission bits for regular files presented to userspace */
+#define SHAREFS_FORBIDDEN_FLAGS O_DIRECT /* these open flags are cleared unconditionally */
+
/* sharefs_private is populated by sharefs_init and contains process-wide context */
struct sharefs_private {
int dirfd; /* source dirfd opened during sharefs_init */