Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/bouyer-quota2]: src Change timeprt to print in weeks, days, hours, minut...
details: https://anonhg.NetBSD.org/src/rev/845338e73931
branches: bouyer-quota2
changeset: 761094:845338e73931
user: bouyer <bouyer%NetBSD.org@localhost>
date: Sun Jan 30 20:54:22 2011 +0000
description:
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"
diffstat:
usr.bin/quota/printquota.c | 66 ++++++++++++++++++++++++++++++-------------
usr.bin/quota/printquota.h | 7 ++--
usr.bin/quota/quota.c | 24 ++++++++--------
usr.sbin/edquota/edquota.c | 20 ++++++------
usr.sbin/repquota/repquota.c | 22 +++++++-------
5 files changed, 82 insertions(+), 57 deletions(-)
diffs (truncated from 325 to 300 lines):
diff -r 3e983d5b5512 -r 845338e73931 usr.bin/quota/printquota.c
--- a/usr.bin/quota/printquota.c Sun Jan 30 19:49:48 2011 +0000
+++ b/usr.bin/quota/printquota.c Sun Jan 30 20:54:22 2011 +0000
@@ -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;
+ }
+ 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;
}
- (void)snprintf(buf, sizeof buf, "%2d", (int)minutes);
+ if (remain < 4 || seconds == 0)
+ return (buf);
+ i = snprintf(append, remain, "%" PRId64 "S", seconds);
return (buf);
}
diff -r 3e983d5b5512 -r 845338e73931 usr.bin/quota/printquota.h
--- a/usr.bin/quota/printquota.h Sun Jan 30 19:49:48 2011 +0000
+++ b/usr.bin/quota/printquota.h Sun Jan 30 20:54:22 2011 +0000
@@ -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);
diff -r 3e983d5b5512 -r 845338e73931 usr.bin/quota/quota.c
--- a/usr.bin/quota/quota.c Sun Jan 30 19:49:48 2011 +0000
+++ b/usr.bin/quota/quota.c Sun Jan 30 20:54:22 2011 +0000
@@ -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;
}
diff -r 3e983d5b5512 -r 845338e73931 usr.sbin/edquota/edquota.c
--- a/usr.sbin/edquota/edquota.c Sun Jan 30 19:49:48 2011 +0000
+++ b/usr.sbin/edquota/edquota.c Sun Jan 30 20:54:22 2011 +0000
@@ -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);
diff -r 3e983d5b5512 -r 845338e73931 usr.sbin/repquota/repquota.c
--- a/usr.sbin/repquota/repquota.c Sun Jan 30 19:49:48 2011 +0000
+++ b/usr.sbin/repquota/repquota.c Sun Jan 30 20:54:22 2011 +0000
@@ -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);
Home |
Main Index |
Thread Index |
Old Index