summaryrefslogtreecommitdiff
path: root/convertquota.c
diff options
context:
space:
mode:
authorjkar8572 <jkar8572>2001-05-02 09:32:22 +0000
committerjkar8572 <jkar8572>2001-05-02 09:32:22 +0000
commit84ec12aa207cb8d5323b63847bfd8115881f2886 (patch)
tree9533951fedda68167081028741a9ec3fd8ad547b /convertquota.c
parent9c4a512419c660c0513db48e038169167e3e7d25 (diff)
Added mntopt.h to dependencies in Makefile.in.
Fixed MNTTYPE_REISER to proper string. sprintf->snprintf Merged Marco's patch with errstr(), configurable BSD behaviour Fixed bug in quota detection IO code now opens file only RO if possible. IO code now doesn't open file if not required. Fixed bug in quotaon. Updated all manpages.
Diffstat (limited to 'convertquota.c')
-rw-r--r--convertquota.c43
1 files changed, 31 insertions, 12 deletions
diff --git a/convertquota.c b/convertquota.c
index c061459..6d3afbf 100644
--- a/convertquota.c
+++ b/convertquota.c
@@ -22,9 +22,17 @@
#include "bylabel.h"
char *mntpoint;
+char *progname;
int ucv, gcv;
struct quota_handle *qn; /* Handle of new file */
+static void usage(void)
+{
+ errstr(_("Utility for converting quota files.\nUsage:\n\t%s [-u] [-g] mountpoint\n"), progname);
+ errstr(_("Bugs to %s\n"), MY_EMAIL);
+ exit(1);
+}
+
void parse_options(int argcnt, char **argstr)
{
int ret;
@@ -34,15 +42,13 @@ void parse_options(int argcnt, char **argstr)
slash = argstr[0];
else
slash++;
+
sstrncpy(cmdname, slash, sizeof(cmdname));
while ((ret = getopt(argcnt, argstr, "Vugh:")) != -1) {
switch (ret) {
case '?':
case 'h':
-usage:
- printf(_("Utility for converting quota files.\nUsage:\n\t%s [-u] [-g] mountpoint\n"), cmdname);
- printf(_("Bugs to %s\n"), MY_EMAIL);
- exit(1);
+ usage();
case 'V':
version();
exit(0);
@@ -54,12 +60,15 @@ usage:
break;
}
}
+
if (optind + 1 != argcnt) {
puts(_("Bad number of arguments."));
- goto usage;
+ usage();
}
+
if (!(ucv | gcv))
ucv = 1;
+
mntpoint = argstr[optind];
}
@@ -79,7 +88,8 @@ int convert_dquot(struct dquot *dquot)
newdquot.dq_dqb.dqb_btime = dquot->dq_dqb.dqb_btime;
newdquot.dq_dqb.dqb_itime = dquot->dq_dqb.dqb_itime;
if (qn->qh_ops->commit_dquot(&newdquot) < 0) {
- fprintf(stderr, _("Can't commit dquot for id %u: %s\n"), (uint)dquot->dq_id, strerror(errno));
+ errstr(_("Can't commit dquot for id %u: %s\n"),
+ (uint)dquot->dq_id, strerror(errno));
return -1;
}
return 0;
@@ -103,12 +113,14 @@ void convert_file(int type)
}
if (!mnt)
die(1, _("Can't find given mountpoint %s\n"), mntpoint);
- if (!(qo = init_io(mnt, type, QF_VFSOLD))) {
- fprintf(stderr, _("Can't open old format file for %ss on %s\n"), type2name(type), mntpoint);
+ if (!(qo = init_io(mnt, type, QF_VFSOLD, 1))) {
+ errstr(_("Can't open old format file for %ss on %s\n"),
+ type2name(type), mntpoint);
return;
}
if (!(qn = new_io(mnt, type, QF_VFSV0))) {
- fprintf(stderr, _("Can't create file for %ss for new format on %s: %s\n"), type2name(type), mntpoint, strerror(errno));
+ errstr(_("Can't create file for %ss for new format on %s: %s\n"),
+ type2name(type), mntpoint, strerror(errno));
end_io(qo);
return;
}
@@ -117,7 +129,8 @@ void convert_file(int type)
strcpy(namebuf, qfname);
sstrncat(namebuf, ".new", sizeof(namebuf));
if (rename(namebuf, qfname) < 0)
- fprintf(stderr, _("Can't rename new quotafile %s to name %s: %s\n"), namebuf, qfname, strerror(errno));
+ errstr(_("Can't rename new quotafile %s to name %s: %s\n"),
+ namebuf, qfname, strerror(errno));
free(qfname);
}
endmntent(mntf);
@@ -125,13 +138,19 @@ void convert_file(int type)
end_io(qn);
}
-int main(int argcnt, char **argstr)
+int main(int argc, char **argv)
{
- parse_options(argcnt, argstr);
+ gettexton();
+ progname = basename(argv[0]);
+
+ parse_options(argc, argv);
+
if (ucv)
convert_file(USRQUOTA);
+
if (ucv)
convert_file(GRPQUOTA);
+
return 0;
}