2

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.

Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
lostdong12
  • 77
  • 7
  • Have you tried to FreeBSD development forum? forums.freebsd.org/forums/34 My feeling is that you will get more help for your issue there. – Greg Mar 11 '16 at 11:06

1 Answers1

2

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.