Functions from quota module

quota-lib.pl

Functions for Unix user and group quota management. Some of the functionality is implemented in OS-specific library files which get automatically included into this one, like linux-lib.pl. Check the documentation on that file for more functions.

foreign_require('quota');
quota::edit_user_quota('joe', '/home', 1000000, 1200000, 1000, 1200);
my $n = quota::user_filesystems('joe');
for (my $i = 0; $i < $n; $i++) {
print "filesystem=",$filesys{$i,'filesys'}," ",
      "block quota=",$filesys{$i,'hblocks'}," ",
      "blocks used=",$filesys{$i,'ublocks'},"\n";
}
list_filesystems

Returns a list of details of local filesystems on which quotas are supported. Each is an array ref whose values are:

  • directory - Mount point, like /home

  • device - Source device, like /dev/hda1

  • type - Filesystem type, like ext4

  • options - Mount options, like rw,usrquota,grpquota

  • quotacan - Can this filesystem type support quotas?

  • quotanow - Are quotas enabled right now?

    • The values of quotacan and quotanow are:

      • 0 - No quotas
      • 1 - User quotas only
      • 2 - Group quotas only
      • 3 - User and group quotas
parse_options(type, options)

Convert an options string for some filesystem into the global hash %options.

user_quota(user, filesystem)

Returns an array of quotas and usage information for some user on some filesystem, or an empty array if no quota has been assigned. The array elements are:

  • Number of blocks used
  • Soft block quota
  • Hard block quota
  • Number of files used
  • Soft file quota
  • Hard file quota
group_quota(group, filesystem)

Returns an array of ublocks, sblocks, hblocks, ufiles, sfiles, hfiles for some group on some filesystem, or an empty array if no quota has been assigned.

edit_user_quota(user, filesys, sblocks, hblocks, sfiles, hfiles)

Sets the disk quota for some user. The parameters are:

  • user - Unix username
  • filesys - Filesystem on which to change quotas
  • sblocks - Soft block limit
  • hblocks - Hard block limit
  • sfiles - Sort files limit
  • hfiles - Hard files limit
edit_group_quota(group, filesys, sblocks, hblocks, sfiles, hfiles)

Sets the disk quota for some group The parameters are:

  • user - Unix group name
  • filesys - Filesystem on which to change quotas
  • sblocks - Soft block limit
  • hblocks - Hard block limit
  • sfiles - Sort files limit
  • hfiles - Hard files limit
edit_user_grace(filesystem, btime, bunits, ftime, funits)

Change the grace times for blocks and files on some filesystem. Parameters are:

  • filesystem - Filesystem to change the grace time on
  • btime - Number of units after which a user over his soft block limit is turned into a hard limit
  • bunits - Units for the block grace time, such as “seconds”, “minutes”, “hours” or “days”
  • ftime - Number of units after which a user over his soft file limit is turned into a hard limit
  • funits - Units for the file grace time, such as “seconds”, “minutes”, “hours” or “days”
edit_group_grace(filesystem, btime, bunits, ftime, funits)

Change the grace times for groups for blocks and files on some filesystem. The parameters are the same as edit_user_grace.

quota_input(name, value, [blocksize])

Returns an input for selecting a quota or unlimited, in a table. For internal use mainly.

quota_inputbox(name, value, [blocksize])

Returns an input for selecting a quota. Mainly for internal use.

quota_parse(name, [bsize], [nodef])

Parses inputs from the form generated by quota_input.

can_edit_filesys(filesys)

Returns 1 if the current Webmin user can manage quotas on some filesystem.

can_edit_user(user)

Returns 1 if the current Webmin user can manage quotas for some Unix user.

can_edit_group(group)

Returns 1 if the current Webmin user can manage quotas for some Unix group.

filesystem_info(filesystem, &hash, count, [blocksize])

Returns two strings containing information about the amount of disk space granted and used on some filesystem. For internal use.

block_size(dir, [for-filesys])

Returns the size (in bytes) of blocks on some filesystem, if known. All quota functions deal with blocks, so they must be multipled by the value returned by this function before display to users.

nice_limit(amount, bsize, no-blocks)

Internal function to show a quota limit nicely formatted.

find_email_job

Returns the cron job hash ref for the quota limit monitoring email job.

create_email_job

Creates the cron job for scheduled emailing, which runs every 10 minutes.

trunc_space(string)

Removes spaces from the start and end of a string.

to_percent(used, total)

Converts an amount used and a total into a percentage.

select_grace_units(name, value)

Returns a menu for selecting grace time units.