I'm writing an operating system and am trying to get it reading FAT12 filesystems. As such, I want a FAT12 disk image with some files on it to get it to read.
To make my FAT12 image, I made a blank .img file and then used mkfs.fat -F12 on it to create the filesystem. This appears to have worked, as mounting it with a loopback device causes lsblk --fs to tell me that it's a vfat filesystem with FSVER=FAT12. I'm not sure why it's saying it's vfat, since it shouldn't be, but I'm assuming that that's just what lsblk says about fat12, since it does correctly give me the FAT12 as its version.
Anyway, to my knowledge, a filename in a FAT12 filesystem has to be 8 chars for the name + 3 for the extension, so I tried creating a file named FILE.TXT after mounting the .img, and this works, as expected. I then tried making a file named longfilename.longextension and, to my surprise, it let me do this!
I opened up the .img file in xxd to have a look at how its storing that filename, and it is indeed storing the entire long filename, even though I don't think that should be possible.
Here's all of the .img which isn't just zeroes:
00000000: eb3c 906d 6b66 732e 6661 7400 0210 1000 .<.mkfs.fat.....
00000010: 0200 0200 80f8 1000 2000 4000 0000 0000 ........ .@.....
00000020: 0000 0000 8000 29d7 c938 d44e 4f20 4e41 ......)..8.NO NA
00000030: 4d45 2020 2020 4641 5431 3220 2020 0e1f ME FAT12 ..
00000040: be5b 7cac 22c0 740b 56b4 0ebb 0700 cd10 .[|.".t.V.......
00000050: 5eeb f032 e4cd 16cd 19eb fe54 6869 7320 ^..2.......This
00000060: 6973 206e 6f74 2061 2062 6f6f 7461 626c is not a bootabl
00000070: 6520 6469 736b 2e20 2050 6c65 6173 6520 e disk. Please
00000080: 696e 7365 7274 2061 2062 6f6f 7461 626c insert a bootabl
00000090: 6520 666c 6f70 7079 2061 6e64 0d0a 7072 e floppy and..pr
000000a0: 6573 7320 616e 7920 6b65 7920 746f 2074 ess any key to t
000000b0: 7279 2061 6761 696e 202e 2e2e 200d 0a00 ry again ... ...
000000c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
*
000001f0: 0000 0000 0000 0000 0000 0000 0000 55aa ..............U.
00000200: 0000 0000 0000 0000 0000 0000 0000 0000 ................
*
00002000: f8ff ff00 f0ff ffff ffff ffff 0000 0000 ................
00002010: 0000 0000 0000 0000 0000 0000 0000 0000 ................
*
00004000: f8ff ff00 f0ff ffff ffff ffff 0000 0000 ................
00004010: 0000 0000 0000 0000 0000 0000 0000 0000 ................
*
00006000: 412e 0054 0072 0061 0073 000f 00e4 6800 A..T.r.a.s....h.
00006010: 2d00 3100 3000 3000 3000 0000 0000 ffff -.1.0.0.0.......
00006020: 5452 4153 482d 7e31 2020 2010 0011 8c7d TRASH-~1 ....}
00006030: 3952 3952 0000 8c7d 3952 0400 0000 0000 9R9R...}9R......
00006040: 4649 4c45 2020 2020 5458 5420 0071 aa7e FILE TXT .q.~
00006050: 3952 3952 0000 aa7e 3952 0300 0e00 0000 9R9R...~9R......
00006060: 426c 006f 006e 0067 0065 000f 00c8 7800 Bl.o.n.g.e....x.
00006070: 7400 6500 6e00 7300 6900 0000 6f00 6e00 t.e.n.s.i...o.n.
00006080: 016c 006f 006e 0067 0066 000f 00c8 6900 .l.o.n.g.f....i.
00006090: 6c00 6500 6e00 6100 6d00 0000 6500 2e00 l.e.n.a.m...e...
000060a0: 4c4f 4e47 4649 7e31 4c4f 4e20 0022 f47e LONGFI~1LON .".~
000060b0: 3952 3952 0000 f47e 3952 0700 1400 0000 9R9R...~9R......
000060c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
*
0000c000: 4865 6c6c 6f2c 2077 6f72 6c64 210a 0000 Hello, world!...
0000c010: 0000 0000 0000 0000 0000 0000 0000 0000 ................
*
0000e000: 2e20 2020 2020 2020 2020 2010 0011 8c7d . ....}
0000e010: 3952 3952 0000 8c7d 3952 0400 0000 0000 9R9R...}9R......
0000e020: 2e2e 2020 2020 2020 2020 2010 0011 8c7d .. ....}
0000e030: 3952 3952 0000 8c7d 3952 0000 0000 0000 9R9R...}9R......
0000e040: 4169 006e 0066 006f 0000 000f 00fb ffff Ai.n.f.o........
0000e050: ffff ffff ffff ffff ffff 0000 ffff ffff ................
0000e060: 494e 464f 2020 2020 2020 2010 0011 8c7d INFO ....}
0000e070: 3952 3952 0000 8c7d 3952 0500 0000 0000 9R9R...}9R......
0000e080: 4166 0069 006c 0065 0073 000f 0079 0000 Af.i.l.e.s...y..
0000e090: ffff ffff ffff ffff ffff 0000 ffff ffff ................
0000e0a0: 4649 4c45 5320 2020 2020 2010 0011 8c7d FILES ....}
0000e0b0: 3952 3952 0000 8c7d 3952 0600 0000 0000 9R9R...}9R......
0000e0c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
*
00010000: 2e20 2020 2020 2020 2020 2010 0011 8c7d . ....}
00010010: 3952 3952 0000 8c7d 3952 0500 0000 0000 9R9R...}9R......
00010020: 2e2e 2020 2020 2020 2020 2010 0011 8c7d .. ....}
00010030: 3952 3952 0000 8c7d 3952 0400 0000 0000 9R9R...}9R......
00010040: 0000 0000 0000 0000 0000 0000 0000 0000 ................
*
00012000: 2e20 2020 2020 2020 2020 2010 0011 8c7d . ....}
00012010: 3952 3952 0000 8c7d 3952 0600 0000 0000 9R9R...}9R......
00012020: 2e2e 2020 2020 2020 2020 2010 0011 8c7d .. ....}
00012030: 3952 3952 0000 8c7d 3952 0400 0000 0000 9R9R...}9R......
00012040: 0000 0000 0000 0000 0000 0000 0000 0000 ................
*
00014000: 5468 6973 2069 7320 6120 6c6f 6e67 2066 This is a long f
00014010: 696c 650a 0000 0000 0000 0000 0000 0000 ile.............
00014020: 0000 0000 0000 0000 0000 0000 0000 0000 ................
*
00fffff0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
So it certainly seems as if it's storing the filename in a similar format to the long filenames in the vfat filesystem spec.
Any idea why?
EDIT: I ran this command:
$ dosfsck test.img -l
fsck.fat 4.1 (2017-01-24)
Checking file /.Trash-1000 (TRASH-~1)
Checking file /FILE.TXT
Checking file /longfilename.longextension (LONGFI~1.LON)
Checking file /.Trash-1000/.
Checking file /.Trash-1000/..
Checking file /.Trash-1000/info (INFO)
Checking file /.Trash-1000/files (FILES)
Checking file /.Trash-1000/info/.
Checking file /.Trash-1000/info/..
Checking file /.Trash-1000/files/.
Checking file /.Trash-1000/files/..
test.img: 5 files, 5/2043 clusters
and looking at the longfilename file, it says after it that it's actually named LONGFI~1.LON, which is more what I expected. But how, then, can it know that I actually named it longfilename.longextension? I'm also unsure of where all these trash files came from, is this what's storing the name?