Skip to main content

FileHeader

Struct FileHeader 

Source
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 of archive mode.

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: u32

The owner uid.

§gid: u32

The owner gid.

§mode: u32

The full logical st_mode.

The file-type bits must name a regular file or a symlink.

§symlink_target: String

The target of a symlink.

A regular file must have an empty target.

§xattrs: Xattrs

The extended attributes of the file.

Implementations§

Source§

impl FileHeader

Returns true if the mode names a symlink.

Source

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::Gvariant if data is not a normal-form GVariant of type (uuuusa(ayay)), or if the xattr array is not in normal form.
  • Error::InvalidFileHeader with the reason “rdev is not zero” if the rdev field is not 0.
  • Error::InvalidXattrs if 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::InvalidFileHeader with the reason “mode is not a regular file or symlink” if the file-type bits of the mode name a different type.
  • Error::InvalidFileHeader with the reason “regular file with a symlink target” if a regular file has a symlink target that is not empty.
Source

pub fn serialize(&self) -> Result<Vec<u8>>

Serializes the uncompressed header form (uuuusa(ayay)).

The output has no framing.

§Errors
  • Error::InvalidFileHeader with the reason “mode is not a regular file or symlink” if the file-type bits of mode name a different type.
  • Error::InvalidFileHeader with the reason “regular file with a symlink target” if a regular file has a symlink target that is not empty.
  • Error::Gvariant if the symlink target holds a NUL byte.
Source

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::Gvariant if data is not a normal-form GVariant of type (uuua(ayay)), or if the xattr array is not in normal form.
  • Error::InvalidXattrs if 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::InvalidFileHeader with 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.
Source

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::InvalidFileHeader with the reason “mode is not a regular file or symlink” if the file-type bits of mode name a different type.
  • Error::InvalidFileHeader with the reason “regular file with a symlink target” if a regular file has a symlink target that is not empty.
Source

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::Gvariant if data is not a normal-form GVariant of type (tuuuusa(ayay)), or if the xattr array is not in normal form.
  • Error::InvalidFileHeader with the reason “rdev is not zero” if the rdev field is not 0.
  • Error::InvalidXattrs if an xattr name is not in the stored form, or if the names are not in strictly increasing byte order.
  • Error::InvalidFileHeader with the reason “mode is not a regular file or symlink” if the file-type bits of the mode name a different type.
  • Error::InvalidFileHeader with the reason “regular file with a symlink target” if a regular file has a symlink target that is not empty.
Source

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::InvalidFileHeader with the reason “mode is not a regular file or symlink” if the file-type bits of mode name a different type.
  • Error::InvalidFileHeader with the reason “regular file with a symlink target” if a regular file has a symlink target that is not empty.
  • Error::Gvariant if the symlink target holds a NUL byte.
Source

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::InvalidFileHeader with the reason “mode is not a regular file or symlink” if the file-type bits of mode name a different type.
  • Error::InvalidFileHeader with the reason “regular file with a symlink target” if a regular file has a symlink target that is not empty.
  • Error::Gvariant if the symlink target holds a NUL byte.
  • Error::InvalidFileHeader with the reason “header exceeds the framing length limit” if the header is longer than u32::MAX bytes.
Source

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::InvalidFileHeader with the reason “mode is not a regular file or symlink” if the file-type bits of mode name a different type.
  • Error::InvalidFileHeader with the reason “regular file with a symlink target” if a regular file has a symlink target that is not empty.
  • Error::Gvariant if the symlink target holds a NUL byte.
  • Error::InvalidFileHeader with the reason “header exceeds the framing length limit” if the header is longer than u32::MAX bytes.

Trait Implementations§

Source§

impl Clone for FileHeader

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FileHeader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for FileHeader

Source§

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§

fn encode(&self, out: &mut Vec<u8>) -> Result<()>

Appends the normal-form bytes of self to out. Read more
Source§

impl GvType for FileHeader

The GVariant type of the uncompressed header form, (uuuusa(ayay)).

Source§

const SIGNATURE: &'static str = "(uuuusa(ayay))"

The GVariant type signature, or "" for a container type. Read more
Source§

const ALIGNMENT: usize = 4

The alignment of the serialized form, in bytes.
Source§

const FIXED_SIZE: Option<usize> = None

The serialized size, or None for a variable-size type.
Source§

impl PartialEq for FileHeader

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FileHeader

Auto Trait Implementations§

§

impl Forget for FileHeader

§

impl Freeze for FileHeader

§

impl Move for FileHeader

§

impl RefUnwindSafe for FileHeader

§

impl Send for FileHeader
where RawVecInner: Send,

§

impl Sync for FileHeader
where RawVecInner: Sync,

§

impl Unpin for FileHeader
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for FileHeader

§

impl UnwindSafe for FileHeader
where RawVecInner: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.