From 5e50c606b0589f04f2992d9367967a7b02ffcfa0 Mon Sep 17 00:00:00 2001 From: Christian Ebner Date: Fri, 2 Aug 2019 15:19:34 +0200 Subject: [PATCH] pxar: cleanup: s/CA_FORMAT/PXAR/g and s/CaFormat/Pxar/g Signed-off-by: Christian Ebner --- src/pxar/decoder.rs | 28 ++--- src/pxar/dir_buffer.rs | 4 +- src/pxar/encoder.rs | 108 +++++++++---------- src/pxar/format_definition.rs | 147 +++++++++++++------------- src/pxar/sequential_decoder.rs | 182 ++++++++++++++++----------------- src/tools/xattr.rs | 16 +-- 6 files changed, 243 insertions(+), 242 deletions(-) diff --git a/src/pxar/decoder.rs b/src/pxar/decoder.rs index da7f1121..6bb160d9 100644 --- a/src/pxar/decoder.rs +++ b/src/pxar/decoder.rs @@ -17,7 +17,7 @@ pub struct CaDirectoryEntry { start: u64, end: u64, pub filename: OsString, - pub entry: CaFormatEntry, + pub entry: PxarEntry, } // This one needs Read+Seek @@ -27,7 +27,7 @@ pub struct Decoder<'a, R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> { root_end: u64, } -const HEADER_SIZE: u64 = std::mem::size_of::() as u64; +const HEADER_SIZE: u64 = std::mem::size_of::() as u64; impl <'a, R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> Decoder<'a, R, F> { @@ -47,7 +47,7 @@ impl <'a, R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> Decoder<'a, R, F> { start: self.root_start, end: self.root_end, filename: OsString::new(), // Empty - entry: CaFormatEntry { + entry: PxarEntry { mode: 0, flags: 0, uid: 0, @@ -80,9 +80,9 @@ impl <'a, R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> Decoder<'a, R, F> { self.seek(SeekFrom::Start(start))?; - let head: CaFormatHeader = self.inner.read_item()?; + let head: PxarHeader = self.inner.read_item()?; - if head.htype != CA_FORMAT_FILENAME { + if head.htype != PXAR_FILENAME { bail!("wrong filename header type for object [{}..{}]", start, end); } @@ -90,9 +90,9 @@ impl <'a, R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> Decoder<'a, R, F> { let filename = self.inner.read_filename(head.size)?; - let head: CaFormatHeader = self.inner.read_item()?; - check_ca_header::(&head, CA_FORMAT_ENTRY)?; - let entry: CaFormatEntry = self.inner.read_item()?; + let head: PxarHeader = self.inner.read_item()?; + check_ca_header::(&head, PXAR_ENTRY)?; + let entry: PxarEntry = self.inner.read_item()?; Ok(CaDirectoryEntry { start: entry_start, @@ -104,7 +104,7 @@ impl <'a, R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> Decoder<'a, R, F> { pub fn list_dir(&mut self, dir: &CaDirectoryEntry) -> Result, Error> { - const GOODBYE_ITEM_SIZE: u64 = std::mem::size_of::() as u64; + const GOODBYE_ITEM_SIZE: u64 = std::mem::size_of::() as u64; let start = dir.start; let end = dir.end; @@ -117,9 +117,9 @@ impl <'a, R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> Decoder<'a, R, F> { self.seek(SeekFrom::Start(end - GOODBYE_ITEM_SIZE))?; - let item: CaFormatGoodbyeItem = self.inner.read_item()?; + let item: PxarGoodbyeItem = self.inner.read_item()?; - if item.hash != CA_FORMAT_GOODBYE_TAIL_MARKER { + if item.hash != PXAR_GOODBYE_TAIL_MARKER { bail!("missing goodbye tail marker for object [{}..{}]", start, end); } @@ -141,9 +141,9 @@ impl <'a, R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> Decoder<'a, R, F> { } self.seek(SeekFrom::Start(goodbye_start))?; - let head: CaFormatHeader = self.inner.read_item()?; + let head: PxarHeader = self.inner.read_item()?; - if head.htype != CA_FORMAT_GOODBYE { + if head.htype != PXAR_GOODBYE { bail!("wrong goodbye table header type for entry [{}..{}]", start, end); } @@ -154,7 +154,7 @@ impl <'a, R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> Decoder<'a, R, F> { let mut range_list = Vec::new(); for i in 0..goodbye_inner_size/GOODBYE_ITEM_SIZE { - let item: CaFormatGoodbyeItem = self.inner.read_item()?; + let item: PxarGoodbyeItem = self.inner.read_item()?; if item.offset > (goodbye_start - start) { bail!("goodbye entry {} offset out of range [{}..{}] {} {} {}", diff --git a/src/pxar/dir_buffer.rs b/src/pxar/dir_buffer.rs index c6cfde34..54a51284 100644 --- a/src/pxar/dir_buffer.rs +++ b/src/pxar/dir_buffer.rs @@ -12,7 +12,7 @@ use nix::NixPath; pub struct PxarDir { pub filename: OsString, - pub entry: CaFormatEntry, + pub entry: PxarEntry, pub attr: PxarAttributes, pub dir: Option, } @@ -23,7 +23,7 @@ pub struct PxarDirBuf { } impl PxarDir { - pub fn new(filename: &OsStr, entry: CaFormatEntry, attr: PxarAttributes) -> Self { + pub fn new(filename: &OsStr, entry: PxarEntry, attr: PxarAttributes) -> Self { Self { filename: filename.to_os_string(), entry, diff --git a/src/pxar/encoder.rs b/src/pxar/encoder.rs index eee26e9a..6271b8b1 100644 --- a/src/pxar/encoder.rs +++ b/src/pxar/encoder.rs @@ -166,8 +166,8 @@ impl <'a, W: Write> Encoder<'a, W> { fn write_header(&mut self, htype: u64, size: u64) -> Result<(), Error> { - let size = size + (std::mem::size_of::() as u64); - self.write_item(CaFormatHeader { size, htype })?; + let size = size + (std::mem::size_of::() as u64); + self.write_item(PxarHeader { size, htype })?; Ok(()) } @@ -175,13 +175,13 @@ impl <'a, W: Write> Encoder<'a, W> { fn write_filename(&mut self, name: &CStr) -> Result<(), Error> { let buffer = name.to_bytes_with_nul(); - self.write_header(CA_FORMAT_FILENAME, buffer.len() as u64)?; + self.write_header(PXAR_FILENAME, buffer.len() as u64)?; self.write(buffer)?; Ok(()) } - fn create_entry(&self, stat: &FileStat) -> Result { + fn create_entry(&self, stat: &FileStat) -> Result { let mode = if is_symlink(&stat) { (libc::S_IFLNK | 0o777) as u64 @@ -195,7 +195,7 @@ impl <'a, W: Write> Encoder<'a, W> { } - let entry = CaFormatEntry { + let entry = PxarEntry { mode: mode, flags: 0, uid: stat.st_uid as u64, @@ -206,7 +206,7 @@ impl <'a, W: Write> Encoder<'a, W> { Ok(entry) } - fn read_chattr(&self, fd: RawFd, entry: &mut CaFormatEntry) -> Result<(), Error> { + fn read_chattr(&self, fd: RawFd, entry: &mut PxarEntry) -> Result<(), Error> { let mut attr: usize = 0; @@ -224,7 +224,7 @@ impl <'a, W: Write> Encoder<'a, W> { Ok(()) } - fn read_fat_attr(&self, fd: RawFd, magic: i64, entry: &mut CaFormatEntry) -> Result<(), Error> { + fn read_fat_attr(&self, fd: RawFd, magic: i64, entry: &mut PxarEntry) -> Result<(), Error> { use fs::magic::*; if magic != MSDOS_SUPER_MAGIC && magic != FUSE_SUPER_MAGIC { @@ -257,7 +257,7 @@ impl <'a, W: Write> Encoder<'a, W> { (self.feature_flags & self.fs_feature_flags & feature_flags) != 0 } - fn read_xattrs(&self, fd: RawFd, stat: &FileStat) -> Result<(Vec, Option), Error> { + fn read_xattrs(&self, fd: RawFd, stat: &FileStat) -> Result<(Vec, Option), Error> { let mut xattrs = Vec::new(); let mut fcaps = None; @@ -295,12 +295,12 @@ impl <'a, W: Write> Encoder<'a, W> { if xattr::is_security_capability(&name) { if self.has_features(flags::WITH_FCAPS) { // fcaps are stored in own format within the archive - fcaps = Some(CaFormatFCaps { + fcaps = Some(PxarFCaps { data: value, }); } } else if self.has_features(flags::WITH_XATTRS) { - xattrs.push(CaFormatXAttr { + xattrs.push(PxarXAttr { name: name.to_vec(), value: value, }); @@ -366,13 +366,13 @@ impl <'a, W: Write> Encoder<'a, W> { acl::ACL_OTHER => other_permissions = Some(permissions), acl::ACL_MASK => mask_permissions = Some(permissions), acl::ACL_USER => { - acl_user.push(CaFormatACLUser { + acl_user.push(PxarACLUser { uid: entry.get_qualifier()?, permissions: permissions, }); }, acl::ACL_GROUP => { - acl_group.push(CaFormatACLGroup { + acl_group.push(PxarACLGroup { gid: entry.get_qualifier()?, permissions: permissions, }); @@ -391,7 +391,7 @@ impl <'a, W: Write> Encoder<'a, W> { // Only in that case we need to store the group permissions, // in the other cases they are identical to the stat group permissions. if let (Some(gop), Some(_)) = (group_obj_permissions, mask_permissions) { - acl_group_obj = Some(CaFormatACLGroupObj { + acl_group_obj = Some(PxarACLGroupObj { permissions: gop, }); } @@ -402,7 +402,7 @@ impl <'a, W: Write> Encoder<'a, W> { other_permissions != None || mask_permissions != None { - acl_default = Some(CaFormatACLDefault { + acl_default = Some(PxarACLDefault { // The value is set to UINT64_MAX as placeholder if one // of the permissions is not set user_obj_permissions: user_obj_permissions.unwrap_or(std::u64::MAX), @@ -424,7 +424,7 @@ impl <'a, W: Write> Encoder<'a, W> { } /// Read the quota project id for an inode, supported on ext4/XFS/FUSE/ZFS filesystems - fn read_quota_project_id(&self, fd: RawFd, magic: i64, stat: &FileStat) -> Result, Error> { + fn read_quota_project_id(&self, fd: RawFd, magic: i64, stat: &FileStat) -> Result, Error> { if !(is_directory(&stat) || is_reg_file(&stat)) { return Ok(None); } @@ -459,24 +459,24 @@ impl <'a, W: Write> Encoder<'a, W> { if projid == 0 { return Ok(None); } else { - return Ok(Some(CaFormatQuotaProjID { projid })); + return Ok(Some(PxarQuotaProjID { projid })); } }, _ => return Ok(None), } } - fn write_entry(&mut self, entry: CaFormatEntry) -> Result<(), Error> { + fn write_entry(&mut self, entry: PxarEntry) -> Result<(), Error> { - self.write_header(CA_FORMAT_ENTRY, std::mem::size_of::() as u64)?; + self.write_header(PXAR_ENTRY, std::mem::size_of::() as u64)?; self.write_item(entry)?; Ok(()) } - fn write_xattr(&mut self, xattr: CaFormatXAttr) -> Result<(), Error> { + fn write_xattr(&mut self, xattr: PxarXAttr) -> Result<(), Error> { let size = xattr.name.len() + xattr.value.len() + 1; // +1 for '\0' separating name and value - self.write_header(CA_FORMAT_XATTR, size as u64)?; + self.write_header(PXAR_XATTR, size as u64)?; self.write(xattr.name.as_slice())?; self.write(&[0])?; self.write(xattr.value.as_slice())?; @@ -484,74 +484,74 @@ impl <'a, W: Write> Encoder<'a, W> { Ok(()) } - fn write_fcaps(&mut self, fcaps: Option) -> Result<(), Error> { + fn write_fcaps(&mut self, fcaps: Option) -> Result<(), Error> { if let Some(fcaps) = fcaps { let size = fcaps.data.len(); - self.write_header(CA_FORMAT_FCAPS, size as u64)?; + self.write_header(PXAR_FCAPS, size as u64)?; self.write(fcaps.data.as_slice())?; } Ok(()) } - fn write_acl_user(&mut self, acl_user: CaFormatACLUser) -> Result<(), Error> { - self.write_header(CA_FORMAT_ACL_USER, std::mem::size_of::() as u64)?; + fn write_acl_user(&mut self, acl_user: PxarACLUser) -> Result<(), Error> { + self.write_header(PXAR_ACL_USER, std::mem::size_of::() as u64)?; self.write_item(acl_user)?; Ok(()) } - fn write_acl_group(&mut self, acl_group: CaFormatACLGroup) -> Result<(), Error> { - self.write_header(CA_FORMAT_ACL_GROUP, std::mem::size_of::() as u64)?; + fn write_acl_group(&mut self, acl_group: PxarACLGroup) -> Result<(), Error> { + self.write_header(PXAR_ACL_GROUP, std::mem::size_of::() as u64)?; self.write_item(acl_group)?; Ok(()) } - fn write_acl_group_obj(&mut self, acl_group_obj: CaFormatACLGroupObj) -> Result<(), Error> { - self.write_header(CA_FORMAT_ACL_GROUP_OBJ, std::mem::size_of::() as u64)?; + fn write_acl_group_obj(&mut self, acl_group_obj: PxarACLGroupObj) -> Result<(), Error> { + self.write_header(PXAR_ACL_GROUP_OBJ, std::mem::size_of::() as u64)?; self.write_item(acl_group_obj)?; Ok(()) } - fn write_acl_default(&mut self, acl_default: CaFormatACLDefault) -> Result<(), Error> { - self.write_header(CA_FORMAT_ACL_DEFAULT, std::mem::size_of::() as u64)?; + fn write_acl_default(&mut self, acl_default: PxarACLDefault) -> Result<(), Error> { + self.write_header(PXAR_ACL_DEFAULT, std::mem::size_of::() as u64)?; self.write_item(acl_default)?; Ok(()) } - fn write_acl_default_user(&mut self, acl_default_user: CaFormatACLUser) -> Result<(), Error> { - self.write_header(CA_FORMAT_ACL_DEFAULT_USER, std::mem::size_of::() as u64)?; + fn write_acl_default_user(&mut self, acl_default_user: PxarACLUser) -> Result<(), Error> { + self.write_header(PXAR_ACL_DEFAULT_USER, std::mem::size_of::() as u64)?; self.write_item(acl_default_user)?; Ok(()) } - fn write_acl_default_group(&mut self, acl_default_group: CaFormatACLGroup) -> Result<(), Error> { - self.write_header(CA_FORMAT_ACL_DEFAULT_GROUP, std::mem::size_of::() as u64)?; + fn write_acl_default_group(&mut self, acl_default_group: PxarACLGroup) -> Result<(), Error> { + self.write_header(PXAR_ACL_DEFAULT_GROUP, std::mem::size_of::() as u64)?; self.write_item(acl_default_group)?; Ok(()) } - fn write_quota_project_id(&mut self, projid: CaFormatQuotaProjID) -> Result<(), Error> { - self.write_header(CA_FORMAT_QUOTA_PROJID, std::mem::size_of::() as u64)?; + fn write_quota_project_id(&mut self, projid: PxarQuotaProjID) -> Result<(), Error> { + self.write_header(PXAR_QUOTA_PROJID, std::mem::size_of::() as u64)?; self.write_item(projid)?; Ok(()) } - fn write_goodbye_table(&mut self, goodbye_offset: usize, goodbye_items: &mut [CaFormatGoodbyeItem]) -> Result<(), Error> { + fn write_goodbye_table(&mut self, goodbye_offset: usize, goodbye_items: &mut [PxarGoodbyeItem]) -> Result<(), Error> { goodbye_items.sort_unstable_by(|a, b| a.hash.cmp(&b.hash)); let item_count = goodbye_items.len(); - let goodbye_table_size = (item_count + 1)*std::mem::size_of::(); + let goodbye_table_size = (item_count + 1)*std::mem::size_of::(); - self.write_header(CA_FORMAT_GOODBYE, goodbye_table_size as u64)?; + self.write_header(PXAR_GOODBYE, goodbye_table_size as u64)?; if self.file_copy_buffer.len() < goodbye_table_size { let need = goodbye_table_size - self.file_copy_buffer.len(); @@ -563,19 +563,19 @@ impl <'a, W: Write> Encoder<'a, W> { copy_binary_search_tree(item_count, |s, d| { let item = &goodbye_items[s]; - let offset = d*std::mem::size_of::(); - let dest = crate::tools::map_struct_mut::(&mut buffer[offset..]).unwrap(); + let offset = d*std::mem::size_of::(); + let dest = crate::tools::map_struct_mut::(&mut buffer[offset..]).unwrap(); dest.offset = u64::to_le(item.offset); dest.size = u64::to_le(item.size); dest.hash = u64::to_le(item.hash); }); - // append CaFormatGoodbyeTail as last item - let offset = item_count*std::mem::size_of::(); - let dest = crate::tools::map_struct_mut::(&mut buffer[offset..]).unwrap(); + // append PxarGoodbyeTail as last item + let offset = item_count*std::mem::size_of::(); + let dest = crate::tools::map_struct_mut::(&mut buffer[offset..]).unwrap(); dest.offset = u64::to_le(goodbye_offset as u64); - dest.size = u64::to_le((goodbye_table_size + std::mem::size_of::()) as u64); - dest.hash = u64::to_le(CA_FORMAT_GOODBYE_TAIL_MARKER); + dest.size = u64::to_le((goodbye_table_size + std::mem::size_of::()) as u64); + dest.hash = u64::to_le(PXAR_GOODBYE_TAIL_MARKER); self.flush_copy_buffer(goodbye_table_size)?; @@ -842,7 +842,7 @@ impl <'a, W: Write> Encoder<'a, W> { let end_pos = self.writer_pos; - goodbye_items.push(CaFormatGoodbyeItem { + goodbye_items.push(PxarGoodbyeItem { offset: start_pos as u64, size: (end_pos - start_pos) as u64, hash: compute_goodbye_hash(filename.to_bytes()), @@ -910,13 +910,13 @@ impl <'a, W: Write> Encoder<'a, W> { if !include_payload { eprintln!("skip content: {:?}", self.full_path()); - self.write_header(CA_FORMAT_PAYLOAD, 0)?; + self.write_header(PXAR_PAYLOAD, 0)?; return Ok(()); } let size = stat.st_size as u64; - self.write_header(CA_FORMAT_PAYLOAD, size)?; + self.write_header(PXAR_PAYLOAD, size)?; let mut pos: u64 = 0; loop { @@ -960,8 +960,8 @@ impl <'a, W: Write> Encoder<'a, W> { //println!("encode_device: {:?} {} {} {}", self.full_path(), stat.st_rdev, major, minor); - self.write_header(CA_FORMAT_DEVICE, std::mem::size_of::() as u64)?; - self.write_item(CaFormatDevice { major, minor })?; + self.write_header(PXAR_DEVICE, std::mem::size_of::() as u64)?; + self.write_item(PxarDevice { major, minor })?; Ok(()) } @@ -983,7 +983,7 @@ impl <'a, W: Write> Encoder<'a, W> { let entry = self.create_entry(&stat)?; self.write_entry(entry)?; - self.write_header(CA_FORMAT_SYMLINK, target.len() as u64)?; + self.write_header(PXAR_SYMLINK, target.len() as u64)?; self.write(target)?; Ok(()) @@ -1041,12 +1041,12 @@ impl <'a, W: Write> Encoder<'a, W> { if !include_payload { eprintln!("skip content: {:?}", self.full_path()); - self.write_header(CA_FORMAT_PAYLOAD, 0)?; + self.write_header(PXAR_PAYLOAD, 0)?; return Ok(()); } let size = content.len(); - self.write_header(CA_FORMAT_PAYLOAD, size as u64)?; + self.write_header(PXAR_PAYLOAD, size as u64)?; self.writer.write_all(content)?; self.writer_pos += size; diff --git a/src/pxar/format_definition.rs b/src/pxar/format_definition.rs index 13d5e043..7030b58f 100644 --- a/src/pxar/format_definition.rs +++ b/src/pxar/format_definition.rs @@ -3,7 +3,7 @@ //! Please note the all values are stored in little endian ordering. //! //! The Archive contains a list of items. Each item starts with a -//! `CaFormatHeader`, followed by the item data. +//! `PxarHeader`, followed by the item data. use failure::*; use std::cmp::Ordering; @@ -11,43 +11,44 @@ use endian_trait::Endian; use siphasher::sip::SipHasher24; -pub const CA_FORMAT_ENTRY: u64 = 0x1396fabcea5bbb51; -pub const CA_FORMAT_FILENAME: u64 = 0x6dbb6ebcb3161f0b; -pub const CA_FORMAT_SYMLINK: u64 = 0x664a6fb6830e0d6c; -pub const CA_FORMAT_DEVICE: u64 = 0xac3dace369dfe643; -pub const CA_FORMAT_XATTR: u64 = 0xb8157091f80bc486; -pub const CA_FORMAT_ACL_USER: u64 = 0x297dc88b2ef12faf; -pub const CA_FORMAT_ACL_GROUP: u64 = 0x36f2acb56cb3dd0b; -pub const CA_FORMAT_ACL_GROUP_OBJ: u64 = 0x23047110441f38f3; -pub const CA_FORMAT_ACL_DEFAULT: u64 = 0xfe3eeda6823c8cd0; -pub const CA_FORMAT_ACL_DEFAULT_USER: u64 = 0xbdf03df9bd010a91; -pub const CA_FORMAT_ACL_DEFAULT_GROUP: u64 = 0xa0cb1168782d1f51; -pub const CA_FORMAT_FCAPS: u64 = 0xf7267db0afed0629; -pub const CA_FORMAT_QUOTA_PROJID:u64 = 0x161baf2d8772a72b; - -// compute_goodbye_hash(b"__PROXMOX_FORMAT_HARDLINK__"); -pub const PXAR_FORMAT_HARDLINK: u64 = 0x2c5e06f634f65b86; - -pub const CA_FORMAT_PAYLOAD: u64 = 0x8b9e1d93d6dcffc9; - -pub const CA_FORMAT_GOODBYE: u64 = 0xdfd35c5e8327c403; -/* The end marker used in the GOODBYE object */ -pub const CA_FORMAT_GOODBYE_TAIL_MARKER: u64 = 0x57446fa533702943; +/// Header types identifying items stored in the archive +pub const PXAR_ENTRY: u64 = 0x1396fabcea5bbb51; +pub const PXAR_FILENAME: u64 = 0x6dbb6ebcb3161f0b; +pub const PXAR_SYMLINK: u64 = 0x664a6fb6830e0d6c; +pub const PXAR_DEVICE: u64 = 0xac3dace369dfe643; +pub const PXAR_XATTR: u64 = 0xb8157091f80bc486; +pub const PXAR_ACL_USER: u64 = 0x297dc88b2ef12faf; +pub const PXAR_ACL_GROUP: u64 = 0x36f2acb56cb3dd0b; +pub const PXAR_ACL_GROUP_OBJ: u64 = 0x23047110441f38f3; +pub const PXAR_ACL_DEFAULT: u64 = 0xfe3eeda6823c8cd0; +pub const PXAR_ACL_DEFAULT_USER: u64 = 0xbdf03df9bd010a91; +pub const PXAR_ACL_DEFAULT_GROUP: u64 = 0xa0cb1168782d1f51; +pub const PXAR_FCAPS: u64 = 0xf7267db0afed0629; +pub const PXAR_QUOTA_PROJID:u64 = 0x161baf2d8772a72b; +/// Marks item as hardlink +/// compute_goodbye_hash(b"__PROXMOX_FORMAT_HARDLINK__"); +pub const PXAR_FORMAT_HARDLINK: u64 = 0x2c5e06f634f65b86; +/// Marks the beginnig of the payload (actual content) of regular files +pub const PXAR_PAYLOAD: u64 = 0x8b9e1d93d6dcffc9; +/// Marks item as entry of goodbye table +pub const PXAR_GOODBYE: u64 = 0xdfd35c5e8327c403; +/// The end marker used in the GOODBYE object +pub const PXAR_GOODBYE_TAIL_MARKER: u64 = 0x57446fa533702943; #[derive(Debug)] #[derive(Endian)] #[repr(C)] -pub struct CaFormatHeader { - /// The size of the item, including the size of `CaFormatHeader`. +pub struct PxarHeader { + /// The size of the item, including the size of `PxarHeader`. pub size: u64, - /// The item type (see `CA_FORMAT_` constants). + /// The item type (see `PXAR_` constants). pub htype: u64, } #[derive(Endian)] #[repr(C)] -pub struct CaFormatEntry { +pub struct PxarEntry { pub mode: u64, pub flags: u64, pub uid: u64, @@ -57,14 +58,14 @@ pub struct CaFormatEntry { #[derive(Endian)] #[repr(C)] -pub struct CaFormatDevice { +pub struct PxarDevice { pub major: u64, pub minor: u64, } #[derive(Endian)] #[repr(C)] -pub struct CaFormatGoodbyeItem { +pub struct PxarGoodbyeItem { /// The offset from the start of the GOODBYE object to the start /// of the matching directory item (point to a FILENAME). The last /// GOODBYE item points to the start of the matching ENTRY @@ -74,7 +75,7 @@ pub struct CaFormatGoodbyeItem { /// repeats the size of the GOODBYE item. pub size: u64, /// SipHash24 of the directory item name. The last GOODBYE item - /// uses the special hash value `CA_FORMAT_GOODBYE_TAIL_MARKER`. + /// uses the special hash value `PXAR_GOODBYE_TAIL_MARKER`. pub hash: u64, } @@ -96,46 +97,46 @@ pub fn read_os_string(buffer: &[u8]) -> std::ffi::OsString { #[derive(Debug, Eq)] #[repr(C)] -pub struct CaFormatXAttr { +pub struct PxarXAttr { pub name: Vec, pub value: Vec, } -impl Ord for CaFormatXAttr { - fn cmp(&self, other: &CaFormatXAttr) -> Ordering { +impl Ord for PxarXAttr { + fn cmp(&self, other: &PxarXAttr) -> Ordering { self.name.cmp(&other.name) } } -impl PartialOrd for CaFormatXAttr { - fn partial_cmp(&self, other: &CaFormatXAttr) -> Option { +impl PartialOrd for PxarXAttr { + fn partial_cmp(&self, other: &PxarXAttr) -> Option { Some(self.cmp(other)) } } -impl PartialEq for CaFormatXAttr { - fn eq(&self, other: &CaFormatXAttr) -> bool { +impl PartialEq for PxarXAttr { + fn eq(&self, other: &PxarXAttr) -> bool { self.name == other.name } } #[derive(Debug)] #[repr(C)] -pub struct CaFormatFCaps { +pub struct PxarFCaps { pub data: Vec, } #[derive(Debug, Endian, Eq)] #[repr(C)] -pub struct CaFormatACLUser { +pub struct PxarACLUser { pub uid: u64, pub permissions: u64, //pub name: Vec, not impl for now } // TODO if also name is impl, sort by uid, then by name and last by permissions -impl Ord for CaFormatACLUser { - fn cmp(&self, other: &CaFormatACLUser) -> Ordering { +impl Ord for PxarACLUser { + fn cmp(&self, other: &PxarACLUser) -> Ordering { match self.uid.cmp(&other.uid) { // uids are equal, entries ordered by permissions Ordering::Equal => self.permissions.cmp(&other.permissions), @@ -145,29 +146,29 @@ impl Ord for CaFormatACLUser { } } -impl PartialOrd for CaFormatACLUser { - fn partial_cmp(&self, other: &CaFormatACLUser) -> Option { +impl PartialOrd for PxarACLUser { + fn partial_cmp(&self, other: &PxarACLUser) -> Option { Some(self.cmp(other)) } } -impl PartialEq for CaFormatACLUser { - fn eq(&self, other: &CaFormatACLUser) -> bool { +impl PartialEq for PxarACLUser { + fn eq(&self, other: &PxarACLUser) -> bool { self.uid == other.uid && self.permissions == other.permissions } } #[derive(Debug, Endian, Eq)] #[repr(C)] -pub struct CaFormatACLGroup { +pub struct PxarACLGroup { pub gid: u64, pub permissions: u64, //pub name: Vec, not impl for now } // TODO if also name is impl, sort by gid, then by name and last by permissions -impl Ord for CaFormatACLGroup { - fn cmp(&self, other: &CaFormatACLGroup) -> Ordering { +impl Ord for PxarACLGroup { + fn cmp(&self, other: &PxarACLGroup) -> Ordering { match self.gid.cmp(&other.gid) { // gids are equal, entries are ordered by permissions Ordering::Equal => self.permissions.cmp(&other.permissions), @@ -177,27 +178,27 @@ impl Ord for CaFormatACLGroup { } } -impl PartialOrd for CaFormatACLGroup { - fn partial_cmp(&self, other: &CaFormatACLGroup) -> Option { +impl PartialOrd for PxarACLGroup { + fn partial_cmp(&self, other: &PxarACLGroup) -> Option { Some(self.cmp(other)) } } -impl PartialEq for CaFormatACLGroup { - fn eq(&self, other: &CaFormatACLGroup) -> bool { +impl PartialEq for PxarACLGroup { + fn eq(&self, other: &PxarACLGroup) -> bool { self.gid == other.gid && self.permissions == other.permissions } } #[derive(Debug, Endian)] #[repr(C)] -pub struct CaFormatACLGroupObj { +pub struct PxarACLGroupObj { pub permissions: u64, } #[derive(Debug, Endian)] #[repr(C)] -pub struct CaFormatACLDefault { +pub struct PxarACLDefault { pub user_obj_permissions: u64, pub group_obj_permissions: u64, pub other_permissions: u64, @@ -205,33 +206,33 @@ pub struct CaFormatACLDefault { } pub (crate) struct PxarACL { - pub users: Vec, - pub groups: Vec, - pub group_obj: Option, - pub default: Option, + pub users: Vec, + pub groups: Vec, + pub group_obj: Option, + pub default: Option, } -pub const CA_FORMAT_ACL_PERMISSION_READ: u64 = 4; -pub const CA_FORMAT_ACL_PERMISSION_WRITE: u64 = 2; -pub const CA_FORMAT_ACL_PERMISSION_EXECUTE: u64 = 1; +pub const PXAR_ACL_PERMISSION_READ: u64 = 4; +pub const PXAR_ACL_PERMISSION_WRITE: u64 = 2; +pub const PXAR_ACL_PERMISSION_EXECUTE: u64 = 1; #[derive(Debug, Endian)] #[repr(C)] -pub struct CaFormatQuotaProjID { +pub struct PxarQuotaProjID { pub projid: u64, } #[derive(Debug, Default)] pub struct PxarAttributes { - pub xattrs: Vec, - pub fcaps: Option, - pub quota_projid: Option, - pub acl_user: Vec, - pub acl_group: Vec, - pub acl_group_obj: Option, - pub acl_default: Option, - pub acl_default_user: Vec, - pub acl_default_group: Vec, + pub xattrs: Vec, + pub fcaps: Option, + pub quota_projid: Option, + pub acl_user: Vec, + pub acl_group: Vec, + pub acl_group_obj: Option, + pub acl_default: Option, + pub acl_default_user: Vec, + pub acl_default_group: Vec, } /// Create SipHash values for goodby tables. @@ -244,11 +245,11 @@ pub fn compute_goodbye_hash(name: &[u8]) -> u64 { hasher.finish() } -pub fn check_ca_header(head: &CaFormatHeader, htype: u64) -> Result<(), Error> { +pub fn check_ca_header(head: &PxarHeader, htype: u64) -> Result<(), Error> { if head.htype != htype { bail!("got wrong header type ({:016x} != {:016x})", head.htype, htype); } - if head.size != (std::mem::size_of::() + std::mem::size_of::()) as u64 { + if head.size != (std::mem::size_of::() + std::mem::size_of::()) as u64 { bail!("got wrong header size for type {:016x}", htype); } diff --git a/src/pxar/sequential_decoder.rs b/src/pxar/sequential_decoder.rs index b2c42064..2c4bfdd2 100644 --- a/src/pxar/sequential_decoder.rs +++ b/src/pxar/sequential_decoder.rs @@ -41,7 +41,7 @@ pub struct SequentialDecoder<'a, R: Read, F: Fn(&Path) -> Result<(), Error>> { callback: F, } -const HEADER_SIZE: u64 = std::mem::size_of::() as u64; +const HEADER_SIZE: u64 = std::mem::size_of::() as u64; impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F> { @@ -155,7 +155,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F (self.feature_flags & feature_flags) == feature_flags } - fn read_xattr(&mut self, size: usize) -> Result { + fn read_xattr(&mut self, size: usize) -> Result { let buffer = self.reader.read_exact_allocated(size)?; let separator = buffer.iter().position(|c| *c == b'\0') @@ -168,83 +168,83 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F bail!("incorrect xattr name - {}.", String::from_utf8_lossy(name)); } - Ok(CaFormatXAttr { + Ok(PxarXAttr { name: name.to_vec(), value: value[1..].to_vec(), }) } - fn read_fcaps(&mut self, size: usize) -> Result { + fn read_fcaps(&mut self, size: usize) -> Result { let buffer = self.reader.read_exact_allocated(size)?; - Ok(CaFormatFCaps { data: buffer }) + Ok(PxarFCaps { data: buffer }) } - fn read_attributes(&mut self) -> Result<(CaFormatHeader, PxarAttributes), Error> { + fn read_attributes(&mut self) -> Result<(PxarHeader, PxarAttributes), Error> { let mut attr = PxarAttributes::default(); - let mut head: CaFormatHeader = self.read_item()?; + let mut head: PxarHeader = self.read_item()?; let mut size = (head.size - HEADER_SIZE) as usize; loop { match head.htype { - CA_FORMAT_XATTR => { + PXAR_XATTR => { if self.has_features(flags::WITH_XATTRS) { attr.xattrs.push(self.read_xattr(size)?); } else { self.skip_bytes(size)?; } }, - CA_FORMAT_FCAPS => { + PXAR_FCAPS => { if self.has_features(flags::WITH_FCAPS) { attr.fcaps = Some(self.read_fcaps(size)?); } else { self.skip_bytes(size)?; } }, - CA_FORMAT_ACL_USER => { + PXAR_ACL_USER => { if self.has_features(flags::WITH_ACL) { - attr.acl_user.push(self.read_item::()?); + attr.acl_user.push(self.read_item::()?); } else { self.skip_bytes(size)?; } }, - CA_FORMAT_ACL_GROUP => { + PXAR_ACL_GROUP => { if self.has_features(flags::WITH_ACL) { - attr.acl_group.push(self.read_item::()?); + attr.acl_group.push(self.read_item::()?); } else { self.skip_bytes(size)?; } }, - CA_FORMAT_ACL_GROUP_OBJ => { + PXAR_ACL_GROUP_OBJ => { if self.has_features(flags::WITH_ACL) { - attr.acl_group_obj = Some(self.read_item::()?); + attr.acl_group_obj = Some(self.read_item::()?); } else { self.skip_bytes(size)?; } }, - CA_FORMAT_ACL_DEFAULT => { + PXAR_ACL_DEFAULT => { if self.has_features(flags::WITH_ACL) { - attr.acl_default = Some(self.read_item::()?); + attr.acl_default = Some(self.read_item::()?); } else { self.skip_bytes(size)?; } }, - CA_FORMAT_ACL_DEFAULT_USER => { + PXAR_ACL_DEFAULT_USER => { if self.has_features(flags::WITH_ACL) { - attr.acl_default_user.push(self.read_item::()?); + attr.acl_default_user.push(self.read_item::()?); } else { self.skip_bytes(size)?; } }, - CA_FORMAT_ACL_DEFAULT_GROUP => { + PXAR_ACL_DEFAULT_GROUP => { if self.has_features(flags::WITH_ACL) { - attr.acl_default_group.push(self.read_item::()?); + attr.acl_default_group.push(self.read_item::()?); } else { self.skip_bytes(size)?; } }, - CA_FORMAT_QUOTA_PROJID => { + PXAR_QUOTA_PROJID => { if self.has_features(flags::WITH_QUOTA_PROJID) { - attr.quota_projid = Some(self.read_item::()?); + attr.quota_projid = Some(self.read_item::()?); } else { self.skip_bytes(size)?; } @@ -262,7 +262,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F &mut self, fd: RawFd, attr: &PxarAttributes, - entry: &CaFormatEntry, + entry: &PxarEntry, ) -> Result<(), Error> { self.restore_xattrs_fcaps_fd(fd, &attr.xattrs, &attr.fcaps)?; @@ -318,8 +318,8 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F fn restore_xattrs_fcaps_fd( &mut self, fd: RawFd, - xattrs: &Vec, - fcaps: &Option + xattrs: &Vec, + fcaps: &Option ) -> Result<(), Error> { for xattr in xattrs { if let Err(err) = xattr::fsetxattr(fd, &xattr) { @@ -338,7 +338,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F fn restore_quota_projid( &mut self, fd: RawFd, - projid: &Option + projid: &Option ) -> Result<(), Error> { if let Some(projid) = projid { let mut fsxattr = fs::FSXAttr::default(); @@ -356,7 +356,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F Ok(()) } - fn restore_mode(&mut self, entry: &CaFormatEntry, fd: RawFd) -> Result<(), Error> { + fn restore_mode(&mut self, entry: &PxarEntry, fd: RawFd) -> Result<(), Error> { let mode = Mode::from_bits_truncate((entry.mode as u32) & 0o7777); @@ -365,7 +365,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F Ok(()) } - fn restore_mode_at(&mut self, entry: &CaFormatEntry, dirfd: RawFd, filename: &OsStr) -> Result<(), Error> { + fn restore_mode_at(&mut self, entry: &PxarEntry, dirfd: RawFd, filename: &OsStr) -> Result<(), Error> { let mode = Mode::from_bits_truncate((entry.mode as u32) & 0o7777); @@ -376,7 +376,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F Ok(()) } - fn restore_ugid(&mut self, entry: &CaFormatEntry, fd: RawFd) -> Result<(), Error> { + fn restore_ugid(&mut self, entry: &PxarEntry, fd: RawFd) -> Result<(), Error> { let uid = entry.uid as u32; let gid = entry.gid as u32; @@ -387,10 +387,10 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F Ok(()) } - fn restore_ugid_at(&mut self, entry: &CaFormatEntry, dirfd: RawFd, filename: &OsStr) -> Result<(), Error> { + fn restore_ugid_at(&mut self, entry: &PxarEntry, dirfd: RawFd, filename: &OsStr) -> Result<(), Error> { - let uid = entry.uid as u32; - let gid = entry.gid as u32; + let uid = entry.uid; + let gid = entry.gid; let res = filename.with_nix_path(|cstr| unsafe { libc::fchownat(dirfd, cstr.as_ptr(), uid, gid, libc::AT_SYMLINK_NOFOLLOW) @@ -400,7 +400,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F Ok(()) } - fn restore_mtime(&mut self, entry: &CaFormatEntry, fd: RawFd) -> Result<(), Error> { + fn restore_mtime(&mut self, entry: &PxarEntry, fd: RawFd) -> Result<(), Error> { let times = nsec_to_update_timespec(entry.mtime); @@ -410,7 +410,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F Ok(()) } - fn restore_mtime_at(&mut self, entry: &CaFormatEntry, dirfd: RawFd, filename: &OsStr) -> Result<(), Error> { + fn restore_mtime_at(&mut self, entry: &PxarEntry, dirfd: RawFd, filename: &OsStr) -> Result<(), Error> { let times = nsec_to_update_timespec(entry.mtime); @@ -422,7 +422,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F Ok(()) } - fn restore_device_at(&mut self, entry: &CaFormatEntry, dirfd: RawFd, filename: &OsStr, device: &CaFormatDevice) -> Result<(), Error> { + fn restore_device_at(&mut self, entry: &PxarEntry, dirfd: RawFd, filename: &OsStr, device: &PxarDevice) -> Result<(), Error> { let rdev = nix::sys::stat::makedev(device.major, device.minor); let mode = ((entry.mode as u32) & libc::S_IFMT) | 0o0600; @@ -472,15 +472,15 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F &mut self, parent_fd: Option, full_path: &PathBuf, - entry: &CaFormatEntry, + entry: &PxarEntry, filename: &OsStr ) -> Result<(), Error> { //fixme: create symlink //fixme: restore permission, acls, xattr, ... - let head: CaFormatHeader = self.read_item()?; + let head: PxarHeader = self.read_item()?; match head.htype { - CA_FORMAT_SYMLINK => { + PXAR_SYMLINK => { let target = self.read_link(head.size)?; //println!("TARGET: {:?}", target); if let Some(fd) = parent_fd { @@ -506,7 +506,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F fn restore_socket( &mut self, parent_fd: Option, - entry: &CaFormatEntry, + entry: &PxarEntry, filename: &OsStr ) -> Result<(), Error> { if !self.has_features(flags::WITH_SOCKETS) { @@ -525,7 +525,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F fn restore_fifo( &mut self, parent_fd: Option, - entry: &CaFormatEntry, + entry: &PxarEntry, filename: &OsStr ) -> Result<(), Error> { if !self.has_features(flags::WITH_FIFOS) { @@ -544,14 +544,14 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F fn restore_device( &mut self, parent_fd: Option, - entry: &CaFormatEntry, + entry: &PxarEntry, filename: &OsStr ) -> Result<(), Error> { - let head: CaFormatHeader = self.read_item()?; - if head.htype != CA_FORMAT_DEVICE { + let head: PxarHeader = self.read_item()?; + if head.htype != PXAR_DEVICE { bail!("got unknown header type inside device entry {:016x}", head.htype); } - let device: CaFormatDevice = self.read_item()?; + let device: PxarDevice = self.read_item()?; if !self.has_features(flags::WITH_DEVICE_NODES) { return Ok(()); } @@ -573,7 +573,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F &mut self, parent_fd: Option, full_path: &PathBuf, - entry: &CaFormatEntry, + entry: &PxarEntry, filename: &OsStr ) -> Result<(), Error> { let mut read_buffer: [u8; 64*1024] = unsafe { std::mem::uninitialized() }; @@ -586,7 +586,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F let mut file = file_openat(fd, filename, flags, open_mode) .map_err(|err| format_err!("open file {:?} failed - {}", full_path, err))?; - if head.htype != CA_FORMAT_PAYLOAD { + if head.htype != PXAR_PAYLOAD { bail!("got unknown header type for file entry {:016x}", head.htype); } @@ -611,7 +611,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F self.restore_mode(&entry, file.as_raw_fd())?; self.restore_mtime(&entry, file.as_raw_fd())?; } else { - if head.htype != CA_FORMAT_PAYLOAD { + if head.htype != PXAR_PAYLOAD { bail!("got unknown header type for file entry {:016x}", head.htype); } if head.size < HEADER_SIZE { @@ -627,7 +627,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F &mut self, base_path: &Path, dirs: &mut PxarDirBuf, - entry: CaFormatEntry, + entry: PxarEntry, filename: &OsStr, matched: MatchType, match_pattern: &Vec, @@ -641,13 +641,13 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F dirs.create_all_dirs(!self.allow_existing_dirs)?; } - while head.htype == CA_FORMAT_FILENAME { + while head.htype == PXAR_FILENAME { let name = self.read_filename(head.size)?; self.restore_dir_entry(base_path, dirs, &name, matched, match_pattern)?; head = self.read_item()?; } - if head.htype != CA_FORMAT_GOODBYE { + if head.htype != PXAR_GOODBYE { bail!("got unknown header type inside directory entry {:016x}", head.htype); } @@ -690,20 +690,20 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F MatchType::None }; - let header: CaFormatHeader = self.read_item()?; - check_ca_header::(&header, CA_FORMAT_ENTRY)?; - let entry: CaFormatEntry = self.read_item()?; + let header: PxarHeader = self.read_item()?; + check_ca_header::(&header, PXAR_ENTRY)?; + let entry: PxarEntry = self.read_item()?; let (mut head, attr) = self.read_attributes() .map_err(|err| format_err!("Reading of directory attributes failed - {}", err))?; - while head.htype == CA_FORMAT_FILENAME { + while head.htype == PXAR_FILENAME { let name = self.read_filename(head.size)?; self.restore_dir_entry(path, &mut dirs, &name, matched, match_pattern)?; head = self.read_item()?; } - if head.htype != CA_FORMAT_GOODBYE { + if head.htype != PXAR_GOODBYE { bail!("got unknown header type inside directory entry {:016x}", head.htype); } @@ -730,7 +730,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F let relative_path = dirs.as_path_buf(); let full_path = base_path.join(&relative_path).join(filename); - let head: CaFormatHeader = self.read_item()?; + let head: PxarHeader = self.read_item()?; if head.htype == PXAR_FORMAT_HARDLINK { let (target, _offset) = self.read_hardlink(head.size)?; let target_path = base_path.join(&target); @@ -741,8 +741,8 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F return Ok(()); } - check_ca_header::(&head, CA_FORMAT_ENTRY)?; - let entry: CaFormatEntry = self.read_item()?; + check_ca_header::(&head, PXAR_ENTRY)?; + let entry: PxarEntry = self.read_item()?; let mut child_pattern = Vec::new(); // If parent was a match, then children should be assumed to match too @@ -800,12 +800,12 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F output: &mut W, ) -> Result<(), Error> { - let print_head = |head: &CaFormatHeader| { + let print_head = |head: &PxarHeader| { println!("Type: {:016x}", head.htype); println!("Size: {}", head.size); }; - let head: CaFormatHeader = self.read_item()?; + let head: PxarHeader = self.read_item()?; if verbose { println!("Path: {:?}", path); print_head(&head); @@ -821,8 +821,8 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F return Ok(()); } - check_ca_header::(&head, CA_FORMAT_ENTRY)?; - let entry: CaFormatEntry = self.read_item()?; + check_ca_header::(&head, PXAR_ENTRY)?; + let entry: PxarEntry = self.read_item()?; if verbose { println!("Mode: {:08x} {:08x}", entry.mode, (entry.mode as u32) & libc::S_IFDIR); @@ -835,7 +835,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F let mut entry_count = 0; loop { - let head: CaFormatHeader = self.read_item()?; + let head: PxarHeader = self.read_item()?; if verbose { print_head(&head); } @@ -849,7 +849,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F } match head.htype { - CA_FORMAT_FILENAME => { + PXAR_FILENAME => { let name = self.read_filename(head.size)?; if verbose { println!("Name: {:?}", name); } entry_count += 1; @@ -857,7 +857,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F self.dump_entry(path, verbose, output)?; path.pop(); }, - CA_FORMAT_GOODBYE => { + PXAR_GOODBYE => { let table_size = (head.size - HEADER_SIZE) as usize; if verbose { println!("Goodbye: {:?}", path); @@ -874,7 +874,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F (ifmt == libc::S_IFLNK) || (ifmt == libc::S_IFREG) { loop { - let head: CaFormatHeader = self.read_item()?; + let head: PxarHeader = self.read_item()?; if verbose { print_head(&head); } @@ -888,21 +888,21 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F } match head.htype { - CA_FORMAT_SYMLINK => { + PXAR_SYMLINK => { let target = self.read_link(head.size)?; if verbose { println!("Symlink: {:?}", target); } break; }, - CA_FORMAT_DEVICE => { - let device: CaFormatDevice = self.read_item()?; + PXAR_DEVICE => { + let device: PxarDevice = self.read_item()?; if verbose { println!("Device: {}, {}", device.major, device.minor); } break; }, - CA_FORMAT_PAYLOAD => { + PXAR_PAYLOAD => { let payload_size = (head.size - HEADER_SIZE) as usize; if verbose { println!("Payload: {}", payload_size); @@ -929,58 +929,58 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F Ok(()) } - fn dump_if_attribute(&mut self, header: &CaFormatHeader, verbose: bool) -> Result { + fn dump_if_attribute(&mut self, header: &PxarHeader, verbose: bool) -> Result { match header.htype { - CA_FORMAT_XATTR => { + PXAR_XATTR => { let xattr = self.read_xattr((header.size - HEADER_SIZE) as usize)?; if verbose && self.has_features(flags::WITH_XATTRS) { println!("XAttr: {:?}", xattr); } }, - CA_FORMAT_FCAPS => { + PXAR_FCAPS => { let fcaps = self.read_fcaps((header.size - HEADER_SIZE) as usize)?; if verbose && self.has_features(flags::WITH_FCAPS) { println!("FCaps: {:?}", fcaps); } }, - CA_FORMAT_ACL_USER => { - let user = self.read_item::()?; + PXAR_ACL_USER => { + let user = self.read_item::()?; if verbose && self.has_features(flags::WITH_ACL) { println!("ACLUser: {:?}", user); } }, - CA_FORMAT_ACL_GROUP => { - let group = self.read_item::()?; + PXAR_ACL_GROUP => { + let group = self.read_item::()?; if verbose && self.has_features(flags::WITH_ACL) { println!("ACLGroup: {:?}", group); } }, - CA_FORMAT_ACL_GROUP_OBJ => { - let group_obj = self.read_item::()?; + PXAR_ACL_GROUP_OBJ => { + let group_obj = self.read_item::()?; if verbose && self.has_features(flags::WITH_ACL) { println!("ACLGroupObj: {:?}", group_obj); } }, - CA_FORMAT_ACL_DEFAULT => { - let default = self.read_item::()?; + PXAR_ACL_DEFAULT => { + let default = self.read_item::()?; if verbose && self.has_features(flags::WITH_ACL) { println!("ACLDefault: {:?}", default); } }, - CA_FORMAT_ACL_DEFAULT_USER => { - let default_user = self.read_item::()?; + PXAR_ACL_DEFAULT_USER => { + let default_user = self.read_item::()?; if verbose && self.has_features(flags::WITH_ACL) { println!("ACLDefaultUser: {:?}", default_user); } }, - CA_FORMAT_ACL_DEFAULT_GROUP => { - let default_group = self.read_item::()?; + PXAR_ACL_DEFAULT_GROUP => { + let default_group = self.read_item::()?; if verbose && self.has_features(flags::WITH_ACL) { println!("ACLDefaultGroup: {:?}", default_group); } }, - CA_FORMAT_QUOTA_PROJID => { - let quota_projid = self.read_item::()?; + PXAR_QUOTA_PROJID => { + let quota_projid = self.read_item::()?; if verbose && self.has_features(flags::WITH_QUOTA_PROJID) { println!("Quota project id: {:?}", quota_projid); } @@ -997,7 +997,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F table_size: usize, ) -> Result<(), Error> { - const GOODBYE_ITEM_SIZE: usize = std::mem::size_of::(); + const GOODBYE_ITEM_SIZE: usize = std::mem::size_of::(); if table_size < GOODBYE_ITEM_SIZE { bail!("Goodbye table to small ({} < {})", table_size, GOODBYE_ITEM_SIZE); @@ -1015,9 +1015,9 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F let mut count = 0; loop { - let item: CaFormatGoodbyeItem = self.read_item()?; + let item: PxarGoodbyeItem = self.read_item()?; count += 1; - if item.hash == CA_FORMAT_GOODBYE_TAIL_MARKER { + if item.hash == PXAR_GOODBYE_TAIL_MARKER { if count != entries { bail!("unexpected goodbye tail marker"); } diff --git a/src/tools/xattr.rs b/src/tools/xattr.rs index 111bf43a..6f49ad65 100644 --- a/src/tools/xattr.rs +++ b/src/tools/xattr.rs @@ -7,7 +7,7 @@ use nix::errno::Errno; use proxmox::tools::vec; -use crate::pxar::{CaFormatXAttr, CaFormatFCaps}; +use crate::pxar::{PxarXAttr, PxarFCaps}; pub fn flistxattr(fd: RawFd) -> Result, nix::errno::Errno> { // Initial buffer size for the attribute list, if content does not fit @@ -64,7 +64,7 @@ pub fn fgetxattr(fd: RawFd, name: &[u8]) -> Result, nix::errno::Errno> { Ok(buffer) } -pub fn fsetxattr(fd: RawFd, xattr: &CaFormatXAttr) -> Result<(), nix::errno::Errno> { +pub fn fsetxattr(fd: RawFd, xattr: &PxarXAttr) -> Result<(), nix::errno::Errno> { let mut name = xattr.name.clone(); name.push('\0' as u8); let flags = 0 as libc::c_int; @@ -79,7 +79,7 @@ pub fn fsetxattr(fd: RawFd, xattr: &CaFormatXAttr) -> Result<(), nix::errno::Err Ok(()) } -pub fn fsetxattr_fcaps(fd: RawFd, fcaps: &CaFormatFCaps) -> Result<(), nix::errno::Errno> { +pub fn fsetxattr_fcaps(fd: RawFd, fcaps: &PxarFCaps) -> Result<(), nix::errno::Errno> { // TODO casync checks and removes capabilities if they are set let name = b"security.capability\0"; let flags = 0 as libc::c_int; @@ -129,22 +129,22 @@ mod tests { let fd = file.as_raw_fd(); - let valid_user = CaFormatXAttr { + let valid_user = PxarXAttr { name: b"user.attribute0".to_vec(), value: b"value0".to_vec(), }; - let valid_empty_value = CaFormatXAttr { + let valid_empty_value = PxarXAttr { name: b"user.empty".to_vec(), value: Vec::new(), }; - let invalid_trusted = CaFormatXAttr { + let invalid_trusted = PxarXAttr { name: b"trusted.attribute0".to_vec(), value: b"value0".to_vec(), }; - let invalid_name_prefix = CaFormatXAttr { + let invalid_name_prefix = PxarXAttr { name: b"users.attribte0".to_vec(), value: b"value".to_vec(), }; @@ -154,7 +154,7 @@ mod tests { name.push(b'a'); } - let invalid_name_length = CaFormatXAttr { + let invalid_name_length = PxarXAttr { name: name, value: b"err".to_vec(), };