Date: Sun, 14 Nov 1999 00:07:52 +2400 From: "Peter Edwards" <peter.edwards@ireland.com> To: current@freebsd.org Cc: peter.edwards@openet-telecom.com Subject: fstat(1) breakage + fix Message-ID: <1829F7D8FD893D1178D000807CFB3258@peter.edwards.ireland.com>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
Hi,
fstat(1) should be able to take a set of filenames as arguments to limit the results of its output to the specified files. However, it doesn't work at the moment, because of the existance of udev_t. (It compares the st_dev from the stat structure used by stat(2) with in-kernel dev_t structures. As it stands, "fstat <filename>" will never produce any output other than a header.)
I've attached a patch that appears reliable. Can someone review it (and possibly commit??)
--
Peter.
_____________________________________
Get your free E-mail at http://www.ireland.com
[-- Attachment #2 --]
*** /usr/src/usr.bin/fstat/fstat.c.old Tue Aug 31 02:12:13 1999
--- /usr/src/usr.bin/fstat/fstat.c Fri Nov 12 23:57:24 1999
***************
*** 61,66 ****
--- 61,67 ----
#include <sys/filedesc.h>
#include <sys/queue.h>
#include <sys/pipe.h>
+ #include <sys/conf.h>
#define KERNEL
#include <sys/file.h>
#include <ufs/ufs/quota.h>
***************
*** 158,163 ****
--- 159,165 ----
void getinetproto __P((int number));
int getfname __P((char *filename));
void usage __P((void));
+ static udev_t dev2udev __P((dev_t dev));
int
***************
*** 487,493 ****
(void *)VTOI(vp), Pid);
return 0;
}
! fsp->fsid = inode.i_dev & 0xffff;
fsp->fileid = (long)inode.i_number;
fsp->mode = (mode_t)inode.i_mode;
fsp->size = (u_long)inode.i_size;
--- 489,500 ----
(void *)VTOI(vp), Pid);
return 0;
}
! /*
! * The st_dev from stat(2) is a udev_t. These kernel structures
! * contain dev_t structures. We need to convert to udev to make
! * comparisons
! */
! fsp->fsid = dev2udev(inode.i_dev) & 0xffff;
fsp->fileid = (long)inode.i_number;
fsp->mode = (mode_t)inode.i_mode;
fsp->size = (u_long)inode.i_size;
***************
*** 727,732 ****
--- 734,756 ----
return;
bad:
printf("* error\n");
+ }
+
+
+ /*
+ * Read the specinfo structure in the kernel (as pointed to by a dev_t)
+ * in order to work out the associated udev_t
+ */
+ static udev_t dev2udev(dev)
+ dev_t dev;
+ {
+ struct specinfo si;
+ if (kvm_read(kd, (u_long)dev, (char *)&si, sizeof si) == sizeof si) {
+ return si.si_udev;
+ } else {
+ dprintf(stderr, "can't convert dev_t %x to a udev_t\n", dev);
+ return -1;
+ }
}
/*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1829F7D8FD893D1178D000807CFB3258>
