Date: Wed, 27 Jan 1999 14:19:59 +0200 (SAT) From: Robert Nordier <rnordier@nordier.com> To: jplevyak@inktomi.com (John Plevyak) Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: raw devices and disk geometry Message-ID: <199901271220.OAA22838@ceia.nordier.com> In-Reply-To: <19990126140251.G19158@proxydev.inktomi.com> from John Plevyak at "Jan 26, 99 02:02:51 pm"
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.
The info I gave was correct, but different terminology and a different
set of assumptions are probably getting in the way.
I think you need to look at the code of an actual utility that does
this stuff, and that you can also try out. I'd suggest newfs_msdos(8),
which will allow you to specify any of
o the whole physical disk
o a slice (what DOS calls a partition)
o a partition (what BSD calls a partition)
as a target device, and will print out the size, disk geometry, etc.
(see the function getdiskinfo in src/sbin/newfs_msdos/newfs_msdos.c).
You could also look at /usr/share/doc/tutorials/diskformat and
fdisk(8), disklabel(5), disktab(5), and disklabel(8).
> 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.
You can't expect lseek(fd, 0, SEEK_END) to work as you expect unless
the file descriptor is associated with a regular file. For other file
types, file size information is not available at that level. "It's
a UNIX thing," and there's no patching it now. Size information
usually is available -- in the FreeBSD case, via ioctl -- but not very
portably across UNIX-like systems.
>
> 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?199901271220.OAA22838>
