From owner-svn-src-projects@FreeBSD.ORG Tue Oct 20 05:37:54 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CF4BC1065672; Tue, 20 Oct 2009 05:37:54 +0000 (UTC) (envelope-from mckusick@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id BF09B8FC16; Tue, 20 Oct 2009 05:37:54 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n9K5bsQA057231; Tue, 20 Oct 2009 05:37:54 GMT (envelope-from mckusick@svn.freebsd.org) Received: (from mckusick@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n9K5bsaJ057227; Tue, 20 Oct 2009 05:37:54 GMT (envelope-from mckusick@svn.freebsd.org) Message-Id: <200910200537.n9K5bsaJ057227@svn.freebsd.org> From: Kirk McKusick Date: Tue, 20 Oct 2009 05:37:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r198265 - projects/quota64/lib/libutil X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Oct 2009 05:37:55 -0000 Author: mckusick Date: Tue Oct 20 05:37:54 2009 New Revision: 198265 URL: http://svn.freebsd.org/changeset/base/198265 Log: Add quota_maxid which returns the maximum user (or group) identifier in an associated quotafile. Needed by repquota. Bug fix in quota_read. Modified: projects/quota64/lib/libutil/libutil.h projects/quota64/lib/libutil/quotafile.3 projects/quota64/lib/libutil/quotafile.c Modified: projects/quota64/lib/libutil/libutil.h ============================================================================== --- projects/quota64/lib/libutil/libutil.h Tue Oct 20 04:36:08 2009 (r198264) +++ projects/quota64/lib/libutil/libutil.h Tue Oct 20 05:37:54 2009 (r198265) @@ -146,6 +146,7 @@ struct fstab; struct quotafile *quota_open(struct fstab *, int, int); const char *quota_fsname(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_read(struct quotafile *, struct dqblk *, int); int quota_write_limits(struct quotafile *, struct dqblk *, int); Modified: projects/quota64/lib/libutil/quotafile.3 ============================================================================== --- projects/quota64/lib/libutil/quotafile.3 Tue Oct 20 04:36:08 2009 (r198264) +++ projects/quota64/lib/libutil/quotafile.3 Tue Oct 20 05:37:54 2009 (r198265) @@ -32,6 +32,7 @@ .Nm quota_open .Nm quota_fsname .Nm quota_qfname +.Nm quota_maxid .Nm quota_check_path .Nm quota_read .Nm quota_write_limits @@ -44,8 +45,9 @@ .In sys/param.h .In sys/mount.h .In ufs/ufs/quota.h -.In libutil.h +.In fcntl.h .In fstab.h +.In libutil.h .Ft "struct quotafile *" .Fn quota_open "struct fstab *fs" "int quotatype" "int openflags" .Ft "const char *" @@ -53,6 +55,8 @@ .Ft "const char *" .Fn quota_qfname "const struct quotafile *qf" .Ft int +.Fn quota_maxid "const struct quotafile *qf" +.Ft int .Fn quota_check_path "const struct quotafile *qf" "const char *path" .Ft int .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. .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 Modified: projects/quota64/lib/libutil/quotafile.c ============================================================================== --- projects/quota64/lib/libutil/quotafile.c Tue Oct 20 04:36:08 2009 (r198264) +++ projects/quota64/lib/libutil/quotafile.c Tue Oct 20 05:37:54 2009 (r198265) @@ -128,13 +128,13 @@ quota_open(struct fstab *fs, int quotaty if (stat(qf->fsname, &st) != 0) 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; - qf->fd = -1; return (qf); } - if (!hasquota(fs, quotatype, qf->qfname, sizeof(qf->qfname))) { + if (serrno == 0) { errno = EOPNOTSUPP; goto error; } @@ -231,6 +231,24 @@ quota_check_path(const struct quotafile 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 quota_read32(struct quotafile *qf, struct dqblk *dqb, int id) { @@ -242,7 +260,7 @@ quota_read32(struct quotafile *qf, struc return (-1); switch (read(qf->fd, &dqb32, sizeof(dqb32))) { case 0: - memset(&dqb, 0, sizeof(*dqb)); + memset(dqb, 0, sizeof(*dqb)); return (0); case sizeof(dqb32): dqb->dqb_bhardlimit = dqb32.dqb_bhardlimit; @@ -270,7 +288,7 @@ quota_read64(struct quotafile *qf, struc return (-1); switch (read(qf->fd, &dqb64, sizeof(dqb64))) { case 0: - memset(&dqb, 0, sizeof(*dqb)); + memset(dqb, 0, sizeof(*dqb)); return (0); case sizeof(dqb64): dqb->dqb_bhardlimit = be64toh(dqb64.dqb_bhardlimit);