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