Repository navigation
Conversation
In ufat the crate is a member of ufat's workspace and takes its edition, rust-version, license, publish setting, lints and dependency versions from there. This repository is going to hold more than the crate: a C library and a tool that generates and checks manifests. So it becomes a workspace the way ufat is one, with every crate below src/. The crate stays in src/uapi16, exactly where it is in ufat. The root Cargo.toml takes over what applies from ufat's. resolver 3 makes cargo update pick dependency versions that build with rust-version 1.85. [workspace.dependencies] has the four crates uapi16 uses. sha2 stays on 0.11.0, since 0.11.1 needs rustc 1.88, and libc on 0.2 like in ufat, so that ufat never builds two versions of it. The lints are ufat's, minus the check-cfg list, which only names cfgs of ufat's own. src/uapi16/Cargo.toml loses a single line, version.workspace = true. The crate gets its version later, together with the rest of what crates.io needs, and cargo refuses to inherit a version the workspace doesn't have. Without one cargo treats the crate as 0.0.0. It isn't published either way, since the workspace says publish = false. Cargo.lock is checked in and lists the versions ufat's Cargo.lock has, so the crate is built and tested with exactly what ufat uses. Builds use --locked. rustfmt.toml is ufat's as well, so the code is formatted the same way. ufat has no clippy configuration beyond the lints. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Bring over the manifests systemd-manifest wrote from ufat, with the two
tests there that only exercise this crate:
- read every manifest and check what its objects hold
- check that a signature changes none of the file objects
- check that fewer fields give the same names and values
- write every manifest back and read the same objects again
They go below src/uapi16/tests, so that they belong to the crate and
come with its package. tests/ at the top is left for the tool.
The six manifests are byte for byte the ones in tests/fixtures of ufat,
where they last changed in c9bcc12 ("manifest: write manifests with the
uapi16 crate"). systemd-manifest of systemd commit 4343b7c7d5 wrote
them. ufat's make-fixtures.sh then added the features and the order,
which that systemd-manifest didn't write yet, and took the hash of no
data out of the empty file. tests/fixtures/README.md in ufat has the
details. The trees the manifests describe stay in ufat, since nothing
here reads them.
The tests use the reader and the writer directly instead of going
through fat::manifest. writes_records_the_way_systemd_does() in
writer.rs points at these manifests, so that holds again.
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
The crate is LGPL-2.1-or-later. Add the text of the LGPL 2.1 twice: at the top for the repository, where GitHub looks for it, and in src/uapi16 for the package cargo publish uploads. cargo packages only what is in the crate's directory, and an include pattern can't reach outside of it. Both are the same file ufat has. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add a README for the repository: what it holds and under which license. The page crates.io shows for the crate is src/uapi16/README.md. cargo would package this README with readme = "../../README.md" as well, but it describes the repository, which is going to hold the C library and the tool too. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Build and test the workspace for every pull request, every push to main and once a week: - build and test with rustc 1.85 and the current stable rustc on x86_64, with glibc and with musl - build for i686 and run the tests there - run clippy with both for the twelve targets ufat checks and for aarch64 and armv7 Android - check the formatting - build the documentation, for Linux and for aarch64 Android - run cargo publish --dry-run for uapi16 and the tests of the package it builds - check the crates in Cargo.lock against an explicit list Warnings fail the build through CARGO_TARGET_<TRIPLE>_RUSTFLAGS, clippy's -D warnings and RUSTDOCFLAGS. All of it comes from ufat's CI, minus what only applies to ufat, and covers every crate of the workspace the way ufat's does. The documentation and the package jobs are new, and so are the two Android targets of clippy, which need no NDK since nothing is linked. Neither does the documentation for Android. What is there on Linux only is missing on Android, and that build fails on a link that would lead to it. The package is tested from its unpacked copy with a target directory of its own, so a file the tests need but the package lacks fails the job. cargo publish --dry-run only warns about a version that is on crates.io already, so the job keeps passing after a release. The actions are pinned to the same commits ufat uses, and dependabot bumps them once a month, together with the crates. sha2 stays on 0.11.0, the last release rustc 1.85 can build. libc stays on 0.2 like pathrs, errno, getrandom and sha2's cpufeatures, so that the tests never build two versions of it. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Every commit to uapi16 carries a Signed-off-by: line from its author. Add the DCO that the line certifies, verbatim, the same file ufat has. There's no HACKING.md here, so the README of the repository says how to submit changes. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Fail when a commit lacks a Signed-off-by: line from its author: for a pull request every commit in it, for a push every commit it added. Merge commits are left out, since GitHub's merge button writes them without a sign-off. A sign-off counts when its address or its name is the author's. An affiliation in parentheses changes the name, and dependabot signs off with another address than it commits with. The job is the one ufat has. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
"uapi16: mark the open-ended enums non-exhaustive" left Step exhaustive because a caller that doesn't know a step can't keep driving the decoder. A new step that asks the caller for something, the way Step::Input asks for more of the manifest, would be passed over by an old caller. It would call step() again without doing what was asked and get the same step back, forever. But that only holds for a step that asks the caller to act. A step that only hands something out, like Step::Root and Step::Object do, needs nothing but another call to step(). So let's promise exactly that in the docs: a step the caller doesn't know needs nothing from it except another call to step(). Then new steps can be added in a compatible release as long as they only hand something out, and Step can be #[non_exhaustive] like the other open-ended enums. The example of Decoder already passes over the steps it doesn't care about with a catch-all arm. Nothing in ufat uses Decoder or matches on Step. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Mode::ALL and Mode::WRITE are built from libc's S_I* constants. Those are mode_t, which is u32 on most targets but u16 on 32-bit Android, so the two constants don't even build there. They also aren't what a mode is in a manifest. The specification gives `mode` the range 0o0000 to 0o7777 and talks about its three 'w' bits, so use exactly that: 0o7777 and 0o222, as named constants that say where they come from. With that the library doesn't use libc anymore. The tests still take errno values from it, so libc moves to [dev-dependencies]. Note that this also takes away the reason the comment in Cargo.toml gives for keeping libc on 0.2, since ufat never builds a dev-dependency of uapi16. The tests stay on 0.2 all the same: sha2's cpufeatures uses libc 0.2 on aarch64 and loongarch64, and a newer libc would mean two versions of it there. So say that instead. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Sha256::EMPTY and Sha256Context::finalize() come from the traits Digest and Finalize, so a caller has to import a trait to use either of them. The traits abstract over the hash algorithm, but the specification only has SHA-256 and there's no second implementation in sight. Make EMPTY an associated constant of Sha256 and finalize() a method of Sha256Context, and drop both traits. Callers drop their imports of Digest and Finalize and nothing else changes for them. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
The specification calls the bytes of a file its data. "contents" is the `contents` field of a file object with the contents objects in it, and "source" is where a contents object says the data is. The crate mixes these up. ContentCheck checks data, copy_contents() copies data, ContentProblem says what is wrong with data, and the docs say contents for the bytes all over the place. Use the terms of the specification for everything that is about the bytes of a file: - Data becomes DataLocation, and FileObject::data() becomes data_location() - Reference becomes ExternalFile, and its field `file` becomes `name` - copy_contents() becomes copy_data() - ContentCheck becomes DataCheck - InodeType::has_contents() becomes has_data() - ContentProblem becomes DataProblem, and ErrorKind::Content becomes ErrorKind::Data - UnsupportedContent becomes UnsupportedData, still inside ErrorKind::Unsupported The docs follow. The error messages stay as they are. Callers use the new names. No functional changes. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Signature and Contents are the signature object and the contents object of the specification, but the names read like a signature and like the contents of a file. Location is what the specification calls the source of a contents object. And ContentSource, DirectorySource and StreamSource aren't sources in the sense of the specification at all. They provide the data of the files when a manifest is applied. Rename them: - Signature becomes SignatureObject, which Object::Signature holds - Contents becomes ContentsObject - Location becomes ContentsSource, and the field `location` of a contents object becomes `source` - ContentSource becomes DataProvider - DirectorySource becomes DirectoryProvider - StreamSource becomes StreamProvider FileObject, RootObject, Object, MAX_CONTENTS and SourceProblem keep their names. The decoder's own marker for a contents object had the name ContentsObject already and is called ContentsElement now. Callers use the new names. Writer::signature() and Encoder::signature() take a &SignatureObject. No functional changes. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
FatSerial is a tuple struct with a public u32, so its representation is part of the API. Make the field private and give FatSerial a constructor and a getter instead, new() and get(), named like Mode::new(), Uuid::new() and NonZeroU32::get(). Both are const, so a serial can still be a constant. Callers write FatSerial::new(x) instead of FatSerial(x) and serial.get() instead of serial.0. While at it, give FatSerial a Debug of its own that prints the serial in hexadecimal, FatSerial(0x1234abcd), the way Mode prints its bits in octal. The derived one printed it in decimal, FatSerial(305441741) for 1234-ABCD. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
The specification has a boolean field for every flag: flagHidden,
flagSystem and flagArchive for the DOS attributes, and flagAppendOnly,
flagImmutable, flagNoAtime, flagNoCow and flagNoDump for the inode
flags. Callers get at them through a FlagStates and a mask:
object.dos_flags.get(DosFlags::HIDDEN)
object.inode.flags.put(InodeFlags::NO_COW, Some(false))
Give every one of these fields a getter and a setter of its own instead,
the way readOnly and the gpt flags have them. They take and return an
Option<bool>: Some(true) for a flag that is set, Some(false) for one
that is cleared, and None where the object says nothing about it:
object.flag_hidden()
object.inode.set_flag_no_cow(Some(false))
FileObject gets the three DOS attributes and InodeAttributes the five
inode flags. That's one pair for every entry of DosFlags::FIELDS and
InodeFlags::FIELDS, which a test checks.
The masks stay the representation, and every accessor is one get() or
put() on them. So filling in, the checks of the inode type and the
writer keep working on whole masks.
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
The objects of a manifest are structs with public fields. That makes how they're stored part of the API: the names of the owners are a Box<str>, the extended attributes a boxed BTreeMap, a partition a Box, and the flags a pair of masks. None of that could change after 0.1.0. It also lets a caller set a value the reader filled in without taking away the mark that says so, and the writer then leaves the new value out. So every public field becomes pub(crate), with a getter named after the field and a set_x() next to it. An optional field has one setter that takes an Option. ExternalFile only gets the getters, since only the crate makes one. The crate keeps using the fields itself, so the reader and the writer don't change. The getters hand out what's stored, but not how: &str for the names, an iterator for the extended attributes and one for the HTTP header fields, Option<&GptPartition> for the partition. The extended attributes can be looked up by name as well. Only the inode attributes of both objects and the identity of the file system get an x_mut(), since callers change those in place, and into_name() is the only into_x(). The flag masks leave the API together with the fields that held them. FlagStates, DosFlags and InodeFlags stay the representation behind the accessors of the flags, but they aren't exported anymore. What a reader filled in needs more care. A value that is set is not one the reader filled in, so its setter takes the mark away. But the sizes and hashes a reader fills in follow from other values: the size 0 from the hash of no data and the other way around, the size of a file from its contents object, and the sizes and hashes of a contents object from each other, from its literal and from having no encoding. Change one of those and what was filled in from it may be wrong. The writer then refuses an object that is fine, or a copy of the data goes by a size that no longer holds. So the setters of the size, the hash and the contents objects of a file object, and those of the sizes, the hashes, the encoding and the source of a contents object drop every size and hash the reader filled in on the same object: they become None and lose their mark. The next reader of the manifest fills them in again. The values a record gave are never dropped. readOnly only takes its own mark away when it is set. FilledIn::insert() and remove() become crate-private, since a caller only ever holds a copy of the marks. FileObject::filled_in() returns the marks of the object together with those of its inode attributes, which is what the writer leaves out. Callers write object.size() for object.size and object.set_size(x) for object.size = x, object.inode().mode() and object.inode_mut().set_mode() for the inode attributes, root.file_system_mut().set_label() for the identity, and use the flag accessors where they used the masks. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Directory and DataProvider are public traits, so any crate can implement them, and the crate could never add a method to either without breaking those implementations. Nobody needs to implement them: the only implementation outside of the crate was ufat's PinnedDirectory, which the previous commit brought into the crate. And a DirectoryProvider relies on its Directory to resolve names below the directory and nowhere else, which is easy to get wrong. So seal DataProvider with a private supertrait. The crate implements it for DirectoryProvider, StreamProvider and the providers of its tests, and the docs of the trait say that it is sealed. Directory goes further and becomes the crate's own, with OpenError. A sealed trait can still be called: generic code over D: Directory calls open() of whatever directory it is handed. PinnedDirectory is the only directory a caller has, so a public trait would only add API that can be called. DirectoryProvider takes a PinnedDirectory and loses its type parameter. A private Provider<D: Directory> does the work, and the tests use it with their directory in memory. A public struct bounded by a private trait would trip the private_bounds lint, which the newtype avoids. Opening the trait up again later is a minor change: a public Directory and DirectoryProvider<D = PinnedDirectory>. Callers that use DirectoryProvider::new() with a PinnedDirectory keep working as they are. Where they spell out the type, as DirectoryProvider<PinnedDirectory>, they drop the type parameter. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
uapi16 is built and tested on Linux, and built for Android. Nothing else is, and reading the data of the files next to a manifest needs Linux anyway. Rather than let it build somewhere nobody ever checked, refuse every target_os but linux and android with a compile_error!(). Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Mode::new() returns None for bits that are not a mode. But the mode of
the inode attributes is an Option as well, and there None means that
the object has no mode. So
inode.mode = Mode::new(0o100644);
builds and records no mode at all. That's an easy mistake to make: an
st_mode always carries the bits of the file type, so a mode handed
straight from stat() to Mode::new() is refused every time, and nothing
says so.
So make Mode::new() return Result<Mode, InvalidMode>, with InvalidMode
a new error like InvalidFatSerial and InvalidUuid. The line above
doesn't build anymore, and callers write
inode.mode = Some(Mode::new(bits)?);
The reader takes and refuses the same modes as before. The tests that
set a mode say Some() now.
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Name derefs to str. The Rust API guidelines keep Deref for smart pointers, and a Name isn't one. It's a string that was checked against the rules of the specification and that has an order of its own. Through Deref every method of str becomes a method of Name, and a Name can never stop being a str without breaking callers. So drop it before 0.1.0. as_str(), AsRef<str>, Display, the comparisons with str and &str, From<Name> for String and the TryFrom impls stay. A caller that used a Name as a str calls as_str() now. In the crate that's about thirty places, most of them in the error messages of content.rs. No functional changes. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Where a manifest records the feature of a flag, a file object without the field has the flag cleared, and the reader fills that in: flag_hidden() of such an object is Some(false). Under user-xattr the reader fills in that a file has no extended attributes. Unlike readOnly, neither is marked. So both look like values the object states: - stated_features() counts them, although its docs say that what a reader filled in doesn't count. - The writer refuses the object for a manifest that doesn't record the feature: "'flagHidden' is a field of the feature 'flag-hidden', which the manifest does not record". - Turned into a FIFO, the object is refused because a FIFO has no flags. - The root file object, set to the default features, is refused for its extendedAttributes. So mark them the way readOnly is marked. FilledIn notes the three DOS attributes, the five inode flags and extendedAttributes as well, which takes it from 8 to 16 bits. FlagStates keeps the marks of the flags next to what it states and what is set, and FileObject::filled_in() and InodeAttributes::filled_in() hand them out with the others. The checks of the writer only look at what the record of an object gives, and the writer leaves the marked values out, as it already did with cleared flags and empty extended attributes. A setter takes the mark away, like every setter does. stated_features() then does what its docs say. A flag that a caller clears is stated, and it still needs its feature: without the feature a missing field means that the flag is not known, so the writer would lose the cleared state. The docs of the flag setters say so now. Note that a manifest that states what its features imply, such as the empty extendedAttributes systemd-manifest writes for every object, doesn't come back with the same marks: the writer leaves those out, and a reader of what it wrote fills them in. The fixture test takes them as stated for the comparison, and the test of the writer whose object clears flags expects them back filled in. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Since the fields became private, a caller that changes an object a reader returned has the setters, x_mut() for the inode attributes and the identity of the file system, and a copy that it changes and sets back. That doesn't work everywhere: - The contents objects are only handed out as a slice. A copy of all of them, set back, drops the size and the hash a reader filled in from them. A copy of the data from a stream then fails with NoSize, although the contents objects still give the size. - The fields of a GPT partition are copied out and set back whole. - One extended attribute is changed by copying and setting back all of them. - The data of a literal, which can be 4 MiB, is only lent out. So do what Rust usually does with private fields. A value that nothing else follows from is changed in place: gpt_mut() hands out the fields of the partition the way inode_mut() hands out the inode attributes, and take_gpt() goes with set_gpt(). A value that other fields follow from gets no _mut(). It is taken out, changed and set back. take_contents() takes the contents objects out, together with the size and the hash a reader filled in from them. set_contents() fills in again what follows from the contents it gets, as the reader does: what each contents object says of its own data, and the size and the hash of the file, marked as filled in. It runs the code of the reader for that, which moves into a method of its own. What a reader filled in that no longer follows is dropped, and what the object states stays. Where the new contents contradict a size or a hash the object states nothing is filled in, and the writer refuses the object as before. The extended attributes get single entries the way HashMap has them: insert_user_xattr() and remove_user_xattr() return what insert() and remove() return, and take away the mark of extendedAttributes like every setter. ContentsObject::into_source() moves the source out of a contents object, so the data of a literal isn't copied. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Three things a consumer of the API missed: - Sha256Context only has Default, so its new() is spelled default(). Add new(), which does the same. - FilledIn only answers contains() for one field at a time. Add is_empty() and iter(), which hands out the fields it notes, so a caller sees what a reader filled in without asking for every field. Its Debug goes through iter() as well. - The docs of Writer don't show a copy of a manifest. Add one. The writer takes the root file object by reference, so it starts before the loop with what the reader returns, and the root needs no clone. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
A caller that writes a manifest for the files on disk has their metadata, and needs the inode type of each. Add TryFrom<FileType> for InodeType, with std's FileTypeExt for the types that are Unix's own: a regular file, a directory, a symbolic link, a FIFO, a character or a block device and a socket each have theirs, and anything else fails with UnknownInodeType. Its docs now say that it is a string or a file type that is not an inode type. The temporary directory of the tests of PinnedDirectory moves into the module the tests share, so the tests of object.rs make their files in one too. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
With the type of a file comes the rest of what its metadata says. Add FileObject::from_metadata(), which makes the file object for a file from its std::fs::Metadata, with the fields that the features it is given record and no others. Callers pass the features of the manifest, root.recorded_features(), so the writer refuses none of the fields it fills in for that manifest. It follows the rules for the fields of each inode type that the reader and the writer check: - the access mode, st_mode without the bits of the file type, on everything but a symbolic link - the user and the group ID of the owner - the modification time, where mTimeNSec can express it - the size of a regular file - the major and the minor number of a device node, which rustix splits st_rdev into It sets no hash, no target of a symbolic link and no inode token, which take more than the metadata of one file. A manifest that records symlink or hardlink, as the default features do, needs them from the caller: a writer refuses a symbolic link without its target there, and takes an object without a token for a file of no other name. The docs say so. The mode comes from a crate-private Mode::from_st_mode(), which drops the bits of the file type itself, so there is no error to handle. rustix becomes a dependency on Android as well, for major() and minor(), and pathrs stays on Linux. Cargo.lock doesn't change: on Android rustix only takes crates the lock has already. The test makes every type of file it can make without privileges and looks at /dev/null for a device node. It makes the objects with no features, the default ones and all of them, checks their fields, and writes them for a manifest that records the same features. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
A reader checks every object against the rules of the specification, but two checks need something only the caller knows: whether it relies on the order of the file objects, and what time it is. The crate docs don't say so. Name both, require_order() and check_validity(). Also say that the validity of a directory doesn't carry over to its entries. What is true of a directory is true of everything in it, but check_validity() of an entry only looks at the entry. A caller that uses an entry checks the directories it is in as well. The docs of FileObject::check_validity() already say that what is true of a directory is true of everything in it, so say there as well that the check looks at the object alone. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Name::new() holds the names the specification reserves for the manifest only against the whole name. "Uapi16Manifest.d/inside" is refused, since it begins with "Uapi16Manifest.", but "Uapi16Manifest/x" is a valid name. Its directory isn't: "Uapi16Manifest" is reserved, so no manifest can list it. A file below it can never be listed either, and the reader refuses one as Misplaced, since the object of its directory never comes right before it. So refuse a name whose first component is reserved, with NameProblem::Reserved like the reserved name itself. The reader then reports such a file as InvalidName, which says what is wrong with it. Name::is_reserved() goes by the first component as well, so it says what Name::new() refuses, and the docs of Name and of NameProblem::Reserved say so too. With that every directory a name is in has a valid name, which the next commit relies on. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Name::parent() returns a &str. A caller that wants to look the directory up, join a name to it or hand it on as a name has to make a Name of it with Name::new(), which checks it all over again, or is left with a string where it wants a Name. Since the previous commit every directory a name is in has a valid name. Each part of a name has valid text and valid components, and only its first component could be reserved, which Name::new() refuses for the whole name now. So parent() returns Option<Name>, and copies the part of the name in front of its last component into a Name without checking it again: None for the root, and Name::ROOT for a name at the top. The tests check that Name::new() takes every parent as it is, for every valid name they have and for the names they make up. The reader looks at the parent of an object only to name it in the error for an object that is out of place. It keeps doing that without a copy, through a crate-private parent_str(). file_name() keeps returning a &str. A component is not always a name: "a/Uapi16Manifest" is one, "Uapi16Manifest" isn't. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
FileSystemIdentity::volume_serial() returns the serial number together with the field it was taken from. Nobody calls it yet, and a caller that needs to know where the serial came from can look at whether fatSerial is set. That's all the rule of the specification says: fatSerial where it's given, and the first four bytes of fsUUID otherwise. So return Option<FatSerial> and leave the Field out of it. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Reader has get_ref() and get_mut(), but Writer only has get_ref(). A caller that wants to flush the output in between, or change something about it, can't get at it until finish() hands it back. Add Writer::get_mut(). Its docs say what those of std's BufWriter::get_mut() say, that writing to the output directly breaks what the writer writes. The writer holds nothing back: every method writes its whole record to the output before it returns, so the output always has the manifest up to the last record. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
DirectoryProvider reads the data of the files from a Directory, but the crate has no Directory a caller can use. ufat has one, PinnedDirectory. It resolves every name below the directory the way systemd's chase() does with a root: an absolute symbolic link starts over at the directory, ".." at the directory stays there, magic links are refused, and symbolic links are only followed when the caller asks for it. It does that with code of ufat's own, openat2() with RESOLVE_IN_ROOT and a walk by hand where openat2() isn't there, and that code needs unsafe, which uapi16 denies. So add PinnedDirectory to uapi16, built on pathrs, which resolves paths below a root the same way, and on rustix. new() and follow_symlinks() keep their signatures and what they do. A file is opened by resolving its name with Root::resolve() to an O_PATH handle, with ResolverFlags::NO_SYMLINKS unless symbolic links are followed. It then checks with fstat() that the handle is a regular file, and only then reopens it for reading with O_RDONLY|O_NONBLOCK|O_NOCTTY. So nothing but a regular file is ever opened, not even a FIFO a manifest names. The errors are those of the system calls, as before, and an error of pathrs itself becomes an io::Error of its own. pathrs refuses the empty path, which ufat took for the directory itself, so the empty name of the root is resolved as "." to keep that. The reopen goes through O_EMPTYPATH where the kernel has it, as it did in ufat: openat(fd, "", O_EMPTYPATH|...) reopens the handle without procfs, and Linux 7.2 has it. The flag is probed the way systemd's fd_reopen() does. An older kernel ignores it and fails the empty path with ENOENT, so the first ENOENT turns O_EMPTYPATH off for the process, unless it worked before. Where it is missing the handle is reopened with Handle::reopen() of pathrs, which goes through procfs and checks it on the way. That costs: opening a small file and reading it takes 2.4us and 9 system calls here with O_EMPTYPATH, as in ufat, and 38us and 53 system calls with Handle::reopen(). new() takes the directory as a descriptor the caller opened, which it can't check. Its docs say that it has to be a directory, since below anything else every file fails to open, the way pathrs documents Root::from_fd(). ufat's callers opened the directory themselves, but a caller that has a path gets open() now, which opens it with O_PATH|O_DIRECTORY|O_CLOEXEC like pathrs's Root::open(). So a path that isn't a directory fails right there with ENOTDIR, and the directory needs no read permission. The tests are those of ufat's chase(), with the names a manifest can have, and give the errors they gave there, below /proc too. They open their directories with open(). A new one reopens a pinned file both ways, after it was replaced under its name and after it was unlinked, and another one checks that open() takes a directory and nothing else. pathrs is empty on Android. So pathrs and rustix are dependencies on Linux only, and PinnedDirectory, Directory, DirectoryProvider and OpenError are there on Linux only as well, which their docs say. On Android the data of the files next to a manifest can't be read, and everything else works as before. The docs of what is there on Android as well mention DirectoryProvider and PinnedDirectory on Linux only, so that no link in them leads to something that isn't there. The tests of content.rs build their directories in memory for a DirectoryProvider, so they're for Linux only too. Cargo.lock gains 18 crates: pathrs and rustix with what they need, the build dependency of pathrs on tempfile with what that needs, and the crates for Windows and UEFI that some of them name, which nothing builds here. pathrs, errno and getrandom use libc 0.2, so the comment in Cargo.toml names them as a reason for the tests to stay on it as well. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
The docs of Features say that a manifest which doesn't list its
features records Features::DEFAULT, "what systemd-manifest make records
unless it is told otherwise". That ties the docs to the defaults of a
tool, and those move: systemd commit 1843e578d2 ("manifest-util: make
the user-xattr field opt-in") changed what make records by default.
What a manifest without features records is the specification's to
say, so say only that: device, gid, hardlink, mode, sha256, size,
symlink and uid. Nothing in the docs names a default of
systemd-manifest anymore.
No functional changes.
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Give the crate what crates.io shows for it: version 0.1.0, a description, the repository, keywords, categories, and a README for its page. The README says what the crate does for the people who use it, which checks are left to the caller, and which systems it supports: Linux 5.10 or newer, the minimum baseline of systemd, and Android. It also says what to do with a Rust older than what later releases of its dependencies need, such as sha2 from 0.11.1 on, and what the versions promise: a new minor release such as 0.2.0 may break callers, and releases within a minor version stay compatible. The version is set in the crate, since the workspace has none. The crate starts at 0.1.0 and not at 0.0.0. cargo takes every 0.0.z release as incompatible with every other one, so a caller that asks for 0.0.0 wouldn't even get 0.0.1. The crate no longer takes publish = false from the workspace. Nothing else in the workspace takes it either, and cargo 1.100 warns about a field of [workspace.package] that no crate uses. So the workspace drops it as well. The package that cargo publish uploads holds what is needed to build and test the crate: the sources with refused.jsonl, the tests with the manifests they read, the README and the license. cargo adds Cargo.toml and Cargo.lock on its own. The include list names them, so that nothing else that ends up in src/uapi16 goes into the package. The tests are part of it so that they can be run from the package as well. cargo publish --dry-run takes it, and the tests of the packaged crate pass on their own. 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 moves uapi16 out of ufat into a repository of its own and gets it
ready for 0.1.0 on crates.io.
The twelve commits on main are the history of src/uapi16 in ufat, taken
over with git filter-repo, so the code starts out exactly as ufat has it
at 49e4987. This series sits on top of that.
It lays the repository out the way ufat is laid out: a root workspace
with the crate in src/uapi16, which leaves room for a C library and a
tool later. It brings over the fixture tests with the manifests
systemd-manifest writes, and adds the license, a README, CI, the DCO and
the sign-off check.
Most of it changes the API before it goes out:
Mode::new() fails with InvalidMode instead of returning None.
component are refused, so Name::parent() can return a Name.
inherent instead of coming from the Digest and Finalize traits.
ExternalFile, ContentsObject, ContentsSource, SignatureObject,
DataProvider, DirectoryProvider, StreamProvider, DataCheck and
DataProblem.
x_mut(), take_x() and into_x() where Rust usually has them. A setter
drops what a reader filled in that no longer follows, and
set_contents() fills it in again. Each flag has an accessor of its
own, and a reader now marks the flags and the extended attributes it
fills in.
rustix, so uapi16 needs no unsafe for it. It reopens a file through
O_EMPTYPATH where the kernel has it and through pathrs otherwise.
DataProvider is sealed and Directory is private.
objects from the metadata of a file. Writer::get_mut(),
Sha256Context::new() and FilledIn::iter() fill gaps.
up to the caller.
The crate starts at 0.1.0. A new minor release may break the API, and
releases within one stay compatible. The README says so, and that uapi16
supports Linux 5.10 or newer, systemd's minimum baseline, and Android.
Every commit builds and passes clippy and the tests with rustc 1.85 and
the current stable, and for the cross targets, musl and i686.
ufat switches to the published crate in a PR of its own afterwards
(systemd/ufat#34).