1 #include <linux/module.h>
2 #include <linux/sched.h>
4 #include <linux/path.h>
5 #include <linux/slab.h>
6 #include <linux/fs_struct.h>
9 * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
12 void set_fs_root(struct fs_struct *fs, struct path *path)
16 write_lock(&fs->lock);
20 write_unlock(&fs->lock);
26 * Replace the fs->{pwdmnt,pwd} with {mnt,dentry}. Put the old values.
29 void set_fs_pwd(struct fs_struct *fs, struct path *path)
33 write_lock(&fs->lock);
37 write_unlock(&fs->lock);
43 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45 struct task_struct *g, *p;
49 read_lock(&tasklist_lock);
50 do_each_thread(g, p) {
54 write_lock(&fs->lock);
55 if (fs->root.dentry == old_root->dentry
56 && fs->root.mnt == old_root->mnt) {
61 if (fs->pwd.dentry == old_root->dentry
62 && fs->pwd.mnt == old_root->mnt) {
67 write_unlock(&fs->lock);
70 } while_each_thread(g, p);
71 read_unlock(&tasklist_lock);
76 void free_fs_struct(struct fs_struct *fs)
80 kmem_cache_free(fs_cachep, fs);
83 void exit_fs(struct task_struct *tsk)
85 struct fs_struct *fs = tsk->fs;
90 write_lock(&fs->lock);
93 write_unlock(&fs->lock);
100 struct fs_struct *copy_fs_struct(struct fs_struct *old)
102 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
103 /* We don't need to lock fs - think why ;-) */
107 rwlock_init(&fs->lock);
108 fs->umask = old->umask;
109 get_fs_root_and_pwd(old, &fs->root, &fs->pwd);
114 int unshare_fs_struct(void)
116 struct fs_struct *fs = current->fs;
117 struct fs_struct *new_fs = copy_fs_struct(fs);
124 write_lock(&fs->lock);
126 current->fs = new_fs;
127 write_unlock(&fs->lock);
128 task_unlock(current);
135 EXPORT_SYMBOL_GPL(unshare_fs_struct);
137 int current_umask(void)
139 return current->fs->umask;
141 EXPORT_SYMBOL(current_umask);
143 /* to be mentioned only in INIT_TASK */
144 struct fs_struct init_fs = {
146 .lock = __RW_LOCK_UNLOCKED(init_fs.lock),
150 void daemonize_fs_struct(void)
152 struct fs_struct *fs = current->fs;
159 write_lock(&init_fs.lock);
161 write_unlock(&init_fs.lock);
163 write_lock(&fs->lock);
164 current->fs = &init_fs;
166 write_unlock(&fs->lock);
168 task_unlock(current);