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