summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2009-02-20 13:05:29 +0000
committered <ed@FreeBSD.org>2009-02-20 13:05:29 +0000
commit72727e8d9fd98552cebb26b2a25985f9bf6f0d65 (patch)
tree7eab17a425e09a913acc34c0b450fa5ccedd74c7 /sys/kern
parent1de5dbac2f2a8b66b5fcaaa64741c357bb26458f (diff)
downloadFreeBSD-src-72727e8d9fd98552cebb26b2a25985f9bf6f0d65.zip
FreeBSD-src-72727e8d9fd98552cebb26b2a25985f9bf6f0d65.tar.gz
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!)
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/vfs_syscalls.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 80da9b7..ad69698 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;
OpenPOWER on IntegriCloud