SCCS-vsn: usr.sbin/quotaon/quotaon.c 4.2
-static char sccsid[] = "@(#)quotaon.c 4.1 (Melbourne) %G%";
+static char sccsid[] = "@(#)quotaon.c 4.2 (Berkeley, Melbourne) %G%";
- * 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];
+
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) {
- 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);
- 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 || 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);
+ if (vflag)
+ printf("%s: quotas turned on\n", fs->fs_file);