From owner-freebsd-hackers Fri Jan 22 15:20:25 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id PAA00884 for freebsd-hackers-outgoing; Fri, 22 Jan 1999 15:20:25 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from ceia.nordier.com (m2-48-dbn.dial-up.net [196.34.155.112]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id PAA00856 for ; Fri, 22 Jan 1999 15:20:18 -0800 (PST) (envelope-from rnordier@nordier.com) Received: (from rnordier@localhost) by ceia.nordier.com (8.8.7/8.6.12) id BAA02045; Sat, 23 Jan 1999 01:19:09 +0200 (SAT) From: Robert Nordier Message-Id: <199901222319.BAA02045@ceia.nordier.com> Subject: Re: raw devices and disk geometry In-Reply-To: <19990122124309.C11064@proxydev.inktomi.com> from John Plevyak at "Jan 22, 99 12:43:09 pm" To: jplevyak@inktomi.com (John Plevyak) Date: Sat, 23 Jan 1999 01:19:07 +0200 (SAT) Cc: freebsd-hackers@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL31 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG John Plevyak wrote: > I am trying to find the disk of a raw disk partition (/dev/rwd2c). > > I have noticed the following in 3.0-CURRENT Jan 12: > > 1) DIOCGPART does not seem to return valid pointers: > > 2) lseek on raw disks does not seem to produce an error > when the size is exceeded. In fact, it acts very > oddly when given SEEK_END > 3) lseek followed by read *can* be used to determine the size of > the partition of course this requires a binary search. > > Are these known issues? Is there a better way of determining > the size of a partition from a program? DIOCGPART is for internal use and not used outside the kernel. You can't necessarily rely on lseek() when applied to a device. However, what you want to do seems fairly simple: if (ioctl(fd, DIOCGDINFO, &dl) == -1) errx(1, "%s: IOCTL(DIOCGDINFO)", argv[1]); for (i = 0; i < dl.d_npartitions; i++) printf("%c: %u\n", 'a' + i, dl.d_partitions[i].p_size); With sample output: /dev/rwd0: a: 0 b: 0 c: 8438850 d: 0 e: 0 f: 0 g: 0 h: 0 /dev/rwd0c: a: 65536 b: 282304 c: 4305357 d: 0 e: 65536 f: 3891981 g: 0 h: 0 The 'c' (raw) partitions give, respectively, the size of the whole disk, and of the FreeBSD slice ("fdisk partition"). -- Robert Nordier To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message