From owner-svn-src-projects@FreeBSD.ORG Mon Nov 16 18:59:04 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 A102210657C1; Mon, 16 Nov 2009 18:59:04 +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 8F2C38FC12; Mon, 16 Nov 2009 18:59:04 +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 nAGIx4Ii078629; Mon, 16 Nov 2009 18:59:04 GMT (envelope-from mckusick@svn.freebsd.org) Received: (from mckusick@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nAGIx4TY078625; Mon, 16 Nov 2009 18:59:04 GMT (envelope-from mckusick@svn.freebsd.org) Message-Id: <200911161859.nAGIx4TY078625@svn.freebsd.org> From: Kirk McKusick Date: Mon, 16 Nov 2009 18:59:04 +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: r199328 - 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: Mon, 16 Nov 2009 18:59:04 -0000 Author: mckusick Date: Mon Nov 16 18:59:04 2009 New Revision: 199328 URL: http://svn.freebsd.org/changeset/base/199328 Log: Add and document new quoat_on and quota_off functions. 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 Mon Nov 16 18:58:45 2009 (r199327) +++ projects/quota64/lib/libutil/libutil.h Mon Nov 16 18:59:04 2009 (r199328) @@ -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 quotaf 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 Modified: projects/quota64/lib/libutil/quotafile.3 ============================================================================== --- projects/quota64/lib/libutil/quotafile.3 Mon Nov 16 18:58:45 2009 (r199327) +++ projects/quota64/lib/libutil/quotafile.3 Mon Nov 16 18:59:04 2009 (r199328) @@ -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 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 . Modified: projects/quota64/lib/libutil/quotafile.c ============================================================================== --- projects/quota64/lib/libutil/quotafile.c Mon Nov 16 18:58:45 2009 (r199327) +++ projects/quota64/lib/libutil/quotafile.c Mon Nov 16 18:59:04 2009 (r199328) @@ -61,7 +61,6 @@ static const char *qfextension[] = INITQ /* * 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, cha 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) {