From 0eee862a5427f8d1975b1b3152949558489afaf7 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Fri, 20 Feb 2009 13:05:29 +0000 Subject: Don't make Linux stat() open character devices to resolve its name. The existing code calls kern_open() to resolve the vnode of a pathname right after a stat(). This is not correct, because it causes random character devices to be opened in /dev. This means ls'ing a tape streamer will cause it to rewind, for example. Changes I have made: - Add kern_statat_vnhook() to allow binary emulators to `post-process' struct stat, using the proper vnode. - Remove unneeded printf's from stat() and statfs(). - Make the Linuxolator use kern_statat_vnhook(), replacing translate_path_major_minor_at(). - Let translate_fd_major_minor() use vp->v_rdev instead of vp->v_un.vu_cdev. Result: crw-rw-rw- 1 root root 0, 14 Feb 20 13:54 /dev/ptmx crw--w---- 1 root adm 136, 0 Feb 20 14:03 /dev/pts/0 crw--w---- 1 root adm 136, 1 Feb 20 14:02 /dev/pts/1 crw--w---- 1 ed tty 136, 2 Feb 20 14:03 /dev/pts/2 Before this commit, ptmx also had a major number of 136, because it silently allocated and deallocated a pseudo-terminal. Device nodes that cannot be opened now have proper major/minor-numbers. Reviewed by: kib, netchild, rdivacky (thanks!) --- sys/kern/vfs_syscalls.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'sys/kern/vfs_syscalls.c') diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 80da9b750190..ad69698b196b 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -339,8 +339,6 @@ kern_statfs(struct thread *td, char *path, enum uio_seg pathseg, out: vfs_unbusy(mp); VFS_UNLOCK_GIANT(vfslocked); - if (mtx_owned(&Giant)) - printf("statfs(%d): %s: %d\n", vfslocked, path, error); return (error); } @@ -2343,6 +2341,15 @@ int kern_statat(struct thread *td, int flag, int fd, char *path, enum uio_seg pathseg, struct stat *sbp) { + + return (kern_statat_vnhook(td, flag, fd, path, pathseg, sbp, NULL)); +} + +int +kern_statat_vnhook(struct thread *td, int flag, int fd, char *path, + enum uio_seg pathseg, struct stat *sbp, + void (*hook)(struct vnode *vp, struct stat *sbp)) +{ struct nameidata nd; struct stat sb; int error, vfslocked; @@ -2362,12 +2369,12 @@ kern_statat(struct thread *td, int flag, int fd, char *path, SDT_PROBE(vfs, , stat, mode, path, sb.st_mode, 0, 0, 0); if (S_ISREG(sb.st_mode)) SDT_PROBE(vfs, , stat, reg, path, pathseg, 0, 0, 0); + if (__predict_false(hook != NULL)) + hook(nd.ni_vp, &sb); } NDFREE(&nd, NDF_ONLY_PNBUF); vput(nd.ni_vp); VFS_UNLOCK_GIANT(vfslocked); - if (mtx_owned(&Giant)) - printf("stat(%d): %s\n", vfslocked, path); if (error) return (error); *sbp = sb; -- cgit v1.2.3