NetBSD-Bugs archive

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

bin/60947: makefs(8) -t ffs -o version=2 creates superblock at SBLOCK_UFS1



>Number:         60947
>Category:       bin
>Synopsis:       makefs(8) -t ffs -o version=2 creates superblock at SBLOCK_UFS1
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Oct 31 16:00:01 +0000 2026
>Originator:     Izumi Tsutsui
>Release:        NetBSD 11.0
>Organization:
>Environment:
System: NetBSD mirage 11.0 NetBSD 11.0 (GENERIC)
Architecture: all
Machine: all

>Description:
I think FFSv2 requires superblocks allocated at SBLOCK_UFS2 (65536),
but current makefs(8) creates superblock for UFS2 at SBLOCK_UFS1 (8192).

It looks intentional per XXX comment:

 https://nxr.netbsd.org/xref/src/usr.sbin/makefs/ffs/mkfs.c?r=1.43#305
```
    305 #if 0 /* XXX makefs is used for small filesystems. */
    306 		sblock.fs_sblockloc = SBLOCK_UFS2;
    307 #else
    308 		sblock.fs_sblockloc = SBLOCK_UFS1;
    309 #endif
```

However I'm afraid this could be problematic because:

- FFSv2 created by makefs(8) is different from ones by newfs(8)
- No options to create FFSv2 as newfs(8) (superblock at SBLOCK_UFS2)
- In future MD developers would assume FFSv2 always reserves 32KB for
  bootloaders?

It looks kernel, and libsa/ffs.c check SBLOCK_UFS2 and then
SBLOCK_UFS1 (via SBLOCKSEARCH etc.) even for FFSv2, though.

>How-To-Repeat:

```
% cd /tmp
% mkdir test
% makefs -t ffs -o version=2 -m 1m -M 1m test.fs test
 [...]
% hexdump -Cv test.fs
 :
00002550  00 00 00 00 00 00 00 00  00 00 00 00 38 20 01 19  |............8 ..|
 :
```

Note makefs(8) always UFS2ea for version=2 as filed in PR/60938:
 https://mail-index.netbsd.org/netbsd-bugs/2026/10/29/msg096098.html
so magic is FS_UFS2EA_MAGIC (0x19012038), not FS_UFS2_MAGIC (0x19540119).


I'm not sure if it's safe to create FFSv2 with bsize=65536
because the first superblock backup is allocated at SBLOCK_UFS2:

```
% makefs -t ffs -o version=2,bsize=65536,fsize=8192 -m 1m -M 1m test.fs test
Calculated size of `test.fs': 1048576 bytes, 2 inodes
Extent size set to 65536
test.fs: 1.0MB (2048 sectors) block size 65536, fragment size 8192
        using 1 cylinder groups of 1.00MB, 16 blks, 256 inodes.
super-block backups (for fsck -b #) at:
 128,
Populating `test.fs'
Image `test.fs' complete
% hexdump -Cv test.fs | grep ' 38 20 01 19 '
00002550  00 00 00 00 00 00 00 00  00 00 00 00 38 20 01 19  |............8 ..|
00010550  00 00 00 00 00 00 00 00  00 00 00 00 38 20 01 19  |............8 ..|
% 
```

It looks fsck_ffs(8) checks SBLOCK_UFS2 first, but doesn't check
fs_blockloc.

>Fix:
No idea. Check and clarify FFSv2 spec?
Add an option to select the superblock position for FFSv2?

---
Izumi Tsutsui




Home | Main Index | Thread Index | Old Index