Module Name: src
Committed By: christos
Date: Sun Mar 6 20:47:59 UTC 2011
Modified Files:
src/usr.bin/quota: Makefile getvfsquota.c getvfsquota.h printquota.c
printquota.h quota.c
Log Message:
- WARNS=4
- KNF
- don't cast malloc
- don't use static buffers
- fix types
- remove extra \n's from errors
- fix prototypes
To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/quota/Makefile
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/quota/getvfsquota.c \
src/usr.bin/quota/getvfsquota.h src/usr.bin/quota/printquota.c \
src/usr.bin/quota/printquota.h
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/quota/quota.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/Makefile
diff -u src/usr.bin/quota/Makefile:1.7 src/usr.bin/quota/Makefile:1.8
--- src/usr.bin/quota/Makefile:1.7 Sun Mar 6 12:08:42 2011
+++ src/usr.bin/quota/Makefile Sun Mar 6 15:47:59 2011
@@ -1,6 +1,7 @@
-# $NetBSD: Makefile,v 1.7 2011/03/06 17:08:42 bouyer Exp $
+# $NetBSD: Makefile,v 1.8 2011/03/06 20:47:59 christos Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/6/93
+WARNS ?= 4
.include <bsd.own.mk>
PROG= quota
SRCS= quota.c printquota.c getvfsquota.c
Index: src/usr.bin/quota/getvfsquota.c
diff -u src/usr.bin/quota/getvfsquota.c:1.2 src/usr.bin/quota/getvfsquota.c:1.3
--- src/usr.bin/quota/getvfsquota.c:1.2 Sun Mar 6 12:08:42 2011
+++ src/usr.bin/quota/getvfsquota.c Sun Mar 6 15:47:59 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: getvfsquota.c,v 1.2 2011/03/06 17:08:42 bouyer Exp $ */
+/* $NetBSD: getvfsquota.c,v 1.3 2011/03/06 20:47:59 christos Exp $ */
/*-
* Copyright (c) 2011 Manuel Bouyer
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: getvfsquota.c,v 1.2 2011/03/06 17:08:42 bouyer Exp $");
+__RCSID("$NetBSD: getvfsquota.c,v 1.3 2011/03/06 20:47:59 christos Exp $");
#include <stdio.h>
#include <stdlib.h>
@@ -49,13 +49,12 @@
/* retrieve quotas from vfs, for the given user id */
int
getvfsquota(const char *mp, struct quota2_entry *q2e, int8_t *versp,
- long id, int type, int defaultq, int debug)
+ uint32_t id, int type, int defaultq, int debug)
{
prop_dictionary_t dict, data, cmd;
prop_array_t cmds, datas;
prop_object_iterator_t iter;
struct plistref pref;
- int error;
int8_t error8;
bool ret;
int retval = 0;
@@ -95,17 +94,14 @@
if (quotactl(mp, &pref) != 0)
err(1, "quotactl");
- if ((error = prop_dictionary_recv_syscall(&pref, &dict)) != 0) {
- errx(1, "prop_dictionary_recv_syscall: %s\n",
- strerror(error));
- }
+ if ((errno = prop_dictionary_recv_syscall(&pref, &dict)) != 0)
+ err(1, "prop_dictionary_recv_syscall");
if (debug)
printf("reply from kernel:\n%s\n",
prop_dictionary_externalize(dict));
- if ((error = quota2_get_cmds(dict, &cmds)) != 0) {
- errx(1, "quota2_get_cmds: %s\n",
- strerror(error));
- }
+ if ((errno = quota2_get_cmds(dict, &cmds)) != 0)
+ err(1, "quota2_get_cmds");
+
iter = prop_array_iterator(cmds);
if (iter == NULL)
err(1, "prop_array_iterator(cmds)");
@@ -120,20 +116,17 @@
if (error8) {
if (error8 != ENOENT && error8 != ENODEV) {
+ errno = error8;
if (defaultq) {
- fprintf(stderr,
- "get default %s quota: %s\n",
- qfextension[type],
- strerror(error8));
+ warn("get default %s quota",
+ qfextension[type]);
} else {
- fprintf(stderr,
- "get %s quota for %ld: %s\n",
- qfextension[type], id,
- strerror(error8));
+ warn("get %s quota for %u",
+ qfextension[type], id);
}
}
prop_object_release(dict);
- return (0);
+ return 0;
}
datas = prop_dictionary_get(cmd, "data");
if (datas == NULL)
@@ -156,11 +149,9 @@
if (data == NULL)
err(1, "prop_array_get(data)");
- error = quota2_dict_get_q2e_usage(data, q2e);
- if (error) {
- errx(1, "quota2_dict_get_q2e_usage: %s\n",
- strerror(error));
- }
+ errno = quota2_dict_get_q2e_usage(data, q2e);
+ if (errno)
+ err(1, "quota2_dict_get_q2e_usage");
retval = 1;
}
}
Index: src/usr.bin/quota/getvfsquota.h
diff -u src/usr.bin/quota/getvfsquota.h:1.2 src/usr.bin/quota/getvfsquota.h:1.3
--- src/usr.bin/quota/getvfsquota.h:1.2 Sun Mar 6 12:08:42 2011
+++ src/usr.bin/quota/getvfsquota.h Sun Mar 6 15:47:59 2011
@@ -1,6 +1,6 @@
-/* $NetBSD: getvfsquota.h,v 1.2 2011/03/06 17:08:42 bouyer Exp $ */
+/* $NetBSD: getvfsquota.h,v 1.3 2011/03/06 20:47:59 christos Exp $ */
int getvfsquota(const char *, struct quota2_entry *, int8_t *,
- long, int, int, int);
+ uint32_t, int, int, int);
extern const char *qfextension[];
Index: src/usr.bin/quota/printquota.c
diff -u src/usr.bin/quota/printquota.c:1.2 src/usr.bin/quota/printquota.c:1.3
--- src/usr.bin/quota/printquota.c:1.2 Sun Mar 6 12:08:42 2011
+++ src/usr.bin/quota/printquota.c Sun Mar 6 15:47:59 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: printquota.c,v 1.2 2011/03/06 17:08:42 bouyer Exp $ */
+/* $NetBSD: printquota.c,v 1.3 2011/03/06 20:47:59 christos 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.2 2011/03/06 17:08:42 bouyer Exp $");
+__RCSID("$NetBSD: printquota.c,v 1.3 2011/03/06 20:47:59 christos Exp $");
#endif
#endif /* not lint */
@@ -65,32 +65,24 @@
* convert 64bit value to a printable string
*/
const char *
-intprt(uint64_t val, u_int flags, int hflag, int space)
+intprt(char *buf, size_t len, uint64_t val, int flags, int hflag)
{
-#define NBUFS 3
- static char bufs[NBUFS][21];
- char *buf;
- static int i = 0;
-
- buf = bufs[i++];
- if (i == NBUFS)
- i = 0;
-#undef NBUFS
if (val == UQUAD_MAX)
- return ((u_int)space > strlen("unlimited")) ? "unlimited" : "-";
+ return (len >= sizeof("unlimited")) ? "unlimited" : "-";
if (flags & HN_B)
val = dbtob(val);
if (hflag) {
- humanize_number(buf, space + 1, val, "", HN_AUTOSCALE, flags);
+ (void)humanize_number(buf, len, (int64_t)val, "", HN_AUTOSCALE,
+ flags);
return buf;
}
if (flags & HN_B) {
/* traditionnal display: blocks are in kilobytes */
val = val / 1024;
}
- snprintf(buf, space + 1, "%" PRIu64, val);
+ (void)snprintf(buf, len, "%" PRId64, val);
return buf;
}
@@ -105,13 +97,12 @@
#define YEAR (DAY * 355)
const char *
-timeprt(time_t now, time_t seconds, int space)
+timeprt(char *buf, size_t len, time_t now, time_t seconds)
{
time_t years, months, weeks, days, hours, minutes;
- static char buf[20];
if (now > seconds)
- return ("none");
+ return "none";
seconds -= now;
@@ -123,81 +114,80 @@
weeks = (seconds + WEEK / 2) / WEEK;
if (years >= 2) {
- (void)snprintf(buf, space+1, "%" PRId64 "years", years);
+ (void)snprintf(buf, len, "%" PRId64 "years", years);
return buf;
}
if (weeks > 9) {
- (void)snprintf(buf, space+1, "%" PRId64 "months", months);
+ (void)snprintf(buf, len, "%" PRId64 "months", months);
return buf;
}
if (days > 9) {
- (void)snprintf(buf, space+1, "%" PRId64 "weeks", weeks);
+ (void)snprintf(buf, len, "%" PRId64 "weeks", weeks);
return buf;
}
if (hours > 36) {
- (void)snprintf(buf, space+1, "%" PRId64 "days", days);
+ (void)snprintf(buf, len, "%" PRId64 "days", days);
return buf;
}
if (minutes > 60) {
- (void)snprintf(buf, space+1, "%2d:%d",
+ (void)snprintf(buf, len, "%2d:%d",
(int)(minutes / 60), (int)(minutes % 60));
return buf;
}
- (void)snprintf(buf, sizeof buf, "%2d", (int)minutes);
+ (void)snprintf(buf, len, "%2d", (int)minutes);
return buf;
}
+#if 0
/*
* Calculate the grace period and return a precise string for it,
* either in seconds or in format xWyDzHtMuS
*/
const char *
-timepprt(time_t seconds, int hflag, int space)
+timepprt(char *buf, size_t len, time_t seconds, int hflag, int space)
{
- static char buf[20], *append;
- int i, remain = space + 1;
+ ssize_t i = 0;
if (hflag == 0) {
- snprintf(buf, remain, "%" PRId64, seconds);
+ (void)snprintf(buf, len, "%" PRId64, seconds);
return buf;
}
- append = &buf[0];
if ((seconds / WEEK) > 0) {
- i = snprintf(append, remain, "%" PRId64 "W", (seconds / WEEK));
- append += i;
- remain -=i;
+ i += snprintf(buf + i, len - i, "%" PRId64 "W", seconds / WEEK);
seconds = seconds % WEEK;
}
+
if (remain < 3 || seconds == 0)
- return (buf);
+ return buf;
+
if ((seconds / DAY) > 0) {
- i = snprintf(append, remain, "%" PRId64 "D", (seconds / DAY));
- append += i;
- remain -=i;
+ i += snprintf(buf + i, len - i, "%" PRId64 "D", seconds / DAY);
seconds = seconds % DAY;
}
+
if (remain < 4 || seconds == 0)
- return (buf);
+ return buf;
+
if ((seconds / HOUR) > 0) {
- i = snprintf(append, remain, "%" PRId64 "H", (seconds / HOUR));
- append += i;
- remain -=i;
+ i += snprintf(buf + i, len - i, "%" PRId64 "H", seconds / HOUR);
seconds = seconds % HOUR;
}
+
if (remain < 4 || seconds == 0)
- return (buf);
+ return buf;
+
if ((seconds / MINUTE) > 0) {
- i = snprintf(append, remain, "%" PRId64 "M",
- (seconds / MINUTE));
- append += i;
- remain -=i;
+ i += snprintf(buf + i , len - i, "%" PRId64 "M",
+ seconds / MINUTE);
seconds = seconds % MINUTE;
}
+
if (remain < 4 || seconds == 0)
- return (buf);
- i = snprintf(append, remain, "%" PRId64 "S", seconds);
- return (buf);
+ return buf;
+
+ (void)snprintf(buf + i, len - i, "%" PRId64 "S", seconds);
+ return buf;
}
/*
@@ -282,3 +272,4 @@
*val = btodb(*val);
return ret;
}
+#endif
Index: src/usr.bin/quota/printquota.h
diff -u src/usr.bin/quota/printquota.h:1.2 src/usr.bin/quota/printquota.h:1.3
--- src/usr.bin/quota/printquota.h:1.2 Sun Mar 6 12:08:42 2011
+++ src/usr.bin/quota/printquota.h Sun Mar 6 15:47:59 2011
@@ -1,8 +1,10 @@
-/* $NetBSD: printquota.h,v 1.2 2011/03/06 17:08:42 bouyer Exp $ */
+/* $NetBSD: printquota.h,v 1.3 2011/03/06 20:47:59 christos Exp $ */
-const char *intprt(uint64_t, u_int, int, int);
-const char *timeprt(time_t, time_t, int);
+const char *intprt(char *, size_t, uint64_t, int, int);
+const char *timeprt(char *, size_t, time_t, time_t);
+#if 0
const char *timepprt(time_t, int, int);
int timeprd(const char *, time_t *);
int intrd(char *str, uint64_t *val, u_int);
+#endif
Index: src/usr.bin/quota/quota.c
diff -u src/usr.bin/quota/quota.c:1.34 src/usr.bin/quota/quota.c:1.35
--- src/usr.bin/quota/quota.c:1.34 Sun Mar 6 12:08:42 2011
+++ src/usr.bin/quota/quota.c Sun Mar 6 15:47:59 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: quota.c,v 1.34 2011/03/06 17:08:42 bouyer Exp $ */
+/* $NetBSD: quota.c,v 1.35 2011/03/06 20:47:59 christos 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.34 2011/03/06 17:08:42 bouyer Exp $");
+__RCSID("$NetBSD: quota.c,v 1.35 2011/03/06 20:47:59 christos Exp $");
#endif
#endif /* not lint */
@@ -88,31 +88,28 @@
#define FOUND 0x01
#define QUOTA2 0x02
-int alldigits(char *);
-int callaurpc(char *, int, int, int, xdrproc_t, void *, xdrproc_t, void *);
-int main(int, char **);
-int getnfsquota(struct statvfs *, struct fstab *, struct quotause *,
- long, int);
-struct quotause *getprivs(long id, int quotatype);
-void heading(int, u_long, const char *, const char *);
-void showgid(gid_t);
-void showgrpname(const char *);
-void showquotas(int, u_long, const char *);
-void showuid(uid_t);
-void showusrname(const char *);
-void usage(void);
-
-int qflag = 0;
-int vflag = 0;
-int hflag = 0;
-int dflag = 0;
-int Dflag = 0;
-uid_t myuid;
+static int alldigits(const char *);
+static int callaurpc(const char *, rpcprog_t, rpcvers_t, rpcproc_t,
+ xdrproc_t, void *, xdrproc_t, void *);
+static int getnfsquota(struct statvfs *, struct quotause *, uint32_t, int);
+static struct quotause *getprivs(uint32_t, int);
+static void heading(int, uint32_t, const char *, const char *);
+static void showgid(gid_t);
+static void showgrpname(const char *);
+static void showquotas(int, uint32_t, const char *);
+static void showuid(uid_t);
+static void showusrname(const char *);
+static void usage(void) __attribute__((__noreturn__));
+
+static int qflag = 0;
+static int vflag = 0;
+static int hflag = 0;
+static int dflag = 0;
+static int Dflag = 0;
+static uid_t myuid;
int
-main(argc, argv)
- int argc;
- char *argv[];
+main(int argc, char *argv[])
{
int ngroups;
gid_t mygid, gidset[NGROUPS];
@@ -153,16 +150,14 @@
uflag++;
if (dflag) {
#if 0
- if (myuid != 0) {
- printf("quota: -d: permission denied\n");
- exit(1);
- }
+ if (myuid != 0)
+ errx(1, "-d: permission denied");
#endif
if (uflag)
showquotas(USRQUOTA, 0, "");
if (gflag)
showquotas(GRPQUOTA, 0, "");
- exit(0);
+ return 0;
}
if (argc == 0) {
if (uflag)
@@ -181,50 +176,48 @@
showgid(gidset[i]);
}
}
- exit(0);
+ return 0;
}
if (uflag && gflag)
usage();
if (uflag) {
for (; argc > 0; argc--, argv++) {
if (alldigits(*argv))
- showuid(atoi(*argv));
+ showuid((uid_t)atoi(*argv));
else
showusrname(*argv);
}
- exit(0);
+ return 0;
}
if (gflag) {
for (; argc > 0; argc--, argv++) {
if (alldigits(*argv))
- showgid(atoi(*argv));
+ showgid((gid_t)atoi(*argv));
else
showgrpname(*argv);
}
- exit(0);
+ return 0;
}
/* NOTREACHED */
- return (0);
+ return 0;
}
-void
-usage()
+static void
+usage(void)
{
-
- fprintf(stderr, "%s\n%s\n%s\n%s\n",
- "usage: quota [-Dhguqv]",
- "\tquota [-Dhqv] -u username ...",
- "\tquota [-Dhqv] -g groupname ...",
- "\tquota -d [-Dhguqv]");
+ const char *p = getprogname();
+ fprintf(stderr, "Usage: %s [-Dhguqv]\n"
+ "\t%s [-Dhqv] -u username ...\n"
+ "\t%s [-Dhqv] -g groupname ...\n"
+ "\t%s -d [-Dhguqv]\n", p, p, p, p);
exit(1);
}
/*
* Print out quotas for a specified user identifier.
*/
-void
-showuid(uid)
- uid_t uid;
+static void
+showuid(uid_t uid)
{
struct passwd *pwd = getpwuid(uid);
const char *name;
@@ -234,7 +227,7 @@
else
name = pwd->pw_name;
if (uid != myuid && myuid != 0) {
- printf("quota: %s (uid %d): permission denied\n", name, uid);
+ warnx("%s (uid %d): permission denied", name, uid);
return;
}
showquotas(USRQUOTA, uid, name);
@@ -243,9 +236,8 @@
/*
* Print out quotas for a specified user name.
*/
-void
-showusrname(name)
- const char *name;
+static void
+showusrname(const char *name)
{
struct passwd *pwd = getpwnam(name);
@@ -263,9 +255,8 @@
/*
* Print out quotas for a specified group identifier.
*/
-void
-showgid(gid)
- gid_t gid;
+static void
+showgid(gid_t gid)
{
struct group *grp = getgrgid(gid);
int ngroups;
@@ -298,9 +289,8 @@
/*
* Print out quotas for a specified group name.
*/
-void
-showgrpname(name)
- const char *name;
+static void
+showgrpname(const char *name)
{
struct group *grp = getgrnam(name);
int ngroups;
@@ -330,17 +320,15 @@
showquotas(GRPQUOTA, grp->gr_gid, name);
}
-void
-showquotas(type, id, name)
- int type;
- u_long id;
- const char *name;
+static void
+showquotas(int type, uint32_t id, const char *name)
{
struct quotause *qup;
struct quotause *quplist;
const char *msgi, *msgb, *nam, *timemsg;
int lines = 0;
static time_t now;
+ char b0[20], b1[20], b2[20], b3[20];
if (now == 0)
time(&now);
@@ -404,43 +392,48 @@
nam = "";
}
if (msgb)
- timemsg = timeprt(now,
- qup->q2e.q2e_val[QL_BLOCK].q2v_time, 8);
+ timemsg = timeprt(b0, 9, now,
+ qup->q2e.q2e_val[QL_BLOCK].q2v_time);
else if ((qup->flags & QUOTA2) != 0 && vflag)
- timemsg = timeprt(0,
- qup->q2e.q2e_val[QL_BLOCK].q2v_grace, 8);
+ timemsg = timeprt(b0, 9, 0,
+ qup->q2e.q2e_val[QL_BLOCK].q2v_grace);
else
timemsg = "";
- printf("%12s%9s%c%8s%9s%8s"
- , nam
- , intprt(qup->q2e.q2e_val[QL_BLOCK].q2v_cur
- ,HN_B, hflag, 8)
- , (msgb == NULL) ? ' ' : '*'
- , intprt(qup->q2e.q2e_val[QL_BLOCK].q2v_softlimit
- , HN_B, hflag, 8)
- , intprt(qup->q2e.q2e_val[QL_BLOCK].q2v_hardlimit
- , HN_B, hflag, 8)
- , timemsg);
+ printf("%12s%9s%c%8s%9s%8s",
+ nam,
+ intprt(b1, 9,
+ qup->q2e.q2e_val[QL_BLOCK].q2v_cur,
+ HN_B, hflag),
+ (msgb == NULL) ? ' ' : '*',
+ intprt(b2, 9,
+ qup->q2e.q2e_val[QL_BLOCK].q2v_softlimit,
+ HN_B, hflag),
+ intprt(b3, 9,
+ qup->q2e.q2e_val[QL_BLOCK].q2v_hardlimit,
+ HN_B, hflag),
+ timemsg);
if (msgi)
- timemsg = timeprt(now,
- qup->q2e.q2e_val[QL_FILE].q2v_time, 8);
+ timemsg = timeprt(b0, 9, now,
+ qup->q2e.q2e_val[QL_FILE].q2v_time);
else if ((qup->flags & QUOTA2) != 0 && vflag)
- timemsg = timeprt(0,
- qup->q2e.q2e_val[QL_FILE].q2v_grace, 8);
+ timemsg = timeprt(b0, 9, 0,
+ qup->q2e.q2e_val[QL_FILE].q2v_grace);
else
timemsg = "";
- printf("%8s%c%7s%8s%8s\n"
- , intprt(qup->q2e.q2e_val[QL_FILE].q2v_cur
- , 0, hflag, 7)
- , (msgi == NULL) ? ' ' : '*'
- , intprt(qup->q2e.q2e_val[QL_FILE].q2v_softlimit
- , 0, hflag, 7)
- , intprt(qup->q2e.q2e_val[QL_FILE].q2v_hardlimit
- , 0, hflag, 7)
- , timemsg);
+ printf("%8s%c%7s%8s%8s\n",
+ intprt(b1, 8,
+ qup->q2e.q2e_val[QL_FILE].q2v_cur, 0, hflag),
+ (msgi == NULL) ? ' ' : '*',
+ intprt(b2, 8,
+ qup->q2e.q2e_val[QL_FILE].q2v_softlimit,
+ 0, hflag),
+ intprt(b3, 8,
+ qup->q2e.q2e_val[QL_FILE].q2v_hardlimit,
+ 0, hflag),
+ timemsg);
continue;
}
}
@@ -448,19 +441,16 @@
heading(type, id, name, "none");
}
-void
-heading(type, id, name, tag)
- int type;
- u_long id;
- const char *name, *tag;
+static void
+heading(int type, uint32_t id, const char *name, const char *tag)
{
if (dflag)
printf("Default %s disk quotas: %s\n",
qfextension[type], tag);
else
- printf("Disk quotas for %s %s (%cid %ld): %s\n",
+ printf("Disk quotas for %s %s (%cid %u): %s\n",
qfextension[type], name, *qfextension[type],
- (u_long)id, tag);
+ id, tag);
if (!qflag && tag[0] == '\0') {
printf("%12s%9s %8s%9s%8s%8s %7s%8s%8s\n"
@@ -480,10 +470,8 @@
/*
* Collect the requested quota information.
*/
-struct quotause *
-getprivs(id, quotatype)
- long id;
- int quotatype;
+static struct quotause *
+getprivs(uint32_t id, int quotatype)
{
struct quotause *qup, *quptail;
struct quotause *quphead;
@@ -498,14 +486,13 @@
errx(2, "no filesystems mounted!");
for (i = 0; i < nfst; i++) {
if (qup == NULL) {
- if ((qup =
- (struct quotause *)malloc(sizeof *qup)) == NULL)
- errx(2, "out of memory");
+ if ((qup = malloc(sizeof *qup)) == NULL)
+ err(1, "out of memory");
}
if (strncmp(fst[i].f_fstypename, "nfs",
sizeof(fst[i].f_fstypename)) == 0) {
version = 0;
- if (getnfsquota(&fst[i], NULL, qup, id, quotatype) == 0)
+ if (getnfsquota(&fst[i], qup, id, quotatype) == 0)
continue;
} else if ((fst[i].f_flag & ST_QUOTA) != 0) {
if (getvfsquota(fst[i].f_mntonname, &qup->q2e, &version,
@@ -525,18 +512,13 @@
quptail->next = 0;
qup = NULL;
}
- if (qup)
- free(qup);
- return (quphead);
+ free(qup);
+ return quphead;
}
-int
-getnfsquota(fst, fs, qup, id, quotatype)
- struct statvfs *fst;
- struct fstab *fs;
- struct quotause *qup;
- long id;
- int quotatype;
+static int
+getnfsquota(struct statvfs *fst, struct quotause *qup,
+ uint32_t id, int quotatype)
{
struct getquota_args gq_args;
struct ext_getquota_args ext_gq_args;
@@ -548,7 +530,7 @@
int ret;
if (fst->f_flag & MNT_LOCAL)
- return (0);
+ return 0;
/*
* must be some form of "hostname:/path"
@@ -556,13 +538,13 @@
cp = strchr(fst->f_mntfromname, ':');
if (cp == NULL) {
warnx("cannot find hostname for %s", fst->f_mntfromname);
- return (0);
+ return 0;
}
*cp = '\0';
if (*(cp+1) != '/') {
*cp = ':';
- return (0);
+ return 0;
}
ext_gq_args.gqa_pathp = cp + 1;
@@ -575,18 +557,18 @@
if (ret == RPC_PROGVERSMISMATCH) {
if (quotatype != USRQUOTA) {
*cp = ':';
- return (0);
+ return 0;
}
/* try RQUOTAVERS */
gq_args.gqa_pathp = cp + 1;
gq_args.gqa_uid = id;
ret = callaurpc(fst->f_mntfromname, RQUOTAPROG, RQUOTAVERS,
RQUOTAPROC_GETQUOTA, xdr_getquota_args, &gq_args,
- xdr_getquota_rslt, &gq_rslt);
+ xdr_getquota_rslt, &gq_rslt);
}
if (ret != RPC_SUCCESS) {
*cp = ':';
- return (0);
+ return 0;
}
switch (gq_rslt.status) {
@@ -597,7 +579,8 @@
break;
case Q_OK:
gettimeofday(&tv, NULL);
- /* blocks*/
+
+ /* blocks*/
q2e->q2e_val[QL_BLOCK].q2v_hardlimit =
dqblk.dqb_bhardlimit =
gq_rslt.getquota_rslt_u.gqr_rquota.rq_bhardlimit *
@@ -608,37 +591,34 @@
dqblk.dqb_curblocks =
gq_rslt.getquota_rslt_u.gqr_rquota.rq_curblocks *
(gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize / DEV_BSIZE);
- /* inodes */
+
+ /* inodes */
dqblk.dqb_ihardlimit =
- gq_rslt.getquota_rslt_u.gqr_rquota.rq_fhardlimit;
+ gq_rslt.getquota_rslt_u.gqr_rquota.rq_fhardlimit;
dqblk.dqb_isoftlimit =
- gq_rslt.getquota_rslt_u.gqr_rquota.rq_fsoftlimit;
+ gq_rslt.getquota_rslt_u.gqr_rquota.rq_fsoftlimit;
dqblk.dqb_curinodes =
- gq_rslt.getquota_rslt_u.gqr_rquota.rq_curfiles;
- /* grace times */
- dqblk.dqb_btime =
- tv.tv_sec + gq_rslt.getquota_rslt_u.gqr_rquota.rq_btimeleft;
- dqblk.dqb_itime =
- tv.tv_sec + gq_rslt.getquota_rslt_u.gqr_rquota.rq_ftimeleft;
+ gq_rslt.getquota_rslt_u.gqr_rquota.rq_curfiles;
+
+ /* grace times */
+ dqblk.dqb_btime = (int)(tv.tv_sec +
+ gq_rslt.getquota_rslt_u.gqr_rquota.rq_btimeleft);
+ dqblk.dqb_itime = (int)(tv.tv_sec +
+ gq_rslt.getquota_rslt_u.gqr_rquota.rq_ftimeleft);
dqblk2q2e(&dqblk, q2e);
*cp = ':';
- return (1);
+ return 1;
default:
warnx("bad rpc result, host: %s", fst->f_mntfromname);
break;
}
*cp = ':';
- return (0);
+ return 0;
}
-int
-callaurpc(host, prognum, versnum, procnum, inproc, in, outproc, out)
- char *host;
- int prognum, versnum, procnum;
- xdrproc_t inproc;
- void *in;
- xdrproc_t outproc;
- void *out;
+static int
+callaurpc(const char *host, rpcprog_t prognum, rpcvers_t versnum,
+ rpcproc_t procnum, xdrproc_t inproc, void *in, xdrproc_t outproc, void *out)
{
struct sockaddr_in server_addr;
enum clnt_stat clnt_stat;
@@ -649,7 +629,7 @@
int sock = RPC_ANYSOCK;
if ((hp = gethostbyname(host)) == NULL)
- return ((int) RPC_UNKNOWNHOST);
+ return (int) RPC_UNKNOWNHOST;
timeout.tv_usec = 0;
timeout.tv_sec = 6;
memmove(&server_addr.sin_addr, hp->h_addr, hp->h_length);
@@ -658,7 +638,7 @@
if ((client = clntudp_create(&server_addr, prognum,
versnum, timeout, &sock)) == NULL)
- return ((int) rpc_createerr.cf_stat);
+ return (int) rpc_createerr.cf_stat;
client->cl_auth = authunix_create_default();
tottimeout.tv_sec = 25;
@@ -666,19 +646,18 @@
clnt_stat = clnt_call(client, procnum, inproc, in,
outproc, out, tottimeout);
- return ((int) clnt_stat);
+ return (int) clnt_stat;
}
-int
-alldigits(s)
- char *s;
+static int
+alldigits(const char *s)
{
- int c;
+ unsigned char c;
c = *s++;
do {
if (!isdigit(c))
- return (0);
+ return 0;
} while ((c = *s++) != 0);
- return (1);
+ return 1;
}