line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ # |
2
|
|
|
|
|
|
|
# Quota.pm - Copyright (C) 1995-2020 T. Zoerner |
3
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ # |
4
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify |
5
|
|
|
|
|
|
|
# it either under the terms of the Perl Artistic License or the GNU |
6
|
|
|
|
|
|
|
# General Public License as published by the Free Software Foundation. |
7
|
|
|
|
|
|
|
# (Either version 1 of the GPL, or any later version.) |
8
|
|
|
|
|
|
|
# For a copy of these licenses see . |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, |
11
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
|
|
|
|
# Perl Artistic License or GNU General Public License for more details. |
14
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ # |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package Quota; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
require Exporter; |
19
|
1
|
|
|
1
|
|
966
|
use AutoLoader; |
|
1
|
|
|
|
|
1222
|
|
|
1
|
|
|
|
|
5
|
|
20
|
|
|
|
|
|
|
require DynaLoader; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
@ISA = qw(Exporter DynaLoader); |
23
|
|
|
|
|
|
|
@EXPORT = (); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$VERSION = '1.8.0'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
bootstrap Quota; |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
1
|
|
59
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
78
|
|
30
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
627
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
## |
33
|
|
|
|
|
|
|
## Get block device for locally mounted file system |
34
|
|
|
|
|
|
|
## !! Do not use this to get the argument for the quota-functions in this |
35
|
|
|
|
|
|
|
## !! module, since not all operating systems use the device path for the |
36
|
|
|
|
|
|
|
## !! quotactl system call and e.g. Solaris doesn't even use a system call |
37
|
|
|
|
|
|
|
## !! Always use getqcarg() instead. |
38
|
|
|
|
|
|
|
## |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub getdev { |
41
|
0
|
0
|
|
0
|
1
|
|
($#_ > 0) && croak("Usage: Quota::getdev(path)"); |
42
|
0
|
0
|
|
|
|
|
my($target) = (($#_ == -1) ? "." : $_[0]); |
43
|
0
|
|
|
|
|
|
my($dev) = (stat($target))[0]; |
44
|
0
|
|
|
|
|
|
my($ret) = undef; |
45
|
0
|
|
|
|
|
|
my($fsname,$path); |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
0
|
|
|
|
if($dev && ($target ne "") && !Quota::setmntent()) { |
|
|
|
0
|
|
|
|
|
48
|
0
|
|
|
|
|
|
while(($fsname,$path) = Quota::getmntent()) { |
49
|
0
|
0
|
|
|
|
|
($ret=$fsname, last) if ($dev == (stat($path))[0]); |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
|
$! = 0; |
52
|
|
|
|
|
|
|
} |
53
|
0
|
|
|
|
|
|
Quota::endmntent(); |
54
|
0
|
|
|
|
|
|
$ret; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
## |
58
|
|
|
|
|
|
|
## Get "device" argument for this module's Quota-functions |
59
|
|
|
|
|
|
|
## |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub getqcarg { |
62
|
0
|
0
|
|
0
|
1
|
|
($#_ > 0) && croak("Usage: Quota::getqcarg(path)"); |
63
|
0
|
0
|
|
|
|
|
my($target) = (($#_ == -1) ? "." : $_[0]); |
64
|
0
|
|
|
|
|
|
my($dev) = (stat($target))[0]; |
65
|
0
|
|
|
|
|
|
my($ret) = undef; |
66
|
0
|
|
|
|
|
|
my($argtyp,$fsupp) = (Quota::getqcargtype() =~ /([^,]*)(,.*)?/); |
67
|
0
|
|
|
|
|
|
my($fsname,$path,$fstyp,$fsopt); |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
0
|
|
|
|
if(defined($dev) && ($target ne "") && !Quota::setmntent()) { |
|
|
|
0
|
|
|
|
|
70
|
0
|
|
|
|
|
|
while(($fsname,$path,$fstyp,$fsopt) = Quota::getmntent()) { |
71
|
0
|
0
|
|
|
|
|
next if $fstyp =~ /^(lofs|ignore|auto.*|proc|rootfs)$/; |
72
|
0
|
|
|
|
|
|
my($pdev) = (stat($path))[0]; |
73
|
0
|
0
|
0
|
|
|
|
if (defined($pdev) && ($dev == $pdev)) { |
74
|
0
|
0
|
0
|
|
|
|
if ($fsname =~ m|^[^/]+:/|) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$ret = $fsname; #NFS host:/path |
76
|
|
|
|
|
|
|
} elsif (($fstyp =~ /^nfs/i) && ($fsname =~ m#^(/.*)\@([^/]+)$#)) { |
77
|
0
|
|
|
|
|
|
$ret = "$2:$1"; #NFS /path@host |
78
|
|
|
|
|
|
|
} elsif ($argtyp eq "dev") { |
79
|
0
|
0
|
|
|
|
|
if ($fsopt =~ m#(^|,)loop=(/dev/[^,]+)#) { |
80
|
0
|
|
|
|
|
|
$ret = $2; # Linux mount -o loop |
81
|
|
|
|
|
|
|
} else { |
82
|
0
|
|
|
|
|
|
$ret = $fsname; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} elsif ($argtyp eq "qfile") { |
85
|
0
|
|
|
|
|
|
$ret = "$path/quotas"; |
86
|
|
|
|
|
|
|
} elsif ($argtyp eq "any") { |
87
|
0
|
|
|
|
|
|
$ret = $target; |
88
|
|
|
|
|
|
|
} else { #($argtyp eq "mntpt") |
89
|
0
|
|
|
|
|
|
$ret = $path; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# XFS, VxFS and AFS quotas require separate access methods |
93
|
|
|
|
|
|
|
# (optional for VxFS: later versions use 'normal' quota interface) |
94
|
0
|
0
|
0
|
|
|
|
if (($fstyp eq "xfs") && ($fsupp =~ /,XFS/)) { $ret = "(XFS)$ret" } |
|
0
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
95
|
|
|
|
|
|
|
elsif(($fstyp eq "vxfs") && |
96
|
0
|
|
|
|
|
|
defined($fsupp) && ($fsupp =~ /,VXFS/)) { $ret = "(VXFS)$ret" } |
97
|
|
|
|
|
|
|
elsif((($fstyp eq "afs") || ($fsname eq "AFS")) && |
98
|
0
|
|
|
|
|
|
($fsupp =~ /,AFS/)) { $ret = "(AFS)$target"; } |
99
|
0
|
0
|
0
|
|
|
|
if (($fstyp eq "jfs2") && ($fsupp =~ /,JFS2/)) { $ret = "(JFS2)$ret" } |
|
0
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
last; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
0
|
|
|
|
|
|
$! = 0; |
104
|
|
|
|
|
|
|
} |
105
|
0
|
|
|
|
|
|
Quota::endmntent(); |
106
|
0
|
|
|
|
|
|
$ret; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
package Quota; # return to package Quota so AutoSplit is happy |
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
__END__ |