Subject: finding the "raw" partition on portable disks
To: None <tech-kern@netbsd.org>
From: David Young <dyoung@pobox.com>
List: tech-kern
Date: 04/18/2007 15:51:13
I am working to support portability of disks from one architecture to
another---for example, i386 to evbmips.
Here is a routine that I wrote to hunt a disk's partition table for the
"raw" partition. The routine prefers the architecture's raw partition
(RAW_PART'th partition) but, allowing for the possibility that the
RAW_PART'th partition does not span the disk, searches for a partition
that does. What do you think, do I select the raw partition using the
right criteria?
/* Search for the raw partition. Prefer the architecture's
* raw partition (RAW_PART), but if it does not span the entire
* disk, choose the first unused (FS_UNUSED) partition that does,
* or else choose the first partition that spans the disk.
*/
static int
dkwedge_compute_rawpart(const struct disk *pdk)
{
int i;
const struct disklabel *d;
const struct partition *p;
d = pdk->dk_label;
if (RAW_PART < d->d_npartitions) {
p = &d->d_partitions[RAW_PART];
if (p->p_offset == 0 && p->p_size == d->d_secperunit)
return RAW_PART;
}
for (i = 0; i < d->d_npartitions; i++) {
p = &d->d_partitions[i];
if (p->p_offset == 0 && p->p_size == d->d_secperunit &&
p->p_fstype == FS_UNUSED)
return i;
}
for (i = 0; i < d->d_npartitions; i++) {
p = &d->d_partitions[i];
if (p->p_offset == 0 && p->p_size == d->d_secperunit)
return i;
}
return -1;
}
Dave
--
David Young OJC Technologies
dyoung@ojctech.com Urbana, IL * (217) 278-3933