From 0b34692854b79ea5438676e3d70cfe1de07b454c Mon Sep 17 00:00:00 2001 From: Jan Kara Date: Tue, 14 Sep 2010 20:44:38 +0200 Subject: quota: Allow printing of mountpoint Add options for quota(1) to print mount point as a part of a filesystem identification and also do not print device a s part of a filesystem identification. Signed-off-by: Jan Kara --- Changelog | 1 + quota.1 | 6 ++++++ quota.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- quotaio.c | 3 +++ quotaio.h | 1 + 5 files changed, 76 insertions(+), 9 deletions(-) diff --git a/Changelog b/Changelog index 6031760..928a292 100644 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ Changes in quota-tools from 3.17 to 4.00-pre2 +* add options for quota(1) modifying formatting of filesystem identificaion (Jan Kara) * minor updates of manpages (Jan Kara) * quotactl manpage was moved to man-pages package (Jan Kara) * fix quotaon to work properly with XFS filesystems (Eric Sandeen, Jan Kara ) diff --git a/quota.1 b/quota.1 index 11f3da1..d562f12 100644 --- a/quota.1 +++ b/quota.1 @@ -141,6 +141,12 @@ Do not wrap the line if the device name is too long. This can be useful when par the output of .BR quota (1) by a script. +.TP +.B --show-mntpoint +Show also mount point as a filesystem identification. +.TP +.B --hide-device +Do not show device name in a filesystem identification. .LP Specifying both .B \-g diff --git a/quota.c b/quota.c index ba44930..e9d1bb3 100644 --- a/quota.c +++ b/quota.c @@ -73,6 +73,8 @@ #define FL_NFSALL 2048 #define FL_RAWGRACE 4096 #define FL_NO_MIXED_PATHS 8192 +#define FL_SHOW_MNTPOINT 16384 +#define FL_SHOW_DEVICE 32768 int flags, fmt = -1; char *progname; @@ -102,6 +104,8 @@ void usage(void) -f, --filesystem-list display quota information only for given filesystems\n\ -A, --nfs-all display quota for all NFS mountpoints\n\ -m, --no-mixed-pathnames trim leading slashes from NFSv4 mountpoints\n\ + --show-mntpoint show mount point of the file system in output\n\ + --hide-device do not show file system device in output\n\ -h, --help display this help message and exit\n\ -V, --version display version information and exit\n\n")); fprintf(stderr, _("Bugs to: %s\n"), MY_EMAIL); @@ -121,11 +125,53 @@ void heading(int type, qid_t id, char *name, char *tag) name, *type2name(type), (uint) id, tag); if (!(flags & FL_QUIET) && !tag[0]) { printf("%15s%8s %7s%8s%8s%8s %7s%8s%8s\n", _("Filesystem"), - spacehdr,_("quota"), _("limit"), _("grace"), + spacehdr, _("quota"), _("limit"), _("grace"), _("files"), _("quota"), _("limit"), _("grace")); } } +void print_fs_location(struct dquot *q) +{ + struct quota_handle *h = q->dq_h; + + if (flags & FL_QUIET) { + if (flags & FL_SHOW_DEVICE) + printf(" %s", h->qh_quotadev); + if (flags & FL_SHOW_MNTPOINT) + printf(" %s", h->qh_dir); + putchar('\n'); + } else { + int wrap = 0; + + if (flags & FL_SHOW_DEVICE && flags & FL_SHOW_MNTPOINT && + !(flags & FL_NOWRAP)) + wrap = 1; + else if (flags & FL_SHOW_DEVICE && strlen(h->qh_quotadev) > 15 && + !(flags & FL_NOWRAP)) + wrap = 1; + else if (flags & FL_SHOW_MNTPOINT && strlen(h->qh_dir) > 15 && + !(flags & FL_NOWRAP)) + wrap = 1; + + if (flags & FL_SHOW_DEVICE) { + if (wrap || flags & FL_SHOW_MNTPOINT) + printf("%s", h->qh_quotadev); + else + printf("%15s", h->qh_quotadev); + } + if (flags & FL_SHOW_MNTPOINT) { + if (flags & FL_SHOW_DEVICE) + putchar(' '); + if (wrap || flags & FL_SHOW_DEVICE) + printf("%s", h->qh_dir); + else + printf("%15s", h->qh_dir); + } + if (wrap) + printf("\n%15s", ""); + } +} + int showquotas(int type, qid_t id, int mntcnt, char **mnt) { struct dquot *qlist, *q; @@ -186,10 +232,14 @@ int showquotas(int type, qid_t id, int mntcnt, char **mnt) if (flags & FL_QUIET) { if ((msgi || msgb) && !lines++) heading(type, id, name, ""); - if (msgi) - printf("\t%s %s\n", msgi, q->dq_h->qh_quotadev); - if (msgb) - printf("\t%s %s\n", msgb, q->dq_h->qh_quotadev); + if (msgi) { + printf("\t%s", msgi); + print_fs_location(q); + } + if (msgb) { + printf("\t%s", msgb); + print_fs_location(q); + } continue; } if ((flags & FL_VERBOSE) || q->dq_dqb.dqb_curspace || q->dq_dqb.dqb_curinodes) { @@ -197,10 +247,7 @@ int showquotas(int type, qid_t id, int mntcnt, char **mnt) if (!lines++) heading(type, id, name, ""); - if (strlen(q->dq_h->qh_quotadev) > 15 && !(flags & FL_NOWRAP)) - printf("%s\n%15s", q->dq_h->qh_quotadev, ""); - else - printf("%15s", q->dq_h->qh_quotadev); + print_fs_location(q); if (!(flags & FL_RAWGRACE)) { if (bover) difftime2str(q->dq_dqb.dqb_btime, timebuf); @@ -269,12 +316,15 @@ int main(int argc, char **argv) { "filesystem-list", 0, NULL, 'f' }, { "all-nfs", 0, NULL, 'A' }, { "no-mixed-pathnames", 0, NULL, 'm' }, + { "show-mntpoint", 0, NULL, 257 }, + { "hide-device", 0, NULL, 258 }, { NULL, 0, NULL, 0 } }; gettexton(); progname = basename(argv[0]); + flags |= FL_SHOW_DEVICE; while ((ret = getopt_long(argc, argv, "guqvsVliQF:wfApm", long_opts, NULL)) != -1) { switch (ret) { case 'g': @@ -323,6 +373,12 @@ int main(int argc, char **argv) case 'm': flags |= FL_NO_MIXED_PATHS; break; + case 257: + flags |= FL_SHOW_MNTPOINT; + break; + case 258: + flags &= ~FL_SHOW_DEVICE; + break; case 'V': version(); exit(0); diff --git a/quotaio.c b/quotaio.c index ee8c48a..dbd7cc8 100644 --- a/quotaio.c +++ b/quotaio.c @@ -59,6 +59,7 @@ struct quota_handle *init_io(struct mntent *mnt, int type, int fmt, int flags) sstrncpy(h->qh_quotadev, mnt_fsname, sizeof(h->qh_quotadev)); free((char *)mnt_fsname); sstrncpy(h->qh_fstype, mnt->mnt_type, MAX_FSTYPE_LEN); + sstrncpy(h->qh_dir, mnt->mnt_dir, PATH_MAX); if (nfs_fstype(mnt->mnt_type)) { /* NFS filesystem? */ if (fmt != -1 && fmt != QF_RPC) { /* User wanted some other format? */ errstr(_("Only RPC quota format is allowed on NFS filesystem.\n")); @@ -232,6 +233,8 @@ struct quota_handle *new_io(struct mntent *mnt, int type, int fmt) h->qh_fd = fd; h->qh_io_flags = 0; sstrncpy(h->qh_quotadev, mnt_fsname, sizeof(h->qh_quotadev)); + sstrncpy(h->qh_fstype, mnt->mnt_type, MAX_FSTYPE_LEN); + sstrncpy(h->qh_dir, mnt->mnt_dir, PATH_MAX); free((char *)mnt_fsname); h->qh_type = type; h->qh_fmt = fmt; diff --git a/quotaio.h b/quotaio.h index 2ee734a..d797034 100644 --- a/quotaio.h +++ b/quotaio.h @@ -80,6 +80,7 @@ struct quota_handle { int qh_fd; /* Handle of file (-1 when IOFL_QUOTAON) */ int qh_io_flags; /* IO flags for file */ char qh_quotadev[PATH_MAX]; /* Device file is for */ + char qh_dir[PATH_MAX]; /* Directory filesystem is mounted at */ char qh_fstype[MAX_FSTYPE_LEN]; /* Type of the filesystem on qh_quotadev */ int qh_type; /* Type of quotafile */ int qh_fmt; /* Quotafile format */ -- cgit v1.2.3