Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Jan 1999 12:43:09 -0800
From:      John Plevyak <jplevyak@inktomi.com>
To:        freebsd-hackers@FreeBSD.ORG
Subject:   raw devices and disk geometry
Message-ID:  <19990122124309.C11064@proxydev.inktomi.com>

next in thread | raw e-mail | index | archive | help

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990122124309.C11064>