svn commit: r225847 - in head: bin/ls bin/ps lib/libc/gen sbin/fsdb
usr.bin/find usr.bin/fstat usr.sbin/pstat
Ed Schouten
ed at FreeBSD.org
Wed Sep 28 18:53:37 UTC 2011
Author: ed
Date: Wed Sep 28 18:53:36 2011
New Revision: 225847
URL: http://svn.freebsd.org/changeset/base/225847
Log:
Get rid of major/minor number distinction.
As of FreeBSD 6, devices can only be opened through devfs. These device
nodes don't have major and minor numbers anymore. The st_rdev field in
struct stat is simply based a copy of st_ino.
Simply display device numbers as hexadecimal, using "%#jx". This is
allowed by POSIX, since it explicitly states things like the following
(example taken from ls(1)):
"If the file is a character special or block special file, the
size of the file may be replaced with implementation-defined
information associated with the device in question."
This makes the output of these commands more compact. For example, ls(1)
now uses approximately four columns less. While there, simplify the
column length calculation from ls(1) by calling snprintf() with a NULL
buffer.
Don't be afraid; if needed one can still obtain individual major/minor
numbers using stat(1).
Modified:
head/bin/ls/ls.1
head/bin/ls/ls.c
head/bin/ls/ls.h
head/bin/ls/print.c
head/bin/ps/print.c
head/lib/libc/gen/devname.c
head/sbin/fsdb/fsdbutil.c
head/usr.bin/find/find.1
head/usr.bin/find/ls.c
head/usr.bin/fstat/fstat.1
head/usr.bin/fstat/fstat.c
head/usr.sbin/pstat/pstat.c
Modified: head/bin/ls/ls.1
==============================================================================
--- head/bin/ls/ls.1 Wed Sep 28 18:49:37 2011 (r225846)
+++ head/bin/ls/ls.1 Wed Sep 28 18:53:36 2011 (r225847)
@@ -32,7 +32,7 @@
.\" @(#)ls.1 8.7 (Berkeley) 7/29/94
.\" $FreeBSD$
.\"
-.Dd April 4, 2008
+.Dd September 28, 2011
.Dt LS 1
.Os
.Sh NAME
@@ -357,8 +357,7 @@ option is given,
the numeric ID's are displayed.
.Pp
If the file is a character special or block special file,
-the major and minor device numbers for the file are displayed
-in the size field.
+the device number for the file is displayed in the size field.
If the file is a symbolic link the pathname of the
linked-to file is preceded by
.Dq Li -> .
Modified: head/bin/ls/ls.c
==============================================================================
--- head/bin/ls/ls.c Wed Sep 28 18:49:37 2011 (r225846)
+++ head/bin/ls/ls.c Wed Sep 28 18:53:36 2011 (r225847)
@@ -563,7 +563,7 @@ display(const FTSENT *p, FTSENT *list, i
long maxblock;
u_long btotal, labelstrlen, maxinode, maxlen, maxnlink;
u_long maxlabelstr;
- u_int devstrlen;
+ u_int sizelen;
int maxflags;
gid_t maxgroup;
uid_t maxuser;
@@ -572,7 +572,6 @@ display(const FTSENT *p, FTSENT *list, i
int entries, needstats;
const char *user, *group;
char *flags, *labelstr = NULL;
- char buf[STRBUF_SIZEOF(u_quad_t) + 1];
char ngroup[STRBUF_SIZEOF(uid_t) + 1];
char nuser[STRBUF_SIZEOF(gid_t) + 1];
@@ -656,7 +655,8 @@ display(const FTSENT *p, FTSENT *list, i
MAKENINES(maxsize);
free(jinitmax);
}
- devstrlen = 0;
+ d.s_size = 0;
+ sizelen = 0;
flags = NULL;
for (cur = list, entries = 0; cur; cur = cur->fts_link) {
if (cur->fts_info == FTS_ERR || cur->fts_info == FTS_NS) {
@@ -796,14 +796,12 @@ label_out:
np->group = &np->data[ulen + 1];
(void)strcpy(np->group, group);
- if ((S_ISCHR(sp->st_mode) ||
- S_ISBLK(sp->st_mode)) &&
- devstrlen < DEVSTR_HEX_LEN) {
- if (minor(sp->st_rdev) > 255 ||
- minor(sp->st_rdev) < 0)
- devstrlen = DEVSTR_HEX_LEN;
- else
- devstrlen = DEVSTR_LEN;
+ if (S_ISCHR(sp->st_mode) ||
+ S_ISBLK(sp->st_mode)) {
+ sizelen = snprintf(NULL, 0,
+ "%#jx", (uintmax_t)sp->st_rdev);
+ if (d.s_size < sizelen)
+ d.s_size = sizelen;
}
if (f_flags) {
@@ -837,23 +835,16 @@ label_out:
d.maxlen = maxlen;
if (needstats) {
d.btotal = btotal;
- (void)snprintf(buf, sizeof(buf), "%lu", maxblock);
- d.s_block = strlen(buf);
+ d.s_block = snprintf(NULL, 0, "%lu", maxblock);
d.s_flags = maxflags;
d.s_label = maxlabelstr;
d.s_group = maxgroup;
- (void)snprintf(buf, sizeof(buf), "%lu", maxinode);
- d.s_inode = strlen(buf);
- (void)snprintf(buf, sizeof(buf), "%lu", maxnlink);
- d.s_nlink = strlen(buf);
- if (f_humanval)
- d.s_size = HUMANVALSTR_LEN;
- else {
- (void)snprintf(buf, sizeof(buf), "%ju", maxsize);
- d.s_size = strlen(buf);
- }
- if (d.s_size < devstrlen)
- d.s_size = devstrlen;
+ d.s_inode = snprintf(NULL, 0, "%lu", maxinode);
+ d.s_nlink = snprintf(NULL, 0, "%lu", maxnlink);
+ sizelen = f_humanval ? HUMANVALSTR_LEN :
+ snprintf(NULL, 0, "%ju", maxsize);
+ if (d.s_size < sizelen)
+ d.s_size = sizelen;
d.s_user = maxuser;
}
printfcn(&d);
Modified: head/bin/ls/ls.h
==============================================================================
--- head/bin/ls/ls.h Wed Sep 28 18:49:37 2011 (r225846)
+++ head/bin/ls/ls.h Wed Sep 28 18:53:36 2011 (r225847)
@@ -36,8 +36,6 @@
#define NO_PRINT 1
#define HUMANVALSTR_LEN 5
-#define DEVSTR_LEN 8
-#define DEVSTR_HEX_LEN 15
extern long blocksize; /* block size units */
Modified: head/bin/ls/print.c
==============================================================================
--- head/bin/ls/print.c Wed Sep 28 18:49:37 2011 (r225846)
+++ head/bin/ls/print.c Wed Sep 28 18:53:36 2011 (r225847)
@@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
#include <langinfo.h>
#include <libutil.h>
#include <stdio.h>
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@@ -351,16 +352,8 @@ printaname(const FTSENT *p, u_long inode
static void
printdev(size_t width, dev_t dev)
{
- char buf[DEVSTR_HEX_LEN + 1];
- if (minor(dev) > 255 || minor(dev) < 0)
- (void)snprintf(buf, sizeof(buf), "%3d, 0x%08x",
- major(dev), (u_int)minor(dev));
- else
- (void)snprintf(buf, sizeof(buf), "%3d, %3d",
- major(dev), minor(dev));
-
- (void)printf("%*s ", (u_int)width, buf);
+ (void)printf("%#*jx ", (u_int)width, (uintmax_t)dev);
}
static void
Modified: head/bin/ps/print.c
==============================================================================
--- head/bin/ps/print.c Wed Sep 28 18:49:37 2011 (r225846)
+++ head/bin/ps/print.c Wed Sep 28 18:53:36 2011 (r225847)
@@ -392,17 +392,13 @@ tdev(KINFO *k, VARENT *ve)
{
VAR *v;
dev_t dev;
- char buff[16];
v = ve->var;
dev = k->ki_p->ki_tdev;
if (dev == NODEV)
(void)printf("%*s", v->width, "??");
- else {
- (void)snprintf(buff, sizeof(buff),
- "%d/%d", major(dev), minor(dev));
- (void)printf("%*s", v->width, buff);
- }
+ else
+ (void)printf("%#*jx", v->width, (uintmax_t)dev);
}
void
Modified: head/lib/libc/gen/devname.c
==============================================================================
--- head/lib/libc/gen/devname.c Wed Sep 28 18:49:37 2011 (r225846)
+++ head/lib/libc/gen/devname.c Wed Sep 28 18:53:36 2011 (r225847)
@@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
#include <sys/sysctl.h>
#include <stdio.h>
+#include <stdint.h>
#include <string.h>
#include <sys/param.h>
#include <sys/stat.h>
@@ -60,8 +61,8 @@ devname_r(dev_t dev, mode_t type, char *
}
/* Finally just format it */
- snprintf(buf, len, "#%c:%d:0x%x",
- S_ISCHR(type) ? 'C' : 'B', major(dev), minor(dev));
+ snprintf(buf, len, "#%c:%#jx",
+ S_ISCHR(type) ? 'C' : 'B', (uintmax_t)dev);
return (buf);
}
Modified: head/sbin/fsdb/fsdbutil.c
==============================================================================
--- head/sbin/fsdb/fsdbutil.c Wed Sep 28 18:49:37 2011 (r225846)
+++ head/sbin/fsdb/fsdbutil.c Wed Sep 28 18:53:36 2011 (r225847)
@@ -126,12 +126,10 @@ printstat(const char *cp, ino_t inum, un
puts("regular file");
break;
case IFBLK:
- printf("block special (%d,%d)",
- major(DIP(dp, di_rdev)), minor(DIP(dp, di_rdev)));
+ printf("block special (%#jx)", (uintmax_t)DIP(dp, di_rdev));
break;
case IFCHR:
- printf("character special (%d,%d)",
- major(DIP(dp, di_rdev)), minor(DIP(dp, di_rdev)));
+ printf("character special (%#jx)", DIP(dp, di_rdev));
break;
case IFLNK:
fputs("symlink",stdout);
Modified: head/usr.bin/find/find.1
==============================================================================
--- head/usr.bin/find/find.1 Wed Sep 28 18:49:37 2011 (r225846)
+++ head/usr.bin/find/find.1 Wed Sep 28 18:53:36 2011 (r225847)
@@ -31,7 +31,7 @@
.\" @(#)find.1 8.7 (Berkeley) 5/9/95
.\" $FreeBSD$
.\"
-.Dd March 17, 2010
+.Dd September 28, 2011
.Dt FIND 1
.Os
.Sh NAME
@@ -507,7 +507,7 @@ This primary always evaluates to true.
The following information for the current file is written to standard output:
its inode number, size in 512-byte blocks, file permissions, number of hard
links, owner, group, size in bytes, last modification time, and pathname.
-If the file is a block or character special file, the major and minor numbers
+If the file is a block or character special file, the device number
will be displayed instead of the size in bytes.
If the file is a symbolic link, the pathname of the linked-to file will be
displayed preceded by
Modified: head/usr.bin/find/ls.c
==============================================================================
--- head/usr.bin/find/ls.c Wed Sep 28 18:49:37 2011 (r225846)
+++ head/usr.bin/find/ls.c Wed Sep 28 18:53:36 2011 (r225847)
@@ -70,8 +70,7 @@ printlong(char *name, char *accpath, str
group_from_gid(sb->st_gid, 0));
if (S_ISCHR(sb->st_mode) || S_ISBLK(sb->st_mode))
- (void)printf("%3d, %3d ", major(sb->st_rdev),
- minor(sb->st_rdev));
+ (void)printf("%#8jx ", (uintmax_t)sb->st_rdev);
else
(void)printf("%8"PRId64" ", sb->st_size);
printtime(sb->st_mtime);
Modified: head/usr.bin/fstat/fstat.1
==============================================================================
--- head/usr.bin/fstat/fstat.1 Wed Sep 28 18:49:37 2011 (r225846)
+++ head/usr.bin/fstat/fstat.1 Wed Sep 28 18:53:36 2011 (r225847)
@@ -28,7 +28,7 @@
.\" @(#)fstat.1 8.3 (Berkeley) 2/25/94
.\" $FreeBSD$
.\"
-.Dd July 9, 2009
+.Dd September 28, 2011
.Dt FSTAT 1
.Os
.Sh NAME
@@ -142,7 +142,7 @@ pathname that the file system the file r
If the
.Fl n
flag is specified, this header is present and is the
-major/minor number of the device that this file resides in.
+number of the device that this file resides in.
.It Li INUM
The inode number of the file.
.It Li MODE
Modified: head/usr.bin/fstat/fstat.c
==============================================================================
--- head/usr.bin/fstat/fstat.c Wed Sep 28 18:49:37 2011 (r225846)
+++ head/usr.bin/fstat/fstat.c Wed Sep 28 18:53:36 2011 (r225847)
@@ -411,7 +411,7 @@ print_pts_info(struct procstat *procstat
}
printf("* pseudo-terminal master ");
if (nflg || !*pts.devname) {
- printf("%10d,%-2d", major(pts.dev), minor(pts.dev));
+ printf("%#10jx", (uintmax_t)pts.dev);
} else {
printf("%10s", pts.devname);
}
@@ -441,7 +441,7 @@ print_vnode_info(struct procstat *procst
}
if (nflg)
- printf(" %2d,%-2d", major(vn.vn_fsid), minor(vn.vn_fsid));
+ printf(" %#8jx", (uintmax_t)vn.vn_fsid);
else if (vn.vn_mntdir != NULL)
(void)printf(" %-8s", vn.vn_mntdir);
@@ -457,7 +457,7 @@ print_vnode_info(struct procstat *procst
if (vn.vn_type == PS_FST_VTYPE_VBLK || vn.vn_type == PS_FST_VTYPE_VCHR) {
if (nflg || !*vn.vn_devname)
- printf(" %2d,%-2d", major(vn.vn_dev), minor(vn.vn_dev));
+ printf(" %#6jx", (uintmax_t)vn.vn_dev);
else {
printf(" %6s", vn.vn_devname);
}
Modified: head/usr.sbin/pstat/pstat.c
==============================================================================
--- head/usr.sbin/pstat/pstat.c Wed Sep 28 18:49:37 2011 (r225846)
+++ head/usr.sbin/pstat/pstat.c Wed Sep 28 18:53:36 2011 (r225847)
@@ -345,7 +345,7 @@ ttyprt(struct xtty *xt)
errx(1, "struct xtty size mismatch");
if (usenumflag || xt->xt_dev == 0 ||
(name = devname(xt->xt_dev, S_IFCHR)) == NULL)
- printf("%5d,%4d ", major(xt->xt_dev), minor(xt->xt_dev));
+ printf("%#10jx ", (uintmax_t)xt->xt_dev);
else
printf("%10s ", name);
printf("%5zu %4zu %4zu %4zu %5zu %4zu %4zu %5u %5d %5d ",
More information about the svn-src-all
mailing list