(t *kernel.Task, dirfd int32, addr hostarch.Addr, mode linux.FileMode, dev uint32)
| 50 | } |
| 51 | |
| 52 | func 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). |
| 85 | func Open(t *kernel.Task, sysno uintptr, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) { |
no test coverage detected
searching dependent graphs…