Subject: Re: Supporting sector size != DEV_BSIZE (fwd)
To: Trevin Beattie <trevin@xmission.com>
From: Christian Limpach <chris@Pin.LU>
List: tech-kern
Date: 06/12/2002 13:03:52
> I just happened to have a MO disk lying around that I had created using
> NeXTSTEP 3.0/68k, so I decided to dump the first few sectors and see what
> it looks like.  The first thing I found is that NeXT's disk label is at
the
> beginning of the disk (sector 0 byte 0), and the super-block starts at
> sector 3 (byte offset 0x1800).

hmm, that's weird since NeXT disklabel are (defined to be) 8192 bytes long.

>  I've confirmed that NeXTSTEP sets
> fs_fsbtodb and fs_nspf in terms of physical sector size / fragment size,
so
> my recent patches do the right thing in that respect.

fs_fsbtodb is set in terms of disklabel sector size / fragment size and
NeXTSTEP tends to having disklabels where the physical sector size is not
equal to the disklabel sector size since the default disklabel sector size
is 1024 byte while most disks have a 512 byte sector size.

> One thing that concerns me is that NetBSD's ffs expects the super-block to
> be at byte offset 0x2000, and I can't figure out where or if we look
> differently when reading a NeXT file system.  Has anybody been able to
> mount a NeXT/68k disk under NetBSD?

I've done some tests on a disk with 512 byte physical sector size, disklabel
sector size set to 512 and 1024 and disklabel code in netbsd which on the
fly converts disklabels to have sector size == physical sector size.  The
results are the same after adjusting fs_fsbtodb (from 0 to 1) on the
filesystem from the test with the 1024 byte disklabel sector size.  It's
possible to mount the partition, it's possible to read the files in the root
directory, subdirectories don't work.  See below for a logfile...

>  Also, if anyone has a 512-byte/sector
> disk formatted by NeXT/68k, I'd like to know whether the super-block in
> that case is also on sector 3 or at byte offset 0x1800.

The superblock is at 0x2000.

You can grab the two disk images (10MB, gzipped to about 85KB each) at:
ftp://lola.pin.lu:21/pub/NetBSD/test/
The partition starts at 0x28000 (i.e. sector 320 w/ 512 bytes/sector, sector
160 w/ 1024 byte/sector)

    christian

[not sure about the weird file dates...  my clock keeps resetting...  I
didn't check what the clock was under NeXTSTEP...]
quant512:\
        :ty=fixed_rw_scsi:nc#121:nt#4:ns#42:ss#512:rm#3600:\
        :fp#320:bp#0:ng#0:gs#0:ga#0:ao#0:\
        :os=sdmach:z0#64:z1#192:r0=a:\
        :pa#0:sa#20008:ba#8192:fa#1024:ca#32:da#4096:ra#10:oa=time:\
        :ia:ta=4.3BSD:

[nextstep]
clapper# /usr/etc/disk -i -t quant512 /dev/rsd0h
disk name: quant512
disk type: fixed_rw_scsi
writing disk label
Writing /usr/standalone/boot
creating new filesystem on /dev/rsd0a
/usr/etc/newfs -n -v /dev/rsd0a
/etc/mkfs /dev/rsd0a 20008 42 4 8192 1024 32 10 60 4096 t
Warning: 152 sector(s) in last cylinder unallocated
/dev/rsd0a:     20008 sectors in 120 cylinders of 4 tracks, 42 sectors
        10.2Mb in 4 cyl groups (32 c/g, 2.75Mb/g, 576 i/g)
super-block backups (for fsck -b#) at:
 32, 5456, 10880, 16304,
initialization complete

[netbsd]
# disklabel sd0
# /dev/rsd0c:
type: SCSI
disk: quant512
label: Disk
flags:
bytes/sector: 512
sectors/track: 42
tracks/cylinder: 4
sectors/cylinder: 168
cylinders: 121
total sectors: 205561
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # microseconds
track-to-track seek: 0  # microseconds
drivedata: 0

3 partitions:
#        size    offset     fstype  [fsize bsize cpg/sgs]
 a:     20008       320    unknown                      # (Cyl.    1*- 120)
 c:    205561         0     unused      0     0         # (Cyl.    0 -
1223*)


# mount -t ffs /dev/sd0a /mnt
mount_ffs: /dev/sd0a on /mnt: Read-only file system
# mount -ordonly -t ffs /dev/sd0a /mnt
# cd /mnt
# ls
lost+found rc.conf    services   test       weekly
# ls -l
First bad, reclen=3a0, DIRSIZ=16, namlen=4, flags=1001 entryoffsetinblock=96
/mnt: bad dir ino 2 at offset 96: mangled entry
/mnt: bad dir ino 2 at offset 512: mangled entry
ls: test: No such file or directory
total 22
drwxr-xr-x  2 root  wheel   8192 Jun 12  1970 lost+found
-rw-r--r--  1 root  wheel    515 Jun 12  1970 rc.conf
-rw-r--r--  1 root  wheel  10683 Jun 12  1970 services
-rw-r--r--  1 root  wheel   1954 Jun 12  1970 weekly
# cat rc.conf
#       $NetBSD: rc.conf,v 1.96 2000/10/14 17:01:29 wiz Exp $
#
[works...]
# cd test
ksh: cd: /mnt/test - No such file or directory
#

# dumpfs /dev/sd0a | less
file system: /dev/sd0a
endian  big-endian
magic   11954   time    Fri Jun 12 10:59:38 1970
id      [ 0 0 ]
cylgrp  static  inodes  4.2/4.3BSD      fslevel 0       softdep disabled
nbfree  1198    ndir    3       nifree  2293    nffree  13
ncg     4       ncyl    120     size    10004   blocks  9635
bsize   8192    shift   13      mask    0xffffe000
fsize   1024    shift   10      mask    0xfffffc00
frag    8       shift   3       fsbtodb 1
cpg     32      bpg     336     fpg     2688    ipg     576
minfree 10%     optim   time    maxcontig 1     maxbpg  256
rotdelay 4ms    rps     60
ntrak   4       nsect   42      npsect  0       spc     168
symlinklen -1   trackskew 0     interleave 0    contigsumsize -1
maxfilesize 0xffffffffffffffff
nindir  2048    inopb   64      nspf    2
avgfilesize -1  avgfpdir -1
sblkno  16      cblkno  24      iblkno  32      dblkno  104
sbsize  2048    cgsize  2048    offset  24      mask    0xfffffffc
csaddr  104     cssize  1024    shift   9       mask    0xfffffe00
cgrotor 0       fmod    0       ronly   0       clean   0x01
blocks available in each of 8 rotational positions
cylinder number 0:
   position 0:      0    8
   position 1:      3
   position 2:      6
   position 3:      1    9
   position 4:      4
   position 5:      7
   position 6:      2   10
   position 7:      5
cylinder number 1:
   position 0:     16


quant1024:\
        :ty=fixed_rw_scsi:nc#121:nt#4:ns#42:ss#1024:rm#3600:\
        :fp#160:bp#0:ng#0:gs#0:ga#0:ao#0:\
        :os=sdmach:z0#32:z1#96:r0=a:\
        :pa#0:sa#10004:ba#8192:fa#1024:ca#32:da#4096:ra#10:oa=time:\
        :ia:ta=4.3BSD:

[nextstep]
clapper# /usr/etc/disk -i -t quant1024 /dev/rsd0h
disk name: quant1024
disk type: fixed_rw_scsi
writing disk label
Writing /usr/standalone/boot
creating new filesystem on /dev/rsd0a
/usr/etc/newfs -n -v /dev/rsd0a
/etc/mkfs /dev/rsd0a 10004 42 4 8192 1024 32 10 60 4096 t
Warning: 76 sector(s) in last cylinder unallocated
/dev/rsd0a:     10004 sectors in 60 cylinders of 4 tracks, 42 sectors
        10.2Mb in 2 cyl groups (32 c/g, 5.51Mb/g, 1216 i/g)
super-block backups (for fsck -b#) at:
 16, 5440,
initialization complete

[netbsd]
# disklabel sd0
# /dev/rsd0c:
type: SCSI
disk: quant1024
label: Disk
flags:
bytes/sector: 512
sectors/track: 42
tracks/cylinder: 4
sectors/cylinder: 168
cylinders: 121
total sectors: 205561
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # microseconds
track-to-track seek: 0  # microseconds
drivedata: 0

3 partitions:
#        size    offset     fstype  [fsize bsize cpg/sgs]
 a:     20008       320    unknown                      # (Cyl.    1*- 120)
 c:    205561         0     unused      0     0         # (Cyl.    0 -
1223*)
# mount -ordonly -t ffs /dev/sd0a /mnt
# cd /mnt
ksh: cd: /mnt - Not a directory
# umount /mnt

[set fsbtodb in superblock to 1]
# mount -ordonly -t ffs /dev/sd0a /mnt
# cd /mnt
# ls
lost+found rc.conf    services   test       weekly
# ls -l
First bad, reclen=3a0, DIRSIZ=16, namlen=4, flags=1001 entryoffsetinblock=96
/mnt: bad dir ino 2 at offset 96: mangled entry
/mnt: bad dir ino 2 at offset 512: mangled entry
ls: test: No such file or directory
total 11
drwxr-xr-x  2 root  wheel   8192 Jun 12  1970 lost+found
-rw-r--r--  1 root  wheel    515 Jun 12  1970 rc.conf
-rw-r--r--  1 root  wheel  10683 Jun 12  1970 services
-rw-r--r--  1 root  wheel   1954 Jun 12  1970 weekly
# cat rc.conf
#       $NetBSD: rc.conf,v 1.96 2000/10/14 17:01:29 wiz Exp $
#
[works...]
# cd test
ksh: cd: /mnt/test - No such file or directory
#

# dumpfs /dev/sd0a | less
file system: /dev/sd0a
endian  big-endian
magic   11954   time    Fri Jun 12 11:16:23 1970
id      [ 0 0 ]
cylgrp  static  inodes  4.2/4.3BSD      fslevel 0       softdep disabled
nbfree  1200    ndir    3       nifree  2421    nffree  13
ncg     2       ncyl    60      size    10004   blocks  9651
bsize   8192    shift   13      mask    0xffffe000
fsize   1024    shift   10      mask    0xfffffc00
frag    8       shift   3       fsbtodb 1
cpg     32      bpg     672     fpg     5376    ipg     1216
minfree 10%     optim   time    maxcontig 1     maxbpg  256
rotdelay 4ms    rps     60
ntrak   4       nsect   42      npsect  0       spc     168
symlinklen -1   trackskew 0     interleave 0    contigsumsize -1
maxfilesize 0xffffffffffffffff
nindir  2048    inopb   64      nspf    1
avgfilesize -1  avgfpdir -1
sblkno  16      cblkno  24      iblkno  32      dblkno  184
sbsize  2048    cgsize  2048    offset  48      mask    0xfffffffc
csaddr  184     cssize  1024    shift   9       mask    0xfffffe00
cgrotor 0       fmod    0       ronly   0       clean   0x01
blocks available in each of 8 rotational positions
cylinder number 0:
   position 0:      0   11   16
   position 1:      1    6   17
   position 2:      7   12
   position 3:      2   13   18
   position 4:      3    8   19
   position 5:      9   14
   position 6:      4   15   20
   position 7:      5   10
cs[].cs_(nbfree,ndir,nifree,nffree):
        (645,2,1209,8) (555,1,1212,5)