]> git.proxmox.com Git - pve-common.git/blob - src/PVE/Syscall.pm
tools: Add mknod syscall
[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 mknod => &SYS_mknod,
20 faccessat => &SYS_faccessat,
21 setresuid => &SYS_setresuid,
22 fchownat => &SYS_fchownat,
23 mount => &SYS_mount,
24 renameat2 => &SYS_renameat2,
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,
31 getxattr => &SYS_getxattr,
32 setxattr => &SYS_setxattr,
33 fgetxattr => &SYS_fgetxattr,
34 fsetxattr => &SYS_fsetxattr,
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
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,
80 );
81 };
82
83 use constant \%syscalls;
84 use constant \%fsmount_constants;
85
86 use base 'Exporter';
87
88 our @EXPORT_OK = (keys(%syscalls), keys(%fsmount_constants), 'file_handle_result');
89 our %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).
93 sub 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 }
102
103 1;