operating-system - 如何从 FreeBSD VFS vnode 读取实际文件数据?

标签 operating-system freebsd vfs

我目前正在尝试从 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 对象。如果有人指出我正确的方向,这将对我有很大帮助。

最佳答案

要从内核读取文件,可以使用 VOP_READ(9) 。看vnode(9) manpage了解更多信息以及处理 vnode 的其他宏列表。

如果你想要一个例子,md(4) source code是一个好的开始。

关于operating-system - 如何从 FreeBSD VFS vnode 读取实际文件数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35933288/

相关文章:

c - printf()函数的实现

php - Free Radius + Captive Portal + MySql 未收到有效的 RADIUS 响应

c - Getrusage 内联汇编

freebsd - 调整 freebsd 分区大小

linux - VFS 如何知道要调用哪些底层文件系统函数?

windows - 你需要 Docker 内的 OS (Windows) 许可证吗

c++ - 获取 OSName 作为字符串 C++

java - 动态确定操作系统

caching - 如何自动清理我的 $JBOSS_HOME/standalone/tmp 目录?

PHPUnit 测试错误 : Object of class (. ..) 无法转换为字符串