OK, here's a patch to fstat(1) which adds an -s option to stat(2)
a list of files on the command line. It's against -STABLE but
should still apply to -CURRENT. Comments are appreciated.
The only other addition I would like to have is have -n option
display everything numericaly as it does now, whereas no -n
would display everything in human readable format (users, groups,
modes, dates, etc.)
If someone else would like to do that, please patch away! :-)
Otherwise, I'll see if I can't get around to it some other time.
-Paul.
Index: fstat.1
===
RCS file: /u02/ncvs/src/usr.bin/fstat/fstat.1,v
retrieving revision 1.9.2.6
diff -u -r1.9.2.6 fstat.1
--- fstat.1 16 Apr 2002 19:53:35 - 1.9.2.6
+++ fstat.1 19 May 2002 06:35:41 -
@@ -87,6 +87,10 @@
and print the mode of the file in octal instead of symbolic form.
.It Fl p
Report all files open by the specified process.
+.It Fl s
+Print
+.Xr stat 2
+contents of files given on the command line.
.It Fl u
Report all files open by the specified user.
.It Fl v
@@ -181,6 +185,40 @@
.Xr ln 1 ) ,
the name printed may not be the actual
name that the process originally used to open that file.
+.El
+.Pp
+unless the
+.Fl s
+option is given in which case the following is printed:
+.Bl -tag -width BLOCKS
+.It Li INODE
+The inode number of the file.
+.It Li DEV
+The device number the file resides on.
+.It Li SIZE
+The size in bytes of the file.
+.It Li BLOCKS
+The number of blocks used by the file.
+.It Li MODE
+The file's protection mode.
+.It Li FLAGS
+The file's
+.Xr chflags 2
+flags.
+.It Li LNK
+The number of hard links.
+.It Li UID
+The user ID of the file's owner.
+.It Li GID
+The group ID of the file's group.
+.It Li ATIME
+The time of last access.
+.It Li MTIME
+The time of last data modification.
+.It Li CTIME
+The time of last file status change.
+.It Li NAME
+The file name.
.El
.Sh SOCKETS
The formating of open sockets depends on the protocol domain.
Index: fstat.c
===
RCS file: /u02/ncvs/src/usr.bin/fstat/fstat.c,v
retrieving revision 1.21.2.7
diff -u -r1.21.2.7 fstat.c
--- fstat.c 21 Nov 2001 10:49:37 - 1.21.2.7
+++ fstat.c 19 May 2002 06:10:58 -
@@ -121,6 +121,7 @@
intnflg; /* (numerical) display f.s. and rdev as dev_t */
intvflg; /* display errors in locating kernel data objects etc... */
intmflg; /* include memory-mapped files */
+intsflg; /* display inode information */
struct file **ofiles; /* buffer of pointers to file structures */
@@ -137,6 +138,7 @@
kvm_t *kd;
+void dostats __P((void));
void dofiles __P((struct kinfo_proc *kp));
void dommap __P((struct kinfo_proc *kp));
void vtrans __P((struct vnode *vp, int i, int flag));
@@ -165,7 +167,7 @@
arg = 0;
what = KERN_PROC_ALL;
nlistf = memf = NULL;
- while ((ch = getopt(argc, argv, fmnp:u:vN:M:)) != -1)
+ while ((ch = getopt(argc, argv, fmnp:su:vN:M:)) != -1)
switch((char)ch) {
case 'f':
fsflg = 1;
@@ -192,6 +194,9 @@
what = KERN_PROC_PID;
arg = atoi(optarg);
break;
+ case 's':
+ sflg = 1;
+ break;
case 'u':
if (uflg++)
usage();
@@ -241,12 +246,24 @@
#endif
if ((p = kvm_getprocs(kd, what, arg, cnt)) == NULL)
errx(1, %s, kvm_geterr(kd));
- if (nflg)
+ if (sflg) {
+ if (!checkfile) {
+ warnx(must provide a filename);
+ usage();
+ }
printf(%s,
+INODE DEVSIZE BLOCKS MODE FLAGS LNK UID GID ATIME MTIME CTIME
+NAME\n);
+ dostats();
+ exit(0);
+ }
+ else {
+ if (nflg)
+ printf(%s,
USER CMD PID FD DEVINUM MODE SZ|DV R/W);
- else
- printf(%s,
+ else
+ printf(%s,
USER CMD PID FD MOUNT INUM MODE SZ|DV R/W);
+ }
if (checkfile fsflg == 0)
printf( NAME\n);
else
@@ -288,6 +305,31 @@
}
/*
+ * print inode information for all files in devs
+ */
+void
+dostats() {
+ struct stat s;
+ register DEVS *d;
+ for (d = devs; d != NULL; d = d-next) {
+ if (d-name == NULL)/* does this ever happen? */
+ errx(1, invalid filename);
+ if (stat(d-name, s) == -1) {
+ warnx(couldn't stat file %s, d-name);
+ continue;
+ }
+ (void)printf(%-6u %-6d %-8qd %-6qd %-6.6o %-6.6o %-3d %-3d %-3d ,
+