MCPcopy
hub / github.com/google/gvisor / mknodat

Function mknodat

pkg/sentry/syscalls/linux/sys_file.go:52–82  ·  view source on GitHub ↗
(t *kernel.Task, dirfd int32, addr hostarch.Addr, mode linux.FileMode, dev uint32)

Source from the content-addressed store, hash-verified

50}
51
52func mknodat(t *kernel.Task, dirfd int32, addr hostarch.Addr, mode linux.FileMode, dev uint32) error {
53 path, err := copyInPath(t, addr)
54 if err != nil {
55 return err
56 }
57 tpop, err := getTaskPathOperation(t, dirfd, path, disallowEmptyPath, nofollowFinalSymlink)
58 if err != nil {
59 return err
60 }
61 defer tpop.Release(t)
62
63 switch ft := mode.FileType(); ft {
64 case 0:
65 // "Zero file type is equivalent to type S_IFREG." - mknod(2)
66 mode |= linux.ModeRegular
67 case linux.ModeCharacterDevice, linux.ModeBlockDevice:
68 // Linux requires CAP_MKNOD in the init user namespace to create
69 // block or character device nodes, except for whiteouts (S_IFCHR
70 // with device number WHITEOUT_DEV). See fs/namei.c:vfs_mknod().
71 isWhiteout := ft == linux.ModeCharacterDevice && dev == linux.WHITEOUT_DEV
72 if !isWhiteout && !t.HasRootCapability(linux.CAP_MKNOD) {
73 return linuxerr.EPERM
74 }
75 }
76 major, minor := linux.DecodeDeviceID(dev)
77 return t.Kernel().VFS().MknodAt(t, t.Credentials(), &tpop.pop, &vfs.MknodOptions{
78 Mode: mode &^ linux.FileMode(t.FSContext().Umask()),
79 DevMajor: uint32(major),
80 DevMinor: minor,
81 })
82}
83
84// Open implements Linux syscall open(2).
85func Open(t *kernel.Task, sysno uintptr, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) {

Callers 2

MknodFunction · 0.85
MknodatFunction · 0.85

Calls 13

DecodeDeviceIDFunction · 0.92
FileModeTypeAlias · 0.92
copyInPathFunction · 0.85
getTaskPathOperationFunction · 0.85
VFSMethod · 0.80
KernelMethod · 0.80
UmaskMethod · 0.80
FSContextMethod · 0.80
ReleaseMethod · 0.65
MknodAtMethod · 0.65
CredentialsMethod · 0.65
FileTypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…