From owner-svn-src-projects@FreeBSD.ORG Mon Nov 16 18:50:52 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 159B01065672; Mon, 16 Nov 2009 18:50:52 +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 0394B8FC21; Mon, 16 Nov 2009 18:50:52 +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 nAGIop1W078347; Mon, 16 Nov 2009 18:50:51 GMT (envelope-from mckusick@svn.freebsd.org) Received: (from mckusick@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nAGIopoG078344; Mon, 16 Nov 2009 18:50:51 GMT (envelope-from mckusick@svn.freebsd.org) Message-Id: <200911161850.nAGIopoG078344@svn.freebsd.org> From: Kirk McKusick Date: Mon, 16 Nov 2009 18:50:51 +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: r199326 - projects/quota64/usr.sbin/quotaon 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:50:52 -0000 Author: mckusick Date: Mon Nov 16 18:50:51 2009 New Revision: 199326 URL: http://svn.freebsd.org/changeset/base/199326 Log: Convert quotaon/quotaoff to use the new quotafile functions. Modified: projects/quota64/usr.sbin/quotaon/Makefile projects/quota64/usr.sbin/quotaon/quotaon.c Modified: projects/quota64/usr.sbin/quotaon/Makefile ============================================================================== --- projects/quota64/usr.sbin/quotaon/Makefile Mon Nov 16 18:46:33 2009 (r199325) +++ projects/quota64/usr.sbin/quotaon/Makefile Mon Nov 16 18:50:51 2009 (r199326) @@ -8,4 +8,7 @@ MLINKS= quotaon.8 quotaoff.8 WARNS?= 4 +DPADD= ${LIBUTIL} +LDADD= -lutil + .include Modified: projects/quota64/usr.sbin/quotaon/quotaon.c ============================================================================== --- projects/quota64/usr.sbin/quotaon/quotaon.c Mon Nov 16 18:46:33 2009 (r199325) +++ projects/quota64/usr.sbin/quotaon/quotaon.c Mon Nov 16 18:50:51 2009 (r199326) @@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -66,17 +67,15 @@ int gflag; /* operate on group quotas * int uflag; /* operate on user quotas */ int vflag; /* verbose */ -int hasquota(struct fstab *, int, char **); int oneof(char *, char *[], int); -int quotaonoff(struct fstab *fs, int, int, char *); -int readonly(struct fstab *); +int quotaonoff(struct fstab *fs, int, int); static void usage(void); int main(int argc, char **argv) { struct fstab *fs; - char *qfnp, *whoami; + char *whoami; long argnum, done = 0; int ch, i, offmode = 0, errs = 0; @@ -119,19 +118,19 @@ main(int argc, char **argv) strcmp(fs->fs_type, FSTAB_RW)) continue; if (aflag) { - if (gflag && hasquota(fs, GRPQUOTA, &qfnp)) - errs += quotaonoff(fs, offmode, GRPQUOTA, qfnp); - if (uflag && hasquota(fs, USRQUOTA, &qfnp)) - errs += quotaonoff(fs, offmode, USRQUOTA, qfnp); + if (gflag) + errs += quotaonoff(fs, offmode, GRPQUOTA); + if (uflag) + errs += quotaonoff(fs, offmode, USRQUOTA); continue; } if ((argnum = oneof(fs->fs_file, argv, argc)) >= 0 || (argnum = oneof(fs->fs_spec, argv, argc)) >= 0) { done |= 1 << argnum; - if (gflag && hasquota(fs, GRPQUOTA, &qfnp)) - errs += quotaonoff(fs, offmode, GRPQUOTA, qfnp); - if (uflag && hasquota(fs, USRQUOTA, &qfnp)) - errs += quotaonoff(fs, offmode, USRQUOTA, qfnp); + if (gflag) + errs += quotaonoff(fs, offmode, GRPQUOTA); + if (uflag) + errs += quotaonoff(fs, offmode, USRQUOTA); } } endfsent(); @@ -154,32 +153,33 @@ usage(void) } int -quotaonoff(fs, offmode, type, qfpathname) - register struct fstab *fs; +quotaonoff(fs, offmode, type) + struct fstab *fs; int offmode, type; - char *qfpathname; { + struct quotafile *qf; - if (strcmp(fs->fs_file, "/") && readonly(fs)) - return (1); + if ((qf = quota_open(fs, type, O_RDONLY)) == NULL) + return (0); if (offmode) { - if (quotactl(fs->fs_file, QCMD(Q_QUOTAOFF, type), 0, 0) < 0) { - warn("%s", fs->fs_file); + if (quota_off(qf) != 0) { + warn("%s", quota_fsname(qf)); return (1); } if (vflag) - printf("%s: quotas turned off\n", fs->fs_file); - return (0); + printf("%s: quotas turned off\n", quota_fsname(qf)); + quota_close(qf); + return(0); } - if (quotactl(fs->fs_file, QCMD(Q_QUOTAON, type), 0, qfpathname) < 0) { - warnx("using %s on", qfpathname); - warn("%s", fs->fs_file); + if (quota_on(qf) != 0) { + warn("using %s on %s", quota_qfname(qf), quota_fsname(qf)); return (1); } if (vflag) printf("%s: %s quotas turned on with data file %s\n", - fs->fs_file, qfextension[type], qfpathname); - return (0); + quota_fsname(qf), qfextension[type], quota_qfname(qf)); + quota_close(qf); + return(0); } /* @@ -195,73 +195,3 @@ oneof(char *target, char *list[], int cn return (i); return (-1); } - -/* - * Check to see if a particular quota is to be enabled. - */ -int -hasquota(struct fstab *fs, int type, char **qfnamep) -{ - char *opt; - char *cp; - struct statfs sfb; - static char initname, usrname[100], grpname[100]; - static char buf[BUFSIZ]; - - if (!initname) { - (void)snprintf(usrname, sizeof(usrname), "%s%s", - qfextension[USRQUOTA], qfname); - (void)snprintf(grpname, sizeof(grpname), "%s%s", - qfextension[GRPQUOTA], qfname); - initname = 1; - } - strcpy(buf, fs->fs_mntops); - for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) { - if ((cp = index(opt, '='))) - *cp++ = '\0'; - if (type == USRQUOTA && strcmp(opt, usrname) == 0) - break; - if (type == GRPQUOTA && strcmp(opt, grpname) == 0) - break; - } - if (!opt) - return (0); - if (cp) - *qfnamep = cp; - else { - (void)snprintf(buf, sizeof(buf), "%s/%s.%s", fs->fs_file, - qfname, qfextension[type]); - *qfnamep = buf; - } - if (statfs(fs->fs_file, &sfb) != 0) { - warn("cannot statfs mount point %s", fs->fs_file); - return (0); - } - if (strcmp(fs->fs_file, sfb.f_mntonname)) { - warnx("%s not mounted for %s quotas", fs->fs_file, - type == USRQUOTA ? "user" : "group"); - return (0); - } - return (1); -} - -/* - * Verify filesystem is mounted and not readonly. - */ -int -readonly(struct fstab *fs) -{ - struct statfs fsbuf; - - if (statfs(fs->fs_file, &fsbuf) < 0 || - strcmp(fsbuf.f_mntonname, fs->fs_file) || - strcmp(fsbuf.f_mntfromname, fs->fs_spec)) { - printf("%s: not mounted\n", fs->fs_file); - return (1); - } - if (fsbuf.f_flags & MNT_RDONLY) { - printf("%s: mounted read-only\n", fs->fs_file); - return (1); - } - return (0); -}