NetBSD-Bugs archive

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

toolchain/42574: makefs(8) should not refer DEV_BSIZE in src/tools



>Number:         42574
>Category:       toolchain
>Synopsis:       makefs(8) should not refer DEV_BSIZE in src/tools
>Confidential:   no
>Severity:       critical
>Priority:       low
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jan 03 18:05:00 +0000 2010
>Originator:     Izumi Tsutsui
>Release:        NetBSD 5.99.23
>Organization:
>Environment:
Build System: CYGWIN_NT-5.1-1.7.1 on Windows XP SP3
Architecture: i686
Machine: i386 (32bit)

Target System: NetBSD 5.99.23 updated around 20100103
Architecture: sparc 
Machine: sparc

>Description:
src/usr.sbin/makefs/ffs/ffs_alloc.c refer DEV_BSIZE
to calculate a number of disk block for an allocated size,
but DEV_BSIZE is not always a value for a target NetBSD system
but a value for host's environment.

Actually DEV_BSIZE is 1024 on Cygwin-1.7.1 so cross makefs(8)
on Cygwin creates corrupted file system.

>How-To-Repeat:
Code inspection.

Or "build.sh -U -m sparc release" on Cygwin-1.7.1,
and boot created netbsd.ram ramdisk kernel.
You'll get:
---
root on md0a dumps on md0b
root file system type: ffs
/: bad dir ino 6 at offset 512: mangled entry
panic: bad dir
---

"fsck_ffs -f /dev/md0a" in that kernel reports as following:

---
# fsck_ffs -f /dev/md0a
** /dev/rmd0a
DIOCGDINFO on /dev/rmd0a failed
** File system is already clean
** Last Mounted on /mnt
** Phase 1 - Check Blocks and Sizes
INCORRECT BLOCK COUNT I=2 (1 should be 2)
CORRECT? [yn] n

INCORRECT BLOCK COUNT I=3 (5 should be 11)
CORRECT? [yn] n

INCORRECT BLOCK COUNT I=4 (1 should be 2)
CORRECT? [yn] n

INCORRECT BLOCK COUNT I=5 (1 should be 2)
CORRECT? [yn] n

INCORRECT BLOCK COUNT I=6 (5 should be 10)
CORRECT? [yn] n

INCORRECT BLOCK COUNT I=7 (1 should be 2)
CORRECT? [yn] n

 :
---
i.e. all inode block counts are wrong (half of the actual count).

>Fix:
Use a disk block size calculated from fs->fs_fsize and fs->fs_fsbtodb
instead of hard coded DEV_BSIZE constant.

Note makefs(8) also needs a patch attached in PR kern/42573
for DIRBLKSIZ which also (ab)uses DEV_BSIZE.

Index: ffs/ffs_alloc.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/makefs/ffs/ffs_alloc.c,v
retrieving revision 1.17
diff -u -r1.17 ffs_alloc.c
--- ffs/ffs_alloc.c     18 Dec 2006 21:03:29 -0000      1.17
+++ ffs/ffs_alloc.c     3 Jan 2010 16:46:40 -0000
@@ -120,7 +120,8 @@
                cg = dtog(fs, bpref);
        bno = ffs_hashalloc(ip, cg, bpref, size, ffs_alloccg);
        if (bno > 0) {
-               DIP_ADD(ip, blocks, size / DEV_BSIZE);
+               DIP_ADD(ip, blocks,
+                   fsbtodb(fs, howmany(size, fs->fs_fsize)));
                *bnp = bno;
                return (0);
        }


(I'm not sure if the original code should also have used howmany() or not)

Note src/sys/ufs/ffs/ffs_alloc.c uses btodb() there (and more places).
btodb() in <sys/param.h> also use DEV_BSHIFT so
it could be problematic on disk which has sectorsize != 512.
(needs another PR?)
---



Home | Main Index | Thread Index | Old Index