xref: /linux/include/linux/nsfs.h (revision 18b19abc3709b109676ffd1f48dcd332c2e477d4)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2025 Christian Brauner <brauner@kernel.org> */
3 
4 #ifndef _LINUX_NSFS_H
5 #define _LINUX_NSFS_H
6 
7 #include <linux/ns_common.h>
8 #include <linux/cred.h>
9 #include <linux/pid_namespace.h>
10 
11 struct path;
12 struct task_struct;
13 struct proc_ns_operations;
14 
15 int ns_get_path(struct path *path, struct task_struct *task,
16 		const struct proc_ns_operations *ns_ops);
17 typedef struct ns_common *ns_get_path_helper_t(void *);
18 int ns_get_path_cb(struct path *path, ns_get_path_helper_t ns_get_cb,
19 		   void *private_data);
20 
21 bool ns_match(const struct ns_common *ns, dev_t dev, ino_t ino);
22 
23 int ns_get_name(char *buf, size_t size, struct task_struct *task,
24 			const struct proc_ns_operations *ns_ops);
25 void nsfs_init(void);
26 
27 #define __current_namespace_from_type(__ns)				\
28 	_Generic((__ns),						\
29 		struct cgroup_namespace *: current->nsproxy->cgroup_ns,	\
30 		struct ipc_namespace *:    current->nsproxy->ipc_ns,	\
31 		struct net *:              current->nsproxy->net_ns,	\
32 		struct pid_namespace *:    task_active_pid_ns(current),	\
33 		struct mnt_namespace *:    current->nsproxy->mnt_ns,	\
34 		struct time_namespace *:   current->nsproxy->time_ns,	\
35 		struct user_namespace *:   current_user_ns(),		\
36 		struct uts_namespace *:    current->nsproxy->uts_ns)
37 
38 #define current_in_namespace(__ns) (__current_namespace_from_type(__ns) == __ns)
39 
40 #endif /* _LINUX_NSFS_H */
41