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