diff options
Diffstat (limited to 'quotaon.c')
-rw-r--r-- | quotaon.c | 119 |
1 files changed, 59 insertions, 60 deletions
@@ -42,6 +42,7 @@ #include <getopt.h> #include <string.h> #include <stdlib.h> +#include <stdarg.h> #include "quotaon.h" #include "quota.h" @@ -54,17 +55,17 @@ #define FL_STAT 16 #define FL_OFF 32 -int flags, fmt = -1; +static int flags, fmt = -1; char *progname; -char **mntpoints; -int mntcnt; -char *xarg = NULL; +static char **mntpoints; +static int mntcnt; +static char *xarg = NULL; static void usage(void) { errstr(_("Usage:\n\t%s [-guvp] [-F quotaformat] [-x state] -a\n\ \t%s [-guvp] [-F quotaformat] [-x state] filesys ...\n\n\ --a, --all turn quotas on for all filesystems\n\ +-a, --all %s\n\ -f, --off turn quotas off\n\ -u, --user operate on user quotas\n\ -g, --group operate on group quotas\n\ @@ -73,7 +74,10 @@ static void usage(void) -F, --format=formatname operate on specific quota format\n\ -v, --verbose print more messages\n\ -h, --help display this help text and exit\n\ --V, --version display version information and exit\n"), progname, progname); +-V, --version display version information and exit\n"), + progname, progname, + strcmp(progname, "quotaon") ? _("turn quotas off for all filesystems") : + _("turn quotas on for all filesystems")); exit(1); } @@ -145,6 +149,19 @@ static void parse_options(int argcnt, char **argstr) } } +int pinfo(char *fmt, ...) +{ + va_list arg; + int ret; + + if (!(flags & FL_VERBOSE)) + return 0; + va_start(arg, fmt); + ret = vprintf(fmt, arg); + va_end(arg); + return ret; +} + /* * Enable/disable rsquash on given filesystem */ @@ -171,10 +188,10 @@ static int quotarsquashonoff(const char *quotadev, int type, int flags) errstr(_("set root_squash on %s: %s\n"), quotadev, strerror(errno)); return 1; } - if ((flags & STATEFLAG_VERBOSE) && (flags & STATEFLAG_OFF)) - printf(_("%s: %s root_squash turned off\n"), quotadev, type2name(type)); - else if ((flags & STATEFLAG_VERBOSE) && (flags & STATEFLAG_ON)) - printf(_("%s: %s root_squash turned on\n"), quotadev, type2name(type)); + if (flags & STATEFLAG_OFF) + pinfo(_("%s: %s root_squash turned off\n"), quotadev, type2name(type)); + else if (flags & STATEFLAG_ON) + pinfo(_("%s: %s root_squash turned on\n"), quotadev, type2name(type)); #endif return 0; } @@ -182,7 +199,7 @@ static int quotarsquashonoff(const char *quotadev, int type, int flags) /* * Enable/disable VFS quota on given filesystem */ -static int quotaonoff(char *quotadev, char *quotadir, char *quotafile, int type, int fmt, int flags) +static int quotaonoff(const char *quotadev, const char *quotadir, char *quotafile, int type, int fmt, int flags) { int qcmd, kqf; @@ -195,8 +212,7 @@ static int quotaonoff(char *quotadev, char *quotadir, char *quotafile, int type, errstr(_("quotactl on %s [%s]: %s\n"), quotadev, quotadir, strerror(errno)); return 1; } - if (flags & STATEFLAG_VERBOSE) - printf(_("%s [%s]: %s quotas turned off\n"), quotadev, quotadir, type2name(type)); + pinfo(_("%s [%s]: %s quotas turned off\n"), quotadev, quotadir, _(type2name(type))); return 0; } if (kernel_iface == IFACE_GENERIC) { @@ -218,81 +234,63 @@ static int quotaonoff(char *quotadev, char *quotadir, char *quotafile, int type, errstr(_("Quota format not supported in kernel.\n")); return 1; } - if (flags & STATEFLAG_VERBOSE) - printf(_("%s [%s]: %s quotas turned on\n"), quotadev, quotadir, type2name(type)); + pinfo(_("%s [%s]: %s quotas turned on\n"), quotadev, quotadir, _(type2name(type))); return 0; } /* * Enable/disable quota/rootsquash on given filesystem (version 1) */ -static int v1_newstate(struct mntent *mnt, int type, char *file, int flags, int fmt) +static int v1_newstate(struct mount_entry *mnt, int type, char *file, int flags, int fmt) { int errs = 0; - const char *dev = get_device_name(mnt->mnt_fsname); - if (!dev) - return 1; - if ((flags & STATEFLAG_OFF) && hasmntopt(mnt, MNTOPT_RSQUASH)) - errs += quotarsquashonoff(dev, type, flags); - if (hasquota(mnt, type, 0)) - errs += quotaonoff((char *)dev, mnt->mnt_dir, file, type, QF_VFSOLD, flags); - if ((flags & STATEFLAG_ON) && hasmntopt(mnt, MNTOPT_RSQUASH)) - errs += quotarsquashonoff(dev, type, flags); - free((char *)dev); + if ((flags & STATEFLAG_OFF) && str_hasmntopt(mnt->me_opts, MNTOPT_RSQUASH)) + errs += quotarsquashonoff(mnt->me_devname, type, flags); + errs += quotaonoff(mnt->me_devname, mnt->me_dir, file, type, QF_VFSOLD, flags); + if ((flags & STATEFLAG_ON) && str_hasmntopt(mnt->me_opts, MNTOPT_RSQUASH)) + errs += quotarsquashonoff(mnt->me_devname, type, flags); return errs; } /* * Enable/disable quota on given filesystem (generic VFS quota) */ -static int v2_newstate(struct mntent *mnt, int type, char *file, int flags, int fmt) +static int v2_newstate(struct mount_entry *mnt, int type, char *file, int flags, int fmt) { - const char *dev = get_device_name(mnt->mnt_fsname); - int errs = 0; - - if (!dev) - return 1; - if (hasquota(mnt, type, 0)) - errs = quotaonoff((char *)dev, mnt->mnt_dir, file, type, fmt, flags); - free((char *)dev); - return errs; + return quotaonoff(mnt->me_devname, mnt->me_dir, file, type, fmt, flags); } /* * For both VFS quota formats, need to pass in the quota file; * for XFS quota manager, pass on the -x command line option. */ -static int newstate(struct mntent *mnt, int type, char *extra) +static int newstate(struct mount_entry *mnt, int type, char *extra) { int sflags, ret = 0; sflags = flags & FL_OFF ? STATEFLAG_OFF : STATEFLAG_ON; - if (flags & FL_VERBOSE) - sflags |= STATEFLAG_VERBOSE; if (flags & FL_ALL) sflags |= STATEFLAG_ALL; - if (!strcmp(mnt->mnt_type, MNTTYPE_XFS)) { /* XFS filesystem has special handling... */ + if (!strcmp(mnt->me_type, MNTTYPE_GFS2)) { + errstr(_("Cannot change state of GFS2 quota.\n")); + return 1; + } else if (!strcmp(mnt->me_type, MNTTYPE_XFS)) { /* XFS filesystem has special handling... */ if (!kern_qfmt_supp(QF_XFS)) { errstr(_("Cannot change state of XFS quota. It's not compiled in kernel.\n")); return 1; } - if ((flags & FL_OFF && (kern_quota_on(mnt->mnt_fsname, USRQUOTA, QF_XFS) != -1 - || kern_quota_on(mnt->mnt_fsname, GRPQUOTA, QF_XFS) != -1)) - || (!(flags & FL_OFF) && kern_quota_on(mnt->mnt_fsname, type, QF_XFS) == -1)) - ret = xfs_newstate(mnt, type, extra, sflags); + ret = xfs_newstate(mnt, type, extra, sflags); } - else if (meta_qf_fstype(mnt->mnt_type)) { - if (!hasquota(mnt, type, 0)) - return 0; + else if (mnt->me_qfmt[type] == QF_META) { /* Must be non-empty because empty path is always invalid. */ ret = v2_newstate(mnt, type, ".", sflags, QF_VFSV0); } else { int usefmt; - if (!hasquota(mnt, type, 0)) + if (!me_hasquota(mnt, type)) return 0; if (fmt == -1) { if (get_qf_name(mnt, type, QF_VFSV0, @@ -305,12 +303,12 @@ static int newstate(struct mntent *mnt, int type, char *extra) NF_FORMAT, &extra) >= 0) usefmt = QF_VFSOLD; else { - errstr(_("Cannot find quota file on %s [%s] to turn quotas on/off.\n"), mnt->mnt_dir, mnt->mnt_fsname); + errstr(_("Cannot find quota file on %s [%s] to turn quotas on/off.\n"), mnt->me_dir, mnt->me_devname); return 1; } } else { if (get_qf_name(mnt, type, fmt, NF_FORMAT, &extra) < 0) { - errstr(_("Quota file on %s [%s] does not exist or has wrong format.\n"), mnt->mnt_dir, mnt->mnt_fsname); + errstr(_("Quota file on %s [%s] does not exist or has wrong format.\n"), mnt->me_dir, mnt->me_devname); return 1; } usefmt = fmt; @@ -325,22 +323,23 @@ static int newstate(struct mntent *mnt, int type, char *extra) } /* Print state of quota (on/off) */ -static int print_state(struct mntent *mnt, int type) +static int print_state(struct mount_entry *mnt, int type) { int on = 0; - if (!strcmp(mnt->mnt_type, MNTTYPE_XFS)) { + if (!strcmp(mnt->me_type, MNTTYPE_XFS) || + !strcmp(mnt->me_type, MNTTYPE_GFS2)) { if (kern_qfmt_supp(QF_XFS)) - on = kern_quota_on(mnt->mnt_fsname, type, QF_XFS) != -1; + on = kern_quota_on(mnt, type, QF_XFS) != -1; } else if (kernel_iface == IFACE_GENERIC) - on = kern_quota_on(mnt->mnt_fsname, type, -1) != -1; + on = kern_quota_on(mnt, type, -1) != -1; else if (kern_qfmt_supp(QF_VFSV0)) - on = kern_quota_on(mnt->mnt_fsname, type, QF_VFSV0) != -1; + on = kern_quota_on(mnt, type, QF_VFSV0) != -1; else if (kern_qfmt_supp(QF_VFSOLD)) - on = kern_quota_on(mnt->mnt_fsname, type, QF_VFSOLD) != -1; + on = kern_quota_on(mnt, type, QF_VFSOLD) != -1; - printf(_("%s quota on %s (%s) is %s\n"), type2name(type), mnt->mnt_dir, mnt->mnt_fsname, + printf(_("%s quota on %s (%s) is %s\n"), _(type2name(type)), mnt->me_dir, mnt->me_devname, on ? _("on") : _("off")); return on; @@ -348,7 +347,7 @@ static int print_state(struct mntent *mnt, int type) int main(int argc, char **argv) { - struct mntent *mnt; + struct mount_entry *mnt; int errs = 0; gettexton(); @@ -370,9 +369,9 @@ int main(int argc, char **argv) if (init_mounts_scan(mntcnt, mntpoints, MS_XFS_DISABLED | MS_LOCALONLY) < 0) return 1; while ((mnt = get_next_mount())) { - if (nfs_fstype(mnt->mnt_type)) { + if (nfs_fstype(mnt->me_type)) { if (!(flags & FL_ALL)) - fprintf(stderr, "%s: Quota cannot be turned on on NFS filesystem\n", mnt->mnt_fsname); + errstr(_("%s: Quota cannot be turned on on NFS filesystem\n"), mnt->me_devname); continue; } |