Project

General

Profile

Bug #6259

size related bugs in /usr/bin/ls

Added by Richard PALO about 4 years ago. Updated about 4 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
cmd - userland programs
Start date:
2015-09-24
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage

Description

As witnessed here:

richard@omnis:/home/richard$ /usr/bin/ls -lah /var/adm/messages*
-rw-r--r--   1 root     root        113K sept. 24 05:32 /var/adm/messages
-rw-r--r--   1 root     root        291K sept. 21 00:19 /var/adm/messages.0
-rw-r--r--   1 root     root        277K sept. 13 22:06 /var/adm/messages.1
-rw-r--r--   1 root     root        240K sept.  7 03:07 /var/adm/messages.2
-rw-r--r--   1 root     root         49K août 31 00:05 /var/adm/messages.3
richard@omnis:/home/richard$ /usr/gnu/bin/ls -lah /var/adm/messages*
-rw-r--r-- 1 root root 113K sept. 24 05:32 /var/adm/messages
-rw-r--r-- 1 root root 291K sept. 21 00:19 /var/adm/messages.0
-rw-r--r-- 1 root root 277K sept. 13 22:06 /var/adm/messages.1
-rw-r--r-- 1 root root 240K sept.  7 03:07 /var/adm/messages.2
-rw-r--r-- 1 root root  50K août  31 00:05 /var/adm/messages.3
richard@omnis:/home/richard$ stat -c "%s %n" /var/adm/messages*
115218 /var/adm/messages
297846 /var/adm/messages.0
283177 /var/adm/messages.1
245488 /var/adm/messages.2
50273 /var/adm/messages.3
richard@omnis:/home/richard$ /usr/bin/ls -1 -hs /var/adm/messages*
  41 /var/adm/messages
 114 /var/adm/messages.0
 102 /var/adm/messages.1
  89 /var/adm/messages.2
  15 /var/adm/messages.3
richard@omnis:/home/richard$ /usr/bin/ls -1 -hs --si /var/adm/messages*
  41 /var/adm/messages
 114 /var/adm/messages.0
 102 /var/adm/messages.1
  89 /var/adm/messages.2
  15 /var/adm/messages.3
richard@omnis:/home/richard$ /usr/gnu/bin/ls -1 -hs /var/adm/messages*
 21K /var/adm/messages
 57K /var/adm/messages.0
 51K /var/adm/messages.1
 45K /var/adm/messages.2
7,5K /var/adm/messages.3
richard@omnis:/home/richard$ /usr/gnu/bin/ls -1 -hs --si /var/adm/messages*
 21k /var/adm/messages
 59k /var/adm/messages.0
 53k /var/adm/messages.1
 46k /var/adm/messages.2
7,7k /var/adm/messages.3

There seems to be at least three issues with /usr/bin/ls
1. rounding is incorrect with human readable form
notably in the case of messages.3
2. the simple case of options '-hs' does not give --human-readable as suggests the manpage
3. and there is an (additional) issue of whether powers of '1000' or '1024' is correctly applied
not to mention scant, and slightly missing, manpage documentation on the '--si' option


Related issues

Related to illumos gate - Bug #640: number_to_scaled_string is duplicated in several commandsIn Progress2011-01-17

Actions

History

#1

Updated by Richard PALO about 4 years ago

What you probably don't want to do is enter the spiral:

richard@omnis:/home/richard$ /usr/bin/stat --format="%s (%b*%B) %n" /var/adm/messages*
115218 (41*512) /var/adm/messages
297846 (114*512) /var/adm/messages.0
283177 (102*512) /var/adm/messages.1
245488 (89*512) /var/adm/messages.2
50273 (15*512) /var/adm/messages.3

where
  %b   number of blocks allocated (see %B)
  %B   the size in bytes of each block reported by %b
  %s   total size, in bytes
 

#2

Updated by Jason King about 4 years ago

Part of it is that the nicenum/humanize_number/number_to_scaled_string function is duplicated quite a bit, often with different methods of rounding. See https://www.illumos.org/issues/640 for some work there.

The other issue is that the original work to add -h didn't include support w/ -s.

#3

Updated by Jason King about 4 years ago

  • Related to Bug #640: number_to_scaled_string is duplicated in several commands added
#4

Updated by Peter Tribble about 4 years ago

Jason King wrote:

The other issue is that the original work to add -h didn't include support w/ -s.

That was deliberate. The point is that -h scales sizes into kilobytes/megabytes etc. And the thing that -s displays is a number - block count, not a size, so it's not obvious that scaling it to a size is correct.

(The -s flag means slightly different things to /usr/bin/ls and /usr/gnu/bin/ls - /usr/bin/ls prints a count, whereas /usr/gnu/bin/ls translates that into a size:

  1. /usr/gnu/bin/ls ls /var/adm/messages
    6791 -rw-r--r-
    1 root root 6882789 Sep 27 10:14 /var/adm/messages
  2. /usr/bin/ls ls /var/adm/messages
    13581 -rw-r--r-
    1 root root 6882789 Sep 27 10:14 /var/adm/messages
    )

Also available in: Atom PDF