2017-11-01 14:08:43 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
|
2016-09-06 07:47:14 +00:00
|
|
|
#ifndef __LINUX_NSFS_H
|
|
|
|
#define __LINUX_NSFS_H
|
|
|
|
|
|
|
|
#include <linux/ioctl.h>
|
2024-07-31 05:47:27 +00:00
|
|
|
#include <linux/types.h>
|
2016-09-06 07:47:14 +00:00
|
|
|
|
|
|
|
#define NSIO 0xb7
|
|
|
|
|
|
|
|
/* Returns a file descriptor that refers to an owning user namespace */
|
2017-01-25 01:04:15 +00:00
|
|
|
#define NS_GET_USERNS _IO(NSIO, 0x1)
|
2016-09-06 07:47:15 +00:00
|
|
|
/* Returns a file descriptor that refers to a parent namespace */
|
2017-01-25 01:04:15 +00:00
|
|
|
#define NS_GET_PARENT _IO(NSIO, 0x2)
|
nsfs: Add an ioctl() to return the namespace type
Linux 4.9 added two ioctl() operations that can be used to discover:
* the parental relationships for hierarchical namespaces (user and PID)
[NS_GET_PARENT]
* the user namespaces that owns a specified non-user-namespace
[NS_GET_USERNS]
For no good reason that I can glean, NS_GET_USERNS was made synonymous
with NS_GET_PARENT for user namespaces. It might have been better if
NS_GET_USERNS had returned an error if the supplied file descriptor
referred to a user namespace, since it suggests that the caller may be
confused. More particularly, if it had generated an error, then I wouldn't
need the new ioctl() operation proposed here. (On the other hand, what
I propose here may be more generally useful.)
I would like to write code that discovers namespace relationships for
the purpose of understanding the namespace setup on a running system.
In particular, given a file descriptor (or pathname) for a namespace,
N, I'd like to obtain the corresponding user namespace. Namespace N
might be a user namespace (in which case my code would just use N) or
a non-user namespace (in which case my code will use NS_GET_USERNS to
get the user namespace associated with N). The problem is that there
is no way to tell the difference by looking at the file descriptor
(and if I try to use NS_GET_USERNS on an N that is a user namespace, I
get the parent user namespace of N, which is not what I want).
This patch therefore adds a new ioctl(), NS_GET_NSTYPE, which, given
a file descriptor that refers to a user namespace, returns the
namespace type (one of the CLONE_NEW* constants).
Signed-off-by: Michael Kerrisk <mtk-manpages@gmail.com>
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
2017-01-25 01:03:36 +00:00
|
|
|
/* Returns the type of namespace (CLONE_NEW* value) referred to by
|
|
|
|
file descriptor */
|
2017-01-25 01:04:15 +00:00
|
|
|
#define NS_GET_NSTYPE _IO(NSIO, 0x3)
|
|
|
|
/* Get owner UID (in the caller's user namespace) for a user namespace */
|
|
|
|
#define NS_GET_OWNER_UID _IO(NSIO, 0x4)
|
2024-06-24 15:49:50 +00:00
|
|
|
/* Get the id for a mount namespace */
|
2024-07-31 05:47:27 +00:00
|
|
|
#define NS_GET_MNTNS_ID _IOR(NSIO, 0x5, __u64)
|
2020-06-07 20:47:08 +00:00
|
|
|
/* Translate pid from target pid namespace into the caller's pid namespace. */
|
2024-07-15 19:27:39 +00:00
|
|
|
#define NS_GET_PID_FROM_PIDNS _IOR(NSIO, 0x6, int)
|
2020-06-07 20:47:08 +00:00
|
|
|
/* Return thread-group leader id of pid in the callers pid namespace. */
|
|
|
|
#define NS_GET_TGID_FROM_PIDNS _IOR(NSIO, 0x7, int)
|
|
|
|
/* Translate pid from caller's pid namespace into a target pid namespace. */
|
2024-07-15 19:27:39 +00:00
|
|
|
#define NS_GET_PID_IN_PIDNS _IOR(NSIO, 0x8, int)
|
2020-06-07 20:47:08 +00:00
|
|
|
/* Return thread-group leader id of pid in the target pid namespace. */
|
2024-07-15 19:27:39 +00:00
|
|
|
#define NS_GET_TGID_IN_PIDNS _IOR(NSIO, 0x9, int)
|
2016-09-06 07:47:14 +00:00
|
|
|
|
2024-07-19 11:41:52 +00:00
|
|
|
struct mnt_ns_info {
|
|
|
|
__u32 size;
|
|
|
|
__u32 nr_mounts;
|
|
|
|
__u64 mnt_ns_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MNT_NS_INFO_SIZE_VER0 16 /* size of first published struct */
|
|
|
|
|
|
|
|
/* Get information about namespace. */
|
|
|
|
#define NS_MNT_GET_INFO _IOR(NSIO, 10, struct mnt_ns_info)
|
|
|
|
/* Get next namespace. */
|
|
|
|
#define NS_MNT_GET_NEXT _IOR(NSIO, 11, struct mnt_ns_info)
|
|
|
|
/* Get previous namespace. */
|
|
|
|
#define NS_MNT_GET_PREV _IOR(NSIO, 12, struct mnt_ns_info)
|
|
|
|
|
2016-09-06 07:47:14 +00:00
|
|
|
#endif /* __LINUX_NSFS_H */
|