Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Jan 1999 14:02:51 -0800
From:      John Plevyak <jplevyak@inktomi.com>
To:        Robert Nordier <rnordier@nordier.com>, John Plevyak <jplevyak@inktomi.com>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: raw devices and disk geometry
Message-ID:  <19990126140251.G19158@proxydev.inktomi.com>
In-Reply-To: <199901222319.BAA02045@ceia.nordier.com>; from Robert Nordier on Sat, Jan 23, 1999 at 01:19:07AM %2B0200
References:  <19990122124309.C11064@proxydev.inktomi.com> <199901222319.BAA02045@ceia.nordier.com>

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



Thanx, but I am not sure this allows me to get the size of a raw partition.
If I call:
  
  fd = open("/dev/rwd2c", O_RDONLY, 0);
  ioctl(fd, DIOCGDINFO, &dl)

I get 

> /dev/rwd0c:
> a: 65536
> b: 282304
> c: 4305357
> d: 0
> e: 65536
> f: 3891981
> g: 0
> h: 0

The "c:" portion of which does not match the "c:" portion of the
whole disk in your example:

> /dev/rwd0:
> a: 0
> b: 0
> c: 8438850
> d: 0
> e: 0
> f: 0
> g: 0
> h: 0

So this does not seem to be sufficient to determine the size
of /dev/rwd0c on your system.   What I really need to know
is a way to determine from /dev/rwd0c

  1. the main disk (/dev/rwd0) so I can get its table
  2. which partition of the main disk corresponds to /dev/rwd0c
  
On my disk which does not have a FreeBSD slice, the program returns:

/dev/rwd2
a: 0
b: 0
c: 4124736
d: 0
e: 0
f: 0
g: 0
h: 0

/dev/rwd2c
a: 0
b: 0
c: 4124736
d: 0
e: 0
f: 0
g: 0
h: 0

Which is helpful if I assume that c: on /dev/rwd2c is the whole
disk, but given your counter example above I am not enclined to do that.

Any hints you could give me would be much appreciated.

Also, why shouldn't lseek work on a device?  Is this something
we would like FreeBSD to do, or is the current undefined behavior
what we want?  Given that this would solve my problem I would consider
making a patch if there was some expectation that it would be accepted.

Thanx again,
john


On Sat, Jan 23, 1999 at 01:19:07AM +0200, Robert Nordier wrote:
> 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

-- 
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?19990126140251.G19158>