Module Name: src
Committed By: bouyer
Date: Sun Jan 30 20:54:23 UTC 2011
Modified Files:
src/usr.bin/quota [bouyer-quota2]: printquota.c printquota.h quota.c
src/usr.sbin/edquota [bouyer-quota2]: edquota.c
src/usr.sbin/repquota [bouyer-quota2]: repquota.c
Log Message:
Change timeprt to print in weeks, days, hours, minutes, seconds
Change timeprt and intprt to take the number of acceptable char as argument
Drop HN_PRIV_UNLIMITED, the printable space will decide how to print
"unlimited"
To generate a diff of this commit:
cvs rdiff -u -r1.1.2.4 -r1.1.2.5 src/usr.bin/quota/printquota.c \
src/usr.bin/quota/printquota.h
cvs rdiff -u -r1.33.2.4 -r1.33.2.5 src/usr.bin/quota/quota.c
cvs rdiff -u -r1.29.16.3 -r1.29.16.4 src/usr.sbin/edquota/edquota.c
cvs rdiff -u -r1.25.2.3 -r1.25.2.4 src/usr.sbin/repquota/repquota.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/quota/printquota.c
diff -u src/usr.bin/quota/printquota.c:1.1.2.4 src/usr.bin/quota/printquota.c:1.1.2.5
--- src/usr.bin/quota/printquota.c:1.1.2.4 Sun Jan 30 19:38:45 2011
+++ src/usr.bin/quota/printquota.c Sun Jan 30 20:54:22 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: printquota.c,v 1.1.2.4 2011/01/30 19:38:45 bouyer Exp $ */
+/* $NetBSD: printquota.c,v 1.1.2.5 2011/01/30 20:54:22 bouyer Exp $ */
/*
* Copyright (c) 1980, 1990, 1993
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)quota.c 8.4 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: printquota.c,v 1.1.2.4 2011/01/30 19:38:45 bouyer Exp $");
+__RCSID("$NetBSD: printquota.c,v 1.1.2.5 2011/01/30 20:54:22 bouyer Exp $");
#endif
#endif /* not lint */
@@ -65,7 +65,7 @@
* convert 64bit value to a printable string
*/
const char *
-intprt(uint64_t val, u_int flags, int hflag)
+intprt(uint64_t val, u_int flags, int hflag, int space)
{
#define NBUFS 3
static char bufs[NBUFS][21];
@@ -77,22 +77,20 @@
i = 0;
#undef NBUFS
if (val == UQUAD_MAX)
- return((flags & HN_PRIV_UNLIMITED) ? "unlimited" : "-");
-
- flags &= ~HN_PRIV_UNLIMITED;
+ return ((u_int)space > strlen("unlimited")) ? "unlimited" : "-";
if (flags & HN_B)
val = dbtob(val);
if (hflag) {
- humanize_number(buf, 6, val, "", HN_AUTOSCALE, flags);
+ humanize_number(buf, space + 1, val, "", HN_AUTOSCALE, flags);
return buf;
}
if (flags & HN_B) {
/* traditionnal display: blocks are in kilobytes */
val = val / 1024;
}
- snprintf(buf, sizeof(buf), "%" PRIu64, val);
+ snprintf(buf, space + 1, "%" PRIu64, val);
return buf;
}
@@ -100,27 +98,55 @@
* Calculate the grace period and return a printable string for it.
*/
const char *
-timeprt(time_t now, time_t seconds)
+timeprt(time_t now, time_t seconds, int space)
{
- time_t hours, minutes;
- static char buf[20];
+#define MINUTE 60
+#define HOUR (MINUTE * 60)
+#define DAY (HOUR * 24)
+#define WEEK (DAY * 7)
+
+ static char buf[20], *append;
+ int i, remain = space + 1;
if (now > seconds)
return ("none");
seconds -= now;
- minutes = (seconds + 30) / 60;
- hours = (minutes + 30) / 60;
- if (hours >= 36) {
- (void)snprintf(buf, sizeof buf, "%ddays",
- (int)((hours + 12) / 24));
+
+ append = &buf[0];
+ if ((seconds / WEEK) > 0) {
+ i = snprintf(append, remain, "%" PRId64 "W", (seconds / WEEK));
+ append += i;
+ remain -=i;
+ seconds = seconds % WEEK;
+ }
+ if (remain < 3 || seconds == 0)
return (buf);
+ if ((seconds / DAY) > 0) {
+ i = snprintf(append, remain, "%" PRId64 "D", (seconds / DAY));
+ append += i;
+ remain -=i;
+ seconds = seconds % DAY;
}
- if (minutes >= 60) {
- (void)snprintf(buf, sizeof buf, "%2d:%d",
- (int)(minutes / 60), (int)(minutes % 60));
+ if (remain < 4 || seconds == 0)
return (buf);
+ if ((seconds / HOUR) > 0) {
+ i = snprintf(append, remain, "%" PRId64 "H", (seconds / HOUR));
+ append += i;
+ remain -=i;
+ seconds = seconds % HOUR;
}
- (void)snprintf(buf, sizeof buf, "%2d", (int)minutes);
+ if (remain < 4 || seconds == 0)
+ return (buf);
+ if ((seconds / MINUTE) > 0) {
+ i = snprintf(append, remain, "%" PRId64 "M",
+ (seconds / MINUTE));
+ append += i;
+ remain -=i;
+ seconds = seconds % MINUTE;
+ }
+ if (remain < 4 || seconds == 0)
+ return (buf);
+ i = snprintf(append, remain, "%" PRId64 "S", seconds);
return (buf);
}
Index: src/usr.bin/quota/printquota.h
diff -u src/usr.bin/quota/printquota.h:1.1.2.4 src/usr.bin/quota/printquota.h:1.1.2.5
--- src/usr.bin/quota/printquota.h:1.1.2.4 Sun Jan 30 19:38:45 2011
+++ src/usr.bin/quota/printquota.h Sun Jan 30 20:54:22 2011
@@ -1,7 +1,6 @@
-/* $NetBSD: printquota.h,v 1.1.2.4 2011/01/30 19:38:45 bouyer Exp $ */
+/* $NetBSD: printquota.h,v 1.1.2.5 2011/01/30 20:54:22 bouyer Exp $ */
-const char *intprt(uint64_t, u_int, int);
-#define HN_PRIV_UNLIMITED 0x80000000 /* print "unlimited" instead of "-" */
-const char *timeprt(time_t, time_t);
+const char *intprt(uint64_t, u_int, int, int);
+const char *timeprt(time_t, time_t, int space);
int intrd(char *str, uint64_t *val, u_int);
Index: src/usr.bin/quota/quota.c
diff -u src/usr.bin/quota/quota.c:1.33.2.4 src/usr.bin/quota/quota.c:1.33.2.5
--- src/usr.bin/quota/quota.c:1.33.2.4 Sun Jan 30 19:38:45 2011
+++ src/usr.bin/quota/quota.c Sun Jan 30 20:54:22 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: quota.c,v 1.33.2.4 2011/01/30 19:38:45 bouyer Exp $ */
+/* $NetBSD: quota.c,v 1.33.2.5 2011/01/30 20:54:22 bouyer Exp $ */
/*
* Copyright (c) 1980, 1990, 1993
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)quota.c 8.4 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: quota.c,v 1.33.2.4 2011/01/30 19:38:45 bouyer Exp $");
+__RCSID("$NetBSD: quota.c,v 1.33.2.5 2011/01/30 20:54:22 bouyer Exp $");
#endif
#endif /* not lint */
@@ -399,41 +399,41 @@
}
if (msgb)
timemsg = timeprt(now,
- qup->q2e.q2e_val[Q2V_BLOCK].q2v_time);
+ qup->q2e.q2e_val[Q2V_BLOCK].q2v_time, 8);
else if ((qup->flags & QUOTA2) != 0 && vflag)
timemsg = timeprt(0,
- qup->q2e.q2e_val[Q2V_BLOCK].q2v_grace);
+ qup->q2e.q2e_val[Q2V_BLOCK].q2v_grace, 8);
else
timemsg = NULL;
printf("%12s%9s%c%8s%9s%8s"
, nam
, intprt(qup->q2e.q2e_val[Q2V_BLOCK].q2v_cur
- ,HN_B, hflag)
+ ,HN_B, hflag, 8)
, (msgb == NULL) ? ' ' : '*'
, intprt(qup->q2e.q2e_val[Q2V_BLOCK].q2v_softlimit
- , HN_B, hflag)
+ , HN_B, hflag, 8)
, intprt(qup->q2e.q2e_val[Q2V_BLOCK].q2v_hardlimit
- , HN_B, hflag)
+ , HN_B, hflag, 8)
, timemsg);
if (msgi)
timemsg = timeprt(now,
- qup->q2e.q2e_val[Q2V_FILE].q2v_time);
+ qup->q2e.q2e_val[Q2V_FILE].q2v_time, 8);
else if ((qup->flags & QUOTA2) != 0 && vflag)
timemsg = timeprt(0,
- qup->q2e.q2e_val[Q2V_FILE].q2v_grace);
+ qup->q2e.q2e_val[Q2V_FILE].q2v_grace, 8);
else
timemsg = NULL;
printf("%8s%c%7s%8s%8s\n"
, intprt(qup->q2e.q2e_val[Q2V_FILE].q2v_cur
- , 0, hflag)
+ , 0, hflag, 7)
, (msgi == NULL) ? ' ' : '*'
, intprt(qup->q2e.q2e_val[Q2V_FILE].q2v_softlimit
- , 0, hflag)
+ , 0, hflag, 7)
, intprt(qup->q2e.q2e_val[Q2V_FILE].q2v_hardlimit
- , 0, hflag)
+ , 0, hflag, 7)
, timemsg);
continue;
}
Index: src/usr.sbin/edquota/edquota.c
diff -u src/usr.sbin/edquota/edquota.c:1.29.16.3 src/usr.sbin/edquota/edquota.c:1.29.16.4
--- src/usr.sbin/edquota/edquota.c:1.29.16.3 Sun Jan 30 19:38:45 2011
+++ src/usr.sbin/edquota/edquota.c Sun Jan 30 20:54:22 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: edquota.c,v 1.29.16.3 2011/01/30 19:38:45 bouyer Exp $ */
+/* $NetBSD: edquota.c,v 1.29.16.4 2011/01/30 20:54:22 bouyer Exp $ */
/*
* Copyright (c) 1980, 1990, 1993
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "from: @(#)edquota.c 8.3 (Berkeley) 4/27/95";
#else
-__RCSID("$NetBSD: edquota.c,v 1.29.16.3 2011/01/30 19:38:45 bouyer Exp $");
+__RCSID("$NetBSD: edquota.c,v 1.29.16.4 2011/01/30 20:54:22 bouyer Exp $");
#endif
#endif /* not lint */
@@ -682,19 +682,19 @@
fprintf(fd, "%s: %s %s, limits (soft = %s, hard = %s)\n",
qup->fsname, "blocks in use:",
intprt(qup->q2e.q2e_val[Q2V_BLOCK].q2v_cur,
- HN_NOSPACE | HN_B | HN_PRIV_UNLIMITED, Hflag),
+ HN_NOSPACE | HN_B, Hflag, 20),
intprt(qup->q2e.q2e_val[Q2V_BLOCK].q2v_softlimit,
- HN_NOSPACE | HN_B | HN_PRIV_UNLIMITED, Hflag),
+ HN_NOSPACE | HN_B, Hflag, 20),
intprt(qup->q2e.q2e_val[Q2V_BLOCK].q2v_hardlimit,
- HN_NOSPACE | HN_B | HN_PRIV_UNLIMITED, Hflag));
+ HN_NOSPACE | HN_B, Hflag, 20));
fprintf(fd, "%s %s, limits (soft = %s, hard = %s)\n",
"\tinodes in use:",
intprt(qup->q2e.q2e_val[Q2V_FILE].q2v_cur,
- HN_NOSPACE | HN_PRIV_UNLIMITED, Hflag),
+ HN_NOSPACE, Hflag, 20),
intprt(qup->q2e.q2e_val[Q2V_FILE].q2v_softlimit,
- HN_NOSPACE | HN_PRIV_UNLIMITED, Hflag),
+ HN_NOSPACE, Hflag, 20),
intprt(qup->q2e.q2e_val[Q2V_FILE].q2v_hardlimit,
- HN_NOSPACE | HN_PRIV_UNLIMITED, Hflag));
+ HN_NOSPACE, Hflag, 20));
}
fclose(fd);
return (1);
@@ -796,10 +796,10 @@
if (strcmp(fsp, qup->fsname))
continue;
if (strcmp(intprt(qup->q2e.q2e_val[Q2V_BLOCK].q2v_cur,
- HN_NOSPACE | HN_B | HN_PRIV_UNLIMITED, Hflag),
+ HN_NOSPACE | HN_B, Hflag, 20),
scurb) != 0 ||
strcmp(intprt(qup->q2e.q2e_val[Q2V_FILE].q2v_cur,
- HN_NOSPACE | HN_PRIV_UNLIMITED, Hflag),
+ HN_NOSPACE, Hflag, 20),
scuri) != 0) {
warnx("%s: cannot change current allocation",
fsp);
Index: src/usr.sbin/repquota/repquota.c
diff -u src/usr.sbin/repquota/repquota.c:1.25.2.3 src/usr.sbin/repquota/repquota.c:1.25.2.4
--- src/usr.sbin/repquota/repquota.c:1.25.2.3 Sun Jan 30 19:38:45 2011
+++ src/usr.sbin/repquota/repquota.c Sun Jan 30 20:54:23 2011
@@ -40,7 +40,7 @@
#if 0
static char sccsid[] = "@(#)repquota.c 8.2 (Berkeley) 11/22/94";
#else
-__RCSID("$NetBSD: repquota.c,v 1.25.2.3 2011/01/30 19:38:45 bouyer Exp $");
+__RCSID("$NetBSD: repquota.c,v 1.25.2.4 2011/01/30 20:54:23 bouyer Exp $");
#endif
#endif /* not lint */
@@ -415,10 +415,10 @@
fup->fu_q2e.q2e_val[Q2V_BLOCK].q2v_cur >=
fup->fu_q2e.q2e_val[Q2V_BLOCK].q2v_softlimit)
timemsg = timeprt(now,
- fup->fu_q2e.q2e_val[Q2V_BLOCK].q2v_time);
+ fup->fu_q2e.q2e_val[Q2V_BLOCK].q2v_time, 7);
else if (vflag && version == 2)
timemsg = timeprt(0,
- fup->fu_q2e.q2e_val[Q2V_BLOCK].q2v_grace);
+ fup->fu_q2e.q2e_val[Q2V_BLOCK].q2v_grace, 7);
else
timemsg = "";
@@ -432,29 +432,29 @@
fup->fu_q2e.q2e_val[Q2V_FILE].q2v_softlimit ?
'+' : '-',
intprt(fup->fu_q2e.q2e_val[Q2V_BLOCK].q2v_cur,
- HN_B, hflag),
+ HN_B, hflag, 9),
intprt(fup->fu_q2e.q2e_val[Q2V_BLOCK].q2v_softlimit,
- HN_B, hflag),
+ HN_B, hflag, 9),
intprt(fup->fu_q2e.q2e_val[Q2V_BLOCK].q2v_hardlimit,
- HN_B, hflag),
+ HN_B, hflag, 9),
timemsg);
if (fup->fu_q2e.q2e_val[Q2V_FILE].q2v_softlimit &&
fup->fu_q2e.q2e_val[Q2V_FILE].q2v_cur >=
fup->fu_q2e.q2e_val[Q2V_FILE].q2v_softlimit)
timemsg = timeprt(now,
- fup->fu_q2e.q2e_val[Q2V_FILE].q2v_time);
+ fup->fu_q2e.q2e_val[Q2V_FILE].q2v_time, 7);
else if (vflag && version == 2)
timemsg = timeprt(0,
- fup->fu_q2e.q2e_val[Q2V_FILE].q2v_grace);
+ fup->fu_q2e.q2e_val[Q2V_FILE].q2v_grace, 7);
else
timemsg = "";
printf(" %8s%8s%8s%7s\n",
intprt(fup->fu_q2e.q2e_val[Q2V_FILE].q2v_cur,
- 0, hflag),
+ 0, hflag, 8),
intprt(fup->fu_q2e.q2e_val[Q2V_FILE].q2v_softlimit,
- 0, hflag),
+ 0, hflag, 8),
intprt(fup->fu_q2e.q2e_val[Q2V_FILE].q2v_hardlimit,
- 0, hflag),
+ 0, hflag, 8),
timemsg);
memset(&fup->fu_q2e, 0, sizeof(fup->fu_q2e));
}