From 5c78e7345a2fd91174249db5a41aec14e57f1fb3 Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 9 Sep 1999 19:08:44 +0000 Subject: Changes to centralise the default blocksize behaviour. More likely to follow. Submitted by: phk@freebsd.org --- sys/dev/ccd/ccd.c | 4 ---- sys/dev/fdc/fdc.c | 3 --- sys/dev/mcd/mcd.c | 4 ++-- sys/dev/scd/scd.c | 4 ++-- sys/dev/vinum/vinum.c | 3 --- sys/dev/vn/vn.c | 5 +---- sys/fs/specfs/spec_vnops.c | 10 ++++++++-- sys/geom/geom_ccd.c | 4 ---- sys/i386/isa/atapi-cd.c | 4 +--- sys/i386/isa/matcd/matcd.c | 6 ++---- sys/i386/isa/mcd.c | 4 ++-- sys/i386/isa/scd.c | 4 ++-- sys/i386/isa/wd_cd.c | 4 +--- sys/isa/fd.c | 3 --- sys/kern/subr_disk.c | 12 ++++++++++++ sys/kern/subr_diskslice.c | 2 -- sys/kern/vfs_vnops.c | 33 ++++++++++++++++++++------------- sys/miscfs/specfs/spec_vnops.c | 10 ++++++++-- sys/pc98/pc98/wd_cd.c | 4 +--- sys/ufs/mfs/mfs_vfsops.c | 4 ++-- 20 files changed, 64 insertions(+), 63 deletions(-) (limited to 'sys') diff --git a/sys/dev/ccd/ccd.c b/sys/dev/ccd/ccd.c index 7badacb..a889ca3 100644 --- a/sys/dev/ccd/ccd.c +++ b/sys/dev/ccd/ccd.c @@ -633,10 +633,6 @@ ccdopen(dev, flags, fmt, p) part = ccdpart(dev); pmask = (1 << part); - dev->si_bsize_phys = DEV_BSIZE; - dev->si_bsize_best = BLKDEV_IOSIZE; - dev->si_bsize_max = MAXBSIZE; - /* * If we're initialized, check to see if there are any other * open partitions. If not, then it's safe to update diff --git a/sys/dev/fdc/fdc.c b/sys/dev/fdc/fdc.c index ee74217..7e6b0b3 100644 --- a/sys/dev/fdc/fdc.c +++ b/sys/dev/fdc/fdc.c @@ -1279,9 +1279,6 @@ Fdopen(dev_t dev, int flags, int mode, struct proc *p) fd_p fd; fdc_p fdc; - dev->si_bsize_phys = DEV_BSIZE; - dev->si_bsize_best = BLKDEV_IOSIZE; - dev->si_bsize_max = MAXBSIZE; /* check bounds */ if ((fd = devclass_get_softc(fd_devclass, fdu)) == 0) return (ENXIO); diff --git a/sys/dev/mcd/mcd.c b/sys/dev/mcd/mcd.c index 37bd508..19f35e6 100644 --- a/sys/dev/mcd/mcd.c +++ b/sys/dev/mcd/mcd.c @@ -296,8 +296,6 @@ int mcdopen(dev_t dev, int flags, int fmt, struct proc *p) if (!(cd->flags & MCDVALID) && cd->openflags) return ENXIO; - dev->si_bsize_phys = 2048; - dev->si_bsize_max = MAXBSIZE; if (mcd_getstat(unit,1) == -1) return EIO; @@ -352,6 +350,8 @@ int mcdopen(dev_t dev, int flags, int fmt, struct proc *p) MCD_TRACE("open: partition=%d, disksize = %ld, blksize=%d\n", part, cd->disksize, cd->blksize); + dev->si_bsize_phys = cd->blksize; + if (part == RAW_PART || (part < cd->dlabel.d_npartitions && cd->dlabel.d_partitions[part].p_fstype != FS_UNUSED)) { diff --git a/sys/dev/scd/scd.c b/sys/dev/scd/scd.c index 1742fdd..719c86b 100644 --- a/sys/dev/scd/scd.c +++ b/sys/dev/scd/scd.c @@ -258,8 +258,6 @@ scdopen(dev_t dev, int flags, int fmt, struct proc *p) XDEBUG(1,("scd%d: DEBUG: status = 0x%x\n", unit, inb(cd->iobase+IREG_STATUS))); - dev->si_bsize_phys = 2048; - dev->si_bsize_max = MAXBSIZE; if ((rc = spin_up(unit)) != 0) { print_error(unit, rc); return EIO; @@ -281,6 +279,8 @@ scdopen(dev_t dev, int flags, int fmt, struct proc *p) } } + dev->si_bsize_phys = cd->blksize; + cd->openflag = 1; cd->flags |= SCDVALID; diff --git a/sys/dev/vinum/vinum.c b/sys/dev/vinum/vinum.c index 2482185..c70b1c7 100644 --- a/sys/dev/vinum/vinum.c +++ b/sys/dev/vinum/vinum.c @@ -268,9 +268,6 @@ vinumopen(dev_t dev, int devminor; /* minor number */ devminor = minor(dev); - dev->si_bsize_phys = DEV_BSIZE; - dev->si_bsize_best = VINUM_BSIZE_BEST; /* kludge until we track drive block sizes */ - dev->si_bsize_max = MAXBSIZE; error = 0; /* First, decide what we're looking at */ switch (DEVTYPE(dev)) { diff --git a/sys/dev/vn/vn.c b/sys/dev/vn/vn.c index f51efca..199c804 100644 --- a/sys/dev/vn/vn.c +++ b/sys/dev/vn/vn.c @@ -510,10 +510,7 @@ vniocattach_file(vn, vio, dev, flag, p) (void) vn_close(nd.ni_vp, flags, p->p_ucred, p); return(error); } - if (dev->si_bsize_phys < vn->sc_secsize) - dev->si_bsize_phys = vn->sc_secsize; - if (dev->si_bsize_best < vn->sc_secsize) - dev->si_bsize_best = vn->sc_secsize; + dev->si_bsize_phys = vn->sc_secsize; vn->sc_flags |= VNF_INITED; if (flags == FREAD) vn->sc_flags |= VNF_READONLY; diff --git a/sys/fs/specfs/spec_vnops.c b/sys/fs/specfs/spec_vnops.c index 9d85bfe..7b2d712 100644 --- a/sys/fs/specfs/spec_vnops.c +++ b/sys/fs/specfs/spec_vnops.c @@ -234,8 +234,6 @@ spec_open(ap) if (vn_isdisk(vp)) { if (!dev->si_bsize_phys) dev->si_bsize_phys = DEV_BSIZE; - if (dev->si_bsize_best < dev->si_bsize_phys) - dev->si_bsize_best = BLKDEV_IOSIZE; if (!dev->si_bsize_max) dev->si_bsize_max = MAXBSIZE; } @@ -296,6 +294,10 @@ spec_read(ap) */ bsize = vp->v_rdev->si_bsize_best; + if (bsize < vp->v_rdev->si_bsize_phys) + bsize = vp->v_rdev->si_bsize_phys; + if (bsize < BLKDEV_IOSIZE) + bsize = BLKDEV_IOSIZE; if ((ioctl = devsw(dev)->d_ioctl) != NULL && (*ioctl)(dev, DIOCGPART, (caddr_t)&dpart, FREAD, p) == 0 && @@ -380,6 +382,10 @@ spec_write(ap) * be larger then the physical minimum. */ bsize = vp->v_rdev->si_bsize_best; + if (bsize < vp->v_rdev->si_bsize_phys) + bsize = vp->v_rdev->si_bsize_phys; + if (bsize < BLKDEV_IOSIZE) + bsize = BLKDEV_IOSIZE; if ((*devsw(vp->v_rdev)->d_ioctl)(vp->v_rdev, DIOCGPART, (caddr_t)&dpart, FREAD, p) == 0) { diff --git a/sys/geom/geom_ccd.c b/sys/geom/geom_ccd.c index 7badacb..a889ca3 100644 --- a/sys/geom/geom_ccd.c +++ b/sys/geom/geom_ccd.c @@ -633,10 +633,6 @@ ccdopen(dev, flags, fmt, p) part = ccdpart(dev); pmask = (1 << part); - dev->si_bsize_phys = DEV_BSIZE; - dev->si_bsize_best = BLKDEV_IOSIZE; - dev->si_bsize_max = MAXBSIZE; - /* * If we're initialized, check to see if there are any other * open partitions. If not, then it's safe to update diff --git a/sys/i386/isa/atapi-cd.c b/sys/i386/isa/atapi-cd.c index a8adbab..678603f 100644 --- a/sys/i386/isa/atapi-cd.c +++ b/sys/i386/isa/atapi-cd.c @@ -399,8 +399,6 @@ acdopen(dev_t dev, int flags, int fmt, struct proc *p) return ENXIO; cdp = acdtab[lun]; - dev->si_bsize_phys = 2048; - dev->si_bsize_max = MAXBSIZE; if (!(cdp->flags & F_BOPEN) && !cdp->refcnt) { /* Prevent user eject */ acd_request_wait(cdp, ATAPI_PREVENT_ALLOW, @@ -411,7 +409,7 @@ acdopen(dev_t dev, int flags, int fmt, struct proc *p) cdp->flags |= F_BOPEN; else ++cdp->refcnt; - + dev->si_bsize_phys = cdp->block_size; if (!(flags & O_NONBLOCK) && acd_read_toc(cdp) && !(flags & FWRITE)) printf("acd%d: read_toc failed\n", lun); return 0; diff --git a/sys/i386/isa/matcd/matcd.c b/sys/i386/isa/matcd/matcd.c index 78e7ce0..bef362d 100644 --- a/sys/i386/isa/matcd/matcd.c +++ b/sys/i386/isa/matcd/matcd.c @@ -623,9 +623,6 @@ int matcdopen(dev_t dev, int flags, int fmt, if (ldrive >= TOTALDRIVES) return(ENXIO); - dev->si_bsize_phys = 2048; - dev->si_bsize_max = MAXBSIZE; - #ifdef DEBUGOPEN printf("matcd%d: Open: dev %x partition %x controller %x flags %x cdrive %x\n", ldrive,(int)dev,partition,controller,cd->flags, @@ -696,7 +693,6 @@ int matcdopen(dev_t dev, int flags, int fmt, if ((cd->flags & MATCDLABEL)==0) { bzero(&cd->dlabel,sizeof(struct disklabel)); - /* Now we query the drive for the actual size of the media. This is where we find out of there is any media or if the media isn't a Mode 1 or Mode 2/XA disc. @@ -749,6 +745,8 @@ int matcdopen(dev_t dev, int flags, int fmt, cd->flags |= MATCDLABEL; /*Mark drive as having TOC*/ } + dev->si_bsize_phys = cd->blksize; + #ifdef DEBUGOPEN printf("matcd%d open2: partition=%d disksize=%d blksize=%x flags=%x\n", ldrive,partition,(int)cd->disksize,cd->blksize,cd->flags); diff --git a/sys/i386/isa/mcd.c b/sys/i386/isa/mcd.c index 37bd508..19f35e6 100644 --- a/sys/i386/isa/mcd.c +++ b/sys/i386/isa/mcd.c @@ -296,8 +296,6 @@ int mcdopen(dev_t dev, int flags, int fmt, struct proc *p) if (!(cd->flags & MCDVALID) && cd->openflags) return ENXIO; - dev->si_bsize_phys = 2048; - dev->si_bsize_max = MAXBSIZE; if (mcd_getstat(unit,1) == -1) return EIO; @@ -352,6 +350,8 @@ int mcdopen(dev_t dev, int flags, int fmt, struct proc *p) MCD_TRACE("open: partition=%d, disksize = %ld, blksize=%d\n", part, cd->disksize, cd->blksize); + dev->si_bsize_phys = cd->blksize; + if (part == RAW_PART || (part < cd->dlabel.d_npartitions && cd->dlabel.d_partitions[part].p_fstype != FS_UNUSED)) { diff --git a/sys/i386/isa/scd.c b/sys/i386/isa/scd.c index 1742fdd..719c86b 100644 --- a/sys/i386/isa/scd.c +++ b/sys/i386/isa/scd.c @@ -258,8 +258,6 @@ scdopen(dev_t dev, int flags, int fmt, struct proc *p) XDEBUG(1,("scd%d: DEBUG: status = 0x%x\n", unit, inb(cd->iobase+IREG_STATUS))); - dev->si_bsize_phys = 2048; - dev->si_bsize_max = MAXBSIZE; if ((rc = spin_up(unit)) != 0) { print_error(unit, rc); return EIO; @@ -281,6 +279,8 @@ scdopen(dev_t dev, int flags, int fmt, struct proc *p) } } + dev->si_bsize_phys = cd->blksize; + cd->openflag = 1; cd->flags |= SCDVALID; diff --git a/sys/i386/isa/wd_cd.c b/sys/i386/isa/wd_cd.c index a8adbab..678603f 100644 --- a/sys/i386/isa/wd_cd.c +++ b/sys/i386/isa/wd_cd.c @@ -399,8 +399,6 @@ acdopen(dev_t dev, int flags, int fmt, struct proc *p) return ENXIO; cdp = acdtab[lun]; - dev->si_bsize_phys = 2048; - dev->si_bsize_max = MAXBSIZE; if (!(cdp->flags & F_BOPEN) && !cdp->refcnt) { /* Prevent user eject */ acd_request_wait(cdp, ATAPI_PREVENT_ALLOW, @@ -411,7 +409,7 @@ acdopen(dev_t dev, int flags, int fmt, struct proc *p) cdp->flags |= F_BOPEN; else ++cdp->refcnt; - + dev->si_bsize_phys = cdp->block_size; if (!(flags & O_NONBLOCK) && acd_read_toc(cdp) && !(flags & FWRITE)) printf("acd%d: read_toc failed\n", lun); return 0; diff --git a/sys/isa/fd.c b/sys/isa/fd.c index ee74217..7e6b0b3 100644 --- a/sys/isa/fd.c +++ b/sys/isa/fd.c @@ -1279,9 +1279,6 @@ Fdopen(dev_t dev, int flags, int mode, struct proc *p) fd_p fd; fdc_p fdc; - dev->si_bsize_phys = DEV_BSIZE; - dev->si_bsize_best = BLKDEV_IOSIZE; - dev->si_bsize_max = MAXBSIZE; /* check bounds */ if ((fd = devclass_get_softc(fd_devclass, fdu)) == 0) return (ENXIO); diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index dbf9c14..cbdb2af 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -235,3 +236,14 @@ diskpsize(dev_t dev) } return (dssize(dev, &dp->d_slice)); } + +SYSCTL_DECL(_debug_sizeof); + +SYSCTL_INT(_debug_sizeof, OID_AUTO, disklabel, CTLFLAG_RD, + 0, sizeof(struct disklabel), "sizeof(struct disklabel)"); + +SYSCTL_INT(_debug_sizeof, OID_AUTO, diskslices, CTLFLAG_RD, + 0, sizeof(struct diskslices), "sizeof(struct diskslices)"); + +SYSCTL_INT(_debug_sizeof, OID_AUTO, disk, CTLFLAG_RD, + 0, sizeof(struct disk), "sizeof(struct disk)"); diff --git a/sys/kern/subr_diskslice.c b/sys/kern/subr_diskslice.c index 49e86f6..6a31e11 100644 --- a/sys/kern/subr_diskslice.c +++ b/sys/kern/subr_diskslice.c @@ -718,8 +718,6 @@ dsopen(dev, mode, flags, sspp, lp) int unit; dev->si_bsize_phys = lp->d_secsize; - dev->si_bsize_best = BLKDEV_IOSIZE; - dev->si_bsize_max = MAXBSIZE; unit = dkunit(dev); if (lp->d_secsize % DEV_BSIZE) { diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index 0a08938..c42ebf6 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -429,22 +429,29 @@ 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: - sb->st_blksize = vp->v_rdev->si_bsize_best; - break; - case VCHR: - sb->st_blksize = vp->v_rdev->si_bsize_max; - break; - default: + + if (vap->va_type == VREG) { sb->st_blksize = vap->va_blocksize; - break; + } else if ((vp->v_type == VBLK || vp->v_type == VCHR) && + devsw(vp->v_rdev) && (devsw(vp->v_rdev)->d_flags & D_DISK)) { + /* XXX use vn_isdisk() above once VCHR is also disk */ + sb->st_blksize = vp->v_rdev->si_bsize_best; + if (sb->st_blksize < vp->v_rdev->si_bsize_phys) + sb->st_blksize = vp->v_rdev->si_bsize_phys; + if (sb->st_blksize < BLKDEV_IOSIZE) + sb->st_blksize = BLKDEV_IOSIZE; + } else { + sb->st_blksize = 0; } + sb->st_flags = vap->va_flags; if (suser_xxx(p->p_ucred, 0, 0)) sb->st_gen = 0; diff --git a/sys/miscfs/specfs/spec_vnops.c b/sys/miscfs/specfs/spec_vnops.c index 9d85bfe..7b2d712 100644 --- a/sys/miscfs/specfs/spec_vnops.c +++ b/sys/miscfs/specfs/spec_vnops.c @@ -234,8 +234,6 @@ spec_open(ap) if (vn_isdisk(vp)) { if (!dev->si_bsize_phys) dev->si_bsize_phys = DEV_BSIZE; - if (dev->si_bsize_best < dev->si_bsize_phys) - dev->si_bsize_best = BLKDEV_IOSIZE; if (!dev->si_bsize_max) dev->si_bsize_max = MAXBSIZE; } @@ -296,6 +294,10 @@ spec_read(ap) */ bsize = vp->v_rdev->si_bsize_best; + if (bsize < vp->v_rdev->si_bsize_phys) + bsize = vp->v_rdev->si_bsize_phys; + if (bsize < BLKDEV_IOSIZE) + bsize = BLKDEV_IOSIZE; if ((ioctl = devsw(dev)->d_ioctl) != NULL && (*ioctl)(dev, DIOCGPART, (caddr_t)&dpart, FREAD, p) == 0 && @@ -380,6 +382,10 @@ spec_write(ap) * be larger then the physical minimum. */ bsize = vp->v_rdev->si_bsize_best; + if (bsize < vp->v_rdev->si_bsize_phys) + bsize = vp->v_rdev->si_bsize_phys; + if (bsize < BLKDEV_IOSIZE) + bsize = BLKDEV_IOSIZE; if ((*devsw(vp->v_rdev)->d_ioctl)(vp->v_rdev, DIOCGPART, (caddr_t)&dpart, FREAD, p) == 0) { diff --git a/sys/pc98/pc98/wd_cd.c b/sys/pc98/pc98/wd_cd.c index a8adbab..678603f 100644 --- a/sys/pc98/pc98/wd_cd.c +++ b/sys/pc98/pc98/wd_cd.c @@ -399,8 +399,6 @@ acdopen(dev_t dev, int flags, int fmt, struct proc *p) return ENXIO; cdp = acdtab[lun]; - dev->si_bsize_phys = 2048; - dev->si_bsize_max = MAXBSIZE; if (!(cdp->flags & F_BOPEN) && !cdp->refcnt) { /* Prevent user eject */ acd_request_wait(cdp, ATAPI_PREVENT_ALLOW, @@ -411,7 +409,7 @@ acdopen(dev_t dev, int flags, int fmt, struct proc *p) cdp->flags |= F_BOPEN; else ++cdp->refcnt; - + dev->si_bsize_phys = cdp->block_size; if (!(flags & O_NONBLOCK) && acd_read_toc(cdp) && !(flags & FWRITE)) printf("acd%d: read_toc failed\n", lun); return 0; diff --git a/sys/ufs/mfs/mfs_vfsops.c b/sys/ufs/mfs/mfs_vfsops.c index 044bf63..1ac1dc8 100644 --- a/sys/ufs/mfs/mfs_vfsops.c +++ b/sys/ufs/mfs/mfs_vfsops.c @@ -332,8 +332,8 @@ mfs_mount(mp, path, data, ndp, p) } devvp->v_type = VBLK; dev = make_dev(&mfs_cdevsw, mfs_minor, 0, 0, 0, "MFS%d", mfs_minor); + /* It is not clear that these will get initialized otherwise */ dev->si_bsize_phys = DEV_BSIZE; - dev->si_bsize_best = BLKDEV_IOSIZE; dev->si_bsize_max = MAXBSIZE; addaliasu(devvp, makeudev(253, mfs_minor++)); devvp->v_data = mfsp; @@ -494,8 +494,8 @@ mfs_init(vfsp) mountrootfsname = "mfs"; rootdev = make_dev(&mfs_cdevsw, mfs_minor, 0, 0, 0, "MFS%d", mfs_minor); + /* It is not clear that these will get initialized otherwise */ rootdev->si_bsize_phys = DEV_BSIZE; - rootdev->si_bsize_best = BLKDEV_IOSIZE; rootdev->si_bsize_max = MAXBSIZE; mfs_minor++; } else if (bootverbose) -- cgit v1.1