pub struct FileHeader {
pub uid: u32,
pub gid: u32,
pub mode: u32,
pub symlink_target: String,
pub xattrs: Xattrs,
}Expand description
The metadata of one file content object, common to all header wire forms.
§Wire forms
The header has two GVariant forms:
- The uncompressed form
(uuuusa(ayay))holds the uid, the gid, the mode, the rdev, the symlink target, and the xattrs. The content stream of a bare mode holds this form. The content checksum uses this form. - The archive form
(tuuuusa(ayay))holds the uncompressed payload size first, then the fields of the uncompressed form. This form is the on-disk form ofarchivemode.
The scalar fields (uid, gid, mode, rdev, and size) are big-endian in the
serialized bytes. A FileHeader holds them in host order, and the parse and
serialize functions convert them. The serialize functions write an rdev of
0, and the parse functions refuse an rdev that is not 0.
parse_stat_metadata reads a third
layout, the user.ostreemeta xattr of a bare-user file object.
Fields§
§uid: u32The owner uid.
gid: u32The owner gid.
mode: u32The full logical st_mode.
The file-type bits must name a regular file or a symlink.
symlink_target: StringThe target of a symlink.
A regular file must have an empty target.
xattrs: XattrsThe extended attributes of the file.
Implementations§
Source§impl FileHeader
impl FileHeader
Sourcepub fn is_symlink(&self) -> bool
pub fn is_symlink(&self) -> bool
Returns true if the mode names a symlink.
Sourcepub fn parse(data: &[u8]) -> Result<FileHeader>
pub fn parse(data: &[u8]) -> Result<FileHeader>
Parses the uncompressed header form (uuuusa(ayay)).
data holds the header bytes with no framing. split_framed removes
the framing.
§Errors
Error::Gvariantifdatais not a normal-form GVariant of type(uuuusa(ayay)), or if the xattr array is not in normal form.Error::InvalidFileHeaderwith the reason “rdev is not zero” if the rdev field is not 0.Error::InvalidXattrsif an xattr name is not in the stored form, or if the names are not in strictly increasing byte order. The stored form has one trailing NUL, no interior NUL, and a prefix that is not empty.Error::InvalidFileHeaderwith the reason “mode is not a regular file or symlink” if the file-type bits of the mode name a different type.Error::InvalidFileHeaderwith the reason “regular file with a symlink target” if a regular file has a symlink target that is not empty.
Sourcepub fn serialize(&self) -> Result<Vec<u8>>
pub fn serialize(&self) -> Result<Vec<u8>>
Serializes the uncompressed header form (uuuusa(ayay)).
The output has no framing.
§Errors
Error::InvalidFileHeaderwith the reason “mode is not a regular file or symlink” if the file-type bits ofmodename a different type.Error::InvalidFileHeaderwith the reason “regular file with a symlink target” if a regular file has a symlink target that is not empty.Error::Gvariantif the symlink target holds a NUL byte.
Sourcepub fn parse_stat_metadata(data: &[u8]) -> Result<FileHeader>
pub fn parse_stat_metadata(data: &[u8]) -> Result<FileHeader>
Parses the stat-metadata form (uuua(ayay)).
The form holds the uid, the gid, and the full st_mode, big-endian,
then the sorted xattr array. It is the layout of a dirmeta object. It is
also the layout of the user.ostreemeta xattr of a .file object in
bare-user mode.
The form has no rdev field and no symlink-target field, so the returned
header has an empty target. A bare-user symlink has a symlink
st_mode in this form and keeps its target in the file content. The
caller reads the target from the file content.
§Errors
Error::Gvariantifdatais not a normal-form GVariant of type(uuua(ayay)), or if the xattr array is not in normal form.Error::InvalidXattrsif an xattr name is not in the stored form, or if the names are not in strictly increasing byte order. The stored form has one trailing NUL, no interior NUL, and a prefix that is not empty.Error::InvalidFileHeaderwith the reason “mode is not a regular file or symlink” if the file-type bits of the mode name a different type. The function refuses a directory mode, so it does not read a dirmeta object.
Sourcepub fn serialize_stat_metadata(&self) -> Result<Vec<u8>>
pub fn serialize_stat_metadata(&self) -> Result<Vec<u8>>
Serializes the stat-metadata form (uuua(ayay)).
parse_stat_metadata describes the form
and reads the output back. The output holds no symlink target, so a
symlink keeps only its S_IFLNK mode here.
§Errors
Error::InvalidFileHeaderwith the reason “mode is not a regular file or symlink” if the file-type bits ofmodename a different type.Error::InvalidFileHeaderwith the reason “regular file with a symlink target” if a regular file has a symlink target that is not empty.
Sourcepub fn parse_archive(data: &[u8]) -> Result<(FileHeader, u64)>
pub fn parse_archive(data: &[u8]) -> Result<(FileHeader, u64)>
Parses the archive header form (tuuuusa(ayay)).
The function returns the header and the uncompressed payload size.
data holds the header bytes with no framing.
§Errors
Error::Gvariantifdatais not a normal-form GVariant of type(tuuuusa(ayay)), or if the xattr array is not in normal form.Error::InvalidFileHeaderwith the reason “rdev is not zero” if the rdev field is not 0.Error::InvalidXattrsif an xattr name is not in the stored form, or if the names are not in strictly increasing byte order.Error::InvalidFileHeaderwith the reason “mode is not a regular file or symlink” if the file-type bits of the mode name a different type.Error::InvalidFileHeaderwith the reason “regular file with a symlink target” if a regular file has a symlink target that is not empty.
Sourcepub fn serialize_archive(&self, uncompressed_size: u64) -> Result<Vec<u8>>
pub fn serialize_archive(&self, uncompressed_size: u64) -> Result<Vec<u8>>
Serializes the archive header form (tuuuusa(ayay)).
uncompressed_size is the size of the payload before compression. The
output has no framing.
§Errors
Error::InvalidFileHeaderwith the reason “mode is not a regular file or symlink” if the file-type bits ofmodename a different type.Error::InvalidFileHeaderwith the reason “regular file with a symlink target” if a regular file has a symlink target that is not empty.Error::Gvariantif the symlink target holds a NUL byte.
Sourcepub fn write_framed(&self, out: &mut Vec<u8>) -> Result<()>
pub fn write_framed(&self, out: &mut Vec<u8>) -> Result<()>
Writes the framed uncompressed header form into out.
The bytes equal frame(&self.serialize()?). The function clears out
first. A caller that uses one buffer for all its headers grows out
only for a header that is longer than each header before it. After an
error, the content of out is unspecified.
§Errors
Error::InvalidFileHeaderwith the reason “mode is not a regular file or symlink” if the file-type bits ofmodename a different type.Error::InvalidFileHeaderwith the reason “regular file with a symlink target” if a regular file has a symlink target that is not empty.Error::Gvariantif the symlink target holds a NUL byte.Error::InvalidFileHeaderwith the reason “header exceeds the framing length limit” if the header is longer thanu32::MAXbytes.
Sourcepub fn write_framed_archive(
&self,
uncompressed_size: u64,
out: &mut Vec<u8>,
) -> Result<()>
pub fn write_framed_archive( &self, uncompressed_size: u64, out: &mut Vec<u8>, ) -> Result<()>
Writes the framed archive header form into out.
The bytes equal frame(&self.serialize_archive(uncompressed_size)?).
The buffer rules of write_framed apply.
§Errors
Error::InvalidFileHeaderwith the reason “mode is not a regular file or symlink” if the file-type bits ofmodename a different type.Error::InvalidFileHeaderwith the reason “regular file with a symlink target” if a regular file has a symlink target that is not empty.Error::Gvariantif the symlink target holds a NUL byte.Error::InvalidFileHeaderwith the reason “header exceeds the framing length limit” if the header is longer thanu32::MAXbytes.
Trait Implementations§
Source§impl Clone for FileHeader
impl Clone for FileHeader
Source§impl Debug for FileHeader
impl Debug for FileHeader
impl Eq for FileHeader
Source§impl GvEncode for FileHeader
Writes the uncompressed header form with an rdev of 0.
impl GvEncode for FileHeader
Writes the uncompressed header form with an rdev of 0.
The encoder does not check the mode or the symlink target.
FileHeader::serialize and FileHeader::write_framed check them.
Source§impl GvType for FileHeader
The GVariant type of the uncompressed header form, (uuuusa(ayay)).
impl GvType for FileHeader
The GVariant type of the uncompressed header form, (uuuusa(ayay)).