summaryrefslogtreecommitdiffstats
path: root/lib/libutil
diff options
context:
space:
mode:
authormckusick <mckusick@FreeBSD.org>2009-11-16 18:59:04 +0000
committermckusick <mckusick@FreeBSD.org>2009-11-16 18:59:04 +0000
commiteb9113cb7d8cee39cc223654d45fe20e9db3a07d (patch)
tree8850988982a36bf51d9451cdd87870d2424e1b01 /lib/libutil
parent9aab49b0ca88e792c6fbb6a7809af8ce6fc4ecc5 (diff)
downloadFreeBSD-src-eb9113cb7d8cee39cc223654d45fe20e9db3a07d.zip
FreeBSD-src-eb9113cb7d8cee39cc223654d45fe20e9db3a07d.tar.gz
Add and document new quoat_on and quota_off functions.
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/libutil.h4
-rw-r--r--lib/libutil/quotafile.3131
-rw-r--r--lib/libutil/quotafile.c18
3 files changed, 104 insertions, 49 deletions
diff --git a/lib/libutil/libutil.h b/lib/libutil/libutil.h
index b5ff6fd..3a05d9b 100644
--- a/lib/libutil/libutil.h
+++ b/lib/libutil/libutil.h
@@ -144,6 +144,9 @@ int pidfile_remove(struct pidfh *pfh);
struct quotafile;
struct fstab;
struct quotafile *quota_open(struct fstab *, int, int);
+void quota_close(struct quotafile *);
+int quota_on(struct quotafile *);
+int quota_off(struct quotafile *);
const char *quota_fsname(const struct quotafile *);
const char *quota_qfname(const struct quotafile *);
int quota_maxid(struct quotafile *);
@@ -151,7 +154,6 @@ int quota_check_path(const struct quotafile *, const char *path);
int quota_read(struct quotafile *, struct dqblk *, int);
int quota_write_limits(struct quotafile *, struct dqblk *, int);
int quota_write_usage(struct quotafile *, struct dqblk *, int);
-void quota_close(struct quotafile *);
#endif
__END_DECLS
diff --git a/lib/libutil/quotafile.3 b/lib/libutil/quotafile.3
index d0c27d7..d2134c5 100644
--- a/lib/libutil/quotafile.3
+++ b/lib/libutil/quotafile.3
@@ -30,14 +30,16 @@
.Os
.Sh NAME
.Nm quota_open
+.Nm quota_close
+.Nm quota_on
+.Nm quota_off
+.Nm quota_read
+.Nm quota_write_limits
+.Nm quota_write_usage
.Nm quota_fsname
.Nm quota_qfname
.Nm quota_maxid
.Nm quota_check_path
-.Nm quota_read
-.Nm quota_write_limits
-.Nm quota_write_usage
-.Nm quota_close
.Nd "Manipulate quotas"
.Sh LIBRARY
.Lb libutil
@@ -50,22 +52,26 @@
.In libutil.h
.Ft "struct quotafile *"
.Fn quota_open "struct fstab *fs" "int quotatype" "int openflags"
-.Ft "const char *"
-.Fn quota_fsname "const struct quotafile *qf"
-.Ft "const char *"
-.Fn quota_qfname "const struct quotafile *qf"
.Ft int
-.Fn quota_maxid "const struct quotafile *qf"
+.Fn quota_close "struct quotafile *qf"
.Ft int
-.Fn quota_check_path "const struct quotafile *qf" "const char *path"
+.Fn quota_on "const struct quotafile *qf"
+.Ft int
+.Fn quota_off "const struct quotafile *qf"
.Ft int
.Fn quota_read "struct quotafile *qf" "struct dqblk *dqb" "int id"
.Ft int
.Fn quota_write_limits "struct quotafile *qf" "struct dqblk *dqb" "int id"
.Ft int
.Fn quota_write_usage "struct quotafile *qf" "struct dqblk *dqb" "int id"
+.Ft "const char *"
+.Fn quota_fsname "const struct quotafile *qf"
+.Ft "const char *"
+.Fn quota_qfname "const struct quotafile *qf"
.Ft int
-.Fn quota_close "struct quotafile *qf"
+.Fn quota_maxid "const struct quotafile *qf"
+.Ft int
+.Fn quota_check_path "const struct quotafile *qf" "const char *path"
.Sh DESCRIPTION
These functions are designed to simplify access to filesystem quotas.
If quotas are active on a filesystem,
@@ -103,46 +109,48 @@ flag should be specified if a new quota file of the requested type
should be created if it does not already exist.
.Pp
The
-.Fn quota_fsname
-function returns a pointer to a buffer containing the path to the root
-of the file system that corresponds to its
-.Va qf
-argument, as listed in
-.Pa /etc/fstab .
-Note that this may be a symbolic link to the actual directory.
+.Fn quota_close
+function closes any open file descriptors and frees any storage
+associated with the filesystem and quota type referenced by
+.Va qf .
.Pp
The
-.Fn quota_qfname
-function returns a pointer to a buffer containing the name of the
-quota file that corresponds to its
+.Fn quota_on
+function enables quotas for the filesystem associated with its
.Va qf
-argument.
-Note that this may be a symbolic link to the actual file.
-.Pp
+argument which may have been opened
+.Dv O_RDONLY
+or
+.Dv O_RDWR .
The
-.Fn quota_maxid
-function returns the maximum user (or group)
-.Va id
-contained in the quota file associated with its
-.Va qf
-argument.
+.Fn quota_on
+function returns 0 if successful;
+otherwise the value\~-1 is returned and the global variable
+.Va errno
+is set to indicate the error, see
+.Xr quotactl 2
+for the possible errors.
.Pp
The
-.Fn quota_check_path
-function checks if the specified path is within the filesystem that
-corresponds to its
+.Fn quota_off
+function disables quotas for the filesystem associated with its
.Va qf
-argument.
-If the
-.Va path
-argument refers to a symbolic link,
-.Fn quota_check_path
-will follow it.
+argument which may have been opened
+.Dv O_RDONLY
+or
+.Dv O_RDWR .
+The
+.Fn quota_off
+function returns 0 if successful;
+otherwise the value\~-1 is returned and the global variable
+.Va errno
+is set to indicate the error, see
+.Xr quotactl 2
+for the possible errors.
.Pp
The
.Fn quota_read
-function reads the quota from the filesystem and quota type referenced
-by
+function reads the quota from the filesystem and quota type referenced by
.Va qf
for the user (or group) specified by
.Va id
@@ -176,10 +184,41 @@ quota structure pointed to by
.Va dqb .
.Pp
The
-.Fn quota_close
-function closes any open file descriptors and frees any storage
-associated with the filesystem and quota type referenced by
-.Va qf .
+.Fn quota_fsname
+function returns a pointer to a buffer containing the path to the root
+of the file system that corresponds to its
+.Va qf
+argument, as listed in
+.Pa /etc/fstab .
+Note that this may be a symbolic link to the actual directory.
+.Pp
+The
+.Fn quota_qfname
+function returns a pointer to a buffer containing the name of the
+quota file that corresponds to its
+.Va qf
+argument.
+Note that this may be a symbolic link to the actual file.
+.Pp
+The
+.Fn quota_maxid
+function returns the maximum user (or group)
+.Va id
+contained in the quota file associated with its
+.Va qf
+argument.
+.Pp
+The
+.Fn quota_check_path
+function checks if the specified path is within the filesystem that
+corresponds to its
+.Va qf
+argument.
+If the
+.Va path
+argument refers to a symbolic link,
+.Fn quota_check_path
+will follow it.
.Sh IMPLEMENTATION NOTES
If the underlying quota file is in the old 32-bit format, limit and
usage values written to the quota file will be clipped to 32 bits.
@@ -230,4 +269,4 @@ The
functions and this manual page were written by
.An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org
and
-.An Marshall Kirk McKusick .
+.An Marshall Kirk McKusick Aq mckusick@mckusick.com .
diff --git a/lib/libutil/quotafile.c b/lib/libutil/quotafile.c
index 4c63a17..9017c4e 100644
--- a/lib/libutil/quotafile.c
+++ b/lib/libutil/quotafile.c
@@ -61,7 +61,6 @@ static const char *qfextension[] = INITQFNAMES;
/*
* Check to see if a particular quota is to be enabled.
- * XXX merge into quota_open
*/
static int
hasquota(struct fstab *fs, int type, char *qfnamep, int qfbufsize)
@@ -73,7 +72,6 @@ hasquota(struct fstab *fs, int type, char *qfnamep, int qfbufsize)
static char initname, usrname[100], grpname[100];
/*
- * XXX
* 1) we only need one of these
* 2) fstab may specify a different filename
*/
@@ -207,6 +205,22 @@ quota_close(struct quotafile *qf)
free(qf);
}
+int
+quota_on(struct quotafile *qf)
+{
+ int qcmd;
+
+ qcmd = QCMD(Q_QUOTAON, qf->quotatype);
+ return (quotactl(qf->fsname, qcmd, 0, qf->qfname));
+}
+
+int
+quota_off(struct quotafile *qf)
+{
+
+ return (quotactl(qf->fsname, QCMD(Q_QUOTAOFF, qf->quotatype), 0, 0));
+}
+
const char *
quota_fsname(const struct quotafile *qf)
{
OpenPOWER on IntegriCloud