From owner-freebsd-hackers Wed Aug 28 23:56:32 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id XAA20150 for hackers-outgoing; Wed, 28 Aug 1996 23:56:32 -0700 (PDT) Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.2.228.19]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id XAA20145 for ; Wed, 28 Aug 1996 23:56:28 -0700 (PDT) Received: (from bde@localhost) by godzilla.zeta.org.au (8.6.12/8.6.9) id QAA31554; Thu, 29 Aug 1996 16:50:35 +1000 Date: Thu, 29 Aug 1996 16:50:35 +1000 From: Bruce Evans Message-Id: <199608290650.QAA31554@godzilla.zeta.org.au> To: hackers@FreeBSD.org, rnordier@iafrica.com Subject: Re: Determining disk type & size Sender: owner-hackers@FreeBSD.org X-Loop: FreeBSD.org Precedence: bulk >Could anyone tell me if there is a quick and easy way to do the >following: >For a given (block special) device, determine whether it represents > > (1) a floppy disk > (2) a hard disk slice that contains a filesystem (probably not ufs) > (3) anything else (not interested, but could be cdrom, tape, etc) >and, given this info, the size (in bytes or 512-byte sectors) of the >disk or slice itself. For example: > > device blocks > ---------- ------ > /dev/fd1 2400 > /dev/wd0s1 65457 > /dev/wd0 (error) No easy way. Perhaps no way. >./fdtest /dev/fd0 >sectors per cylinder: 158 [<-- 30 expected] > if (ioctl(fd, DIOCGDINFO, &dl) == -1) > err(1, argv[1]); > printf("sectors per cylinder: %lu\n", dl.d_secpercyl); DIOCGDINFO for floppies just returns whatever happens to be in the label area on the disk (*). The label is garbage unless the disk actually has a label. There is no way to tell from the ioctl() return value whether the label is garbage. Bruce