14 #define FL_USER 1 /* sync user quotas */
15 #define FL_GROUP 2 /* sync group quotas */
16 #define FL_ALL 4 /* sync quotas on all filesystems */
18 static int flags, fmt = -1;
23 static void usage(void)
25 errstr(_("Utility for syncing quotas.\nUsage:\n%s [-ug] -a | mntpoint...\n\n"), progname);
26 fprintf(stderr, _("Bugs to %s\n"), MY_EMAIL);
30 static void parse_options(int argcnt, char **argstr)
33 struct option long_opts[] = {
34 { "user", 0, NULL, 'u' },
35 { "group", 0, NULL, 'g' },
36 { "all", 0, NULL, 'a' },
37 { "version", 0, NULL, 'V' },
38 { "help", 0, NULL, 'h' },
42 while ((ret = getopt_long(argcnt, argstr, "ahugV", long_opts, NULL)) != -1) {
62 if ((flags & FL_ALL && optind != argcnt) ||
63 (!(flags & FL_ALL) && optind == argcnt)) {
64 fputs(_("Bad number of arguments.\n"), stderr);
67 if (!(flags & FL_ALL)) {
68 mnt = argstr + optind;
69 mntcnt = argcnt - optind;
71 if (!(flags & (FL_USER | FL_GROUP)))
75 static int sync_one(int type, char *dev)
77 int qcmd = QCMD(Q_SYNC, type);
79 return quotactl(qcmd, dev, 0, NULL);
82 static int syncquotas(int type)
84 struct quota_handle **handles, *h;
88 if (sync_one(type, NULL) < 0)
89 errstr(_("%s quota sync failed: %s\n"), _(type2name(type)),
94 handles = create_handle_list(mntcnt, mnt, type, fmt,
95 IOI_READONLY, MS_LOCALONLY | MS_NO_AUTOFS);
97 for (i = 0; handles[i]; i++) {
99 if (sync_one(type, h->qh_quotadev)) {
100 errstr(_("%s quota sync failed for %s: %s\n"),
101 _(type2name(type)), h->qh_quotadev, strerror(errno));
105 dispose_handle_list(handles);
110 int main(int argc, char **argv)
115 progname = basename(argv[0]);
117 parse_options(argc, argv);
118 init_kernel_interface();
121 if (syncquotas(USRQUOTA))
123 if (flags & FL_GROUP)
124 if (syncquotas(GRPQUOTA))