Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/fstat Slurp in the struct mount at vp->v_mount and t...
details: https://anonhg.NetBSD.org/src/rev/30ac38ec93cf
branches: trunk
changeset: 572026:30ac38ec93cf
user: atatat <atatat%NetBSD.org@localhost>
date: Tue Dec 14 03:10:23 2004 +0000
description:
Slurp in the struct mount at vp->v_mount and the struct specinfo at
vp->v_specinfo to get the proper st_dev and st_rdev numbers. We're
already picking over the kernel, so let's do it right. That means
also asserting the file type for the /dev/pts directory (S_IFDIR) and
nodes therein (S_IFCHR).
Remove getptsmajor(), since we no longer need it. Besides, it was
being used wrongly.
diffstat:
usr.bin/fstat/ptyfs.c | 64 ++++++++++++++++++++++----------------------------
1 files changed, 28 insertions(+), 36 deletions(-)
diffs (104 lines):
diff -r b1167b0d5d90 -r 30ac38ec93cf usr.bin/fstat/ptyfs.c
--- a/usr.bin/fstat/ptyfs.c Tue Dec 14 03:09:24 2004 +0000
+++ b/usr.bin/fstat/ptyfs.c Tue Dec 14 03:10:23 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ptyfs.c,v 1.1 2004/12/12 22:41:04 christos Exp $ */
+/* $NetBSD: ptyfs.c,v 1.2 2004/12/14 03:10:23 atatat Exp $ */
/*-
* Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: ptyfs.c,v 1.1 2004/12/12 22:41:04 christos Exp $");
+__RCSID("$NetBSD: ptyfs.c,v 1.2 2004/12/14 03:10:23 atatat Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -49,6 +49,7 @@
#include <sys/mount.h>
#define _KERNEL
+#include <miscfs/specfs/specdev.h>
#include <fs/ptyfs/ptyfs.h>
#undef _KERNEL
@@ -58,52 +59,43 @@
#include <dirent.h>
#include "fstat.h"
-static mode_t getptsmajor(void);
-
-/* XXX: Dup code from gen/devname.c */
-static mode_t
-getptsmajor(void)
-{
- DIR *dirp;
- struct dirent *dp;
- struct stat st;
- char buf[MAXPATHLEN];
-
- if ((dirp = opendir(_PATH_DEV_PTS)) == NULL)
- return (mode_t)~0;
-
- while ((dp = readdir(dirp)) != NULL) {
- if (dp->d_name[0] == '.')
- continue;
- (void)snprintf(buf, sizeof(buf), "%s%s", _PATH_DEV_PTS,
- dp->d_name);
- if (stat(buf, &st) == -1)
- continue;
- (void)closedir(dirp);
- return major(st.st_rdev);
- }
- (void)closedir(dirp);
- return (mode_t)~0;
-}
-
int
ptyfs_filestat(struct vnode *vp, struct filestat *fsp)
{
struct ptyfsnode pn;
- static mode_t maj = 0;
+ struct specinfo si;
+ struct mount mt;
if (!KVM_READ(VTOPTYFS(vp), &pn, sizeof(pn))) {
dprintf("can't read ptyfs_node at %p for pid %d",
VTOPTYFS(vp), Pid);
return 0;
}
- fsp->fsid = 0; /* XXX */
+ if (!KVM_READ(vp->v_mount, &mt, sizeof(mt))) {
+ dprintf("can't read mount at %p for pid %d",
+ VTOPTYFS(vp), Pid);
+ return 0;
+ }
+ fsp->fsid = mt.mnt_stat.f_fsidx.__fsid_val[0];
fsp->fileid = (long)pn.ptyfs_fileno;
fsp->mode = pn.ptyfs_mode;
fsp->size = 0;
- if (maj == 0)
- maj = getptsmajor();
- if (maj == ~0)
- fsp->rdev = makedev(maj, pn.ptyfs_pty);
+ switch (pn.ptyfs_type) {
+ case PTYFSpts:
+ case PTYFSptc:
+ if (!KVM_READ(vp->v_specinfo, &si, sizeof(si))) {
+ dprintf("can't read specinfo at %p for pid %d",
+ VTOPTYFS(vp), Pid);
+ return 0;
+ }
+ fsp->rdev = si.si_rdev;
+ fsp->mode |= S_IFCHR;
+ break;
+ case PTYFSroot:
+ fsp->rdev = 0;
+ fsp->mode |= S_IFDIR;
+ break;
+ }
+
return 1;
}
Home |
Main Index |
Thread Index |
Old Index