From owner-freebsd-hackers Fri Jan 22 12:43:20 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id MAA08567 for freebsd-hackers-outgoing; Fri, 22 Jan 1999 12:43:20 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from mercury.inktomi.com (mercury.inktomi.com [209.1.32.126]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id MAA08560 for ; Fri, 22 Jan 1999 12:43:19 -0800 (PST) (envelope-from jplevyak@inktomi.com) Received: from proxydev.inktomi.com (proxydev.inktomi.com [209.1.32.44]) by mercury.inktomi.com (8.9.1a/8.9.1) with ESMTP id MAA08062 for ; Fri, 22 Jan 1999 12:43:20 -0800 (PST) Received: (from jplevyak@localhost) by proxydev.inktomi.com (8.8.5/8.7.3) id MAA12266 for freebsd-hackers@FreeBSD.ORG; Fri, 22 Jan 1999 12:43:09 -0800 (PST) Message-ID: <19990122124309.C11064@proxydev.inktomi.com> Date: Fri, 22 Jan 1999 12:43:09 -0800 From: John Plevyak To: freebsd-hackers@FreeBSD.ORG Subject: raw devices and disk geometry Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.93.2i Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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: The code: struct disklabel dl; struct partinfo dp; int fd,res; fd = open("/dev/rwd2c", O_RDWR, 0); printf("%d : %s\n", fd, strerror(errno)); res = ioctl(fd,DIOCGDINFO,&dl); printf("%d : %s\n", res, strerror(errno)); res = ioctl(fd,DIOCGPART,&dp); printf("%d : %s\n", res, strerror(errno)); printf("%d %d\n", dp.disklab, dp.part); returns: 3 : Undefined error: 0 0 : Undefined error: 0 0 : Undefined error: 0 879 0 dl has valid data in it, but dp has invalid pointers. There is a comment in /usr/include/sys/disklabel.h that DIOCGPART is used internally. Does this mean that this ioctl cannot be used outside of the kernel? 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 for a 2GB disk the following code: o = lseek(fd,0,SEEK_END); printf("%llu\n", o); printf("%d\n", read(fd,d,8192)); o = lseek(fd,0,SEEK_CUR); printf("%llu\n", o); printf("%d\n", read(fd,d,8192)); o = 2*1073741824LL - 128 * 8192; o = lseek(fd,o,SEEK_SET); printf("%llu\n", o); printf("%d\n", read(fd,d,8192)); o = lseek(fd,-8192,SEEK_END); printf("%lld\n", o); printf("%d\n", read(fd,d,8192)); produces 0 8192 8192 8192 2146435072 -1 -8192 -1 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? I am willing to debug if this is not the desired behavior. john -- John Bradley Plevyak, PhD, jplevyak@inktomi.com, PGP KeyID: 051130BD Inktomi Corporation, 1900 S. Norfolk Street, Suite 110, San Mateo, CA 94403 W:(415)653-2830 F:(415)653-2801 P:(888)491-1332/5103192436.4911332@pagenet.net To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message