]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/ProcFSTools.pm
half-revert: remove autostart property from bridge ports
[pve-common.git] / src / PVE / ProcFSTools.pm
index 8bb0d729b50b8ab974cdbc5d3b2ac57d5fe24e70..3dc5680df69aa7b4d96a4c49a95a1aa01d571efd 100644 (file)
@@ -6,6 +6,7 @@ use POSIX;
 use Time::HiRes qw (gettimeofday);
 use IO::File;
 use PVE::Tools;
+use Cwd qw();
 
 my $clock_ticks = POSIX::sysconf(&POSIX::_SC_CLK_TCK);
 
@@ -284,4 +285,47 @@ sub read_proc_net_route {
     return $res;
 }
 
+sub read_proc_mounts {
+    return PVE::Tools::file_get_contents("/proc/mounts");
+}
+
+sub is_mounted {
+    my ($mountpoint) = @_;
+
+    $mountpoint = Cwd::realpath($mountpoint);
+
+    my $mountdata = read_proc_mounts();
+
+    if ($mountdata =~ m/\s$mountpoint\s/) {
+       return 1;
+    } else {
+       return 0;
+    }
+}
+
+sub read_proc_net_ipv6_route {
+    my $filename = "/proc/net/ipv6_route";
+
+    my $res = [];
+
+    my $fh = IO::File->new ($filename, "r");
+    return $res if !$fh;
+
+    my $read_v6addr = sub { s/....(?!$)/$&:/g };
+
+    # ipv6_route has no header
+    while (defined(my $line = <$fh>)) {
+       my ($dest, $prefix, $nexthop, $metric, $iface) = (split(/\s+/, $line))[0,1,4,5,9];
+       push @$res, {
+           dest => &$read_v6addr($dest),
+           prefix => $prefix,
+           gateway => &$read_v6addr($nexthop),
+           metric => $metric,
+           iface => $iface
+       };
+    }
+
+    return $res;
+}
+
 1;