24 Commits

Author SHA1 Message Date
Michael Stapelberg
71d9c6c36b fat: add Exists method for detecting accidental overwrites 2024-06-23 10:32:20 +02:00
Michael Stapelberg
cb94242910 writer: fix writing directories with many entries
This fixes writing out (for example) device tree overlay directory.

We now write the directory entries twice:
Once for figuring out the correct firstCluster values,
then again for writing out the correct firstCluster values.

related to https://github.com/gokrazy/gokrazy/issues/216
related to https://github.com/gokrazy/tools/pull/67
2023-12-15 08:53:26 +01:00
Michael Stapelberg
a51d461685 fat: fix padding (for FAT16): need to use usable FAT entries 2023-10-13 08:52:06 +02:00
Michael Stapelberg
5aab2d692f fat: fix data sector calculation
The FAT contains two unusable entries at the beginning that do not represent
data, so those shouldn’t be counted when determining the number of data sectors.
2023-10-13 08:52:06 +02:00
Michael Stapelberg
4e41a6d1cc add minimal fuzz test 2023-10-13 08:52:06 +02:00
Michael Stapelberg
1b3b5687a0 (fat.Reader).Extents: implement support for subdirectories 2021-06-21 18:25:16 +02:00
Michael Stapelberg
4716d3fefe fat: fix: calculate offset instead of keeping track
Keeping track of the offset depends on the order in which entries are written,
i.e. breaks as soon as you have multiple nested directories.
Calculating the offset is shorter and more robust.

related to https://github.com/gokrazy/internal/issues/6
2021-06-20 14:43:41 +02:00
Michael Stapelberg
1f95c50d27 fat: skip long file name (LFN) entries for . and .. 2021-06-19 20:29:54 +02:00
Michael Stapelberg
f2bd9b32d8 fat: fix writing directories and subdirectories
When writing directory entries, we now allocate the FAT entries
before writing, so that we can synthesize the . and .. entries
which need FirstCluster and parent.FirstCluster to be set.

This code currently assumes each directory consumes only 1 cluster
(space for 64 directory entries, I think).
2021-06-19 20:29:54 +02:00
Michael Stapelberg
3567162db3 fat: pad the file system for now-stricter dosfsck 2021-06-19 20:29:54 +02:00
Michael Stapelberg
4a4698a463 fat: fix empty file handling (do not consume FAT entries) 2021-06-19 20:29:54 +02:00
Michael Stapelberg
613eeb147f fat: set fw.pending = nil to avoid accidental double Close() 2021-06-19 20:29:54 +02:00
Michael Stapelberg
de61a87169 fat: use attrDirectory instead of 0x10 throughout 2021-06-19 20:29:54 +02:00
Michael Stapelberg
cf2fc1492b fat: write volume id root directory entry
This is required to make fsck.vfat happy.
2021-06-19 20:29:54 +02:00
Joonas Kuorilehto
ab6fc6e02a Fix short name with short primary and long extension (#7)
Fixes gokrazy/internal#5
2020-07-13 10:41:55 +02:00
Michael Stapelberg
faec26b22a internal/fat: fix unusableClusters after previous commit 2019-06-30 11:10:30 +02:00
Michael Stapelberg
c3231df868 fat/writer: represent first 2 FAT entries in w.fat
Before this commit, the special first two entries (media descriptor copy, file
system state) were only written out in writeFAT.

For the edge case where the two entries are what pushes the FAT from one sector
to the next, this resulted in incorrect fatSectors calculation.
2019-06-30 11:03:35 +02:00
Michael Stapelberg
8508a2c816 Bugfix: exempt special . and .. entries from leading dot stripping 2018-05-16 18:24:07 +02:00
Michael Stapelberg
5ba2f5ad38 FAT: add support for long file names
This is in preparation for adding Raspberry Pi 3 B+ support, for which we’ll
need to let the firmware locate the DTB file under file names such as
bcm2710-rpi-3-b-plus.dtb.

Note that short names are not upper-cased currently (the standard says they
should, but neither the firmware nor the linux kernel care) so that upgrades
from older gokrazy installations work. In a year or so, we can change this.
2018-05-16 09:33:23 +02:00
Michael Stapelberg
dafaf92bf7 fat: add Reader.ModTime() for the timestamps package 2017-09-06 09:37:57 +02:00
Michael Stapelberg
482fe4e5c6 fat: store timestamps in UTC (Linux interprets them in UTC) 2017-09-06 09:37:30 +02:00
Michael Stapelberg
ebb63d7e97 fat: store seconds correctly (divide, not multiply) 2017-09-06 09:37:13 +02:00
Michael Stapelberg
e166c599fa update import paths 2017-07-14 03:18:19 +02:00
Michael Stapelberg
580b69f8dc Move FAT16B writer from github.com/gokrazy/fat to internal 2017-07-14 03:14:28 +02:00