1 #ifndef _LINUX_FS_STRUCT_H
2 #define _LINUX_FS_STRUCT_H
3 #ifdef __KERNEL__
4 
5 struct fs_struct {
6 	atomic_t count;
7 	rwlock_t lock;
8 	int umask;
9 	struct dentry * root, * pwd, * altroot;
10 	struct vfsmount * rootmnt, * pwdmnt, * altrootmnt;
11 };
12 
13 #define INIT_FS { \
14 	ATOMIC_INIT(1), \
15 	RW_LOCK_UNLOCKED, \
16 	0022, \
17 	NULL, NULL, NULL, NULL, NULL, NULL \
18 }
19 
20 extern void exit_fs(struct task_struct *);
21 extern void set_fs_altroot(void);
22 
23 /*
24  * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
25  * It can block. Requires the big lock held.
26  */
27 
set_fs_root(struct fs_struct * fs,struct vfsmount * mnt,struct dentry * dentry)28 static inline void set_fs_root(struct fs_struct *fs,
29 	struct vfsmount *mnt,
30 	struct dentry *dentry)
31 {
32 	struct dentry *old_root;
33 	struct vfsmount *old_rootmnt;
34 	write_lock(&fs->lock);
35 	old_root = fs->root;
36 	old_rootmnt = fs->rootmnt;
37 	fs->rootmnt = mntget(mnt);
38 	fs->root = dget(dentry);
39 	write_unlock(&fs->lock);
40 	if (old_root) {
41 		dput(old_root);
42 		mntput(old_rootmnt);
43 	}
44 }
45 
46 /*
47  * Replace the fs->{pwdmnt,pwd} with {mnt,dentry}. Put the old values.
48  * It can block. Requires the big lock held.
49  */
50 
set_fs_pwd(struct fs_struct * fs,struct vfsmount * mnt,struct dentry * dentry)51 static inline void set_fs_pwd(struct fs_struct *fs,
52 	struct vfsmount *mnt,
53 	struct dentry *dentry)
54 {
55 	struct dentry *old_pwd;
56 	struct vfsmount *old_pwdmnt;
57 	write_lock(&fs->lock);
58 	old_pwd = fs->pwd;
59 	old_pwdmnt = fs->pwdmnt;
60 	fs->pwdmnt = mntget(mnt);
61 	fs->pwd = dget(dentry);
62 	write_unlock(&fs->lock);
63 	if (old_pwd) {
64 		dput(old_pwd);
65 		mntput(old_pwdmnt);
66 	}
67 }
68 
69 struct fs_struct *copy_fs_struct(struct fs_struct *old);
70 void put_fs_struct(struct fs_struct *fs);
71 
72 #endif
73 #endif
74