Date: Wed, 16 Jul 2008 18:08:09 +0300 (EEST) From: Jaakko Heinonen <jh@saunalahti.fi> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/125678: [patch] ls(1) -h option doesn't work if the listing contains a device file Message-ID: <200807161508.m6GF89PP004183@ws64.jh.dy.fi> Resent-Message-ID: <200807161510.m6GFA1gY053419@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 125678
>Category: bin
>Synopsis: [patch] ls(1) -h option doesn't work if the listing contains a device file
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Wed Jul 16 15:10:01 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator: Jaakko Heinonen
>Release: FreeBSD 7.0-STABLE / 8.0-CURRENT
>Organization:
>Environment:
>Description:
If a ls(1) long formatted listing has at least one character or block device
file the -h switch has no effect.
>How-To-Repeat:
$ ls -lh 10MBnull
-rw-r--r-- 1 jaakko jaakko 10M Jul 16 13:29 10MBnull
$ ls -lh /dev/null 10MBnull
crw-rw-rw- 1 root wheel 0, 26 Jul 16 13:22 /dev/null
-rw-r--r-- 1 jaakko jaakko 10485760 Jul 16 13:29 10MBnull
After applying the patch:
$ ls -lh 10MBnull
-rw-r--r-- 1 jaakko jaakko 10M Jul 16 13:29 10MBnull
$ ls -lh /dev/null 10MBnull
crw-rw-rw- 1 root wheel 0, 26 Jul 16 13:33 /dev/null
-rw-r--r-- 1 jaakko jaakko 10M Jul 16 13:29 10MBnull
>Fix:
--- ls--h-with-device-files.diff begins here ---
Index: bin/ls/print.c
===================================================================
--- bin/ls/print.c (revision 180487)
+++ bin/ls/print.c (working copy)
@@ -65,7 +65,7 @@ static int printaname(const FTSENT *, u_
static void printlink(const FTSENT *);
static void printtime(time_t);
static int printtype(u_int);
-static void printsize(size_t, off_t);
+static void printsize(size_t, off_t, int);
#ifdef COLORLS
static void endcolor(int);
static int colortype(mode_t);
@@ -183,11 +183,8 @@ printlong(const DISPLAY *dp)
else
(void)printf("%3d, %3d ",
major(sp->st_rdev), minor(sp->st_rdev));
- else if (dp->bcfile)
- (void)printf("%*s%*jd ",
- 8 - dp->s_size, "", dp->s_size, sp->st_size);
else
- printsize(dp->s_size, sp->st_size);
+ printsize(dp->s_size, sp->st_size, dp->bcfile);
if (f_accesstime)
printtime(sp->st_atime);
else if (f_birthtime)
@@ -599,7 +596,7 @@ printlink(const FTSENT *p)
}
static void
-printsize(size_t width, off_t bytes)
+printsize(size_t width, off_t bytes, int bcfile)
{
if (f_humanval) {
@@ -607,8 +604,11 @@ printsize(size_t width, off_t bytes)
humanize_number(buf, sizeof(buf), (int64_t)bytes, "",
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
- (void)printf("%5s ", buf);
- } else
+ (void)printf("%*s ", bcfile ? 8 : 5, buf);
+ } else if (bcfile)
+ (void)printf("%*s%*jd ",
+ 8 - (u_int)width, "", (u_int)width, bytes);
+ else
(void)printf("%*jd ", (u_int)width, bytes);
}
--- ls--h-with-device-files.diff ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200807161508.m6GF89PP004183>
