diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-03 01:14:15 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-03 01:14:15 +0200 |
commit | 87c150c7cc6ac12ce3ce14f55148c65830a746fd (patch) | |
tree | a11c6b3f2653aaca0263a26b872b7647b8ceec0b /coreutils | |
parent | 26ff18b424c84a8948e0dcd1322a4bda0cb12fe4 (diff) | |
download | busybox-w32-87c150c7cc6ac12ce3ce14f55148c65830a746fd.tar.gz busybox-w32-87c150c7cc6ac12ce3ce14f55148c65830a746fd.tar.bz2 busybox-w32-87c150c7cc6ac12ce3ce14f55148c65830a746fd.zip |
ls: add "total NNNN" header if DESKTOP. By Johannes Stezenbach (js AT sig21.net)
function old new delta
showdirs 492 564 +72
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/ls.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index 19d38049c..bb6165b39 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -17,8 +17,7 @@ | |||
17 | * it more portable. | 17 | * it more portable. |
18 | * | 18 | * |
19 | * KNOWN BUGS: | 19 | * KNOWN BUGS: |
20 | * 1. ls -l of a directory doesn't give "total <blocks>" header | 20 | * 1. hidden files can make column width too large |
21 | * 2. hidden files can make column width too large | ||
22 | * | 21 | * |
23 | * NON-OPTIMAL BEHAVIOUR: | 22 | * NON-OPTIMAL BEHAVIOUR: |
24 | * 1. autowidth reads directories twice | 23 | * 1. autowidth reads directories twice |
@@ -598,6 +597,24 @@ static void showfiles(struct dnode **dn, int nfiles) | |||
598 | } | 597 | } |
599 | 598 | ||
600 | 599 | ||
600 | #if ENABLE_DESKTOP | ||
601 | static off_t calculate_blocks(struct dnode **dn, int nfiles) | ||
602 | { | ||
603 | uoff_t blocks = 1; | ||
604 | while (nfiles) { | ||
605 | blocks += (*dn)->dstat.st_blocks; /* in 512 byte blocks */ | ||
606 | dn++; | ||
607 | nfiles--; | ||
608 | } | ||
609 | |||
610 | /* Even though POSIX says use 512 byte blocks, coreutils use 1k */ | ||
611 | /* Actually, we round up by calculating (blocks + 1) / 2, | ||
612 | * "+ 1" was done when we initialized blocks to 1 */ | ||
613 | return blocks >> 1; | ||
614 | } | ||
615 | #endif | ||
616 | |||
617 | |||
601 | static void showdirs(struct dnode **dn, int ndirs, int first) | 618 | static void showdirs(struct dnode **dn, int ndirs, int first) |
602 | { | 619 | { |
603 | int i, nfiles; | 620 | int i, nfiles; |
@@ -617,6 +634,10 @@ static void showdirs(struct dnode **dn, int ndirs, int first) | |||
617 | } | 634 | } |
618 | subdnp = list_dir(dn[i]->fullname); | 635 | subdnp = list_dir(dn[i]->fullname); |
619 | nfiles = countfiles(subdnp); | 636 | nfiles = countfiles(subdnp); |
637 | #if ENABLE_DESKTOP | ||
638 | if (all_fmt & STYLE_LONG) | ||
639 | printf("total %"OFF_FMT"u\n", calculate_blocks(subdnp, nfiles)); | ||
640 | #endif | ||
620 | if (nfiles > 0) { | 641 | if (nfiles > 0) { |
621 | /* list all files at this level */ | 642 | /* list all files at this level */ |
622 | dnsort(subdnp, nfiles); | 643 | dnsort(subdnp, nfiles); |