我目前正在尝试从Freebsd VFS vnode中提取文件数据。
struct vnode {
/*
* Fields which define the identity of the vnode. These fields are
* owned by the filesystem (XXX: and vgone() ?)
*/
const char *v_tag; /* u type of underlying data */
struct vop_vector *v_op; /* u vnode operations vector */
void *v_data; /* u private data for fs */
/*
* Filesystem instance stuff
*/
struct mount *v_mount; /* u ptr to vfs we are in */
TAILQ_ENTRY(vnode) v_nmntvnodes; /* m vnodes for mount point */
/*
* Type specific fields, only one applies to any given vnode.
* See #defines below for renaming to v_* namespace.
*/
union {
struct mount *vu_mount; /* v ptr to mountpoint (VDIR) */
struct socket *vu_socket; /* v unix domain net (VSOCK) */
struct cdev *vu_cdev; /* v device (VCHR, VBLK) */
struct fifoinfo *vu_fifoinfo; /* v fifo (VFIFO) */
} v_un;
/*
* vfs_hash: (mount + inode) -> vnode hash. The hash value
* itself is grouped with other int fields, to avoid padding.
*/
LIST_ENTRY(vnode) v_hashlist;
/*
* VFS_namecache stuff
*/
LIST_HEAD(, namecache) v_cache_src; /* c Cache entries from us */
TAILQ_HEAD(, namecache) v_cache_dst; /* c Cache entries to us */
struct namecache *v_cache_dd; /* c Cache entry for .. vnode */
/*
* Locking
*/
struct lock v_lock; /* u (if fs don't have one) */
struct mtx v_interlock; /* lock for "i" things */
struct lock *v_vnlock; /* u pointer to vnode lock */
/*
* The machinery of being a vnode
*/
TAILQ_ENTRY(vnode) v_actfreelist; /* f vnode active/free lists */
struct bufobj v_bufobj; /* * Buffer cache object */
/*
* Hooks for various subsystems and features.
*/
struct vpollinfo *v_pollinfo; /* i Poll events, p for *v_pi */
struct label *v_label; /* MAC label for vnode */
struct lockf *v_lockf; /* Byte-level advisory lock list */
struct rangelock v_rl; /* Byte-range lock */
/*
* clustering stuff
*/
daddr_t v_cstart; /* v start block of cluster */
daddr_t v_lasta; /* v last allocation */
daddr_t v_lastw; /* v last write */
int v_clen; /* v length of cur. cluster */
int v_holdcnt; /* i prevents recycling. */
int v_usecount; /* i ref count of users */
u_int v_iflag; /* i vnode flags (see below) */
u_int v_vflag; /* v vnode flags */
int v_writecount; /* v ref count of writers */
u_int v_hash;
enum vtype v_type; /* u vnode type */
};
我认为数据存在于bufobj中,但我不知道如何提取它。 Bufobj还包含其他bufobj的列表。它还包含包含干净和脏缓冲区的bufvs对象。如果有人指出我正确的方向,这对我有很大的帮助。
答案 0 :(得分:1)
要从内核中读取文件,您可以使用VOP_READ(9)
。查看vnode(9)
manpage以获取更多信息以及处理vnode的其他宏列表。
如果你想要一个例子,md(4)
source code是一个好的开始。