Make fstat work with file arguments again after being broken by dev_t

changes.  Thanks, Mr. Edwards!

Submitted by:	Peter Edwards <peter.edwards@ireland.com>
This commit is contained in:
Brian Feldman 1999-11-13 21:13:25 +00:00
parent b04b572b08
commit 38cd1ee7d3
1 changed files with 28 additions and 1 deletions

View File

@ -61,6 +61,7 @@ static const char rcsid[] =
#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>
@ -157,6 +158,7 @@ void pipetrans __P((struct pipe *pi, int i, int flag));
void socktrans __P((struct socket *sock, int i));
void getinetproto __P((int number));
int getfname __P((char *filename));
udev_t dev2udev __P((dev_t dev));
void usage __P((void));
@ -487,7 +489,12 @@ ufs_filestat(vp, fsp)
(void *)VTOI(vp), Pid);
return 0;
}
fsp->fsid = inode.i_dev & 0xffff;
/*
* 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;
@ -729,6 +736,26 @@ 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
*/
udev_t
dev2udev(dev)
dev_t dev;
{
struct specinfo si;
if (KVM_READ(dev, &si, sizeof si)) {
return si.si_udev;
} else {
dprintf(stderr, "can't convert dev_t %p to a udev_t\n",
(void *)dev);
return -1;
}
}
/*
* getinetproto --
* print name of protocol number