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)
17 write_seqcount_begin(&fs->seq);
21 write_seqcount_end(&fs->seq);
22 spin_unlock(&fs->lock);
28 * Replace the fs->{pwdmnt,pwd} with {mnt,dentry}. Put the old values.
31 void set_fs_pwd(struct fs_struct *fs, struct path *path)
36 write_seqcount_begin(&fs->seq);
40 write_seqcount_end(&fs->seq);
41 spin_unlock(&fs->lock);
47 void chroot_fs_refs(struct path *old_root, struct path *new_root)
49 struct task_struct *g, *p;
53 read_lock(&tasklist_lock);
54 do_each_thread(g, p) {
59 write_seqcount_begin(&fs->seq);
60 if (fs->root.dentry == old_root->dentry
61 && fs->root.mnt == old_root->mnt) {
66 if (fs->pwd.dentry == old_root->dentry
67 && fs->pwd.mnt == old_root->mnt) {
72 write_seqcount_end(&fs->seq);
73 spin_unlock(&fs->lock);
76 } while_each_thread(g, p);
77 read_unlock(&tasklist_lock);
82 void free_fs_struct(struct fs_struct *fs)
86 kmem_cache_free(fs_cachep, fs);
89 void exit_fs(struct task_struct *tsk)
91 struct fs_struct *fs = tsk->fs;
97 write_seqcount_begin(&fs->seq);
100 write_seqcount_end(&fs->seq);
101 spin_unlock(&fs->lock);
108 struct fs_struct *copy_fs_struct(struct fs_struct *old)
110 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
111 /* We don't need to lock fs - think why ;-) */
115 spin_lock_init(&fs->lock);
116 seqcount_init(&fs->seq);
117 fs->umask = old->umask;
118 get_fs_root_and_pwd(old, &fs->root, &fs->pwd);
123 int unshare_fs_struct(void)
125 struct fs_struct *fs = current->fs;
126 struct fs_struct *new_fs = copy_fs_struct(fs);
133 spin_lock(&fs->lock);
135 current->fs = new_fs;
136 spin_unlock(&fs->lock);
137 task_unlock(current);
144 EXPORT_SYMBOL_GPL(unshare_fs_struct);
146 int current_umask(void)
148 return current->fs->umask;
150 EXPORT_SYMBOL(current_umask);
152 /* to be mentioned only in INIT_TASK */
153 struct fs_struct init_fs = {
155 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
160 void daemonize_fs_struct(void)
162 struct fs_struct *fs = current->fs;
169 spin_lock(&init_fs.lock);
171 spin_unlock(&init_fs.lock);
173 spin_lock(&fs->lock);
174 current->fs = &init_fs;
176 spin_unlock(&fs->lock);
178 task_unlock(current);