xref: /openbmc/linux/include/linux/fs_struct.h (revision 26475371)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds #ifndef _LINUX_FS_STRUCT_H
31da177e4SLinus Torvalds #define _LINUX_FS_STRUCT_H
41da177e4SLinus Torvalds 
56ac08c39SJan Blunck #include <linux/path.h>
6c28cc364SNick Piggin #include <linux/spinlock.h>
7c28cc364SNick Piggin #include <linux/seqlock.h>
81da177e4SLinus Torvalds 
91da177e4SLinus Torvalds struct fs_struct {
10498052bbSAl Viro 	int users;
112a4419b5SNick Piggin 	spinlock_t lock;
1226475371SAhmed S. Darwish 	seqcount_spinlock_t seq;
131da177e4SLinus Torvalds 	int umask;
14498052bbSAl Viro 	int in_exec;
157f2da1e7SAl Viro 	struct path root, pwd;
163859a271SKees Cook } __randomize_layout;
171da177e4SLinus Torvalds 
18aa362a83SChristoph Lameter extern struct kmem_cache *fs_cachep;
19aa362a83SChristoph Lameter 
201da177e4SLinus Torvalds extern void exit_fs(struct task_struct *);
21dcf787f3SAl Viro extern void set_fs_root(struct fs_struct *, const struct path *);
22dcf787f3SAl Viro extern void set_fs_pwd(struct fs_struct *, const struct path *);
231da177e4SLinus Torvalds extern struct fs_struct *copy_fs_struct(struct fs_struct *);
24498052bbSAl Viro extern void free_fs_struct(struct fs_struct *);
253e93cd67SAl Viro extern int unshare_fs_struct(void);
261da177e4SLinus Torvalds 
get_fs_root(struct fs_struct * fs,struct path * root)27f7ad3c6bSMiklos Szeredi static inline void get_fs_root(struct fs_struct *fs, struct path *root)
28f7ad3c6bSMiklos Szeredi {
292a4419b5SNick Piggin 	spin_lock(&fs->lock);
30f7ad3c6bSMiklos Szeredi 	*root = fs->root;
31f7ad3c6bSMiklos Szeredi 	path_get(root);
322a4419b5SNick Piggin 	spin_unlock(&fs->lock);
33f7ad3c6bSMiklos Szeredi }
34f7ad3c6bSMiklos Szeredi 
get_fs_pwd(struct fs_struct * fs,struct path * pwd)35f7ad3c6bSMiklos Szeredi static inline void get_fs_pwd(struct fs_struct *fs, struct path *pwd)
36f7ad3c6bSMiklos Szeredi {
372a4419b5SNick Piggin 	spin_lock(&fs->lock);
38f7ad3c6bSMiklos Szeredi 	*pwd = fs->pwd;
39f7ad3c6bSMiklos Szeredi 	path_get(pwd);
402a4419b5SNick Piggin 	spin_unlock(&fs->lock);
41f7ad3c6bSMiklos Szeredi }
42f7ad3c6bSMiklos Szeredi 
433151527eSEric W. Biederman extern bool current_chrooted(void);
443151527eSEric W. Biederman 
451da177e4SLinus Torvalds #endif /* _LINUX_FS_STRUCT_H */
46