Bend the 'L', 'M', and 'H' modifiers to work on the size, whereby it
is rounded to the nearest kilobyte, megabyte, or gigabyte. Implemented at lukem's request since some things can't deal with overly large numbers when files are really large. Have to do something like humanize_number(3), but that interface isn't really what I'm looking for. I think. More examination required.
This commit is contained in:
parent
a30f20fce8
commit
277396bd87
|
@ -1,6 +1,6 @@
|
|||
.\" $NetBSD: stat.1,v 1.16 2005/04/04 13:34:40 wiz Exp $
|
||||
.\" $NetBSD: stat.1,v 1.17 2005/06/23 03:13:24 atatat Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
.\" Copyright (c) 2002-2005 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to The NetBSD Foundation
|
||||
|
@ -34,7 +34,7 @@
|
|||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd December 31, 2004
|
||||
.Dd June 23, 2005
|
||||
.Dt STAT 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -257,78 +257,85 @@ is a string, but if specified explicitly, these four characters are
|
|||
prepended.
|
||||
.El
|
||||
.It Cm sub
|
||||
An optional sub field specifier (high, middle, low).
|
||||
An optional sub field specifier (high, middle, or low).
|
||||
Only applies to the
|
||||
.Cm p ,
|
||||
.Cm d ,
|
||||
.Cm r ,
|
||||
.Cm T ,
|
||||
.Cm N ,
|
||||
and
|
||||
.Cm T
|
||||
.Cm z
|
||||
output formats.
|
||||
It can be one of the following:
|
||||
.Bl -tag -width Ds
|
||||
.It Cm H
|
||||
.Dq High
|
||||
-- specifies the major number for devices from
|
||||
.Cm r
|
||||
or
|
||||
.Cm d ,
|
||||
the
|
||||
.Dq user
|
||||
bits for permissions from the string form of
|
||||
.Cm p ,
|
||||
the file
|
||||
-- depending on the
|
||||
.Cm datum :
|
||||
.Bl -tag -compact -width door
|
||||
.It Cm d , r
|
||||
Major number for devices
|
||||
.It Cm p
|
||||
.Dq User
|
||||
bits from the string form of permissions or the file
|
||||
.Dq type
|
||||
bits from the numeric forms of
|
||||
.Cm p ,
|
||||
the long output form of
|
||||
.Cm T ,
|
||||
and the directory path from the
|
||||
.Cm N
|
||||
output similar to what
|
||||
bits from the numeric forms
|
||||
.It Cm T
|
||||
The long output form of file type
|
||||
.It Cm N
|
||||
Directory path of the file, similar to what
|
||||
.Xr dirname 1
|
||||
would show.
|
||||
.It Cm L
|
||||
.Dq Low
|
||||
-- specifies the minor number for devices from
|
||||
.Cm r
|
||||
or
|
||||
.Cm d ,
|
||||
the
|
||||
.Dq other
|
||||
bits for permissions from the string form of
|
||||
.Cm p ,
|
||||
the
|
||||
.Dq user ,
|
||||
.Dq group ,
|
||||
and
|
||||
.Dq other
|
||||
bits from the numeric forms of
|
||||
.Cm p ,
|
||||
the
|
||||
.Ic ls -F
|
||||
style output character for file type when used with
|
||||
.Cm T
|
||||
(the use of
|
||||
.Cm L
|
||||
for this is optional), and the filename component of the
|
||||
.Cm N
|
||||
output form similar to what
|
||||
.Xr basename 1
|
||||
would display.
|
||||
would show
|
||||
.It Cm z
|
||||
File size, rounded to the nearest gigabyte
|
||||
.El
|
||||
.It Cm M
|
||||
.Dq Middle
|
||||
-- specifies the
|
||||
-- depending on the
|
||||
.Cm datum :
|
||||
.Bl -tag -compact -width door
|
||||
.It Cm p
|
||||
The
|
||||
.Dq group
|
||||
bits for permissions from the string output form of
|
||||
.Cm p ,
|
||||
or the
|
||||
bits from the string form of permissions or the
|
||||
.Dq suid ,
|
||||
.Dq sgid ,
|
||||
and
|
||||
.Dq sticky
|
||||
bits for the numeric forms of
|
||||
.Cm p .
|
||||
bits from the numeric forms
|
||||
.It Cm z
|
||||
File size, rounded to the nearest megabyte
|
||||
.El
|
||||
.It Cm L
|
||||
.Dq Low
|
||||
-- depending on the
|
||||
.Cm datum :
|
||||
.Bl -tag -compact -width door
|
||||
.It Cm r , d
|
||||
Minor number for devices
|
||||
.It Cm p
|
||||
The
|
||||
.Dq other
|
||||
bits from the string form of permissions or the
|
||||
.Dq user ,
|
||||
.Dq group ,
|
||||
and
|
||||
.Dq other
|
||||
bits from the numeric forms
|
||||
.It Cm T
|
||||
The
|
||||
.Ic ls -F
|
||||
style output character for file type (the use of
|
||||
.Cm L
|
||||
here is optional)
|
||||
.It Cm N
|
||||
Base filename of the file, similar to what
|
||||
.Xr basename 1
|
||||
would show
|
||||
.It Cm z
|
||||
File size, rounded to the nearest kilobyte
|
||||
.El
|
||||
.El
|
||||
.It Cm datum
|
||||
A required field specifier, being one of the following:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: stat.c,v 1.22 2005/04/22 03:36:48 atatat Exp $ */
|
||||
/* $NetBSD: stat.c,v 1.23 2005/06/23 03:13:24 atatat Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
|
@ -42,7 +42,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(lint)
|
||||
__RCSID("$NetBSD: stat.c,v 1.22 2005/04/22 03:36:48 atatat Exp $");
|
||||
__RCSID("$NetBSD: stat.c,v 1.23 2005/06/23 03:13:24 atatat Exp $");
|
||||
#endif
|
||||
|
||||
#if ! HAVE_NBTOOL_CONFIG_H
|
||||
|
@ -560,13 +560,14 @@ format1(const struct stat *st,
|
|||
struct tm *tm;
|
||||
time_t secs;
|
||||
long nsecs;
|
||||
int l, small, formats, gottime;
|
||||
int l, small, formats, gottime, shift;
|
||||
|
||||
formats = 0;
|
||||
small = 0;
|
||||
gottime = 0;
|
||||
secs = 0;
|
||||
nsecs = 0;
|
||||
shift = 0;
|
||||
|
||||
/*
|
||||
* First, pick out the data and tweak it based on hilo or
|
||||
|
@ -732,6 +733,20 @@ format1(const struct stat *st,
|
|||
formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
|
||||
if (ofmt == 0)
|
||||
ofmt = FMTF_UNSIGNED;
|
||||
switch (hilo) {
|
||||
case HIGH_PIECE:
|
||||
shift = 30; /* gigabytes */
|
||||
hilo = 0;
|
||||
break;
|
||||
case MIDDLE_PIECE:
|
||||
shift = 20; /* megabytes */
|
||||
hilo = 0;
|
||||
break;
|
||||
case LOW_PIECE:
|
||||
shift = 10; /* kilobytes */
|
||||
hilo = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SHOW_st_blocks:
|
||||
small = (sizeof(st->st_blocks) == 4);
|
||||
|
@ -1045,10 +1060,20 @@ format1(const struct stat *st,
|
|||
(void)strcat(lfmt, "ll");
|
||||
switch (ofmt) {
|
||||
case FMTF_DECIMAL: (void)strcat(lfmt, "d"); break;
|
||||
case FMTF_OCTAL: (void)strcat(lfmt, "o"); break;
|
||||
case FMTF_OCTAL: (void)strcat(lfmt, "o"); break;
|
||||
case FMTF_UNSIGNED: (void)strcat(lfmt, "u"); break;
|
||||
case FMTF_HEX: (void)strcat(lfmt, "x"); break;
|
||||
}
|
||||
|
||||
/*
|
||||
* shift and round to nearest for kilobytes, megabytes,
|
||||
* gigabytes.
|
||||
*/
|
||||
if (shift > 0) {
|
||||
data >>= (shift - 1);
|
||||
data++;
|
||||
data >>= 1;
|
||||
}
|
||||
|
||||
return (snprintf(buf, blen, lfmt, data));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue