原文:http://blog.sina.com.cn/s/blog_5219094a0100calt.html
mount 文件系統
主要數據結構:
struct namespace {
atomic_t count;
struct vfsmount * root;
struct list_head list;
struct rw_semaphore sem;
};
struct vfsmount
{
struct list_head mnt_hash;
struct vfsmount *mnt_parent;
struct dentry *mnt_mountpoint;
struct dentry *mnt_root;
struct super_block *mnt_sb;
struct list_head mnt_mounts;
struct list_head mnt_child;
atomic_t mnt_count;
int mnt_flags;
int mnt_expiry_mark;
char *mnt_devname;
struct list_head mnt_list;
struct list_head mnt_fslink;
struct namespace *mnt_namespace;
};
struct nameidata {
struct dentry *dentry;
struct vfsmount *mnt;
struct qstr last;
unsigned int flags;
int last_type;
unsigned depth;
char *saved_names[MAX_NESTED_LINKS + 1];
union {
struct open_intent open;
} intent;
};
enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
#define LOOKUP_FOLLOW 1
#define LOOKUP_DIRECTORY 2
#define LOOKUP_CONTINUE 4
#define LOOKUP_PARENT 16
#define LOOKUP_NOALT 32
#define LOOKUP_REVAL 64
#define LOOKUP_OPEN (0x0100)
#define LOOKUP_CREATE (0x0200)
#define LOOKUP_ACCESS (0x0400)
struct qstr {
unsigned int hash;
unsigned int len;
const unsigned char *name;
};
--------------------------------------------------------------------------
需要補習的內容:
對於一個文件(在Linux下所有都是文件,包括目錄等等) ,如何判斷該文件 是不是目錄,或者是不是符號鏈接, 是通過inode :
如果是目錄,則一定有 inode->i_op->lookup 方法,即 inode->i_op->lookup 一定不是NULL
如果是符號鏈接, 則一定有 inode->i_op->follow_link 方法,即 inode->i_op->follow_link 一定不是NULL
--------------------------------------------------------------------------
對於每一個 mount 的文件系統,都由一個 vfsmount 實例來表示。
對於每一個進程,都有自己的 namespace , 這可以理解爲這個進程的地盤。
在這裏,所有的文件系統都要掛上來統一管理, 如下所示:
task_struct
+-------------+
| |
+-------------+
| name_space |-------\
+-------------+ |
| | |
+-------------+ | namespace