执行文件操作时,经常需要把文件的路径名传递给某一个系统调用,比如说open(), mkdir(), rename()等。VFS将解析路径名并把它拆分成一个文件序列,除了最后一个文件之外,所有的文件都必须是目录。为了识别目录文件,VFS将沿着路径逐层查找,为了配合路径查找,VFS引入了nameidata

nameidata 定义于 fs/namei.c

struct nameidata {
    struct path     path;
    struct qstr     last;
    struct path     root;
    struct inode    *inode; /* path.dentry.d_inode */
    unsigned int    flags;
    unsigned        seq, m_seq;
    int             last_type;
    unsigned        depth;
    int             total_link_count;
    struct saved {
        struct path link;
        void *cookie;
        const char *name;
        struct inode *inode;
        unsigned seq;
    } *stack, internal[EMBEDDED_LEVELS];
    struct filename *name;
    struct nameidata *saved;
    unsigned        root_seq;
    int             dfd;
};

path 定义于 include/linux/path.h

struct path {
    struct vfsmount *mnt;
    struct dentry *dentry;
};