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
This commit is contained in:
parent
31b6611abf
commit
289b04677a
18 changed files with 26 additions and 46 deletions
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "fsdriver.h"
|
||||
|
||||
/* Library-local variables. */
|
||||
dev_t fsdriver_device;
|
||||
ino_t fsdriver_root;
|
||||
int fsdriver_mounted = FALSE;
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#define dprintf(x)
|
||||
#endif
|
||||
|
||||
#include "type.h"
|
||||
#include "const.h"
|
||||
#include "proto.h"
|
||||
#include "glo.h"
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 */
|
|
@ -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)
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
|
||||
EXTERN struct fs_hooks *vtreefs_hooks;
|
||||
|
||||
EXTERN dev_t fs_dev;
|
||||
|
||||
extern struct fsdriver vtreefs_table;
|
||||
|
||||
#endif /* _VTREEFS_GLO_H */
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue