#include <sys/quota.h>

sys/quota.h

includes: sys/appleapiopts.h, sys/cdefs.h, sys/types.h, mach/boolean.h
31 macros · 3 functions · 2 structs

macroMAX_IQ_TIME

Definitions for disk quotas imposed on the average user (big brother finally hits UNIX). The following constants define the amount of time given a user before the soft limits are treated as hard limits (usually resulting in an allocation failure). The timer is started when the user crosses their soft limit, it is reset when they go below their soft limit.
#define MAX_IQ_TIME (7*24*60*60)
seconds in 1 week

macroMAX_DQ_TIME

#define MAX_DQ_TIME (7*24*60*60)
seconds in 1 week

macroMAXQUOTAS

The following constants define the usage of the quota file array in the file system mount structure and dquot array in the inode structure. The semantics of the elements of these arrays are defined in the routine getinoquota; the remainder of the quota code treats them generically and need not be inspected when changing the size of the array.
#define MAXQUOTAS 2

macroUSRQUOTA

#define USRQUOTA 0
element used for user quotas

macroGRPQUOTA

#define GRPQUOTA 1
element used for group quotas

macroINITQFNAMES

Definitions for the default names of the quotas files.
#define INITQFNAMES {
	"user",         /* USRQUOTA */
	"group",        /* GRPQUOTA */
	"undefined",
};

macroQUOTAFILENAME

#define QUOTAFILENAME ".quota"

macroQUOTAOPSNAME

#define QUOTAOPSNAME ".quota.ops"

macroQUOTAGROUP

#define QUOTAGROUP "operator"

macroSUBCMDMASK

Command definitions for the 'quotactl' system call. The commands are broken into a main command defined below and a subcommand that is used to convey the type of quota that is being manipulated (see above).
#define SUBCMDMASK 0x00ff

macroSUBCMDSHIFT

#define SUBCMDSHIFT 8

macroQCMD

#define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK))

macroQ_QUOTAON

#define Q_QUOTAON 0x0100
enable quotas

macroQ_QUOTAOFF

#define Q_QUOTAOFF 0x0200
disable quotas

macroQ_GETQUOTA

#define Q_GETQUOTA 0x0300
get limits and usage

macroQ_SETQUOTA

#define Q_SETQUOTA 0x0400
set limits and usage

macroQ_SETUSE

#define Q_SETUSE 0x0500
set usage

macroQ_SYNC

#define Q_SYNC 0x0600
sync disk copy of a filesystems quotas

macroQ_QUOTASTAT

#define Q_QUOTASTAT 0x0700
get quota on/off status

structdqfilehdr

The following two structures define the format of the disk quota file (as it appears on disk) - the file contains a header followed by a hash table of dqblk entries. To find a particular entry, the user or group number (id) is first converted to an index into this table by means of the hash function dqhash1. If there is a collision at that index location then a second hash value is computed which using dqhash2. This second hash value is then used as an offset to the next location to probe. ID = 0 is used to indicate an empty (unused) entry. So there can never be an entry in the quota file for user 0 or group 0 (which is OK since disk quotas are never enforced for user 0). The setquota system call establishes the vnode for each quota file (a pointer is retained in the filesystem mount structure).
size 64, align 4
u_int32_tdqh_magic
u_int32_tdqh_version== QF_VERSION
u_int32_tdqh_maxentriesmust be a power of 2
u_int32_tdqh_entrycntcount of active entries
u_int32_tdqh_flagsreserved for now (0)
u_int32_tdqh_chktimetime of last quota check
u_int32_tdqh_btimetime limit for excessive disk use
u_int32_tdqh_itimetime limit for excessive files
char[16]dqh_stringtag string
u_int32_t[4]dqh_sparepad struct to power of 2

structdqblk

size 64, align 8
u_int64_tdqb_bhardlimitabsolute limit on disk bytes alloc
u_int64_tdqb_bsoftlimitpreferred limit on disk bytes
u_int64_tdqb_curbytescurrent byte count
u_int32_tdqb_ihardlimitmaximum # allocated inodes + 1
u_int32_tdqb_isoftlimitpreferred inode limit
u_int32_tdqb_curinodescurrent # allocated inodes
u_int32_tdqb_btimetime limit for excessive disk use
u_int32_tdqb_itimetime limit for excessive files
u_int32_tdqb_ididentifier (0 for empty entries)
u_int32_t[4]dqb_sparepad struct to power of 2

macroINITQMAGICS

#define INITQMAGICS {
	0xff31ff35,     /* USRQUOTA */
	0xff31ff27,     /* GRPQUOTA */
}

macroQF_VERSION

#define QF_VERSION 1

macroQF_STRING_TAG

#define QF_STRING_TAG "QUOTA HASH FILE"

macroQF_USERS_PER_GB

#define QF_USERS_PER_GB 256

macroQF_MIN_USERS

#define QF_MIN_USERS 2048

macroQF_MAX_USERS

#define QF_MAX_USERS (2048*1024)

macroQF_GROUPS_PER_GB

#define QF_GROUPS_PER_GB 32

macroQF_MIN_GROUPS

#define QF_MIN_GROUPS 2048

macroQF_MAX_GROUPS

#define QF_MAX_GROUPS (256*1024)

macrodqhash1

The primary and secondary multiplicative hash functions are derived from Knuth (vol. 3). They use a prime that is in golden ratio to the machine's word size.
#define dqhash1(id, shift, mask) ((((id) * 2654435761U) >> (shift)) & (mask))

macrodqhash2

#define dqhash2(id, mask) (dqhash1((id), 11, (mask)>>1) | 1)

macrodqoffset

Compute a disk offset into a quota file.
#define dqoffset(index) (sizeof (struct dqfilehdr) + ((index) * sizeof (struct dqblk)))

functiondqhashshift

static __inline int dqhashshift(u_int32_t)
Compute the hash shift value. It is the word size, in bits, minus the hash table size, in bits.

functiondqhashshift

static __inline int dqhashshift(u_int32_t size)

functionquotactl

int quotactl(const char *, int, int, caddr_t)
man page · June 4, 1993
quotactl(2) — manipulate filesystem quotas