Add quota_maxid which returns the maximum user (or group) identifier

in an associated quotafile. Needed by repquota.

Bug fix in quota_read.
This commit is contained in:
Kirk McKusick 2009-10-20 05:37:54 +00:00
parent 6cfc1c1e18
commit 6197731d81
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/projects/quota64/; revision=198265
3 changed files with 36 additions and 5 deletions

View file

@ -146,6 +146,7 @@ struct fstab;
struct quotafile *quota_open(struct fstab *, int, int); struct quotafile *quota_open(struct fstab *, int, int);
const char *quota_fsname(const struct quotafile *); const char *quota_fsname(const struct quotafile *);
const char *quota_qfname(const struct quotafile *); const char *quota_qfname(const struct quotafile *);
int quota_maxid(struct quotafile *);
int quota_check_path(const struct quotafile *, const char *path); int quota_check_path(const struct quotafile *, const char *path);
int quota_read(struct quotafile *, struct dqblk *, int); int quota_read(struct quotafile *, struct dqblk *, int);
int quota_write_limits(struct quotafile *, struct dqblk *, int); int quota_write_limits(struct quotafile *, struct dqblk *, int);

View file

@ -32,6 +32,7 @@
.Nm quota_open .Nm quota_open
.Nm quota_fsname .Nm quota_fsname
.Nm quota_qfname .Nm quota_qfname
.Nm quota_maxid
.Nm quota_check_path .Nm quota_check_path
.Nm quota_read .Nm quota_read
.Nm quota_write_limits .Nm quota_write_limits
@ -44,8 +45,9 @@
.In sys/param.h .In sys/param.h
.In sys/mount.h .In sys/mount.h
.In ufs/ufs/quota.h .In ufs/ufs/quota.h
.In libutil.h .In fcntl.h
.In fstab.h .In fstab.h
.In libutil.h
.Ft "struct quotafile *" .Ft "struct quotafile *"
.Fn quota_open "struct fstab *fs" "int quotatype" "int openflags" .Fn quota_open "struct fstab *fs" "int quotatype" "int openflags"
.Ft "const char *" .Ft "const char *"
@ -53,6 +55,8 @@
.Ft "const char *" .Ft "const char *"
.Fn quota_qfname "const struct quotafile *qf" .Fn quota_qfname "const struct quotafile *qf"
.Ft int .Ft int
.Fn quota_maxid "const struct quotafile *qf"
.Ft int
.Fn quota_check_path "const struct quotafile *qf" "const char *path" .Fn quota_check_path "const struct quotafile *qf" "const char *path"
.Ft int .Ft int
.Fn quota_read "struct quotafile *qf" "struct dqblk *dqb" "int id" .Fn quota_read "struct quotafile *qf" "struct dqblk *dqb" "int id"
@ -116,6 +120,14 @@ argument.
Note that this may be a symbolic link to the actual file. Note that this may be a symbolic link to the actual file.
.Pp .Pp
The 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 .Fn quota_check_path
function checks if the specified path is within the filesystem that function checks if the specified path is within the filesystem that
corresponds to its corresponds to its

View file

@ -128,13 +128,13 @@ quota_open(struct fstab *fs, int quotatype, int openflags)
if (stat(qf->fsname, &st) != 0) if (stat(qf->fsname, &st) != 0)
goto error; goto error;
qf->dev = st.st_dev; qf->dev = st.st_dev;
serrno = hasquota(fs, quotatype, qf->qfname, sizeof(qf->qfname));
qcmd = QCMD(Q_GETQUOTA, quotatype); qcmd = QCMD(Q_GETQUOTA, quotatype);
if (quotactl(fs->fs_file, qcmd, 0, &dqh) == 0) { if (quotactl(fs->fs_file, qcmd, 0, &dqh) == 0) {
qf->wordsize = 64; qf->wordsize = 64;
qf->fd = -1;
return (qf); return (qf);
} }
if (!hasquota(fs, quotatype, qf->qfname, sizeof(qf->qfname))) { if (serrno == 0) {
errno = EOPNOTSUPP; errno = EOPNOTSUPP;
goto error; goto error;
} }
@ -231,6 +231,24 @@ quota_check_path(const struct quotafile *qf, const char *path)
return (st.st_dev == qf->dev); return (st.st_dev == qf->dev);
} }
int
quota_maxid(struct quotafile *qf)
{
struct stat st;
if (stat(qf->qfname, &st) < 0)
return (0);
switch (qf->wordsize) {
case 32:
return (st.st_size / sizeof(struct dqblk32));
case 64:
return (st.st_size / sizeof(struct dqblk64) - 1);
default:
return (0);
}
/* not reached */
}
static int static int
quota_read32(struct quotafile *qf, struct dqblk *dqb, int id) quota_read32(struct quotafile *qf, struct dqblk *dqb, int id)
{ {
@ -242,7 +260,7 @@ quota_read32(struct quotafile *qf, struct dqblk *dqb, int id)
return (-1); return (-1);
switch (read(qf->fd, &dqb32, sizeof(dqb32))) { switch (read(qf->fd, &dqb32, sizeof(dqb32))) {
case 0: case 0:
memset(&dqb, 0, sizeof(*dqb)); memset(dqb, 0, sizeof(*dqb));
return (0); return (0);
case sizeof(dqb32): case sizeof(dqb32):
dqb->dqb_bhardlimit = dqb32.dqb_bhardlimit; dqb->dqb_bhardlimit = dqb32.dqb_bhardlimit;
@ -270,7 +288,7 @@ quota_read64(struct quotafile *qf, struct dqblk *dqb, int id)
return (-1); return (-1);
switch (read(qf->fd, &dqb64, sizeof(dqb64))) { switch (read(qf->fd, &dqb64, sizeof(dqb64))) {
case 0: case 0:
memset(&dqb, 0, sizeof(*dqb)); memset(dqb, 0, sizeof(*dqb));
return (0); return (0);
case sizeof(dqb64): case sizeof(dqb64):
dqb->dqb_bhardlimit = be64toh(dqb64.dqb_bhardlimit); dqb->dqb_bhardlimit = be64toh(dqb64.dqb_bhardlimit);