osbase/fat32: fix corrupted directories

Previously, after writing the contents of a file or directory, any
remaining space in the last cluster was left as is instead of zeroed.
For files this may be acceptable, but directories do not have an
explicit size in bytes. The result is that, if the device was not zeroed
before writing the FAT32, each directory contains some number of
additional garbage entries, with a random name, size, and initial
cluster.

The fix is to ensure that the last cluster of a directory is filled up
with zeroes, following the FAT32 spec (page 24): "initialize all bytes
of that cluster to 0". The change also applies to files, where zeroing
the remainder of the last cluster should not be necessary, but also
doesn't hurt. At most 32 KiB of zeroes (the maximum cluster size) will
be written for each file.

The fsck test is extended to initialize the file with random bytes.
Without the fix, this results in fsck reporting a large number of
problems.

Change-Id: I7729e028c92bfad9b879a4256f3fa4f7af25553a
Reviewed-on: https://review.monogon.dev/c/monogon/+/3607
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
Tested-by: Jenkins CI
2 files changed
tree: fd404d8cdda2f86a1298aaa85b15a3946770e597
  1. .github/
  2. build/
  3. cloud/
  4. go/
  5. intellij/
  6. metropolis/
  7. osbase/
  8. third_party/
  9. tools/
  10. version/
  11. .bazelignore
  12. .bazelproject
  13. .bazelrc
  14. .bazelrc.ci
  15. .bazelrc.sandboxroot
  16. .bazelversion
  17. .git-ignore-revs
  18. .gitignore
  19. BUILD.bazel
  20. CODING_STANDARDS.md
  21. go.mod
  22. go.sum
  23. LICENSE
  24. MODULE.bazel
  25. MODULE.bazel.lock
  26. README.md
  27. SETUP.md
  28. shell.nix
  29. WORKSPACE
README.md

Monogon Monorepo

This is the main repository containing the source code for the Monogon Platform.

This is pre-release software - take a look, and check back later! In the meantime, join us on Matrix (#monogon-os-community:matrix.org) or Discord.

Environment

Our build environment is self-contained and requires only minimal host dependencies:

  • A Linux machine or VM.
  • Bazelisk >= v1.15.0 (or a working Nix environment).
  • A reasonably recent kernel with user namespaces enabled.
  • Working KVM with access to /dev/kvm (if you want to run tests).

Our docs assume that Bazelisk is available as bazel on your PATH.

Refer to SETUP.md for detailed instructions.

Monogon OS

The source code lives in //metropolis (Metropolis is the codename of Monogon OS).

See the //metropolis/README.md for a developer quick start guide, or see the Monogon OS Handbook for user documentation.