summaryrefslogtreecommitdiffstats
path: root/sys/kern/vfs_vnops.c
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1999-09-01 05:36:55 +0000
committerphk <phk@FreeBSD.org>1999-09-01 05:36:55 +0000
commitbe3ce843d293abb26f41f84cf52d0e8114621325 (patch)
tree438ad63d313880d2ca2900f20d00e04bb71d278b /sys/kern/vfs_vnops.c
parent61eef2dc3522cc8ff3ca644bd33707979489c38d (diff)
downloadFreeBSD-src-be3ce843d293abb26f41f84cf52d0e8114621325.zip
FreeBSD-src-be3ce843d293abb26f41f84cf52d0e8114621325.tar.gz
Improve the returned values in st_blksize a little bit, avoid
accessing union fields not valid for dev_t type.
Diffstat (limited to 'sys/kern/vfs_vnops.c')
-rw-r--r--sys/kern/vfs_vnops.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index e1459d1..c64a77e 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -429,21 +429,31 @@ vn_stat(vp, sb, p)
sb->st_atimespec = vap->va_atime;
sb->st_mtimespec = vap->va_mtime;
sb->st_ctimespec = vap->va_ctime;
+
/*
- * For block and char device nodes we don't really care
- * about what the filesystem told us, we want to know
- * what the device told us
+ * According to www.opengroup.org, the meaning of st_blksize is
+ * "a filesystem-specific preferred I/O block size for this
+ * object. In some filesystem types, this may vary from file
+ * to file"
+ * Default to zero to catch bogus uses of this field.
*/
- switch (vap->va_type) {
- case VBLK:
- case VCHR:
- sb->st_blksize = vp->v_rdev->si_bsize_max;
- break;
- default:
+ sb->st_blksize = 0;
+
+ if (vp->v_type == VREG)
sb->st_blksize = vap->va_blocksize;
- break;
- }
+
+ /*
+ * For disks we can say something sensible. We report the max
+ * size because we prefer few big transfers than many small.
+ * XXX: Only reliable if the disk is opened.
+ * XXX: Use vn_isdisk when it allows VCHR too
+ */
+ if ((vp->v_type == VBLK || vp->v_type == VCHR) &&
+ devsw(vp->v_rdev) && (devsw(vp->v_rdev)->d_flags & D_DISK))
+ sb->st_blksize = vp->v_rdev->si_bsize_max;
+
sb->st_flags = vap->va_flags;
+
if (suser_xxx(p->p_ucred, 0, 0))
sb->st_gen = 0;
else
OpenPOWER on IntegriCloud