Module Name: src
Committed By: simonb
Date: Wed Dec 11 12:56:31 UTC 2024
Modified Files:
src/bin/ls: ls.c ls.h print.c
Log Message:
Use the number of blocks used in the current directory instead of the
total file byte count when printing the initial "total" line with the
-h option combined with -s or -l options.
To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/bin/ls/ls.c
cvs rdiff -u -r1.19 -r1.20 src/bin/ls/ls.h
cvs rdiff -u -r1.58 -r1.59 src/bin/ls/print.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/bin/ls/ls.c
diff -u src/bin/ls/ls.c:1.78 src/bin/ls/ls.c:1.79
--- src/bin/ls/ls.c:1.78 Fri Feb 2 22:58:26 2024
+++ src/bin/ls/ls.c Wed Dec 11 12:56:31 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: ls.c,v 1.78 2024/02/02 22:58:26 christos Exp $ */
+/* $NetBSD: ls.c,v 1.79 2024/12/11 12:56:31 simonb Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
#if 0
static char sccsid[] = "@(#)ls.c 8.7 (Berkeley) 8/5/94";
#else
-__RCSID("$NetBSD: ls.c,v 1.78 2024/02/02 22:58:26 christos Exp $");
+__RCSID("$NetBSD: ls.c,v 1.79 2024/12/11 12:56:31 simonb Exp $");
#endif
#endif /* not lint */
@@ -347,7 +347,7 @@ ls_main(int argc, char *argv[])
if (f_inode || f_longform || f_size) {
if (!kflag)
(void)getbsize(NULL, &blocksize);
- blocksize /= 512;
+ blocksize /= POSIX_BLOCK_SIZE;
}
/* Select a sort function. */
@@ -495,7 +495,7 @@ display(FTSENT *p, FTSENT *list)
DISPLAY d;
FTSENT *cur;
NAMES *np;
- u_int64_t btotal, stotal;
+ u_int64_t btotal;
off_t maxsize;
blkcnt_t maxblock;
ino_t maxinode;
@@ -524,7 +524,7 @@ display(FTSENT *p, FTSENT *list)
maxinode = maxnlink = 0;
bcfile = 0;
maxuser = maxgroup = maxflags = maxlen = 0;
- btotal = stotal = maxblock = maxsize = 0;
+ btotal = maxblock = maxsize = 0;
maxmajor = maxminor = 0;
for (cur = list, entries = 0; cur; cur = cur->fts_link) {
if (cur->fts_info == FTS_ERR || cur->fts_info == FTS_NS) {
@@ -573,7 +573,6 @@ display(FTSENT *p, FTSENT *list)
}
btotal += sp->st_blocks;
- stotal += sp->st_size;
if (f_longform) {
if (f_numericonly ||
(user = user_from_uid(sp->st_uid, 0)) ==
@@ -629,7 +628,6 @@ display(FTSENT *p, FTSENT *list)
d.maxlen = maxlen;
if (needstats) {
d.btotal = btotal;
- d.stotal = stotal;
if (f_humanize) {
d.s_block = 4; /* min buf length for humanize_number */
} else {
Index: src/bin/ls/ls.h
diff -u src/bin/ls/ls.h:1.19 src/bin/ls/ls.h:1.20
--- src/bin/ls/ls.h:1.19 Thu Feb 20 18:56:36 2014
+++ src/bin/ls/ls.h Wed Dec 11 12:56:31 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: ls.h,v 1.19 2014/02/20 18:56:36 christos Exp $ */
+/* $NetBSD: ls.h,v 1.20 2024/12/11 12:56:31 simonb Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -36,6 +36,8 @@
#define NO_PRINT 1
+/* POSIX (IEEE Std 1003.1-2001) says we should use 512 blocks */
+#define POSIX_BLOCK_SIZE 512
extern long blocksize; /* block size units */
extern int f_accesstime; /* use time of last access */
@@ -59,7 +61,6 @@ extern int f_leafonly; /* when recursin
typedef struct {
FTSENT *list;
u_int64_t btotal;
- u_int64_t stotal;
int entries;
unsigned int maxlen;
int s_block;
Index: src/bin/ls/print.c
diff -u src/bin/ls/print.c:1.58 src/bin/ls/print.c:1.59
--- src/bin/ls/print.c:1.58 Wed Nov 6 16:40:58 2024
+++ src/bin/ls/print.c Wed Dec 11 12:56:31 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: print.c,v 1.58 2024/11/06 16:40:58 jschauma Exp $ */
+/* $NetBSD: print.c,v 1.59 2024/12/11 12:56:31 simonb Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)print.c 8.5 (Berkeley) 7/28/94";
#else
-__RCSID("$NetBSD: print.c,v 1.58 2024/11/06 16:40:58 jschauma Exp $");
+__RCSID("$NetBSD: print.c,v 1.59 2024/12/11 12:56:31 simonb Exp $");
#endif
#endif /* not lint */
@@ -440,7 +440,8 @@ printtotal(DISPLAY *dp)
if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size)) {
if (f_humanize) {
- if ((humanize_number(szbuf, sizeof(szbuf), (int64_t)dp->stotal,
+ if ((humanize_number(szbuf, sizeof(szbuf),
+ dp->btotal * POSIX_BLOCK_SIZE,
"", HN_AUTOSCALE,
(HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
err(1, "humanize_number");