How to read actual file data from Freebsd VFS vnode

拈花ヽ惹草 提交于 2019-12-11 13:38:42

问题


I am currently trying to extract file data from 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 */
    };

I assumed the data lives in bufobj, but I have no clue how to extract it. Bufobj also contains list of other bufobj. It also contain bufvs objects that contain clean and dirty buffers. It would help me greatly if someone points me to the correct direction.


回答1:


To read a file from the kernel, you can use VOP_READ(9). Look at the vnode(9) manpage for more informations and a list of other macros to handle vnodes.

If you want an example, md(4) source code is a good start.



来源:https://stackoverflow.com/questions/35933288/how-to-read-actual-file-data-from-freebsd-vfs-vnode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!