Repository navigation
Conversation
ufat is going to create, populate and check FAT32 file systems without mounting them. The use-case is the EFI System Partition. systemd-repart and friends shell out to mkfs.vfat and mtools to format the ESP and to copy UKIs, boot loader entries and the random seed into it. That works but it drags in two external projects, every file costs a fork, and getting reproducible images out of it needs a pile of environment variables and care about readdir ordering. So let's have a library and a tool that do exactly what we need and nothing else. The scope is narrow on purpose: FAT32 with long file names, Linux only, and nothing but the Rust standard library. There are no crates and there is no cargo. meson drives rustc directly, builds the library and its unit tests, and refuses a rustc older than 1.85, which is the oldest one we support. The tests always run with overflow checks and debug assertions. rustfmt formats the code with the width set in rustfmt.toml. Its check is a test in the style suite, which a plain meson test leaves out. The code is LGPL-2.1-or-later. Errors carry a positive errno, a message for people and a detail for programs. The message is English prose for the command line. The detail is an enum that grows with the code, so a caller can act on what went wrong without parsing any text. err!() and bail!() build them. HACKING.md says how to build, test and format the code. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add the computation of how a FAT32 volume is laid out: how many sectors go to the reserved area, to the FATs and to the data clusters. The forward computation, compute(), follows mkfs.fat so that a volume we format and one mkfs.fat formats come out identical for the same parameters. The reverse computation, minimal(), answers the question systemd-repart asks: how many sectors does a volume need to offer a given number of data clusters. Both refuse what FAT32 cannot express with a reason a caller can act on: a volume too small for the geometry asked for, a size beyond what FAT32 can address, or an option out of range. The module is pure, so besides the unit tests it carries harnesses for the Kani model checker, among them the proof that minimal() is the inverse of compute(). Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add the FAT32 boot sector (BPB) and the FSInfo sector: encoding them for a new volume, and decoding and checking them when a volume is opened. Decoding refuses what is not a FAT32 volume with the reason: a blank boot sector, a FAT12 or FAT16 volume or no FAT at all, a sector size we don't support, or an image too small to hold a file system. A boot sector that claims something impossible is reported as damage in the boot sector, naming the field. The 0x55AA signature is not checked, since Linux mounts a volume without it as well. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
The FAT of a volume can be large. At the FAT32 maximum the first copy alone is a gigabyte and the size is whatever the boot sector claims, so we never hold the table in memory as a whole. Instead, entries are read and written through a direct-mapped cache of FAT sectors, 4 MiB by default, the way EDK2's FAT driver does it. A dirty sector that is evicted is written to every FAT copy first, so a sector that reached the device reached all copies. The sectors still dirty in the cache are handed out as runs for the volume to write when it flushes. When a volume is opened we scan the first copy once for the free cluster count and remember one bit per FAT sector that says whether it holds a free entry at all. Allocation follows mtools and the kernel: a cursor remembers the last allocated cluster and the search starts right after it, so files written one after another on a fresh volume end up contiguous and in order. Sectors without a free entry are skipped without being read. A chain is followed cluster by cluster and never collected into a list. The FAT copies live behind FatStore, which the volume is going to implement on top of the device and which the tests and proofs implement on top of a vector. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
FAT stores local time in two second steps without a time zone. For reproducible images we always take on-disk timestamps as UTC, which is also what systemd does when it drives mtools (TZ=UTC) and what the kernel does with the tz=UTC mount option. Timestamps are decoded with the kernel's arithmetic so that they read back the way Linux shows them, and times outside what FAT can store are refused at both ends. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add the 32 byte FAT directory entry: the short name, the attributes, the NT case flags, the creation, modification and access times, the first cluster and the size, and the checksum a set of long name entries carries for its short entry. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add the naming rules. They follow what mtools and Windows NT do, so a directory we populate looks like one mcopy populates: - A name that fits 8.3 without loss and whose base and extension are each entirely upper or entirely lower case gets a short entry only, with the NT case flags recording which part is lower case. - Every other name gets long name entries, and when its 8.3 alias is lossy a numeric tail from ~1 upwards that keeps the alias unique in its directory. A name FAT cannot store is refused with the reason. Names are compared without regard to case. A character folds to its upper case form when that form is a single character. The table behind that is not the compiler's. rustc 1.85 ships Unicode 16.0.0 and rustc 1.97 ships 17.0.0 with 28 more case pairs, so the same tree would give different images depending on the compiler that built ufat. Instead, tools/fold-table.rs generates the table once from a compiler that ships the pinned version, Unicode 16.0.0, and the result is checked in. In a build directory set up with such a compiler the update-fold-table target regenerates it and check-fold-table compares it with a fresh one. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add access to the image file or block device that holds the file system. A Device is a window of a given length at an offset into an open file, so a file system inside a partition of a larger image can be addressed as if it started at byte 0. FAT has no journal, so two writers must never interleave. A block device is opened for writing with O_EXCL, which the kernel treats as an exclusive claim: a mounted file system holds one already, so we fail with EBUSY, and while we hold the device a mount fails the same way. On top of that every image takes a BSD lock, shared for reading and exclusive for writing. systemd locks block devices the same way. A path we are given is resolved once. host.rs turns it into a descriptor, and sys.rs has the system calls std does not wrap and the descriptor based helpers built on them: open a path once, pin a single directory entry with O_PATH, reopen a pinned inode for real. A FIFO or a device node where an image is expected is refused without blocking on it. sys.rs is the only module with unsafe code. Zeroing a range punches a hole into an image file, which reads back as zeros, and sends BLKZEROOUT to a block device, with plain writes as the fallback. A block device is sized with BLKGETSIZE64, and its logical block size and the start of its partition, from sysfs, are there for the formatter. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add formatting. With mkfs_fat_compat set and the same parameters the result is byte for byte what mkfs.fat -F 32 writes. Without it a few legacy quirks are dropped: the total sector count is not truncated to a multiple of the made-up track size, and it always goes into the 32-bit field. A label follows mkfs.fat's rules and is refused with the reason when it doesn't. A volume serial is taken as XXXX-XXXX the way blkid shows it or as eight hex digits, and random_volume_id() draws one from getrandom(). The hidden sectors field is filled in from the start of the partition, as mkfs.fat does it, converted to the file system's sector size. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add Volume, an open FAT32 file system on a device. It looks paths up case insensitively against long and short names, creates, reads, replaces and removes files and directories, removes whole trees, and sets times and attributes. Files are written sequentially. Paths use / as separator, and "." and ".." are refused since there is no working directory to resolve them against. All times are UTC. A directory is loaded into an in-memory image of its clusters, which every lookup, create and delete goes through. Three invariants hold: - After the first unused slot every slot is zero. A directory that breaks this is read up to the marker, the way Linux reads it since 7.2, but never written to. Linux refuses to create entries over the data behind the marker and so do we, with EUCLEAN. - Deleted slots and orphaned long name entries are reused first fit, and deleted slots at the end are zeroed, so deleting an entry and creating it again leaves the same bytes as creating it once. - A set of long name entries always immediately precedes its short entry. The directory keeps an index of itself: the entries by slot, the slots answering to each folded name, the free runs, where the end marker is and which numeric alias tails are taken. Every change keeps the index current, so loading costs O(n) for n slots and every operation after that O(log n) at most. Rescanning instead costs O(n^2) parses for n files in one directory, which made 10000 colliding long names take minutes to populate. Under Kani the hash maps are association lists, so the index can be checked there. Directories also stay in memory between operations, up to 8 MiB of them, least recently used out first. A directory whose changes did not all reach the disk is dropped instead and read again on its next use. The slots reserved for files that are still being written are recorded apart from the cached directories, so a directory that is read again keeps them. A path costs one lookup per component and a new file one directory write. FAT has no journal, so the order of the writes is what keeps a volume consistent across a crash. Everything is ordered so that the worst case is a leaked cluster: - The data and the FAT go out before the directory entry that points at them. A new file's entry is written only when the file is complete, until then its slots are reserved in memory. So a crash leaves the old state behind, never an empty file or two entries of one name. - An entry is deleted before its clusters are freed. - A new directory cluster is zeroed on disk before the parent names it. - A replacement that fits goes into the old entry's slots. The order only holds as long as the device keeps it, and a device with a volatile write cache does not. So on block devices there is an fdatasync before every write that publishes what came before it. Image files are synced once at the end. While a volume is written it is marked dirty in the boot sector and in FAT entry 1, and its FSInfo counts say unknown, which is what Linux, EDK2 and fsck.fat look at. An interrupted volume says so and nobody trusts its free count. Closing the volume puts the bits back and writes the real counts. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add tests/exhaustive.rs, sweeps that take about a minute on 16 cores. They are only built and run when the slow-tests option is set: - layout::compute() over every u32 sector count for the default parameters at 512 and 4096 byte sectors, and every 1009th one for 216 further parameter sets - layout::minimal() for every cluster count up to 200000 over 84 parameter sets - every representable second and every 32-bit FAT date and time word - case folding over all code points, every single character long name, and every name of up to three printable ASCII characters HACKING.md says how to run them. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
The pure modules carry Kani harnesses next to their unit tests. Add what runs them: verify/lib.rs, a crate root with the pure modules only, so that Kani needs neither I/O nor other crates, and the verify target, which runs Kani through verify/run.sh. The harnesses run four at a time at most, since every CBMC instance can take several GB. HARNESS= in the environment picks one, SLOW=1 adds the ones that take longer than half an hour, and DIR=1 the harness of the directory index, which has not finished yet. HACKING.md says how to install Kani and run the harnesses. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add a read-only check. It reads the boot sector and its backup, the FSInfo sector, every FAT copy and the whole directory tree, and reports every deviation from what Linux, EDK2 and the FAT specification expect. What makes a reader fail or refuse the volume, or puts data at risk, is an error. Everything else is a warning. Beyond the specification it looks for what firmware and boot loaders trip over: FAT entry 0 without the media byte, which GRUB refuses, the clean and hardware error bits in FAT entry 1 that EDK2 and Windows act on, reserved bits set in FAT entries, entries behind a directory's end marker, and a volume below the 65525 cluster minimum. A finding is a kind with its fields and a class, not text, so a program can act on it and render it in its own language. Memory stays bounded whatever the image claims. The FAT is read through the cache and no path is kept, paths are rendered only for the problems reported. While at it, add the volume's tests. They check what they write with fsck, so they come with it, and the device counts its syncs for the tests of the write order. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add copying files and directory trees from the host into a volume. Trees are walked in byte order of the file names, so the directory entries and the cluster allocation don't depend on the host file system's readdir order. Only regular files and directories are copied, everything else is skipped and counted. Symbolic links inside a tree are followed and resolved below its root. Times are preserved, fixed, or clamped to a given time, which is how SOURCE_DATE_EPOCH is honoured. The walk lives in host.rs because the planner and the manifest generator are going to walk trees the same way and have to see the same entries in the same order. It works by descriptor, the way systemd's recurse_dir() does it. Every entry is pinned with O_PATH below its directory's descriptor and examined through it, and a file is read by reopening the pinned inode. So what we copy is what we looked at, whatever happens to the tree meanwhile. One entry is pinned at a time and the walk holds one directory per level, so a large directory costs no descriptors. The buffer the contents are copied through is allocated once per volume. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add the planner. It counts directory slots with the rules the populator uses and rounds files to clusters the way the writer does, and then asks layout::minimal() for the smallest volume that offers that many clusters. Formatting a volume of that size and copying the planned tree into it succeeds, with no cluster to spare beyond what the FAT32 minimum of 65525 clusters demands. Nothing but names and sizes is read. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Manifests list the SHA-256 of every file, and we have to verify them while assembling. Add SHA-256 as FIPS 180-4 defines it, portable code and std only, checked against the FIPS vectors. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Assembling from a manifest is going to hash every byte it writes, and writing a manifest every byte it describes. The portable code does about 315 MB/s where sha256sum does 2.2 GB/s with the SHA extensions on the same machine. So add the SHA-NI compression function, with the schedule of Intel's reference implementation: four rounds per pair of _mm_sha256rnds2_epu32 with the message schedule running alongside in msg1 and msg2. It runs behind a runtime check for the sha, ssse3 and sse4.1 features with the portable code as the fallback, and a test compares the two over a range of lengths and alignments. This is the second place with unsafe code next to sys.rs. The intrinsics are unsafe to call because the CPU has to support them, which the check establishes. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Manifests are JSON and so is Varlink. Add a crate of its own for it, std only: a value type, an RFC 8259 parser and a compact serializer. Numbers keep their nature. Anything written without a fraction or an exponent that fits into 128 bits stays an integer, so 64-bit sizes and offsets survive a round trip exactly. Objects keep their insertion order and refuse duplicate keys. Small objects are searched linearly instead of hashed. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add a reader for the UAPI group's file manifests (UAPI.16). A manifest is an RFC 7464 JSON text sequence: every object is preceded by an ASCII record separator, the object describing the manifest comes first, then the file objects, optional signature objects and the trailer. Objects with unknown media types are skipped, as the specification requires. The structural and the field rules are those of systemd's reader, src/shared/uapi16-manifest.c, rule for rule: unsigned integers are also taken as decimal strings, modes also as octal strings, whitespace inside hex and Base64 strings is skipped, and so on. We are stricter only where FAT demands it, for example names have to be unique after case folding. Signatures are recognised but not verified since that needs an X.509 stack. Callers who need authenticated manifests have to verify them before handing them over. A defect is reported with the record, the object's name and the field it is about, so a caller can point at it. The library links the json crate from now on. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Turn the dir objects of a manifest into directories and the reg objects into files, with the contents coming from one of two sources: - The files below a source directory. Every reference is resolved below that directory the way systemd's chase() does it, with openat2(RESOLVE_IN_ROOT) or a walk by hand on kernels without it. An absolute symbolic link starts over at the source directory, ".." at its top stays there and no link leads out of it. systemd runs the assembler as root, so a symlink planted in the tree must not make it copy whatever it points at into the image. - One stream carrying the contents of every file back to back in manifest order, for a caller that pipes them in. Every file's size and SHA-256 are verified while it is written, and a mismatch removes the file again and fails with EBADMSG. What FAT cannot store, symbolic links, device nodes, FIFOs and sockets, is refused unless the caller asks for it to be skipped. Revoked entries and entries outside their validity window are refused unless the caller says otherwise. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add the generator, the manifest of a host tree the way systemd-manifest make writes it. The leading object carries the tree's mTimeNSec, regular files their size, sha256 and mTimeNSec, directories their type and mTimeNSec, sorted by name, keys sorted, one record per line. For a tree of regular files and directories the output is byte for byte what systemd-manifest make --field=size,hash,mtime writes. A manifest stored in the tree's top level, Uapi16Manifest or Uapi16Manifest.*, is left out since those names are reserved. The generator walks the tree the way the populator does, so a generated manifest describes exactly what populating the tree writes. A test feeds one through the reader, the planner and the assembler. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add manifests the reference tool itself wrote, made with systemd commit 4343b7c7d5, together with the trees they describe as far as git can hold them: - an ESP with a boot loader, a UKI, loader.conf, entries and a random seed, with the default fields, with size, hash and mtime only, with names only, and signed with a throwaway key - a tree with everything FAT cannot hold next to what it can - an empty tree - reading, planning, assembling and generating each of them tests/fixtures/make-fixtures.sh rebuilds them. tests/meson.build builds every integration test into a test binary of its own and tells it where the fixtures are through UFAT_FIXTURES. The helpers the integration tests share are in tests/common/. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add the ufat binary, which meson installs. It is linked statically
against glibc by default, -Dstatic=false links it dynamically, and it
has these commands:
assemble make a file system sized to fit and fill it, or an empty
one without a source
populate fill an existing file system with trees or one file, or
make a directory
remove remove files and directories, whole trees with -r
list list a directory
describe show a file system's geometry
check check a file system
cat print a file
manifest write the UAPI.16 manifest of a directory tree
assemble plans, formats and fills in one go, and assemble --plan only
plans. Everything that can fail before the first write is found out
while the image is untouched, so a failed command leaves nothing behind.
Timestamps come from --timestamp or SOURCE_DATE_EPOCH. What FAT cannot
store is left out and reported, or refused with --unsupported fail.
check exits with the codes fsck(8) and systemd-fsck know: 0 for a clean
volume, warnings or not, 4 when errors were found, and 8 when the image
could not be checked. The soft limit on descriptors is raised at
startup, since a tree walk holds one descriptor per level.
Note that meson links with -Cdefault-linker-libraries, which turns a
crt-static binary into a dynamically linked one again. So the static
build passes -Cdefault-linker-libraries=no after it.
tests/cli.rs runs the binary. The integration tests find it through
UFAT.
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add differential tests against the reference tools. A test whose tool is missing is skipped with a note, and UFAT_MTOOLS points at an mtools build: - mkfs.fat and ufat format the same bytes for the same parameters - fsck.fat is happy with what we write - mtools reads our images, and populating gives the bytes mcopy gives - the planner's size is exact - our SHA-256 matches sha256sum - a real-world tree assembled by us comes back through mtools HACKING.md lists the tools they use. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add a crash consistency harness for the volume's write sequence: - record a scenario on a device built with --cfg ufat_trace and durable mode on: nested directories, long names, a directory grown past its first cluster, files replaced in place, into reused slots and into another cluster, a removed file, close - fill the free clusters with stale entries first, so that a directory chain running into an unwritten cluster shows - build every state a crash can leave under three storage models: every prefix, every prefix with its last write torn at a sector, and within one fsync epoch every pair dropped and every subset - check each state: fsck finds nothing a crash does not explain, every file is old, new or absent and never damaged, directories hold the expected names only, and no cluster is lost that no file ever owned The harness needs the library with the trace compiled in. meson builds that copy as ufat_trace and hands it to the harness under the name ufat. It runs with meson test. HACKING.md describes the storage models and how to get the full output. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add a crate that does Varlink the way systemd's tools do it. The service manager, or varlinkctl call exec:, passes one socket as fd 3, announced through LISTEN_FDS, LISTEN_PID and LISTEN_FDNAMES=varlink, and the process serves that connection until the peer hangs up. SYSTEMD_VARLINK_LISTEN takes what sd-varlink takes: "-" for stdin and stdout, an absolute path or @name for a socket to listen on. The wire protocol follows sd-varlink: NUL terminated JSON objects, method, parameters, oneway, more and upgrade in calls, and a malformed message ends the connection. Interfaces are described in the IDL, which we parse, and the parameters of a call are checked against the method's declared inputs before a handler sees them. org.varlink.service answers introspection. SIGTERM is deferred while a call is handled, a listening service stops cleanly on it, and what one connection can hold is bounded. File descriptors travel with a call as SCM_RIGHTS, which is how systemd's services take images and directories. A socket is read with MSG_PEEK up to the next NUL and then exactly that far, so the descriptors the kernel hands out with the first byte of a message belong to that message and no other. A client side is there as well, for tests and benchmarks, and it can call with the more flag and with descriptors. varlink/sys.rs holds the only unsafe code of the crate. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
systemd makes every filesystem through one function, make_filesystem(), and learns nothing back from the tool but its exit status. To replace the argv it builds per filesystem with one Varlink call we studied the mkfs, fsck and populate tools of ext4, xfs, btrfs, f2fs, erofs, squashfs, exfat and vfat, and what systemd-repart and mkosi need from them, and vetted every claim against the tools' sources. docs/org.uapi-group.FileSystem.varlink is the interface that came out of it. GetCapabilities comes first, so a caller knows what a filesystem can do, then Assemble, Describe, Populate, Remove, List and Check, with typed options, content from a tree or a UAPI.16 manifest, the manifest of what was stored written back, and typed errors without text. ufat is going to implement it for vfat. Options that only one filesystem has go into a struct named after it. VfatOptions is the only one for now. An implementation for another filesystem adds its own struct when it comes. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Assemble is going to hash the image it wrote on request, with sha256 or sha512 as systemd's ManifestHash names them. We have SHA-256, so add SHA-512 with the same shape, portable code and std only. The constants are recomputed from their definition and the digests checked against coreutils, with the FIPS vectors and the padding boundaries pinned in the tests. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
The service is going to take every file on the host as a descriptor passed along with the call. A descriptor another process hands over has to be checked before we use it, the way systemd's fd_verify_safe_flags() checks an extrinsic descriptor before a privileged service works with it. Its open flags are read back with F_GETFL. An O_PATH descriptor is refused, since nothing can be read through it and reopening it would give the client access it does not have, and so is every status flag that is not on the allowlist. O_APPEND would make positional writes append and O_DIRECT would make them fail on alignment. On top of that every use gets the checks that fit it: - an image is a regular file or a block device, open read-only when it is only read and read-write when it is written, and a block device to be written is claimed exclusively - a source directory is a directory open read-only - a file to copy is a regular file open read-only, read from its start with positional reads so the client's file position is left alone - a stream is a regular file or a pipe open read-only and blocking - a manifest sink is a regular file or a pipe open for writing What is wrong is reported as a typed problem, together with the flags that were found. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
The generator describes a host tree. The Varlink interface also wants the manifest of what a filesystem stores, after an Assemble or Populate call and for Describe. So add a writer that walks a volume: the root object first, then every directory followed by its entries, sorted by the bytes of their names and never in on-disk order, the trailer last. The fields follow systemd-manifest's vocabulary and default set. A field FAT has no notion of is left out without being counted: no mode, owner, hardlink, device numbers or user and group names ever appear. What FAT does have goes out as the specification has it: size and sha256 read from the volume, the stored 2 s time when mtime is asked for, and readOnly for the read-only attribute. An entry whose name a manifest cannot carry is left out with everything below it and counted. The framing of the records and the time conversion are shared with the host tree generator, so both write what systemd-manifest writes. The command line writes it with --write-manifest on assemble, populate and describe. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Started with a socket passed through LISTEN_FDS, as varlinkctl call exec: and systemd socket units do it, the binary now serves the org.uapi-group.FileSystem interface for vfat on that socket and exits when the client hangs up. Otherwise it runs the command line as before. The interface description is compiled in from docs/, where it is the spec. All seven methods are there: - GetCapabilities answers the static table for vfat. - Assemble plans, formats and fills in one call, from a tree, a file or a manifest over a directory or a stream, sized to fit when no size is given, and hashes the image with SHA-256 or SHA-512 on request. - Describe reads what is there and writes the manifest of it on request. - Populate puts a tree, a file or an empty directory at a path, and a manifest's contents into the root. - Remove takes a file, an empty directory, or a tree with recursive. - List streams one entry per reply. - Check keeps fsck read-only and gives every finding its class. Everything on the host reaches the service as a vetted file descriptor passed along with the call, never as a path, so nothing is resolved with the service's privileges on the caller's behalf. Nothing the service answers is text meant for a person, every error is a name with typed fields. With the more flag the long calls report their phases, and a phase that lasts repeats itself about once a second with the counts so far. So a caller can show progress, and its idle timeout does not fire during a long copy. The long operations of the library take a progress callback for that. The command line's plan and format steps are shared with Assemble now. Its commands carry the names of the methods already. It gains capabilities, which prints what GetCapabilities answers, and --hash for assemble. tests/varlink.rs drives every method over a socket passed as fd 3, over stdin and stdout and over a listening socket, and holds every reply and every error to the interface description. A unit test holds fsck's problem classes to it as well. docs/varlink.md is the reference for callers of the service. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add a mutation campaign against the binary and the service as tests/fuzz/ with a fuzz target, a short smoke by default that WORKERS= and ITERATIONS= scale up: - seeds.sh builds the corpus: a source tree, small images the library formats through the fuzz-seeds helper, images made by mkfs.fat and mcopy when they are found, and the manifest fixtures - mutate.py mutates images (boot sector, FSInfo, FAT, directory entries, flips, truncation) and manifests (structure, records, bytes) and runs the commands on them under a timeout and a memory limit - varlink_fuzz.py sends broken protocol, hostile calls and mutated inputs through the service - targeted.py probes edge cases one by one - summarize.py sums up the reports - run.sh runs all of it for the fuzz target and fails when a campaign found something - repro/ keeps the three defects the first campaign found as regression checks Findings land below FUZZ_OUT with the input that triggered them. HACKING.md says how to run it. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add bench/ and a bench target, so that the numbers can be reproduced and a change can be measured before it goes in. bench/run.sh builds deterministic inputs on tmpfs, an ESP with four 64 MiB UKIs and 50 small files and trees of 10000 files with colliding long names, with 8.3 names and spread over 100 directories. It times mkfs, populate, size, manifest, assemble, fsck and the Varlink calls against mkfs.fat, mcopy, sha256sum and fsck.fat, and compares the mkfs images with mkfs.fat's byte for byte in every run. bench/measure.rs runs one command or one Varlink call and reports wall, user and system time, peak RSS and the bytes read and written. bench/genfile.rs writes the reproducible inputs. HACKING.md says how to run it. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
A build directory set up with -Db_coverage=true builds everything with -C instrument-coverage. Let the tests leave their profiles in coverage/ of such a build directory, and add a coverage-report target that merges them with llvm-profdata and reports line coverage with llvm-cov over every binary of the suite. meson's own coverage targets run gcovr or lcov and cannot report LLVM's source based coverage. Each report consumes the profiles it merged, so the next one covers the test runs that came after it. The llvm tools have to be at least as new as the LLVM inside rustc. The first of llvm-profdata-21, -20, -19 and llvm-profdata that is found is used, LLVM_PROFDATA= and LLVM_COV= override. Test code and the toolchain's sources are left out of the report. HACKING.md says what it needs. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add the README for users of ufat: what it is for, how to build and install it, how to use the command line tool, sizing and sector sizes, checking a file system, crash safety, the Varlink service, the library, and where ufat differs from other tools. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Move from meson and plain rustc to a cargo workspace. libc is the only dependency. Cargo.lock is checked in and a CI job fails if anything else shows up in the dependency graph. The hand-written system call constants were wrong on several architectures. O_DIRECTORY and O_NOFOLLOW were off on arm and arm64, signalfd4 used x86_64's syscall number everywhere, f_type of statfs was read with the wrong width on s390x, and the signal set was put together for 64-bit words only. sparc64 did not build at all. So take all of it from libc instead. What libc doesn't have yet lives in src/sys/uapi.rs and varlink/sys.rs and is checked at compile time. On 32-bit, use openat64, fstatfs64 and fallocate64 so that images over 2 GiB and large host file systems work, and holes get punched. This is a draft to run CI on all supported architectures. Once it is green the history gets rebuilt with cargo from the first commit. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
The static default from the meson build doesn't carry over to cargo. A committed crt-static setting overrides the build flags Debian passes to cargo, breaks every proc-macro build inside the tree, and rustc 1.99 can't link it at all on armv7, powerpc, powerpc64, powerpc64le and sparc64, where glibc ships no rcrt1.o. So link dynamically by default, as systemd does, and document a static build with an explicit --target. CI tests both on x86_64 and aarch64 and runs the dynamic build of the other targets under qemu. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
ufat links dynamically against glibc like systemd's own tools. A static glibc build only brings glibc's NSS caveats and the static-pie differences between rustc versions and architectures, and nothing needs it. So stop documenting and testing it. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
The vetting test opened its non-blocking source with a hard-coded 0o4000, which is O_NONBLOCK almost everywhere but O_EXCL on sparc. So the descriptor wasn't non-blocking there, the service rightly accepted it, and the test failed on sparc64. Take the flag from libc. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
The runtime tests for O_EMPTYPATH and SO_PASSRIGHTS read the kernel version to decide whether the feature has to work. A version says little about what a kernel supports, so probe for the feature instead: openat2 rejects an open flag it doesn't know with EINVAL, and setsockopt answers ENOPROTOOPT for an option it doesn't know. While at it, drop "the verify target" from the comments of the Kani harnesses. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Replace the hand-written SHA-256 and SHA-512 with RustCrypto's sha2, which brings the SHA extensions on more architectures, and the command line parser with lexopt. Both come without proc-macros. CI's dependency check now holds an explicit list of the crates in Cargo.lock. The Base64 decoder for UAPI.16 literal contents accepted input that systemd's unbase64mem_full() refuses, unpadded groups and stray padding among them. Decode exactly what systemd decodes. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
With lexopt a -h inside a bundle like -hl was dropped silently. Treat -h and --help the same wherever they appear, and refuse a short option that the command doesn't take instead of ignoring it. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
The table came from the compiler's own Unicode data, so only rustc 1.85 could generate or check it and a test had to skip on every newer compiler. Generate it from UnicodeData.txt and SpecialCasing.txt of Unicode 16.0.0 instead, pinned by their sha256 in tools/fold-table.sha256, and check it in CI on any toolchain. The pairs are unchanged. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
When two entries of a source tree folded to the same FAT name, like A.txt and a.txt, the later one silently replaced the earlier one. Refuse such a tree with caseCollision before anything is written. Replacing what is in the image already stays as it is. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This reverts commit d62736c. No other tool refuses such a tree. On a case-insensitive file system cp, rsync and tar let the later of the two names replace the earlier one, git does the same and warns about it, and mcopy skips the later one. The check also cost populate a second walk of the whole source, about a quarter of its time for 10000 small files. So let's go back to what we did before: the name that comes later in byte order replaces the earlier one. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add a perf job that builds the release binary of the base and of the head and compares them with bench/compare.sh. It counts the instructions under cachegrind and the system calls under strace, and neither depends on how busy the runner is. It also compares the bytes read and written and the peak RSS. Wall time is reported but only fails on a gross regression. The base is the target branch for a pull request, main before a push, and main of a week earlier for the weekly run. A commit that makes a workload slower on purpose names it in a Perf-regression: trailer. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
The target of this pull request is still the meson tree, which the perf job can't build. So compare with the commit before for now, and compare the head with itself as well to see the noise on a runner. This gets dropped before the series lands. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the tree the history will be rebuilt into, as a draft so CI can
run it on all supported architectures before anything is rewritten.
ufat moves from meson to a cargo workspace with libc as its only
dependency. Cargo.lock is checked in, everything builds with --locked,
and the deps job fails if anything but libc shows up in the dependency
graph.
The system interface now comes from libc. The few values libc doesn't
have yet (O_EMPTYPATH, the kernel's O_LARGEFILE, SO_PASSRIGHTS,
BLKGETSIZE64 and BLKZEROOUT) are local and checked at compile time. That
fixes the per-architecture values that were wrong on arm, arm64, s390x,
sparc64 and 32-bit big-endian, and large files on 32-bit.
CI builds and tests natively on x86_64 and aarch64 with rustc 1.85 and
stable, runs clippy for all ten targets with both, and runs the test
suite under qemu-user for i686, armv7, powerpc, powerpc64, powerpc64le,
riscv64, s390x, sparc64 and loongarch64.
Supersedes #1.