2 # Quota functions for HPUX
11 # Returns 1 for user quotas, 2 for group quotas or 3 for both
17 # free_space(filesystem)
18 # Returns an array containing btotal, bfree, ftotal, ffree
23 $out =~ /(\d+) blocks\s+(\d+) files\n.*\s+(\d+) blocks\s+(\d+) files/;
24 return ($3, $1, $4, $2);
27 # quota_can(&mnttab, &fstab)
28 # Can this filesystem type support quotas?
29 # 0 = No quota support (or not turned on in /etc/fstab)
30 # 1 = User quotas only
31 # 2 = Group quotas only
32 # 3 = User and group quotas
35 return $_[0]->[2] eq "hfs" || $_[0]->[2] eq "vxfs" ? 1 : 0;
38 # quota_now(&mnttab, &fstab)
39 # Are quotas currently active?
41 # 1 = User quotas active
42 # 2 = Group quotas active
46 return $_[0]->[3] =~ /,quota/ || $_[0]->[3] =~ /^quota/ ? 1 : 0;
49 # filesystem_users(filesystem)
50 # Fills the array %user with information about all users with quotas
51 # on this filesystem. This may not be all users on the system..
54 local($rep, @rep, $n, $newfmt);
55 $rep = `$config{'user_repquota_command'} $_[0] 2>&1`;
56 if ($?) { return -1; }
57 @rep = split(/\n/, $rep); @rep = @rep[3..$#rep];
58 `uname -r` =~ /(\d+)\.(\d+)/;
59 if ($1 > 10 || $1 == 10 && $2 >= 20) { $newfmt = 1; }
60 for($n=0; $n<@rep; $n++) {
61 if ($newfmt && $rep[$n] =~ /(\S+)\s+..(.{7})(.{7})(.{7}).{13}(.{7})(.{7})(.{7})/ || !$newfmt && $rep[$n] =~ /(\S+)\s+..(\d+)\s+(\d+)\s+(\d+)\s+.{11}(\d+)\s+(\d+)\s+(\d+)/) {
62 $user{$n,'user'} = $1;
63 $user{$n,'ublocks'} = int($2);
64 $user{$n,'sblocks'} = int($3);
65 $user{$n,'hblocks'} = int($4);
66 $user{$n,'ufiles'} = int($5);
67 $user{$n,'sfiles'} = int($6);
68 $user{$n,'hfiles'} = int($7);
69 $user{$n,'user'} =~ s/^#//g;
75 # edit_quota_file(data, filesys, sblocks, hblocks, sfiles, hfiles)
79 foreach $line (split(/\n/, $_[0])) {
80 if ($line =~ /^fs (\S+) blocks \(soft = (\d+), hard = (\d+)\) inodes \(soft = (\d+), hard = (\d+)\)$/ && $1 eq $_[1]) {
81 # found line to change
82 $line = "fs $_[1] blocks (soft = $_[2], hard = $_[3]) inodes (soft = $_[4], hard = $_[5])";
89 # quotaon(filesystem, mode)
90 # Activate quotas and create quota file for some filesystem. The mode can
91 # be 1 for user only, 2 for group only or 3 for user and group
94 return if (&is_readonly_mode());
98 &open_tempfile(QUOTAFILE, ">$qf", 0, 1);
99 &close_tempfile(QUOTAFILE);
100 &set_ownership_permissions(undef, undef, 0600, $qf);
102 $out = &backquote_logged("$config{'user_quotaon_command'} $_[0] 2>&1");
103 if ($?) { return $out; }
107 # quotaoff(filesystem, mode)
108 # Turn off quotas for some filesystem
111 return if (&is_readonly_mode());
113 $out = &backquote_logged("$config{'user_quotaoff_command'} $_[0] 2>&1");
114 if ($?) { return $out; }
118 # quotacheck(filesystem, mode)
119 # Runs quotacheck on some filesystem
122 $out = &backquote_logged("$config{'quotacheck_command'} $_[0] 2>&1");
123 if ($?) { return $out; }
127 # copy_user_quota(user, [user]+)
128 # Copy the quotas for some user to many others
131 for($i=1; $i<@_; $i++) {
132 $out = &backquote_logged("$config{'user_copy_command'} ".
133 quotemeta($_[0])." ".quotemeta($_[$i])." 2>&1");
134 if ($?) { return $out; }
139 # user_filesystems(user)
140 # Fills the array %filesys with details of all filesystems some user has
145 open(QUOTA, "$config{'user_quota_command'} ".quotemeta($_[0])." |");
146 $n=0; while(<QUOTA>) {
148 if (/^(Disk|Filesystem)/) { next; }
150 # Bogus wrapped line!
151 $filesys{$n,'filesys'} = $1;
153 if ($nl =~ /^\s+(\d+)\s+(\d+)\s+(\d+)\s.{0,15}\s(\d+)\s+(\d+)\s+(\d+)/ ||
154 $nl =~ /^.{13}(.{7})(.{7})(.{7}).{12}(.{7})(.{7})(.{7})/) {
155 $filesys{$n,'ublocks'} = int($1);
156 $filesys{$n,'sblocks'} = int($2);
157 $filesys{$n,'hblocks'} = int($3);
158 $filesys{$n,'ufiles'} = int($4);
159 $filesys{$n,'sfiles'} = int($5);
160 $filesys{$n,'hfiles'} = int($6);
164 elsif (/^(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s.{0,15}\s(\d+)\s+(\d+)\s+(\d+)/ ||
165 /^(.{13})(.{7})(.{7})(.{7}).{12}(.{7})(.{7})(.{7})/) {
166 $filesys{$n,'filesys'} = $1;
167 $filesys{$n,'ublocks'} = int($2);
168 $filesys{$n,'sblocks'} = int($3);
169 $filesys{$n,'hblocks'} = int($4);
170 $filesys{$n,'ufiles'} = int($5);
171 $filesys{$n,'sfiles'} = int($6);
172 $filesys{$n,'hfiles'} = int($7);
173 $filesys{$n,'filesys'} =~ s/\s+$//g;
181 # get_user_grace(filesystem)
182 # Returns an array containing btime, bunits, ftime, funits
183 # The units can be 0=sec, 1=min, 2=hour, 3=day, 4=week, 5=month
187 $ENV{'EDITOR'} = $ENV{'VISUAL'} = "cat";
188 open(GRACE, "$config{'user_grace_command'} |");
190 if (/^fs (\S+) blocks time limit = ([0-9\.]+) (\S+), files time limit = ([0-9\.]+) (\S+)/ && $1 eq $_[0]) {
191 if ($2 == 0) { push(@rv, 0, 0); }
192 else { push(@rv, $2, $name_to_unit{$3}); }
193 if ($4 == 0) { push(@rv, 0, 0); }
194 else { push(@rv, $4, $name_to_unit{$5}); }
202 # Returns 0 if grace time can be 0, 1 if zero grace means default
208 # edit_grace_file(data, filesystem, btime, bunits, ftime, funits)
212 foreach $line (split(/\n/, $_[0])) {
213 if ($line =~ /^fs (\S+) blocks time limit = ([0-9\.]+) (\S+), files time limit = ([0-9\.]+) (\S+)/ && $1 eq $_[1]) {
215 $line = "fs $_[1] blocks time limit = $_[2] $unit_to_name{$_[3]}, files time limit = $_[4] $unit_to_name{$_[5]}";
223 # Returns an array of possible units for grace periods
226 return ($text{'grace_seconds'}, $text{'grace_minutes'}, $text{'grace_hours'},
227 $text{'grace_days'}, $text{'grace_weeks'}, $text{'grace_months'});
230 %name_to_unit = ( "sec", 0, "secs", 0,
232 "hour", 2, "hours", 2,
234 "week", 4, "weeks", 4,
235 "month", 5, "months", 5
237 foreach $k (keys %name_to_unit) {
238 $unit_to_name{$name_to_unit{$k}} = $k;