From owner-freebsd-current@FreeBSD.ORG Fri Feb 20 20:16:42 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 42E2C16A4CE for ; Fri, 20 Feb 2004 20:16:42 -0800 (PST) Received: from mailout1.pacific.net.au (mailout1.pacific.net.au [61.8.0.84]) by mx1.FreeBSD.org (Postfix) with ESMTP id B93E043D2F for ; Fri, 20 Feb 2004 20:16:41 -0800 (PST) (envelope-from bde@zeta.org.au) Received: from mailproxy1.pacific.net.au (mailproxy1.pacific.net.au [61.8.0.86])i1L4GCLE012054; Sat, 21 Feb 2004 15:16:12 +1100 Received: from gamplex.bde.org (katana.zip.com.au [61.8.7.246]) i1L4G80I004950; Sat, 21 Feb 2004 15:16:10 +1100 Date: Sat, 21 Feb 2004 15:16:08 +1100 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: John-Mark Gurney In-Reply-To: <20040220183634.GK85686@funkthat.com> Message-ID: <20040221145653.L7690@gamplex.bde.org> References: <9615.162.114.211.143.1077213472.squirrel@mail.alpete.com> <29352.162.114.211.143.1077222503.squirrel@mail.alpete.com> <20040219204012.GA33771@troutmask.apl.washington.edu> <46490.162.114.211.143.1077223809.squirrel@mail.alpete.com> <20040220183634.GK85686@funkthat.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: Peter Jeremy cc: freebsd-current@freebsd.org cc: ticso@cicely.de cc: Steve Kargl cc: Aaron Peterson Subject: Re: bcwipe won't wipe a block device... X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Feb 2004 04:16:42 -0000 On Fri, 20 Feb 2004, John-Mark Gurney wrote: > Peter Jeremy wrote this message on Fri, Feb 20, 2004 at 18:23 +1100: > > Summary: bcwipe is trying to read 1 byte from an offset of 2^N-1. > > FreeBSD no longer has block devices (since 4.0) - /dev/da0 is a > > character device. Character devices can only be read in blocksize > > units (typically 512 bytes for disks). You need to fix bcwipe to > > handle character devices. > > this can be done by using the fstat call on the device node.. it will > provide both the proper block size (so it'll work w/ md swap backed > devices that have a 4k block size) and device size... Um, this can not be done by using the fstat call on the device node. fstat() on devices always gives 0 for the device size and is little better for the block size. The block size is always the nominal value PAGE_SIZE for non-disk devices and is not always the nominal value BLKDEV_IOSIZE for disk devices. From vfs_vnops.c: % } else if (vn_isdisk(vp, NULL)) { % 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 = PAGE_SIZE; % } Here si_bsize_phys is the sector size of drivers or GEOM set it, else it is defaulted to DEV_BSIZE in spec_open(). si_bsize_bestt is fully rotted garbage -- it is only used above, but never set except using bzero() to 0. Since sector sizes are normally smaller than BLKDEV_IOSIZE and BLKDEV_IOSIZE is normally PAGE_SIZE, the above normally sets st_blksize to PAGE_SIZE for all devices. Bruce