newfs_msdos(8) creates faulty filesystems

2013-10-21 Thread Kenneth R Westerback
While harmless it seesm pointless to create a filesystem that generates
warnings when fsck'd.

So check for -1 (an allowed value) in FSFree and FSNext fields, and
set FSNext to -1 in newfs_msdos, rather than setting it to a
value sure to be not a free cluster.

Anybody know of reasons to not do this?

 Ken

Index: fsck_msdos/fat.c
===
RCS file: /cvs/src/sbin/fsck_msdos/fat.c,v
retrieving revision 1.18
diff -u -p -r1.18 fat.c
--- fsck_msdos/fat.c27 Oct 2009 23:59:33 -  1.18
+++ fsck_msdos/fat.c21 Oct 2013 09:53:56 -
@@ -527,7 +527,7 @@ checklost(int dosfs, struct bootblock *b
 
if (boot->FSInfo) {
ret = 0;
-   if (boot->FSFree != boot->NumFree) {
+   if (boot->FSFree != -1 && boot->FSFree != boot->NumFree) {
pwarn("Free space in FSInfo block (%d) not correct 
(%d)\n",
  boot->FSFree, boot->NumFree);
if (ask(1, "fix")) {
@@ -535,7 +535,8 @@ checklost(int dosfs, struct bootblock *b
ret = 1;
}
}
-   if (boot->NumFree && fat[boot->FSNext].next != CLUST_FREE) {
+   if (boot->NumFree && boot->FSNext != -1 &&
+   fat[boot->FSNext].next != CLUST_FREE) {
pwarn("Next free cluster in FSInfo block (%u) not 
free\n",
  boot->FSNext);
if (ask(1, "fix"))
Index: newfs_msdos/newfs_msdos.c
===
RCS file: /cvs/src/sbin/newfs_msdos/newfs_msdos.c,v
retrieving revision 1.20
diff -u -p -r1.20 newfs_msdos.c
--- newfs_msdos/newfs_msdos.c   18 May 2010 04:41:14 -  1.20
+++ newfs_msdos/newfs_msdos.c   21 Oct 2013 09:48:48 -
@@ -626,7 +626,7 @@ main(int argc, char *argv[])
mk4(img, 0x41615252);
mk4(img + bpb.bps - 28, 0x61417272);
mk4(img + bpb.bps - 24, 0x);
-   mk4(img + bpb.bps - 20, bpb.rdcl);
+   mk4(img + bpb.bps - 20, 0x);
mk2(img + bpb.bps - 2, DOSMAGIC);
} else if (lsn >= bpb.res && lsn < dir &&
   !((lsn - bpb.res) %



Re: newfs_msdos(8) creates faulty filesystems

2013-10-20 Thread Kenneth Westerback
Neither field is required. 'Free Space' in fsinfo can be -1 or just wrong,
and 'Next Free Cluster' is a  hint only. Hence in either case you can fix
them up, or ignore their incorrectness and the filesystem is still
considered ok.

And since they are not required I guess newfs never bothered to fill them
out correctly.

 Ken






On Sun, Oct 20, 2013 at 2:13 PM, David Vasek  wrote:

> Hello,
>
> a filesystem created by newfs_msdos(8) is reported as faulty by
> fsck_msdos(8). And it is indeed. Repeatable. There must be something wrong.
> The media itself (a USB flash drive) doesn't have any issues.
>
> # newfs -t msdos /dev/rsd4i /dev/rsd4i: 31224352 sectors in 3903044 FAT32
> clusters (4096 bytes/cluster)
> bps=512 spc=8 res=32 nft=2 mid=0xf8 spt=63 hds=255 hid=8064 bsec=31285376
> bspf=30493 rdcl=2 infs=1 bkbs=2
>
> # fsck -n /dev/rsd4i
> ** /dev/rsd4i (NO WRITE)
> ** Phase 1 - Read and Compare FATs
> ** Phase 2 - Check Cluster Chains
> ** Phase 3 - Check Directories
> ** Phase 4 - Check for Lost Files
> Free space in FSInfo block (-1) not correct (3903043)
> fix? no
> Next free cluster in FSInfo block (2) not free
> fix? no
> 1 files, 3029260 free (3903043 clusters)
>
> # fsck /dev/rsd4i
> ** /dev/rsd4i
> ** Phase 1 - Read and Compare FATs
> ** Phase 2 - Check Cluster Chains
> ** Phase 3 - Check Directories
> ** Phase 4 - Check for Lost Files
> Free space in FSInfo block (-1) not correct (3903043)
> fix? [Fyn] y
> Next free cluster in FSInfo block (2) not free
> fix? [Fyn] y
> 1 files, 3029260 free (3903043 clusters)
>
> # fsck /dev/rsd4i ** /dev/rsd4i
> ** Phase 1 - Read and Compare FATs
> ** Phase 2 - Check Cluster Chains
> ** Phase 3 - Check Directories
> ** Phase 4 - Check for Lost Files
> 1 files, 3029260 free (3903043 clusters)
>
>
> OpenBSD 5.3 (GENERIC.MP) #53: Fri Mar  1 09:34:37 MST 2013
> 
> dera...@i386.openbsd.org:/usr/**src/sys/arch/i386/compile/GENE**RIC.MP
>
> umass1 at uhub0 port 4 configuration 1 interface 0 "Kingston DT 101 G2"
> rev 2.00/1.00 addr 3
> umass1: using SCSI over Bulk-Only
> scsibus4 at umass1: 2 targets, initiator 0
> sd4 at scsibus4 targ 1 lun 0:  SCSI0 0/direct
> removable serial.09511642BC81D71A0189
> sd4: 15280MB, 512 bytes/sector, 31293440 sectors
>
> # fdisk sd4
> Disk: sd4   geometry: 1947/255/63 [31293440 Sectors]
> Offset: 0   Signature: 0xAA55
> Starting Ending LBA Info:
>  #: id  C   H   S -  C   H   S [   start:size ]
> --**--**
> ---
> *0: 0C  0 128   1 -   1947 236  17 [8064:31285376 ] Win95
> FAT32L
>  1: 00  0   0   0 -  0   0   0 [   0:   0 ] unused
>  2: 00  0   0   0 -  0   0   0 [   0:   0 ] unused
>  3: 00  0   0   0 -  0   0   0 [   0:   0 ] unused
>
> # disklabel sd4
> # /dev/rsd4c:
> type: SCSI
> disk: SCSI disk
> label: DT 101 G2 duid: 
> flags:
> bytes/sector: 512
> sectors/track: 63
> tracks/cylinder: 255
> sectors/cylinder: 16065
> cylinders: 1947
> total sectors: 31293440
> boundstart: 0
> boundend: 31293440
> drivedata: 0
>
> 16 partitions:
> #size   offset  fstype [fsize bsize  cpg]
>   c: 312934400  unused
>   i: 31285376 8064   MSDOS
>
> Regards,
> David



newfs_msdos(8) creates faulty filesystems

2013-10-20 Thread David Vasek

Hello,

a filesystem created by newfs_msdos(8) is reported as faulty by 
fsck_msdos(8). And it is indeed. Repeatable. There must be something 
wrong. The media itself (a USB flash drive) doesn't have any issues.


# newfs -t msdos /dev/rsd4i 
/dev/rsd4i: 31224352 sectors in 3903044 FAT32 clusters (4096 bytes/cluster)

bps=512 spc=8 res=32 nft=2 mid=0xf8 spt=63 hds=255 hid=8064 bsec=31285376 
bspf=30493 rdcl=2 infs=1 bkbs=2

# fsck -n /dev/rsd4i
** /dev/rsd4i (NO WRITE)
** Phase 1 - Read and Compare FATs
** Phase 2 - Check Cluster Chains
** Phase 3 - Check Directories
** Phase 4 - Check for Lost Files
Free space in FSInfo block (-1) not correct (3903043)
fix? no
Next free cluster in FSInfo block (2) not free
fix? no
1 files, 3029260 free (3903043 clusters)

# fsck /dev/rsd4i
** /dev/rsd4i
** Phase 1 - Read and Compare FATs
** Phase 2 - Check Cluster Chains
** Phase 3 - Check Directories
** Phase 4 - Check for Lost Files
Free space in FSInfo block (-1) not correct (3903043)
fix? [Fyn] y
Next free cluster in FSInfo block (2) not free
fix? [Fyn] y
1 files, 3029260 free (3903043 clusters)

# fsck /dev/rsd4i 
** /dev/rsd4i

** Phase 1 - Read and Compare FATs
** Phase 2 - Check Cluster Chains
** Phase 3 - Check Directories
** Phase 4 - Check for Lost Files
1 files, 3029260 free (3903043 clusters)


OpenBSD 5.3 (GENERIC.MP) #53: Fri Mar  1 09:34:37 MST 2013
dera...@i386.openbsd.org:/usr/src/sys/arch/i386/compile/GENERIC.MP

umass1 at uhub0 port 4 configuration 1 interface 0 "Kingston DT 101 G2" rev 
2.00/1.00 addr 3
umass1: using SCSI over Bulk-Only
scsibus4 at umass1: 2 targets, initiator 0
sd4 at scsibus4 targ 1 lun 0:  SCSI0 0/direct 
removable serial.09511642BC81D71A0189
sd4: 15280MB, 512 bytes/sector, 31293440 sectors

# fdisk sd4
Disk: sd4   geometry: 1947/255/63 [31293440 Sectors]
Offset: 0   Signature: 0xAA55
Starting Ending LBA Info:
 #: id  C   H   S -  C   H   S [   start:size ]
---
*0: 0C  0 128   1 -   1947 236  17 [8064:31285376 ] Win95 FAT32L
 1: 00  0   0   0 -  0   0   0 [   0:   0 ] unused
 2: 00  0   0   0 -  0   0   0 [   0:   0 ] unused
 3: 00  0   0   0 -  0   0   0 [   0:   0 ] unused

# disklabel sd4
# /dev/rsd4c:
type: SCSI
disk: SCSI disk
label: DT 101 G2 
duid: 

flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 255
sectors/cylinder: 16065
cylinders: 1947
total sectors: 31293440
boundstart: 0
boundend: 31293440
drivedata: 0

16 partitions:
#size   offset  fstype [fsize bsize  cpg]
  c: 312934400  unused
  i: 31285376 8064   MSDOS

Regards,
David