NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: kern/59924: NetBSD improperly does not update FAT0 on FAT12 MSDOS filesystem
The following reply was made to PR kern/59924; it has been noted by GNATS.
From: Michael Cheponis <michael.cheponis%gmail.com@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: kern-bug-people%netbsd.org@localhost, gnats-admin%netbsd.org@localhost, netbsd-bugs%netbsd.org@localhost,
mac%culver.net@localhost
Subject: Re: kern/59924: NetBSD improperly does not update FAT0 on FAT12 MSDOS filesystem
Date: Sun, 18 Jan 2026 21:13:06 -0800
--0000000000003053970648b6c112
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
I have figured out how to succeed with my use case, which is, indeed, to
use the raw floppy (via e.g. /dev/rsd3a).
And, if one does 'mount_msdos /dev/rsd3a /a[' and then 'disklabel -W sd3a'
then... standard reads / writes to files, deletion, creation, all work
properly.
The PROBLEM, as I see it, is: mount_mdsos needs to, effectively, ALSO do
"disklabel -W <disk>" because otherwise, other parts of the kernel protect
some sectors on cylinder 0 (prevent writes to it) because on other
filesystem types, that's the superblock etc. In the case of MS-DOS,
however, you must keep the two FATs synchronized (they are both in cylinder
0 on an actual 1.44 floppy). FAT 0 is not updated unless 'disklabel -W
<disk>' is performed first.
I created two small shell scripts
msmount:
echo example: msmount sd3a a
# this takes -x bit off msdos files
mount_msdos -m 0644 -M 0755 /dev/$1 /$2
disklabel -W $1
and the corresponding 'msumount' :
echo 'example: msumount sd3a a'
umount /$2
disklabel -N $1
This fixes the problem.
Thanks everybody,
Mike
On Sun, Jan 18, 2026 at 1:45=E2=80=AFAM Michael van Elst via gnats <
gnats-admin%netbsd.org@localhost> wrote:
> The following reply was made to PR kern/59924; it has been noted by GNATS=
.
>
> From: mlelstv%serpens.de@localhost (Michael van Elst)
> To: gnats-bugs%netbsd.org@localhost
> Cc:
> Subject: Re: kern/59924: NetBSD improperly does not update FAT0 on FAT12
> MSDOS filesystem
> Date: Sun, 18 Jan 2026 09:39:54 -0000 (UTC)
>
> gnats-admin%NetBSD.org@localhost ("RVP via gnats") writes:
>
> > So, there's only 1 reserved sector, and FAT starts at byte 512. Looks
> like
> > A.I. might be right after all. :)
> >
> > However, I think that since floppies don't have a MBR, you're supposed
> to
> > use the whole-disk device for mounting them.
>
>
> If you access a partition (but not the raw partition) then the
> "label sector" (=3D=3D the partition table) is protected and writes
> are blocked with an EROFS error. That allows either partitions
> beyond the label sector or safe filesystems like FFS on a "whole disk"
> that don't touch the label sector.
>
>
> Unfortunately, write errors of a filesystem are hidden as they
> occur asynchronously to the program doing the write. You may see
> kernel messages on the console or logged in /var/log/messages. Only
> direct accesses to the device (e.g. newfs writing to /dev/rvnd0a)
> would see the error, but in the example newfs was used together
> with the raw partition.
>
> So, for a floppy image on a disk device, you need to use the raw
> partition.
>
>
>
> But it is slightly more complicated :)
>
> The driver for a physical floppy (i.e. not some USB stick where you
> want to write a floppy image to but the real vintage thing) abuses
> the label.
>
> The different partitions are used to select different floppy formats,
> e.g. b is a 1.44MB 3.5" disk, c is a 1.2MB 5.25" disk. You must
> use the correct partition for the medium and even the 'raw' partition
> is abused.
>
> To make this work, the floppy driver has its own private routine
> to check write boundaries, and that one just ignores the label
> sector.
>
> Writing to a physical floppy therefore doesn't have such problems.
>
>
--0000000000003053970648b6c112
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-family:arial,he=
lvetica,sans-serif;font-size:small">I have figured out how to succeed with =
my use case, which is, indeed, to use the raw floppy (via e.g. /dev/rsd3a).=
=C2=A0=C2=A0</div><div class=3D"gmail_default" style=3D"font-family:arial,h=
elvetica,sans-serif;font-size:small"><br></div><div class=3D"gmail_default"=
style=3D"font-family:arial,helvetica,sans-serif;font-size:small">And, if o=
ne does 'mount_msdos /dev/rsd3a /a[' and then 'disklabel -W sd3=
a'=C2=A0 =C2=A0 then... standard reads / writes to files, deletion, cre=
ation, all work properly.</div><div class=3D"gmail_default" style=3D"font-f=
amily:arial,helvetica,sans-serif;font-size:small"><br></div><div class=3D"g=
mail_default" style=3D"font-family:arial,helvetica,sans-serif;font-size:sma=
ll">The PROBLEM, as I see it, is: mount_mdsos needs to, effectively, ALSO d=
o "disklabel -W <disk>" because otherwise, other parts of t=
he kernel protect some sectors on cylinder 0 (prevent writes to it) because=
on other filesystem types, that's the superblock etc.=C2=A0 In the cas=
e of MS-DOS, however, you must keep the two FATs synchronized (they are bot=
h in cylinder 0 on an actual 1.44 floppy).=C2=A0 FAT 0 is not updated unles=
s 'disklabel -W <disk>' is performed first.</div><div class=
=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-serif;font-siz=
e:small"><br></div><div class=3D"gmail_default" style=3D"font-family:arial,=
helvetica,sans-serif;font-size:small">I created two small shell scripts</di=
v><div class=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-se=
rif;font-size:small"><br></div><div class=3D"gmail_default" style=3D"font-f=
amily:arial,helvetica,sans-serif;font-size:small">msmount:</div><div class=
=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-serif;font-siz=
e:small"><br></div><div class=3D"gmail_default" style=3D"font-size:small"><=
font face=3D"monospace">echo example: msmount sd3a a<br># this takes -x bit=
off msdos files<br>mount_msdos -m 0644 -M 0755 /dev/$1 /$2<br>disklabel -W=
$1</font></div><div class=3D"gmail_default" style=3D"font-family:arial,hel=
vetica,sans-serif;font-size:small"><br></div><div class=3D"gmail_default" s=
tyle=3D"font-family:arial,helvetica,sans-serif;font-size:small">and the cor=
responding 'msumount' :</div><div class=3D"gmail_default" style=3D"=
font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div clas=
s=3D"gmail_default" style=3D"font-size:small"><font face=3D"monospace">echo=
'example: msumount =C2=A0sd3a a'<br>umount /$2<br>disklabel -N $1<=
/font><br></div><div class=3D"gmail_default" style=3D"font-family:arial,hel=
vetica,sans-serif;font-size:small"><br></div><div class=3D"gmail_default" s=
tyle=3D"font-family:arial,helvetica,sans-serif;font-size:small">This fixes =
the problem.</div><div class=3D"gmail_default" style=3D"font-family:arial,h=
elvetica,sans-serif;font-size:small"><br></div><div class=3D"gmail_default"=
style=3D"font-family:arial,helvetica,sans-serif;font-size:small">Thanks ev=
erybody,</div><div class=3D"gmail_default" style=3D"font-family:arial,helve=
tica,sans-serif;font-size:small">Mike</div><div class=3D"gmail_default" sty=
le=3D"font-family:arial,helvetica,sans-serif;font-size:small"><br></div><di=
v class=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-serif;f=
ont-size:small"><br></div></div><br><div class=3D"gmail_quote gmail_quote_c=
ontainer"><div dir=3D"ltr" class=3D"gmail_attr">On Sun, Jan 18, 2026 at 1:4=
5=E2=80=AFAM Michael van Elst via gnats <<a href=3D"mailto:gnats-admin@n=
etbsd.org">gnats-admin%netbsd.org@localhost</a>> wrote:<br></div><blockquote class=
=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rg=
b(204,204,204);padding-left:1ex">The following reply was made to PR kern/59=
924; it has been noted by GNATS.<br>
<br>
From: <a href=3D"mailto:mlelstv%serpens.de@localhost" target=3D"_blank">mlelstv@serpe=
ns.de</a> (Michael van Elst)<br>
To: <a href=3D"mailto:gnats-bugs%netbsd.org@localhost" target=3D"_blank">gnats-bugs@n=
etbsd.org</a><br>
Cc: <br>
Subject: Re: kern/59924: NetBSD improperly does not update FAT0 on FAT12 MS=
DOS filesystem<br>
Date: Sun, 18 Jan 2026 09:39:54 -0000 (UTC)<br>
<br>
=C2=A0gnats-admin%NetBSD.org@localhost ("RVP via gnats") writes:<br>
<br>
=C2=A0> So, there's only 1 reserved sector, and FAT starts at byte 5=
12. Looks like<br>
=C2=A0> A.I. might be right after all. :)<br>
=C2=A0> <br>
=C2=A0> However, I think that since floppies don't have a MBR, you&#=
39;re supposed to<br>
=C2=A0> use the whole-disk device for mounting them.<br>
<br>
<br>
=C2=A0If you access a partition (but not the raw partition) then the<br>
=C2=A0"label sector" (=3D=3D the partition table) is protected an=
d writes<br>
=C2=A0are blocked with an EROFS error. That allows either partitions<br>
=C2=A0beyond the label sector or safe filesystems like FFS on a "whole=
disk"<br>
=C2=A0that don't touch the label sector.<br>
<br>
<br>
=C2=A0Unfortunately, write errors of a filesystem are hidden as they<br>
=C2=A0occur asynchronously to the program doing the write. You may see<br>
=C2=A0kernel messages on the console or logged in /var/log/messages. Only<b=
r>
=C2=A0direct accesses to the device (e.g. newfs writing to /dev/rvnd0a)<br>
=C2=A0would see the error, but in the example newfs was used together<br>
=C2=A0with the raw partition.<br>
<br>
=C2=A0So, for a floppy image on a disk device, you need to use the raw part=
ition.<br>
<br>
<br>
<br>
=C2=A0But it is slightly more complicated :)<br>
<br>
=C2=A0The driver for a physical floppy (i.e. not some USB stick where you<b=
r>
=C2=A0want to write a floppy image to but the real vintage thing) abuses<br=
>
=C2=A0the label.<br>
<br>
=C2=A0The different partitions are used to select different floppy formats,=
<br>
=C2=A0e.g. b is a 1.44MB 3.5" disk, c is a 1.2MB 5.25" disk. You =
must<br>
=C2=A0use the correct partition for the medium and even the 'raw' p=
artition<br>
=C2=A0is abused.<br>
<br>
=C2=A0To make this work, the floppy driver has its own private routine<br>
=C2=A0to check write boundaries, and that one just ignores the label<br>
=C2=A0sector.<br>
<br>
=C2=A0Writing to a physical floppy therefore doesn't have such problems=
.<br>
<br>
</blockquote></div>
--0000000000003053970648b6c112--
Home |
Main Index |
Thread Index |
Old Index