1 #include <linux/module.h>
2 #include <linux/sched.h>
4 #include <linux/path.h>
5 #include <linux/slab.h>
8 * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
11 void set_fs_root(struct fs_struct
*fs
, struct path
*path
)
15 write_lock(&fs
->lock
);
19 write_unlock(&fs
->lock
);
25 * Replace the fs->{pwdmnt,pwd} with {mnt,dentry}. Put the old values.
28 void set_fs_pwd(struct fs_struct
*fs
, struct path
*path
)
32 write_lock(&fs
->lock
);
36 write_unlock(&fs
->lock
);
42 void chroot_fs_refs(struct path
*old_root
, struct path
*new_root
)
44 struct task_struct
*g
, *p
;
48 read_lock(&tasklist_lock
);
49 do_each_thread(g
, p
) {
53 write_lock(&fs
->lock
);
54 if (fs
->root
.dentry
== old_root
->dentry
55 && fs
->root
.mnt
== old_root
->mnt
) {
60 if (fs
->pwd
.dentry
== old_root
->dentry
61 && fs
->pwd
.mnt
== old_root
->mnt
) {
66 write_unlock(&fs
->lock
);
69 } while_each_thread(g
, p
);
70 read_unlock(&tasklist_lock
);
75 void free_fs_struct(struct fs_struct
*fs
)
79 kmem_cache_free(fs_cachep
, fs
);
82 void exit_fs(struct task_struct
*tsk
)
84 struct fs_struct
*fs
= tsk
->fs
;
89 write_lock(&fs
->lock
);
92 write_unlock(&fs
->lock
);
99 struct fs_struct
*copy_fs_struct(struct fs_struct
*old
)
101 struct fs_struct
*fs
= kmem_cache_alloc(fs_cachep
, GFP_KERNEL
);
102 /* We don't need to lock fs - think why ;-) */
106 rwlock_init(&fs
->lock
);
107 fs
->umask
= old
->umask
;
108 read_lock(&old
->lock
);
109 fs
->root
= old
->root
;
110 path_get(&old
->root
);
113 read_unlock(&old
->lock
);
118 int unshare_fs_struct(void)
120 struct fs_struct
*fs
= current
->fs
;
121 struct fs_struct
*new_fs
= copy_fs_struct(fs
);
128 write_lock(&fs
->lock
);
130 current
->fs
= new_fs
;
131 write_unlock(&fs
->lock
);
132 task_unlock(current
);
139 EXPORT_SYMBOL_GPL(unshare_fs_struct
);
141 /* to be mentioned only in INIT_TASK */
142 struct fs_struct init_fs
= {
144 .lock
= __RW_LOCK_UNLOCKED(init_fs
.lock
),
148 void daemonize_fs_struct(void)
150 struct fs_struct
*fs
= current
->fs
;
157 write_lock(&init_fs
.lock
);
159 write_unlock(&init_fs
.lock
);
161 write_lock(&fs
->lock
);
162 current
->fs
= &init_fs
;
164 write_unlock(&fs
->lock
);
166 task_unlock(current
);