From 6a6e374db6bbd47c54be7a9e552a2b54b5e4f928 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 25 Jun 2024 23:07:13 -0400 Subject: kernel: vfs: Add getattr vop Signed-off-by: Ian Moffett --- sys/include/sys/vnode.h | 19 +++++++++++++++++++ sys/kern/vfs_subr.c | 13 +++++++++++++ 2 files changed, 32 insertions(+) diff --git a/sys/include/sys/vnode.h b/sys/include/sys/vnode.h index 1caf2cb..545fa2f 100644 --- a/sys/include/sys/vnode.h +++ b/sys/include/sys/vnode.h @@ -30,6 +30,7 @@ #ifndef _SYS_VNODE_H_ #define _SYS_VNODE_H_ +#include #include #if defined(_KERNEL) @@ -50,14 +51,31 @@ struct vnode { #define VCHR 0x03 /* Character device */ #define VBLK 0x04 /* Block device */ +#define VNOVAL -1 + struct vop_lookup_args { const char *name; /* Current path component */ struct vnode *dirvp; /* Directory vnode */ struct vnode **vpp; /* Result vnode */ }; +/* + * A field in this structure is unavailable + * if it has a value of VNOVAL. + */ +struct vattr { + mode_t mode; + size_t size; +}; + +struct vop_getattr_args { + struct vnode *vp; + struct vattr *res; +}; + struct vops { int(*lookup)(struct vop_lookup_args *args); + int(*getattr)(struct vop_getattr_args *args); int(*read)(struct vnode *vp, struct sio_txn *sio); int(*reclaim)(struct vnode *vp); }; @@ -69,6 +87,7 @@ int vfs_release_vnode(struct vnode *vp); int vfs_vop_lookup(struct vnode *vp, struct vop_lookup_args *args); int vfs_vop_read(struct vnode *vp, struct sio_txn *sio); +int vfs_vop_getattr(struct vnode *vp, struct vop_getattr_args *args); #endif /* _KERNEL */ #endif /* !_SYS_VNODE_H_ */ diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index e1eefaa..850961e 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -115,3 +115,16 @@ vfs_vop_read(struct vnode *vp, struct sio_txn *sio) return vops->read(vp, sio); } + +int +vfs_vop_getattr(struct vnode *vp, struct vop_getattr_args *args) +{ + const struct vops *vops = vp->vops; + + if (vops == NULL) + return -EIO; + if (vops->getattr == NULL) + return -EIO; + + return vops->getattr(args); +} -- cgit v1.2.3