Manual browser: quotacursor_close(3)
|LIBQUOTA(3)||Library Functions Manual||LIBQUOTA(3)|
NAMElibquota, quota_open, quota_close, quota_getmountdevice, quota_getmountpoint, quota_getimplname, quota_getrestrictions, quota_getnumidtypes, quota_getnumobjtypes, quota_idtype_getname, quota_objtype_getname, quota_objtype_isbytes, quota_get, quota_put, quota_delete, quota_opencursor, quotacursor_close, quotacursor_skipidtype, quotacursor_get, quotacursor_getn, quotacursor_atend, quotacursor_rewind, quota_quotaon, quota_quotaoff, quotaval_clear — disk quota access and control library
LIBRARYDisk Quota Access and Control Library (libquota, -lquota)
struct quotahandle *
quota_open(const char *path);
quota_close(struct quotahandle *qh);
const char *
quota_getmountdevice(struct quotahandle *qh);
const char *
quota_getmountpoint(struct quotahandle *qh);
const char *
quota_getimplname(struct quotahandle *qh);
quota_getrestrictions(struct quotahandle *qh);
quota_getnumidtypes(struct quotahandle *qh);
quota_getnumobjtypes(struct quotahandle *qh);
const char *
quota_idtype_getname(struct quotahandle *qh, int idtype);
const char *
quota_objtype_getname(struct quotahandle *qh, int objtype);
quota_objtype_isbytes(struct quotahandle *qh, int objtype);
quota_get(struct quotahandle *qh, const struct quotakey *key, struct quotaval *val);
quota_put(struct quotahandle *qh, const struct quotakey *key, const struct quotaval *val);
quota_delete(struct quotahandle *qh, const struct quotakey *key);
struct quotacursor *
quota_opencursor(struct quotahandle *qh);
quotacursor_close(struct quotacursor *qc);
quotacursor_skipidtype(struct quotacursor *qc, int idtype);
quotacursor_get(struct quotacursor *qc, struct quotakey *key, const struct quotaval *val);
quotacursor_getn(struct quotacursor *qc, struct quotakey *keys, const struct quotaval *vals, unsigned maxnum);
quotacursor_atend(struct quotacursor *qc);
quotacursor_rewind(struct quotacursor *qc);
quota_quotaon(struct quotahandle *qh, int idtype);
quota_quotaoff(struct quotahandle *qh, int idtype);
quotaval_clear(struct quotaval *qv);
DESCRIPTIONThe libquota library provides uniform access to disk quota functionality across all file systems and file system types. Programs should be linked with -lquota -lrpcsvc.
Quota information is organized as a key/value store, where the key names a particular limit and the value contains information about that limit. The information includes a configured soft limit, hard limit, and grace time, as well as the current usage and the expire time of any pending grace period. The soft limit may be exceeded temporarily, but only for the length of time specified; after that further usage is rejected. The hard limit may not be exceeded.
Each mounted file system that supports quotas contains its own key/value store for quota information. (The underlying representation may vary.) The library supports get, put, and delete operations, as well as a cursor interface for iterating an entire store. It also provides functions for inspecting the properties of a particular file system's quota implementation.
All functionality is accessed by first calling quota_open() on a particular volume to get a handle for that volume's quota information. Other operations can be called at this point. The quota_close() function should be called when done to release internal resources.
Data StructuresThe key part of the key/value schema is defined as struct quotakey, which contains the following members:
- int qk_idtype
- The type of principal (user, group, etc.) to retrieve quota information for.
- id_t qk_id
- The ID number (uid, gid, etc.) to retrieve quota information for.
- int qk_objtype
- The type of file system resource (blocks, files, etc.) to retrieve quota information for.
- uint64_t qv_softlimit
- The soft limit.
- uint64_t qv_hardlimit
- The hard limit.
- uint64_t qv_usage
- The current usage.
- int64_t qv_expiretime
- The time (in time_t terms) at which the current grace period, if any, expires.
- int64_t qv_grace
- The configured length of grace period.
ConstantsThe basic ID and object types are predefined. QUOTA_IDTYPE_USER is the code number for quotas on users; QUOTA_IDTYPE_GROUP is the code number for quotas on groups. Similarly, QUOTA_OBJTYPE_BLOCKS retrieves limits on file system blocks, while QUOTA_OBJTYPE_FILES retrieves limits on the number of existing files.
Some backends support a default configuration; this can be accessed by using QUOTA_DEFAULTID as the ID number.
When no limit is in place, the value QUOTA_NOLIMIT appears in the limit fields of struct quotaval, and if no time is indicated the value QUOTA_NOTIME appears in the time fields.
Quota v1The historic BSD quota implementation for FFS, known as “quota v1”, has additional restrictions and requirements. All file systems to be mounted with v1 quotas must be listed in fstab(5) with the userquota and/or groupquota mount options specified. The tools quotacheck(8) and quotaon(8) must be used on quota v1 volumes before quotas become fully operational, and quotaoff(8) must be used at system shutdown time. The libquota library provides access to quota v1 data even before quotaon(8) is called by direct access to the on-disk quota information. However, this method is not recommended. Note that the userquota and groupquota mount options are read and interpreted at quotaon time, not mount(8) time. This allowed historic implementations to avoid storing the path in the kernel.
Semantic RestrictionsSome quota implementations are restricted in their functionality or semantics. The following restriction codes are defined to allow libquota client code to adapt or to provide more helpful diagnostic messages.
- The quota implementation is a quota v1 system and requires the old-style quota check and mount process as described in the previous section.
- The grace period for how long a quota can be over the soft limit can be specified only once, globally, for all principals. It is set via the default (QUOTA_DEFAULTID) quota entry.
- The values in struct quotaval are limited to 32 bits wide. Larger values will be treated as QUOTA_NOLIMIT.
- The quota information is read-only. Attempts to update it using quota_put() or other functions will fail.
- Open a volume for access with the quota library. The path may be any file or file system object on the desired volume. On success, returns a quota handle for further use. On failure, returns NULL and sets errno.
- Close a quota handle previously created with quota_open().
- Return the path of the device the target volume is mounted from. This is retrieved with statvfs(2).
- Return the path in the directory tree where the target volume is mounted. This is retrieved with statvfs(2).
- Return a human-readable string describing the underlying quota implementation. Client programs should not attempt to interpret this string.
- Return the semantic restriction flags for the underlying quota implementation. The possible flags are described above.
- Return the number of ID types supported by this volume. Will ordinarily be two; ideally code using this library should be prepared for other values, including possibly one. However, as of this writing it is difficult to foresee any other likely ID types beyond users and groups.
- Return the number of object types supported by this volume. Will ordinarily be two; ideally code using this library should be prepared for larger values. As of this writing there are deployed file systems (though not in NetBSD) that support quotas for more than two object types.
- Return a printable name for an ID type.
- Return a printable name for an object type.
- Return true if the object type refers to something measured in bytes. (This can be used for calling humanize_number(3)).
- Return, in val, the quota information associated with the quota key key. On failure, returns -1 and sets errno.
- Update the quota information associated with the quota key key from the value val. Note that the current usage (which is maintained by the file system) cannot be updated via libquota. If it becomes incorrect or corrupted, quotacheck(8) or fsck(8) must be used. Also note that sufficient privilege is required. On failure, returns -1 and sets errno.
- Remove the quota information associated with the quota key key. Depending on the backend implementation this might just blank it out or might physically remove the quota record from disk. Note that sufficient privilege is required. On failure, returns -1 and sets errno.
- Prepare to iterate the store by creating a cursor. The cursor starts at the beginning of the store. On success, returns a pointer to a cursor object that can be used with the quotacursor calls. On failure, returns NULL and sets errno.
- Destroy a cursor previously created with quota_opencursor(). This releases internal storage.
- Hint to the implementation that the caller is not interested in retrieving records with ID type idtype. As this is a hint, the implementation may ignore it; the caller should still be prepared to receive and ignore such records. On failure, returns -1 and sets errno.
- Retrieve the next record (key and value) from a cursor. Note that records are not guaranteed to be returned in any particular order. On failure, returns -1 and sets errno.
- Retrieve the next several keys and values from a cursor. Up to maxnum keys and values will be stored in the arrays pointed to by the keys and vals arguments. Returns the number of records retrieved. On failure, returns -1 and sets errno.
- Returns true if the cursor has reached the end of the quota store.
- Resets a cursor to point to the beginning of the quota store, allowing another pass over the data.
- For old-style quota v1 implementations, this function enables quotas for the specified ID type. To ensure that the quota files are consistent with the file system state, quotacheck(8) must have been run beforehand. As described above, the file system volume must be listed in fstab(5) and the corresponding old-style mount option, userquota or groupquota, must be set therein. The path name for the quota file is retrieved from fstab(5) and passed to the kernel. This function will fail if used on newer quota implementations with in-file-system quotas.
- For old-style quotas, this function disables quotas for the specified ID type. This function will fail if used on newer quota implementations with in-file-system quotas.
- A convenience function for initializing a struct quotaval instance to the default empty state.
ERRORSError conditions include:
- An inconsistency was detected during quotacursor_get() or quotacursor_getn(). The application should discard information collected so far and use quotacursor_rewind() to start the iteration over.
- The quota information requested from quota_get() does not exist.
- The path passed to quota_open() was on a volume whose quota support is not enabled.
- The path passed to quota_open() was on a volume that has no quota support. Or, the iterator functions, quota_put(), or other unsupported operations were attempted on an NFS volume, or on some other volume type that does not support the full semantic range of quota information.
SEE ALSOquota(1), edquota(8), mount_ffs(8), mount_nfs(8), quotacheck(8), quotaon(8), repquota(8), rpc.rquotad(8)
HISTORYThe libquota library first appeared in NetBSD 6.0.
AUTHORSThe libquota library was written by .
|February 13, 2012||NetBSD 7.0|