| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # ------------------------------------------------------------------------ # | 
| 2 |  |  |  |  |  |  | # Quota.pm - Copyright (C) 1995-2021 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 |  | 2165 | use AutoLoader; | 
|  | 1 |  |  |  |  | 1607 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 20 |  |  |  |  |  |  | require DynaLoader; | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | @ISA = qw(Exporter DynaLoader); | 
| 23 |  |  |  |  |  |  | @EXPORT = (); | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | $VERSION = '1.8.2'; | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | bootstrap Quota; | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 1 |  |  | 1 |  | 73 | use Carp; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 81 |  | 
| 30 | 1 |  |  | 1 |  | 7 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 750 |  | 
| 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 | 37 | 50 |  | 37 | 1 | 11472 | ($#_ > 0) && croak("Usage: Quota::getdev(path)"); | 
| 42 | 37 | 50 |  |  |  | 103 | my($target) = (($#_ == -1) ? "." : $_[0]); | 
| 43 | 37 |  |  |  |  | 484 | my($dev) = (stat($target))[0]; | 
| 44 | 37 |  |  |  |  | 113 | my($ret) = undef; | 
| 45 | 37 |  |  |  |  | 57 | my($fsname,$path); | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 37 | 50 | 33 |  |  | 919 | if(defined($dev) && ($target ne "") && !Quota::setmntent()) { | 
|  |  |  | 33 |  |  |  |  | 
| 48 | 37 |  |  |  |  | 2449 | while(($fsname,$path) = Quota::getmntent()) { | 
| 49 | 441 | 100 |  |  |  | 7860 | ($ret=$fsname, last) if ($dev == (stat($path))[0]); | 
| 50 |  |  |  |  |  |  | } | 
| 51 | 37 |  |  |  |  | 137 | $! = 0; | 
| 52 |  |  |  |  |  |  | } | 
| 53 | 37 |  |  |  |  | 351 | Quota::endmntent(); | 
| 54 | 37 |  |  |  |  | 163 | $ret; | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | ## | 
| 58 |  |  |  |  |  |  | ##  Get "device" argument for this module's Quota-functions | 
| 59 |  |  |  |  |  |  | ## | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | sub getqcarg { | 
| 62 | 37 | 50 |  | 37 | 1 | 309 | ($#_ > 0) && croak("Usage: Quota::getqcarg(path)"); | 
| 63 | 37 | 50 |  |  |  | 103 | my($target) = (($#_ == -1) ? "." : $_[0]); | 
| 64 | 37 |  |  |  |  | 403 | my($dev) = (stat($target))[0]; | 
| 65 | 37 |  |  |  |  | 103 | my($ret) = undef; | 
| 66 | 37 |  |  |  |  | 303 | my($argtyp,$fsupp) = (Quota::getqcargtype() =~ /([^,]*)(,.*)?/); | 
| 67 | 37 |  |  |  |  | 72 | my($fsname,$path,$fstyp,$fsopt); | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 37 | 50 | 33 |  |  | 918 | if(defined($dev) && ($target ne "") && !Quota::setmntent()) { | 
|  |  |  | 33 |  |  |  |  | 
| 70 | 37 |  |  |  |  | 2413 | while(($fsname,$path,$fstyp,$fsopt) = Quota::getmntent()) { | 
| 71 | 651 | 100 |  |  |  | 2608 | next if $fstyp =~ /^(lofs|ignore|auto.*|proc|rootfs)$/; | 
| 72 | 570 |  |  |  |  | 6233 | my($pdev) = (stat($path))[0]; | 
| 73 | 570 | 100 | 66 |  |  | 6075 | if (defined($pdev) && ($dev == $pdev)) { | 
| 74 | 31 | 50 | 33 |  |  | 166 | if ($fsname =~ m|^[^/]+:/|) { | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
| 75 | 0 |  |  |  |  | 0 | $ret = $fsname;  #NFS host:/path | 
| 76 |  |  |  |  |  |  | } elsif (($fstyp =~ /^nfs/i) && ($fsname =~ m#^(/.*)\@([^/]+)$#)) { | 
| 77 | 0 |  |  |  |  | 0 | $ret = "$2:$1";  #NFS /path@host | 
| 78 |  |  |  |  |  |  | } elsif ($argtyp eq "dev") { | 
| 79 | 31 | 50 |  |  |  | 71 | if ($fsopt =~ m#(^|,)loop=(/dev/[^,]+)#) { | 
| 80 | 0 |  |  |  |  | 0 | $ret = $2;  # Linux mount -o loop | 
| 81 |  |  |  |  |  |  | } else { | 
| 82 | 31 |  |  |  |  | 55 | $ret = $fsname; | 
| 83 |  |  |  |  |  |  | } | 
| 84 |  |  |  |  |  |  | } elsif ($argtyp eq "qfile") { | 
| 85 | 0 |  |  |  |  | 0 | $ret = "$path/quotas"; | 
| 86 |  |  |  |  |  |  | } elsif ($argtyp eq "any") { | 
| 87 | 0 |  |  |  |  | 0 | $ret = $target; | 
| 88 |  |  |  |  |  |  | } else { #($argtyp eq "mntpt") | 
| 89 | 0 |  |  |  |  | 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 | 31 | 50 | 33 |  |  | 162 | if   (($fstyp eq "xfs") && ($fsupp =~ /,XFS/)) { $ret = "(XFS)$ret" } | 
|  | 0 | 50 | 33 |  |  | 0 |  | 
|  |  | 50 | 33 |  |  |  |  | 
|  |  |  | 33 |  |  |  |  | 
|  |  |  | 33 |  |  |  |  | 
| 95 |  |  |  |  |  |  | elsif(($fstyp eq "vxfs") && | 
| 96 | 0 |  |  |  |  | 0 | defined($fsupp) && ($fsupp =~ /,VXFS/)) { $ret = "(VXFS)$ret" } | 
| 97 |  |  |  |  |  |  | elsif((($fstyp eq "afs") || ($fsname eq "AFS")) && | 
| 98 | 0 |  |  |  |  | 0 | ($fsupp =~ /,AFS/)) { $ret = "(AFS)$target"; } | 
| 99 | 31 | 50 | 33 |  |  | 61 | if   (($fstyp eq "jfs2") && ($fsupp =~ /,JFS2/)) { $ret = "(JFS2)$ret" } | 
|  | 0 |  |  |  |  | 0 |  | 
| 100 | 31 |  |  |  |  | 60 | last; | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  | } | 
| 103 | 37 |  |  |  |  | 92 | $! = 0; | 
| 104 |  |  |  |  |  |  | } | 
| 105 | 37 |  |  |  |  | 388 | Quota::endmntent(); | 
| 106 | 37 |  |  |  |  | 181 | $ret; | 
| 107 |  |  |  |  |  |  | } | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | package Quota; # return to package Quota so AutoSplit is happy | 
| 110 |  |  |  |  |  |  | 1; | 
| 111 |  |  |  |  |  |  | __END__ |