summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authormckusick <mckusick@FreeBSD.org>2010-03-16 06:12:30 +0000
committermckusick <mckusick@FreeBSD.org>2010-03-16 06:12:30 +0000
commitf63b97928b6dff04ed1652eee2d75a7577479818 (patch)
tree8218da33f517c5e82ea83e7c71daba26e9dd1ed0 /lib
parent834fb25a9ed2240101506d137b5be7d71c75f306 (diff)
downloadFreeBSD-src-f63b97928b6dff04ed1652eee2d75a7577479818.zip
FreeBSD-src-f63b97928b6dff04ed1652eee2d75a7577479818.tar.gz
Debugging nits found while testing the new 64-bit quota code.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/sys/quotactl.222
-rw-r--r--lib/libutil/quotafile.c34
2 files changed, 36 insertions, 20 deletions
diff --git a/lib/libc/sys/quotactl.2 b/lib/libc/sys/quotactl.2
index 4b4dca5..ff3cb4b 100644
--- a/lib/libc/sys/quotactl.2
+++ b/lib/libc/sys/quotactl.2
@@ -84,7 +84,7 @@ and group identifiers (GRPQUOTA).
The
.Dq ufs
specific commands are:
-.Bl -tag -width Q_QUOTAOFFxx
+.Bl -tag -width Q_GETQUOTASIZEx
.It Dv Q_QUOTAON
Enable disk quotas for the file system specified by
.Fa path .
@@ -110,6 +110,17 @@ and
.Fa id
arguments are unused.
Only the super-user may turn quotas off.
+.It Dv Q_GETQUOTASIZE
+Get the wordsize used to represent the quotas for the user or group
+(as determined by the command type).
+Possible values are 32 for the old-style quota file
+and 64 for the new-style quota file.
+The
+.Fa addr
+argument is a pointer to an integer into which the size is stored.
+The identifier
+.Fa id
+is not used.
.It Dv Q_GETQUOTA
Get disk quota limits and current usage for the user or group
(as determined by the command type) with identifier
@@ -177,9 +188,11 @@ The
argument
or the command type is invalid.
In
-.Dv Q_GETQUOTA
-and
+.Dv Q_GETQUOTASIZE ,
+.Dv Q_GETQUOTA ,
.Dv Q_SETQUOTA ,
+and
+.Dv Q_SETUSE ,
quotas are not currently enabled for this file system.
.Pp
The
@@ -208,7 +221,8 @@ Too many symbolic links were encountered in translating a pathname.
.It Bq Er EROFS
In
.Dv Q_QUOTAON ,
-the quota file resides on a read-only file system.
+either the file system on which quotas are to be enabled is mounted read-only
+or the quota file resides on a read-only file system.
.It Bq Er EIO
An
.Tn I/O
diff --git a/lib/libutil/quotafile.c b/lib/libutil/quotafile.c
index ab57d66..0fda5f6 100644
--- a/lib/libutil/quotafile.c
+++ b/lib/libutil/quotafile.c
@@ -129,11 +129,9 @@ quota_open(struct fstab *fs, int quotatype, int openflags)
goto error;
qf->dev = st.st_dev;
serrno = hasquota(fs, quotatype, qf->qfname, sizeof(qf->qfname));
- qcmd = QCMD(Q_GETQUOTA, quotatype);
- if (quotactl(fs->fs_file, qcmd, 0, &dqh) == 0) {
- qf->wordsize = 64;
+ qcmd = QCMD(Q_GETQUOTASIZE, quotatype);
+ if (quotactl(qf->fsname, qcmd, 0, &qf->wordsize) == 0)
return (qf);
- }
if (serrno == 0) {
errno = EOPNOTSUPP;
goto error;
@@ -250,18 +248,22 @@ int
quota_maxid(struct quotafile *qf)
{
struct stat st;
+ int maxid;
if (stat(qf->qfname, &st) < 0)
return (0);
switch (qf->wordsize) {
case 32:
- return (st.st_size / sizeof(struct dqblk32) - 1);
+ maxid = st.st_size / sizeof(struct dqblk32) - 1;
+ break;
case 64:
- return (st.st_size / sizeof(struct dqblk64) - 2);
+ maxid = st.st_size / sizeof(struct dqblk64) - 2;
+ break;
default:
- return (0);
+ maxid = 0;
+ break;
}
- /* not reached */
+ return (maxid > 0 ? maxid : 0);
}
static int
@@ -395,10 +397,6 @@ quota_write_usage(struct quotafile *qf, struct dqblk *dqb, int id)
struct dqblk dqbuf;
int qcmd;
- if ((qf->accmode & O_RDWR) != O_RDWR) {
- errno = EBADF;
- return (-1);
- }
if (qf->fd == -1) {
qcmd = QCMD(Q_SETUSE, qf->quotatype);
return (quotactl(qf->fsname, qcmd, id, dqb));
@@ -406,6 +404,10 @@ quota_write_usage(struct quotafile *qf, struct dqblk *dqb, int id)
/*
* Have to do read-modify-write of quota in file.
*/
+ if ((qf->accmode & O_RDWR) != O_RDWR) {
+ errno = EBADF;
+ return (-1);
+ }
if (quota_read(qf, &dqbuf, id) != 0)
return (-1);
/*
@@ -443,10 +445,6 @@ quota_write_limits(struct quotafile *qf, struct dqblk *dqb, int id)
struct dqblk dqbuf;
int qcmd;
- if ((qf->accmode & O_RDWR) != O_RDWR) {
- errno = EBADF;
- return (-1);
- }
if (qf->fd == -1) {
qcmd = QCMD(Q_SETQUOTA, qf->quotatype);
return (quotactl(qf->fsname, qcmd, id, dqb));
@@ -454,6 +452,10 @@ quota_write_limits(struct quotafile *qf, struct dqblk *dqb, int id)
/*
* Have to do read-modify-write of quota in file.
*/
+ if ((qf->accmode & O_RDWR) != O_RDWR) {
+ errno = EBADF;
+ return (-1);
+ }
if (quota_read(qf, &dqbuf, id) != 0)
return (-1);
/*
OpenPOWER on IntegriCloud