PR/36817: Zafer Aydogan: Don't use -g to implement the same named option

in solaris to display statvfs output, use -G instead. I researched this
and all other implementations except Solaris (OS/X, FreeBSD, us before June
24, 2007) use -g to signify gigabytes. So revert to that.
PR/38154: YAMAMOTO Takashi: df -P doesn't work without -k. Fix from Anon Ymous
together with passing lint, and exiting with the right values.
This commit is contained in:
christos 2008-03-04 17:59:55 +00:00
parent cee019495b
commit 7ca37f5cdc
3 changed files with 51 additions and 36 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.15 2002/08/19 09:56:01 lukem Exp $
# $NetBSD: Makefile,v 1.16 2008/03/04 17:59:55 christos Exp $
# @(#)Makefile 8.3 (Berkeley) 5/8/95
.include <bsd.own.mk>
@ -6,5 +6,6 @@
PROG= df
.PATH: ${NETBSDSRCDIR}/bin/csh
SRCS= df.c strpct.c
WARNS=4
.include <bsd.prog.mk>

View File

@ -1,4 +1,4 @@
.\" $NetBSD: df.1,v 1.41 2007/06/24 01:52:46 christos Exp $
.\" $NetBSD: df.1,v 1.42 2008/03/04 17:59:55 christos Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@ -29,7 +29,7 @@
.\"
.\" @(#)df.1 8.2 (Berkeley) 1/13/92
.\"
.Dd June 23, 2007
.Dd March 4, 2008
.Dt DF 1
.Os
.Sh NAME
@ -37,8 +37,8 @@
.Nd display free disk space
.Sh SYNOPSIS
.Nm
.Op Fl aGklmn
.Op Fl g | Fl i | Fl P
.Op Fl agklmn
.Op Fl G | Fl i | Fl P
.Op Fl t Ar type
.Op Ar file | Ar file_system ...
.Sh DESCRIPTION
@ -72,21 +72,23 @@ Show all mount points,
including those that were mounted with the
.Dv MNT_IGNORE
flag.
.It Fl G
.It Fl g
The
.Fl G
.Fl g
option causes the numbers to be reported in gigabytes (1024*1024*1024
bytes).
.It Fl g
.It Fl G
Display all the fields of the structure(s) returned by
.Xr statvfs 2 .
This option cannot be used with the
.Fl i
or
.Fl P
options.
options, and it is modelled after the Solaris
.Fl g
option.
This option will override the
.Fl G ,
.Fl g ,
.Fl h ,
.Fl k ,
and
@ -177,7 +179,7 @@ that file system.
If the environment variable
.Ev BLOCKSIZE
is set, and the
.Fl G ,
.Fl g ,
.Fl h ,
.Fl k
and

View File

@ -1,4 +1,4 @@
/* $NetBSD: df.c,v 1.79 2008/03/04 09:03:28 yamt Exp $ */
/* $NetBSD: df.c,v 1.80 2008/03/04 17:59:55 christos Exp $ */
/*
* Copyright (c) 1980, 1990, 1993, 1994
@ -45,7 +45,7 @@ __COPYRIGHT(
#if 0
static char sccsid[] = "@(#)df.c 8.7 (Berkeley) 4/2/94";
#else
__RCSID("$NetBSD: df.c,v 1.79 2008/03/04 09:03:28 yamt Exp $");
__RCSID("$NetBSD: df.c,v 1.80 2008/03/04 17:59:55 christos Exp $");
#endif
#endif /* not lint */
@ -129,7 +129,8 @@ main(int argc, char *argv[])
break;
case 't':
if (typelist != NULL)
errx(1, "only one -t option may be specified.");
errx(EXIT_FAILURE,
"only one -t option may be specified.");
maketypelist(optarg);
break;
case '?':
@ -138,26 +139,34 @@ main(int argc, char *argv[])
}
if (gflag && (Pflag || iflag))
errx(1, "only one of -g and -P or -i may be specified");
errx(EXIT_FAILURE,
"only one of -g and -P or -i may be specified");
if (Pflag && iflag)
errx(1, "only one of -P and -i may be specified");
errx(EXIT_FAILURE,
"only one of -P and -i may be specified");
#if 0
/*
* The block size cannot be checked until after getbsize() is called.
*/
if (Pflag && (hflag || (usize != 1024 && usize != 512)))
errx(1, "non-standard block size incompatible with -P");
errx(EXIT_FAILURE,
"non-standard block size incompatible with -P");
#endif
argc -= optind;
argv += optind;
mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
if (mntsize == 0)
err(1, "retrieving information on mounted file systems");
err(EXIT_FAILURE,
"retrieving information on mounted file systems");
if (*argv == NULL) {
mntsize = regetmntinfo(&mntbuf, mntsize);
} else {
if ((mntbuf = malloc(argc * sizeof(*mntbuf))) == NULL)
err(1, "can't allocate statvfs array");
err(EXIT_FAILURE, "can't allocate statvfs array");
mntsize = 0;
for (; *argv != NULL; argv++) {
for (/*EMPTY*/; *argv != NULL; argv++) {
if (stat(*argv, &stbuf) < 0) {
if ((mntpt = getmntpt(*argv)) == 0) {
warn("%s", *argv);
@ -193,7 +202,7 @@ main(int argc, char *argv[])
maxwidth = 0;
for (i = 0; i < mntsize; i++) {
width = strlen(mntbuf[i].f_mntfromname);
width = (int)strlen(mntbuf[i].f_mntfromname);
if (width > maxwidth)
maxwidth = width;
}
@ -240,7 +249,7 @@ maketypelist(char *fslist)
char *nextcp, **av;
if ((fslist == NULL) || (fslist[0] == '\0'))
errx(1, "empty type list");
errx(EXIT_FAILURE, "empty type list");
/*
* XXX
@ -260,7 +269,7 @@ maketypelist(char *fslist)
/* Build an array of that many types. */
if ((av = typelist = malloc((i + 1) * sizeof(char *))) == NULL)
err(1, "can't allocate type array");
err(EXIT_FAILURE, "can't allocate type array");
av[0] = fslist;
for (i = 1, nextcp = fslist;
(nextcp = strchr(nextcp, ',')) != NULL; i++) {
@ -318,7 +327,7 @@ prthumanval(int64_t bytes, const char *pad)
{
char buf[6];
humanize_number(buf, sizeof(buf) - (bytes < 0 ? 0 : 1),
(void)humanize_number(buf, sizeof(buf) - (bytes < 0 ? 0 : 1),
bytes, "", HN_AUTOSCALE,
HN_B | HN_NOSPACE | HN_DECIMAL);
@ -329,9 +338,9 @@ void
prthuman(struct statvfs *sfsp, int64_t used, int64_t bavail)
{
prthumanval(sfsp->f_blocks * sfsp->f_frsize, " ");
prthumanval(used * sfsp->f_frsize, " ");
prthumanval(bavail * sfsp->f_frsize, " ");
prthumanval((int64_t)(sfsp->f_blocks * sfsp->f_frsize), " ");
prthumanval((int64_t)(used * sfsp->f_frsize), " ");
prthumanval((int64_t)(bavail * sfsp->f_frsize), " ");
}
/*
@ -361,9 +370,9 @@ prtstat(struct statvfs *sfsp, int maxwidth)
/*
* From SunOS-5.6:
*
* /var (/dev/dsk/c0t0d0s3 ): 8192 block size 1024 frag size
* /var (/dev/dsk/c0t0d0s3 ): 8192 block size 1024 frag size
* 984242 total blocks 860692 free blocks 859708 available 249984 total files
* 248691 free files 8388611 filesys id
* 248691 free files 8388611 filesys id
* ufs fstype 0x00000004 flag 255 filename length
*
*/
@ -380,7 +389,7 @@ prtstat(struct statvfs *sfsp, int maxwidth)
* block size" is the frag
* size.
*/
(void)printf("%10" PRId64 " total blocks %10" PRId64
(void)printf("%10" PRId64 " total blocks %10" PRId64
" free blocks %10" PRId64 " available\n",
(uint64_t)sfsp->f_blocks, (uint64_t)sfsp->f_bfree,
(uint64_t)sfsp->f_bavail);
@ -407,20 +416,20 @@ prtstat(struct statvfs *sfsp, int maxwidth)
switch (blocksize = usize) {
case 1024:
header = Pflag ? "1024-blocks" : "1K-blocks";
headerlen = strlen(header);
headerlen = (int)strlen(header);
break;
case 1024 * 1024:
header = "1M-blocks";
headerlen = strlen(header);
headerlen = (int)strlen(header);
break;
case 1024 * 1024 * 1024:
header = "1G-blocks";
headerlen = strlen(header);
headerlen = (int)strlen(header);
break;
default:
if (hflag) {
header = "Size";
headerlen = strlen(header);
headerlen = (int)strlen(header);
} else
header = getbsize(&headerlen, &blocksize);
break;
@ -432,6 +441,9 @@ prtstat(struct statvfs *sfsp, int maxwidth)
* or:
* "Filesystem 512-blocks Used Available Capacity Mounted on\n"
*/
if (blocksize != 1024 && blocksize != 512)
errx(EXIT_FAILURE,
"non-standard block size incompatible with -P");
(void)printf("Filesystem %s Used Available Capacity "
"Mounted on\n", header);
} else {
@ -453,7 +465,7 @@ prtstat(struct statvfs *sfsp, int maxwidth)
/*
* "%s %d %d %d %s %s\n", <file system name>, <total space>,
* <space used>, <space free>, <percentage used>,
* <file system root>
* <file system root>
*/
(void)printf("%s %" PRId64 " %" PRId64 " %" PRId64 " %s %s\n",
sfsp->f_mntfromname,