Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Jan 2006 12:34:46 +0000
From:      Brian Candler <B.Candler@pobox.com>
To:        freebsd-stable@freebsd.org
Subject:   newfs_msdos onto an image file
Message-ID:  <20060115123445.GA14271@uk.tiscali.com>

next in thread | raw e-mail | index | archive | help
I am trying to prepare an MS-DOS disk image file (for later dd to a USB
device) but am having difficulties getting newfs_msdos to work in this way.
This is under 5.4-RELEASE.

Firstly, newfs_msdos seems to insist on a block-special device; it won't
talk to a disk file. OK, no problem, I'll fake it using an md device. I'll
make an image file exactly the right size for my USB device:

Jan 15 11:19:39 mappit kernel: umass0: EM102I Mp3 Player, rev 1.10/0.12, addr 2
Jan 15 11:19:41 mappit kernel: da0 at umass-sim0 bus 0 target 0 lun 0
Jan 15 11:19:41 mappit kernel: da0: <EM102I Mp3 Player FLASH v1.0> Removable Direct Access SCSI-0 device 
Jan 15 11:19:41 mappit kernel: da0: 1.000MB/s transfers
Jan 15 11:19:41 mappit kernel: da0: 125MB (256000 512 byte sectors: 64H 32S/T 125C)

Here we go:

# dd if=/dev/zero of=test.img bs=512 count=256000
256000+0 records in
256000+0 records out
131072000 bytes transferred in 6.334723 secs (20691039 bytes/sec)
# mdconfig -a -t vnode -f test.img
md0
# newfs_msdos -s 131072000 /dev/md0
newfs_msdos: Cannot get number of sectors, Operation not supported
# 

Hmm. Attempting to provide some suitable parameters don't seem to help:

# newfs_msdos -s 131072000 -S 512 -b 4096 -c 8 -u 256 /dev/md0 
newfs_msdos: Cannot get number of sectors, Operation not supported

OK, so let's try pretending it's a floppy disk:

# newfs_msdos -f 1440 -s 131072000 /dev/md0
newfs_msdos: warning: sectors/FAT limits file system to 3070 clusters
/dev/md0: 3070 sectors in 3070 FAT12 clusters (512 bytes/cluster)
bps=512 spc=1 res=1 nft=2 rde=224 mid=0xf0 spf=9 spt=18 hds=2 hid=0 bsec=131072000
# mount -t msdos /dev/md0 /mnt 
# df -k | grep md0
/dev/md0         1152       1     1151     0%    /mnt
# umount /dev/md0

That's not right - the filesystem has been sized for a 1440K floppy, even
though I said (using -s) that the disk size was larger than that.

So let's try overriding some parameters:

# newfs_msdos -f 1440 -s 131072000 -S 512 -b 4096 -c 8 -u 256 /dev/md0
newfs_msdos: warning: sectors/FAT limits file system to 3070 clusters
/dev/md0: 24560 sectors in 3070 FAT12 clusters (4096 bytes/cluster)
bps=512 spc=8 res=1 nft=2 rde=224 mid=0xf0 spf=9 spt=256 hds=2 hid=0 bsec=131072000
# mount -t msdos /dev/md0 /mnt
msdosfs: /dev/md0: Invalid argument

Ugh, that's not even recognised by the kernel as a DOS filesystem!

Anyway, it seems to be saying we're limited to 3070 clusters, and 3070 x 4K
is only 12MB which is too small for the disk image I have. So let's try
FAT16:

# newfs_msdos -F 16 -f 1440 -s 131072000 -S 512 -b 4096 -c 8 -u 256 /dev/md0
newfs_msdos: warning: sectors/FAT limits file system to 2302 clusters
newfs_msdos: 2302 clusters too few clusters for FAT16, need 4096

Nope, that fails completely. (Why? Given a cluster size of 4K, that
filesystem needs around 32,000 clusters)

Let's try fiddling with the sectors per FAT. I have no idea what to use, but
earlier examples had spf=9, so let's try 20 instead:

# newfs_msdos -a 20 -F 16 -f 1440 -s 131072000 -S 512 -b 4096 -c 8 -u 256 /dev/md0
newfs_msdos: warning: sectors/FAT limits file system to 5118 clusters
/dev/md0: 40944 sectors in 5118 FAT16 clusters (4096 bytes/cluster)
bps=512 spc=8 res=1 nft=2 rde=224 mid=0xf0 spf=20 spt=256 hds=2 hid=0 bsec=131072000

OK that's seems to be getting there. 20 sectors per FAT limits me to 5118
clusters, and I need about 32000, which implies spf=(32000/5118)*20 = 125.
For safety let's try 150:

# newfs_msdos -a 150 -F 16 -f 1440 -s 131072000 -S 512 -b 4096 -c 8 -u 256
/dev/md0
newfs_msdos: warning: sectors/FAT limits file system to 38398 clusters
/dev/md0: 307184 sectors in 38398 FAT16 clusters (4096 bytes/cluster)
bps=512 spc=8 res=1 nft=2 rde=224 mid=0xf0 spf=150 spt=256 hds=2 hid=0 bsec=131072000

Now that's a bit worrying. It's saying that my filesystem is 307184 sectors
large, when the underlying disk image is only 256000 sectors. In any case,
it still won't mount:

# mount -t msdos /dev/md0 /mnt
msdosfs: /dev/md0: Invalid argument

So - how should I go about creating an MS-DOS filesystem in this image file?

Thanks,

Brian.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060115123445.GA14271>