break out into "quotaon" and "quotaoff" (still same binary)
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Mon, 23 May 1983 09:20:42 +0000 (01:20 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Mon, 23 May 1983 09:20:42 +0000 (01:20 -0800)
SCCS-vsn: usr.sbin/quotaon/quotaon.c 4.2

usr/src/usr.sbin/quotaon/quotaon.c

index 5909a1a..61f9599 100644 (file)
@@ -1,23 +1,39 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)quotaon.c  4.1 (Melbourne) %G%";
+static char sccsid[] = "@(#)quotaon.c  4.2 (Berkeley, Melbourne) %G%";
 #endif
 /*
 #endif
 /*
- * Turn quota on/off for a filesystem
+ * Turn quota on/off for a filesystem.
+ *
+ * NEED TO REFLECT CURRENT STATUS IN MTAB.
  */
 #include <sys/param.h>
  */
 #include <sys/param.h>
-
 #include <stdio.h>
 #include <fstab.h>
 
 int    vflag;          /* verbose */
 int    aflag;          /* all file systems */
 
 #include <stdio.h>
 #include <fstab.h>
 
 int    vflag;          /* verbose */
 int    aflag;          /* all file systems */
 
+char *qfname = "quotas";
+char quotafile[MAXPATHLEN + 1];
+
 main(argc, argv)
 main(argc, argv)
+       int argc;
        char **argv;
 {
        char **argv;
 {
-       register i, on;
        register struct fstab *fs;
        register struct fstab *fs;
+       char *whoami, *rindex();
+       int offmode = 0, errs = 0;
 
 
+       whoami = rindex(*argv, '/') + 1;
+       if (whoami == (char *)1)
+               whoami = *argv;
+       if (strcmp(whoami, "quotaoff") == 0)
+               offmode++;
+       else if (strcmp(whoami, "quotaon") != 0) {
+               fprintf(stderr, "Name must be quotaon or quotaoff not %s\n",
+                       whoami);
+               exit(1);
+       }
 again:
        argc--, argv++;
        if (argc > 0 && strcmp(*argv, "-v") == 0) {
 again:
        argc--, argv++;
        if (argc > 0 && strcmp(*argv, "-v") == 0) {
@@ -28,39 +44,42 @@ again:
                aflag++;
                goto again;
        }
                aflag++;
                goto again;
        }
-       if (argc <= 0 || strcmp(*argv, "on") && strcmp(*argv, "off")) {
-               fprintf(stderr,
-                       "usage: setquota [-v] [-a] on | off [filesys...]\n");
+       if (argc <= 0 && !aflag) {
+               fprintf(stderr, "Usage:\n\t%s [-v] -a\n\t%s [-v] filesys ...\n",
+                       whoami, whoami);
                exit(1);
        }
                exit(1);
        }
-       on = strcmp(*argv, "on") == 0;
-       argc--, argv++;
        setfsent();
        while ((fs = getfsent()) != NULL) {
        setfsent();
        while ((fs = getfsent()) != NULL) {
-               if (fs->fs_quotafile == 0 || *fs->fs_quotafile == '\0')
+               if (fs->fs_type == 0)
                        continue;
                        continue;
-               if (fs->fs_type == 0 || strcmp(fs->fs_type, "rw"))
+               if (aflag && strcmp(fs->fs_type, "rq") != 0)
                        continue;
                if (!aflag && !oneof(fs->fs_file, argv, argc))
                        continue;
                        continue;
                if (!aflag && !oneof(fs->fs_file, argv, argc))
                        continue;
-               if (vflag)
-                       printf("%s: quotas turned %s\n", fs->fs_file,
-                               on ? "on" : "off");
-               if (on) {
-                       char quotafile[MAXPATHLEN + 1];
-
-                       (void) sprintf(quotafile, "%s/%s", fs->fs_file,
-                          fs->fs_quotafile);
-                       i = setquota(fs->fs_spec, quotafile);
-               } else
-                       i = setquota(fs->fs_spec, NULL);
-               if (i < 0) {
+               if (offmode) {
+                       if (setquota(fs->fs_spec, NULL) < 0) {
+                               fprintf(stderr, "setquota: ");
+                               perror(fs->fs_spec);
+                               errs++;
+                               continue;
+                       }
+                       if (vflag)
+                               printf("%s: quotas turned off\n", fs->fs_file);
+                       continue;
+               }
+               (void) sprintf(quotafile, "%s/%s", fs->fs_file, qfname);
+               if (setquota(fs->fs_spec, quotafile) < 0) {
                        fprintf(stderr, "setquota: ");
                        perror(fs->fs_spec);
                        fprintf(stderr, "setquota: ");
                        perror(fs->fs_spec);
+                       errs++;
+                       continue;
                }
                }
+               if (vflag)
+                       printf("%s: quotas turned on\n", fs->fs_file);
        }
        endfsent();
        }
        endfsent();
-       exit(i < 0);
+       exit(errs);
 }
 
 oneof(target, list, n)
 }
 
 oneof(target, list, n)