[pve-devel] [PATCH common 1/2] added: openat, mkdirat
Wolfgang Bumiller
w.bumiller at proxmox.com
Tue May 31 14:58:26 CEST 2016
---
src/PVE/Tools.pm | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index 8c7f373..3ad3794 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -12,6 +12,7 @@ use Filesys::Df (); # don't overwrite our df()
use IO::Pipe;
use IO::File;
use IO::Dir;
+use IO::Handle;
use IPC::Open3;
use Fcntl qw(:DEFAULT :flock);
use base 'Exporter';
@@ -1322,4 +1323,24 @@ sub validate_ssh_public_keys {
}
}
+sub openat($$$;$) {
+ my ($dirfd, $pathname, $flags, $mode) = @_;
+ my $fd = syscall(257, $dirfd, $pathname, $flags, $mode//0);
+ return undef if $fd < 0;
+ # sysopen() doesn't deal with numeric file descriptors apparently
+ # so we need to convert to a mode string for IO::Handle->new_from_fd
+ my $flagstr = ($flags & O_RDWR) ? 'rw' : ($flags & O_WRONLY) ? 'w' : 'r';
+ my $handle = IO::Handle->new_from_fd($fd, $flagstr);
+ return $handle if $handle;
+ my $err = $!; # save error before closing the raw fd
+ syscall(3, $fd); # close
+ $! = $err;
+ return undef;
+}
+
+sub mkdirat($$$) {
+ my ($dirfd, $name, $mode) = @_;
+ return syscall(258, $dirfd, $name, $mode) == 0;
+}
+
1;
--
2.1.4
More information about the pve-devel
mailing list