tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: disklabel(8) allows addressing non-existent space

> I just played a bit around with disklabel(8), trying to copy checks
> for batch-mode, but then I found out: There are virtually no checks
> checking the disklabel for consistency.

> I wonder: Are you aware of that, do you want this happening?

Speaking purely personally, yes and yes.  (It's also not quite true;
when I'm doing unusual things I regularly have disklabel warn me that
partitions overlap.)  This is a good example of not preventing stupid
things because that also prevents clever things.

> Mainly, there were two things I wondered about (examples are
> intuitive):

Um, you listed three things. :)

>  * you can edit the number of sectors to make the disklabel extend
>    the disk it is on, resulting in I/O errors when you try to address
>    that partition.

If, not when.  Even then, only if it's still on the same disk, and the
disk is still the same size (think vnd!), as when the label was

>  * you can edit partitions that extend the space that is in use by
>    the slice the disklabel is placed in, thus you could easily create
>    partitions overwriting other mbr partitions than the one you're
>    in.

Well, if you _have_ MBR partitions; not all ports do.  Yes, you can.
This is a feature.  In particular, it lets you access other OS's
filesystems in those other partitions.

>  * you can create overlapping partitions if you set their fs type to
>    unused.

Even if you don't, I should hope; I would call it a crippling bug if
you can't.  While it's hardly an everyday thing, I regularly (probably
at least a half-dozen times a year) create partitions that overlap in
various ways, deliberately.  The simplest case is probably when I have
a machine booted single-user and I want to copy from its / to another
disk; this makes me want to mount / RO somewhere other than /, for
which I usually create another partition co-extensive with /, as a
workaround for the system's refusing to let me mount the same partition
more than once even when all the mounts are RO.  I've used other forms
of overlap for various other special purposes, though that's less
frequent.  If I found a system where the disklabel equivalent didn't
let me do such things, I would call it an outright bug.  Warning is OK.
Even making me turn on an expert-mode switch of some sort, provided
it's not hard to find.  But preventing it outright is going too far.

> I cannot imagine a use case for creating invalid disklabels.

I can, barely - but your idea of "invalid" is, apparently,
substantially more inclusive than mine, and I have real uses for
disklabels you (appear to) consider invalid.

> Plus, one thing I wondered about: Is there a clean way to determine
> the "mother" partition (i.e. c or d)?

If you mean RAW_PART, the kern.rawpartition sysctl is what you want.
If you mean the equivalent of c on i386 ("the NetBSD MBR partition"),
it doesn't exist at all on many ports, so, no, there isn't.  If you
mean something else, then I think you'd need to explain in somewhat
more detail what you mean by `the "mother" partition'.

/~\ The ASCII                             Mouse
\ / Ribbon Campaign
 X  Against HTML      
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B

Home | Main Index | Thread Index | Old Index