]> git.proxmox.com Git - pve-common.git/blame - src/PVE/Syscall.pm
tools: Add mknod syscall
[pve-common.git] / src / PVE / Syscall.pm
CommitLineData
c8e94d4b
TL
1package PVE::Syscall;
2
967e9823
TL
3use strict;
4use warnings;
5
c8e94d4b 6my %syscalls;
5569cc16 7my %fsmount_constants;
c8e94d4b
TL
8BEGIN {
9 die "syscall.ph can only be required once!\n" if $INC{'syscall.ph'};
10 require("syscall.ph");
11 %syscalls = (
12 unshare => &SYS_unshare,
13 setns => &SYS_setns,
14 syncfs => &SYS_syncfs,
cee0e23a 15 fsync => &SYS_fsync,
c8e94d4b
TL
16 openat => &SYS_openat,
17 close => &SYS_close,
18 mkdirat => &SYS_mkdirat,
b792e8df 19 mknod => &SYS_mknod,
c8e94d4b 20 faccessat => &SYS_faccessat,
0c078e66 21 setresuid => &SYS_setresuid,
6cf6b404 22 fchownat => &SYS_fchownat,
5569cc16 23 mount => &SYS_mount,
bd9eb367 24 renameat2 => &SYS_renameat2,
bfa10639
TL
25 open_tree => &SYS_open_tree,
26 move_mount => &SYS_move_mount,
27 fsopen => &SYS_fsopen,
28 fsconfig => &SYS_fsconfig,
29 fsmount => &SYS_fsmount,
30 fspick => &SYS_fspick,
4c0c5c90
TL
31 getxattr => &SYS_getxattr,
32 setxattr => &SYS_setxattr,
33 fgetxattr => &SYS_fgetxattr,
34 fsetxattr => &SYS_fsetxattr,
bfa10639
TL
35
36 # Below aren't yet in perl's syscall.ph but use asm-generic, so the same across (sane) archs
37 # -> none unknown currently, yay
5569cc16
WB
38 );
39
40 %fsmount_constants = (
41 OPEN_TREE_CLONE => 0x0000_0001,
42 OPEN_TREE_CLOEXEC => 000200_0000, # octal!
43
44 MOVE_MOUNT_F_SYMLINKS => 0x0000_0001,
45 MOVE_MOUNT_F_AUTOMOUNTS => 0x0000_0002,
46 MOVE_MOUNT_F_EMPTY_PATH => 0x0000_0004,
47 MOVE_MOUNT_F_MASK => 0x0000_0007,
48
49 MOVE_MOUNT_T_SYMLINKS => 0x0000_0010,
50 MOVE_MOUNT_T_AUTOMOUNTS => 0x0000_0020,
51 MOVE_MOUNT_T_EMPTY_PATH => 0x0000_0040,
52 MOVE_MOUNT_T_MASK => 0x0000_0070,
53
54 FSMOUNT_CLOEXEC => 0x0000_0001,
55
56 FSOPEN_CLOEXEC => 0x0000_0001,
57
58 MOUNT_ATTR_RDONLY => 0x0000_0001,
59 MOUNT_ATTR_NOSUID => 0x0000_0002,
60 MOUNT_ATTR_NODEV => 0x0000_0004,
61 MOUNT_ATTR_NOEXEC => 0x0000_0008,
62 MOUNT_ATTR_RELATIME => 0x0000_0000,
63 MOUNT_ATTR_NOATIME => 0x0000_0010,
64 MOUNT_ATTR_STRICTATIME => 0x0000_0020,
65 MOUNT_ATTR_NODIRATIME => 0x0000_0080,
66
67 FSPICK_CLOEXEC => 0x0000_0001,
68 FSPICK_SYMLINK_NOFOLLOW => 0x0000_0002,
69 FSPICK_NO_AUTOMOUNT => 0x0000_0004,
70 FSPICK_EMPTY_PATH => 0x0000_0008,
71
72 FSCONFIG_SET_FLAG => 0,
73 FSCONFIG_SET_STRING => 1,
74 FSCONFIG_SET_BINARY => 2,
75 FSCONFIG_SET_PATH => 3,
76 FSCONFIG_SET_PATH_EMPTY => 4,
77 FSCONFIG_SET_FD => 5,
78 FSCONFIG_CMD_CREATE => 6,
79 FSCONFIG_CMD_RECONFIGURE => 7,
c8e94d4b
TL
80 );
81};
82
83use constant \%syscalls;
5569cc16 84use constant \%fsmount_constants;
c8e94d4b
TL
85
86use base 'Exporter';
87
5569cc16
WB
88our @EXPORT_OK = (keys(%syscalls), keys(%fsmount_constants), 'file_handle_result');
89our %EXPORT_TAGS = (fsmount => [keys(%fsmount_constants)]);
90
91# Create a file handle from a numeric file descriptor (to make sure it's close()d when it goes out
92# of scope).
93sub file_handle_result($) {
94 my ($fd_num) = @_;
95 return undef if $fd_num < 0;
96
97 open(my $fh, '<&=', $fd_num)
98 or return undef;
99
100 return $fh;
101}
88c2babd
WB
102
1031;