From 4295b530eeb68aaacbbeb5b2197ed14bf9295c2b Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Tue, 11 Jan 2011 11:53:05 -0800 Subject: [PATCH] Add vn_mode_to_vtype/vn_vtype to_mode helpers Add simple helpers to convert a vnode->v_type to a inode->i_mode. These should be used sparingly but they are handy to have. --- include/sys/mode.h | 4 ++++ include/sys/vnode.h | 2 ++ module/spl/spl-vnode.c | 41 +++++++++++++++++++++++++++++++++++------ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/include/sys/mode.h b/include/sys/mode.h index f3d890944..ddd504f9f 100644 --- a/include/sys/mode.h +++ b/include/sys/mode.h @@ -25,4 +25,8 @@ #ifndef _SPL_MODE_H #define _SPL_MODE_H +#define IFTOVT(mode) vn_mode_to_vtype(mode) +#define VTTOIF(vtype) vn_vtype_to_mode(vtype) +#define MAKEIMODE(T, M) (VTTOIF(T) | ((M) & ~S_IFMT)) + #endif /* SPL_MODE_H */ diff --git a/include/sys/vnode.h b/include/sys/vnode.h index 104e65d15..b5969b352 100644 --- a/include/sys/vnode.h +++ b/include/sys/vnode.h @@ -202,6 +202,8 @@ typedef struct caller_context { extern vnode_t *vn_alloc(int flag); void vn_free(vnode_t *vp); +extern vtype_t vn_mode_to_vtype(mode_t); +extern mode_t vn_vtype_to_mode(vtype_t); extern int vn_open(const char *path, uio_seg_t seg, int flags, int mode, vnode_t **vpp, int x1, void *x2); extern int vn_openat(const char *path, uio_seg_t seg, int flags, int mode, diff --git a/module/spl/spl-vnode.c b/module/spl/spl-vnode.c index 1847c7794..765dc4e2e 100644 --- a/module/spl/spl-vnode.c +++ b/module/spl/spl-vnode.c @@ -42,8 +42,8 @@ static spl_kmem_cache_t *vn_file_cache; static spinlock_t vn_file_lock = SPIN_LOCK_UNLOCKED; static LIST_HEAD(vn_file_list); -static vtype_t -vn_get_sol_type(umode_t mode) +vtype_t +vn_mode_to_vtype(mode_t mode) { if (S_ISREG(mode)) return VREG; @@ -70,7 +70,36 @@ vn_get_sol_type(umode_t mode) return VCHR; return VNON; -} /* vn_get_sol_type() */ +} /* vn_mode_to_vtype() */ +EXPORT_SYMBOL(vn_mode_to_vtype); + +mode_t +vn_vtype_to_mode(vtype_t vtype) +{ + if (vtype == VREG) + return S_IFREG; + + if (vtype == VDIR) + return S_IFDIR; + + if (vtype == VCHR) + return S_IFCHR; + + if (vtype == VBLK) + return S_IFBLK; + + if (vtype == VFIFO) + return S_IFIFO; + + if (vtype == VLNK) + return S_IFLNK; + + if (vtype == VSOCK) + return S_IFSOCK; + + return VNON; +} /* vn_vtype_to_mode() */ +EXPORT_SYMBOL(vn_vtype_to_mode); vnode_t * vn_alloc(int flag) @@ -150,7 +179,7 @@ vn_open(const char *path, uio_seg_t seg, int flags, int mode, mapping_set_gfp_mask(fp->f_mapping, saved_gfp & ~(__GFP_IO|__GFP_FS)); mutex_enter(&vp->v_lock); - vp->v_type = vn_get_sol_type(stat.mode); + vp->v_type = vn_mode_to_vtype(stat.mode); vp->v_file = fp; vp->v_gfp_mask = saved_gfp; *vpp = vp; @@ -439,7 +468,7 @@ vn_getattr(vnode_t *vp, vattr_t *vap, int flags, void *x3, void *x4) if (rc) SRETURN(-rc); - vap->va_type = vn_get_sol_type(stat.mode); + vap->va_type = vn_mode_to_vtype(stat.mode); vap->va_mode = stat.mode; vap->va_uid = stat.uid; vap->va_gid = stat.gid; @@ -539,7 +568,7 @@ vn_getf(int fd) SGOTO(out_vnode, rc); mutex_enter(&vp->v_lock); - vp->v_type = vn_get_sol_type(stat.mode); + vp->v_type = vn_mode_to_vtype(stat.mode); vp->v_file = lfp; mutex_exit(&vp->v_lock); -- 2.40.0