]>
git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - fs/fs_struct.c
1 #include <linux/export.h>
2 #include <linux/sched.h>
4 #include <linux/path.h>
5 #include <linux/slab.h>
6 #include <linux/fs_struct.h>
10 * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
13 void set_fs_root(struct fs_struct
*fs
, const struct path
*path
)
19 write_seqcount_begin(&fs
->seq
);
22 write_seqcount_end(&fs
->seq
);
23 spin_unlock(&fs
->lock
);
29 * Replace the fs->{pwdmnt,pwd} with {mnt,dentry}. Put the old values.
32 void set_fs_pwd(struct fs_struct
*fs
, const struct path
*path
)
38 write_seqcount_begin(&fs
->seq
);
41 write_seqcount_end(&fs
->seq
);
42 spin_unlock(&fs
->lock
);
48 static inline int replace_path(struct path
*p
, const struct path
*old
, const struct path
*new)
50 if (likely(p
->dentry
!= old
->dentry
|| p
->mnt
!= old
->mnt
))
56 void chroot_fs_refs(const struct path
*old_root
, const struct path
*new_root
)
58 struct task_struct
*g
, *p
;
62 read_lock(&tasklist_lock
);
63 do_each_thread(g
, p
) {
69 write_seqcount_begin(&fs
->seq
);
70 hits
+= replace_path(&fs
->root
, old_root
, new_root
);
71 hits
+= replace_path(&fs
->pwd
, old_root
, new_root
);
72 write_seqcount_end(&fs
->seq
);
77 spin_unlock(&fs
->lock
);
80 } while_each_thread(g
, p
);
81 read_unlock(&tasklist_lock
);
86 void free_fs_struct(struct fs_struct
*fs
)
90 kmem_cache_free(fs_cachep
, fs
);
93 void exit_fs(struct task_struct
*tsk
)
95 struct fs_struct
*fs
= tsk
->fs
;
100 spin_lock(&fs
->lock
);
103 spin_unlock(&fs
->lock
);
110 struct fs_struct
*copy_fs_struct(struct fs_struct
*old
)
112 struct fs_struct
*fs
= kmem_cache_alloc(fs_cachep
, GFP_KERNEL
);
113 /* We don't need to lock fs - think why ;-) */
117 spin_lock_init(&fs
->lock
);
118 seqcount_init(&fs
->seq
);
119 fs
->umask
= old
->umask
;
121 spin_lock(&old
->lock
);
122 fs
->root
= old
->root
;
126 spin_unlock(&old
->lock
);
131 int unshare_fs_struct(void)
133 struct fs_struct
*fs
= current
->fs
;
134 struct fs_struct
*new_fs
= copy_fs_struct(fs
);
141 spin_lock(&fs
->lock
);
143 current
->fs
= new_fs
;
144 spin_unlock(&fs
->lock
);
145 task_unlock(current
);
152 EXPORT_SYMBOL_GPL(unshare_fs_struct
);
154 int current_umask(void)
156 return current
->fs
->umask
;
158 EXPORT_SYMBOL(current_umask
);
160 /* to be mentioned only in INIT_TASK */
161 struct fs_struct init_fs
= {
163 .lock
= __SPIN_LOCK_UNLOCKED(init_fs
.lock
),
164 .seq
= SEQCNT_ZERO(init_fs
.seq
),