Subject: Disklabel and non 512-byte media
To: None <tech-kern@netbsd.org>
From: Steve Woodford <scw@netbsd.org>
List: tech-kern
Date: 10/13/2006 23:05:44
Hi,

I've noticed an interesting oddity with disklabels on media with 
physical sector size != DEV_BSIZE. Here's one I prepared earlier based 
on a Samsung YP-U2 USB MP3 player:

sd0 at scsibus0 target 0 lun 0: <Samsung, YP-U2, 0100> disk removable
sd0: fabricating a geometry
sd0: 999 MB, 249 cyl, 64 head, 32 sec, 2048 bytes/sect x 511616 sectors

# disklabel sd0
...
bytes/sector: 2048
...
5 partitions:
#        size  offset   fstype [fsize bsize cpg/sgs]
 d:   2046464       0   unused      0     0        # (Cyl. 0 - 999+)
 e:    511560      56    MSDOS                     # (Cyl. 0*- 249*)

Note that the size and offset fields for partition 'e' are specified in 
terms of the physical sector size, namely 2048 bytes. Yet the raw 
partition is specified in 512 byte sectors.

The reason for this is the 'e' partition's vital statistics are copied 
straight from the MBR, whereas the raw partition's details are set in 
sdgetdefaultlabel() after conversion to the DEV_BSIZE equivalent.

Right now I have MSDOSFS working on 2048 bytes/sector media based on the 
patch in kern/17398, with an additional tweak to 
bounds_check_with_label() to account for the disklabel discrepancy.

The alternative is to ensure disklabels are always specified in 
DEV_BSIZE units (at least until we ditch fixed DEV_BSIZE).

I prefer the former aproach but I'd be interested in hearing others' 
views.

Cheers, Steve