From 289b04677a1b234d09a045a727f5e614a6c8d716 Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Fri, 14 Nov 2014 15:52:22 +0000 Subject: [PATCH] libfsdriver: prefill st_dev for stat requests This obviates the need for several file system implementations to remember the device on which they are mounted. Change-Id: Ida8325cf4bcf072e61761cfee34e3f7ed2d750b9 --- lib/libpuffs/glo.h | 2 -- lib/libpuffs/inode.c | 4 ++-- lib/libpuffs/mount.c | 5 ++--- lib/libpuffs/stadir.c | 1 - minix/lib/libfsdriver/call.c | 2 ++ minix/lib/libfsdriver/fsdriver.c | 1 + minix/lib/libfsdriver/fsdriver.h | 1 + minix/lib/libsffs/glo.h | 2 +- minix/lib/libsffs/handle.c | 4 ++-- minix/lib/libsffs/inc.h | 1 - minix/lib/libsffs/link.c | 10 +++++----- minix/lib/libsffs/mount.c | 7 +++---- minix/lib/libsffs/stat.c | 7 +++---- minix/lib/libsffs/type.h | 11 ----------- minix/lib/libsffs/write.c | 4 ++-- minix/lib/libvtreefs/glo.h | 2 -- minix/lib/libvtreefs/mount.c | 7 ++----- minix/lib/libvtreefs/stadir.c | 1 - 18 files changed, 26 insertions(+), 46 deletions(-) delete mode 100644 minix/lib/libsffs/type.h diff --git a/lib/libpuffs/glo.h b/lib/libpuffs/glo.h index 6e4645216..bc39b8120 100644 --- a/lib/libpuffs/glo.h +++ b/lib/libpuffs/glo.h @@ -25,8 +25,6 @@ EXTERN int err_code; /* temporary storage for error number */ EXTERN struct puffs_kcred global_kcred; -EXTERN dev_t fs_dev; /* The device that is handled by this FS proc - */ EXTERN char fs_name[PATH_MAX+1]; EXTERN int mounted; diff --git a/lib/libpuffs/inode.c b/lib/libpuffs/inode.c index e62149dc7..50a6ad4fd 100644 --- a/lib/libpuffs/inode.c +++ b/lib/libpuffs/inode.c @@ -52,8 +52,8 @@ int fs_putnode(ino_t ino_nr, unsigned int count) } if (pn == NULL) { - lpuffs_debug("%s:%d putnode: pnode #%"PRIu64" dev: %"PRIu64 - " not found\n", __FILE__, __LINE__, ino_nr, fs_dev); + lpuffs_debug("%s:%d putnode: pnode #%"PRIu64" not found\n", + __FILE__, __LINE__, ino_nr); panic("fs_putnode failed"); } diff --git a/lib/libpuffs/mount.c b/lib/libpuffs/mount.c index 05272e9f8..237744e15 100644 --- a/lib/libpuffs/mount.c +++ b/lib/libpuffs/mount.c @@ -12,12 +12,11 @@ /*===========================================================================* * fs_mount * *===========================================================================*/ -int fs_mount(dev_t dev, unsigned int flags, struct fsdriver_node *root_node, - unsigned int *res_flags) +int fs_mount(dev_t __unused dev, unsigned int flags, + struct fsdriver_node *root_node, unsigned int *res_flags) { struct vattr *root_va; - fs_dev = dev; is_readonly_fs = !!(flags & REQ_RDONLY); /* Open root pnode */ diff --git a/lib/libpuffs/stadir.c b/lib/libpuffs/stadir.c index a5be843bb..6d1d14d07 100644 --- a/lib/libpuffs/stadir.c +++ b/lib/libpuffs/stadir.c @@ -45,7 +45,6 @@ int fs_stat(ino_t ino_nr, struct stat *statbuf) /* true iff special */ s = (mo == I_CHAR_SPECIAL || mo == I_BLOCK_SPECIAL); - statbuf->st_dev = fs_dev; statbuf->st_ino = va.va_fileid; statbuf->st_mode = va.va_mode; statbuf->st_nlink = va.va_nlink; diff --git a/minix/lib/libfsdriver/call.c b/minix/lib/libfsdriver/call.c index 8ebda1c29..cb40015b6 100644 --- a/minix/lib/libfsdriver/call.c +++ b/minix/lib/libfsdriver/call.c @@ -55,6 +55,7 @@ fsdriver_readsuper(const struct fsdriver * __restrict fdp, /* Update library-local state. */ fsdriver_mounted = TRUE; + fsdriver_device = dev; fsdriver_root = root_node.fn_ino_nr; } @@ -654,6 +655,7 @@ fsdriver_stat(const struct fsdriver * __restrict fdp, return ENOSYS; memset(&buf, 0, sizeof(buf)); + buf.st_dev = fsdriver_device; if ((r = fdp->fdr_stat(ino_nr, &buf)) == OK) r = sys_safecopyto(m_in->m_source, grant, 0, (vir_bytes)&buf, diff --git a/minix/lib/libfsdriver/fsdriver.c b/minix/lib/libfsdriver/fsdriver.c index 145ac5466..1443e9ff7 100644 --- a/minix/lib/libfsdriver/fsdriver.c +++ b/minix/lib/libfsdriver/fsdriver.c @@ -2,6 +2,7 @@ #include "fsdriver.h" /* Library-local variables. */ +dev_t fsdriver_device; ino_t fsdriver_root; int fsdriver_mounted = FALSE; diff --git a/minix/lib/libfsdriver/fsdriver.h b/minix/lib/libfsdriver/fsdriver.h index 7c83f7b75..65a6ba512 100644 --- a/minix/lib/libfsdriver/fsdriver.h +++ b/minix/lib/libfsdriver/fsdriver.h @@ -75,6 +75,7 @@ extern int fsdriver_bpeek(const struct fsdriver * __restrict, extern int fsdriver_getname(endpoint_t endpt, cp_grant_id_t grant, size_t len, char *name, size_t size, int not_empty); +extern dev_t fsdriver_device; extern ino_t fsdriver_root; extern int fsdriver_mounted; extern int (*fsdriver_callvec[])(const struct fsdriver * __restrict, diff --git a/minix/lib/libsffs/glo.h b/minix/lib/libsffs/glo.h index 2ec5e942c..485004b84 100644 --- a/minix/lib/libsffs/glo.h +++ b/minix/lib/libsffs/glo.h @@ -10,7 +10,7 @@ EXTERN char *sffs_name; /* file server name */ EXTERN const struct sffs_table *sffs_table; /* call table */ EXTERN struct sffs_params *sffs_params; /* parameters */ -EXTERN struct state state; /* global state */ +EXTERN int read_only; /* mounted read-only? */ extern struct fsdriver sffs_dtable; /* driver table */ diff --git a/minix/lib/libsffs/handle.c b/minix/lib/libsffs/handle.c index ed416c134..b346175c0 100644 --- a/minix/lib/libsffs/handle.c +++ b/minix/lib/libsffs/handle.c @@ -33,13 +33,13 @@ int get_handle(struct inode *ino) r = sffs_table->t_opendir(path, &ino->i_dir); } else { - if (!state.s_read_only) + if (!read_only) r = sffs_table->t_open(path, O_RDWR, 0, &ino->i_file); /* Protection or mount status might prevent us from writing. With the * information that we have available, this is the best we can do.. */ - if (state.s_read_only || r != OK) + if (read_only || r != OK) r = sffs_table->t_open(path, O_RDONLY, 0, &ino->i_file); } diff --git a/minix/lib/libsffs/inc.h b/minix/lib/libsffs/inc.h index 61d537f08..d04f36f4e 100644 --- a/minix/lib/libsffs/inc.h +++ b/minix/lib/libsffs/inc.h @@ -16,7 +16,6 @@ #define dprintf(x) #endif -#include "type.h" #include "const.h" #include "proto.h" #include "glo.h" diff --git a/minix/lib/libsffs/link.c b/minix/lib/libsffs/link.c index e1a01ad92..c55466e08 100644 --- a/minix/lib/libsffs/link.c +++ b/minix/lib/libsffs/link.c @@ -30,7 +30,7 @@ int do_create(ino_t dir_nr, char *name, mode_t mode, uid_t uid, gid_t gid, int r; /* We cannot create files on a read-only file system. */ - if (state.s_read_only) + if (read_only) return EROFS; if ((parent = find_inode(dir_nr)) == NULL) @@ -129,7 +129,7 @@ int do_mkdir(ino_t dir_nr, char *name, mode_t mode, uid_t uid, gid_t gid) int r; /* We cannot create directories on a read-only file system. */ - if (state.s_read_only) + if (read_only) return EROFS; if ((parent = find_inode(dir_nr)) == NULL) @@ -228,7 +228,7 @@ int do_unlink(ino_t dir_nr, char *name, int call) int r; /* We cannot delete files on a read-only file system. */ - if (state.s_read_only) + if (read_only) return EROFS; if ((parent = find_inode(dir_nr)) == NULL) @@ -269,7 +269,7 @@ int do_rmdir(ino_t dir_nr, char *name, int call) int r; /* We cannot remove directories on a read-only file system. */ - if (state.s_read_only) + if (read_only) return EROFS; if ((parent = find_inode(dir_nr)) == NULL) @@ -312,7 +312,7 @@ int do_rename(ino_t old_dir_nr, char *old_name, ino_t new_dir_nr, int r; /* We cannot do rename on a read-only file system. */ - if (state.s_read_only) + if (read_only) return EROFS; /* Get possibly preexisting inodes for the old and new paths. */ diff --git a/minix/lib/libsffs/mount.c b/minix/lib/libsffs/mount.c index a8d1a41ec..998e0151f 100644 --- a/minix/lib/libsffs/mount.c +++ b/minix/lib/libsffs/mount.c @@ -13,8 +13,8 @@ /*===========================================================================* * do_mount * *===========================================================================*/ -int do_mount(dev_t dev, unsigned int flags, struct fsdriver_node *root_node, - unsigned int *res_flags) +int do_mount(dev_t __unused dev, unsigned int flags, + struct fsdriver_node *root_node, unsigned int *res_flags) { /* Mount the file system. */ @@ -31,8 +31,7 @@ int do_mount(dev_t dev, unsigned int flags, struct fsdriver_node *root_node, return EINVAL; } - state.s_read_only = !!(flags & REQ_RDONLY); - state.s_dev = dev; + read_only = !!(flags & REQ_RDONLY); init_dentry(); ino = init_inode(); diff --git a/minix/lib/libsffs/stat.c b/minix/lib/libsffs/stat.c index bd9902b30..330afbf08 100644 --- a/minix/lib/libsffs/stat.c +++ b/minix/lib/libsffs/stat.c @@ -28,7 +28,7 @@ mode_t get_mode(struct inode *ino, int mode) else mode = S_IFREG | (mode & sffs_params->p_file_mask); - if (state.s_read_only) + if (read_only) mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); return mode; @@ -56,7 +56,6 @@ int do_stat(ino_t ino_nr, struct stat *stat) if ((r = verify_inode(ino, path, &attr)) != OK) return r; - stat->st_dev = state.s_dev; stat->st_ino = ino_nr; stat->st_mode = get_mode(ino, attr.a_mode); stat->st_uid = sffs_params->p_uid; @@ -100,7 +99,7 @@ int do_chmod(ino_t ino_nr, mode_t *mode) struct sffs_attr attr; int r; - if (state.s_read_only) + if (read_only) return EROFS; if ((ino = find_inode(ino_nr)) == NULL) @@ -137,7 +136,7 @@ int do_utime(ino_t ino_nr, struct timespec *atime, struct timespec *mtime) struct sffs_attr attr; int r; - if (state.s_read_only) + if (read_only) return EROFS; if ((ino = find_inode(ino_nr)) == NULL) diff --git a/minix/lib/libsffs/type.h b/minix/lib/libsffs/type.h deleted file mode 100644 index b4d705420..000000000 --- a/minix/lib/libsffs/type.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _SFFS_TYPE_H -#define _SFFS_TYPE_H - -/* Structure with global file system state. */ -struct state { - int s_read_only; /* is the file system mounted read-only? note, - * has no relation to the shared folder mode */ - dev_t s_dev; /* device the file system is mounted on */ -}; - -#endif /* _SFFS_TYPE_H */ diff --git a/minix/lib/libsffs/write.c b/minix/lib/libsffs/write.c index 711c26f41..d18a5831a 100644 --- a/minix/lib/libsffs/write.c +++ b/minix/lib/libsffs/write.c @@ -72,7 +72,7 @@ ssize_t do_write(ino_t ino_nr, struct fsdriver_data *data, size_t count, */ struct inode *ino; - if (state.s_read_only) + if (read_only) return EROFS; if ((ino = find_inode(ino_nr)) == NULL) @@ -98,7 +98,7 @@ int do_trunc(ino_t ino_nr, off_t start, off_t end) uint64_t delta; ssize_t r; - if (state.s_read_only) + if (read_only) return EROFS; if ((ino = find_inode(ino_nr)) == NULL) diff --git a/minix/lib/libvtreefs/glo.h b/minix/lib/libvtreefs/glo.h index 0e5fd1a59..49ca2e86e 100644 --- a/minix/lib/libvtreefs/glo.h +++ b/minix/lib/libvtreefs/glo.h @@ -8,8 +8,6 @@ EXTERN struct fs_hooks *vtreefs_hooks; -EXTERN dev_t fs_dev; - extern struct fsdriver vtreefs_table; #endif /* _VTREEFS_GLO_H */ diff --git a/minix/lib/libvtreefs/mount.c b/minix/lib/libvtreefs/mount.c index c94becc7c..f30184bd0 100644 --- a/minix/lib/libvtreefs/mount.c +++ b/minix/lib/libvtreefs/mount.c @@ -7,14 +7,11 @@ * Mount the file system. Obtain the root inode and send back its details. */ int -fs_mount(dev_t dev, unsigned int flags, struct fsdriver_node * root_node, - unsigned int * res_flags) +fs_mount(dev_t __unused dev, unsigned int flags, + struct fsdriver_node * root_node, unsigned int * res_flags) { struct inode *root; - /* Get the device number, for stat requests. */ - fs_dev = dev; - /* VTreeFS must not be mounted as a root file system. */ if (flags & REQ_ISROOT) return EINVAL; diff --git a/minix/lib/libvtreefs/stadir.c b/minix/lib/libvtreefs/stadir.c index 329c6e065..3f0d17df7 100644 --- a/minix/lib/libvtreefs/stadir.c +++ b/minix/lib/libvtreefs/stadir.c @@ -17,7 +17,6 @@ fs_stat(ino_t ino_nr, struct stat * buf) return EINVAL; /* Fill in the basic info. */ - buf->st_dev = fs_dev; buf->st_ino = get_inode_number(node); buf->st_mode = node->i_stat.mode; buf->st_nlink = !is_inode_deleted(node);