pxar: cleanup: s/CA_FORMAT/PXAR/g and s/CaFormat/Pxar/g

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
This commit is contained in:
Christian Ebner 2019-08-02 15:19:34 +02:00 committed by Dietmar Maurer
parent 47651f9530
commit 5e50c606b0
6 changed files with 243 additions and 242 deletions

View File

@ -17,7 +17,7 @@ pub struct CaDirectoryEntry {
start: u64, start: u64,
end: u64, end: u64,
pub filename: OsString, pub filename: OsString,
pub entry: CaFormatEntry, pub entry: PxarEntry,
} }
// This one needs Read+Seek // This one needs Read+Seek
@ -27,7 +27,7 @@ pub struct Decoder<'a, R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> {
root_end: u64, root_end: u64,
} }
const HEADER_SIZE: u64 = std::mem::size_of::<CaFormatHeader>() as u64; const HEADER_SIZE: u64 = std::mem::size_of::<PxarHeader>() as u64;
impl <'a, R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> Decoder<'a, R, F> { 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, start: self.root_start,
end: self.root_end, end: self.root_end,
filename: OsString::new(), // Empty filename: OsString::new(), // Empty
entry: CaFormatEntry { entry: PxarEntry {
mode: 0, mode: 0,
flags: 0, flags: 0,
uid: 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))?; 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); 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 filename = self.inner.read_filename(head.size)?;
let head: CaFormatHeader = self.inner.read_item()?; let head: PxarHeader = self.inner.read_item()?;
check_ca_header::<CaFormatEntry>(&head, CA_FORMAT_ENTRY)?; check_ca_header::<PxarEntry>(&head, PXAR_ENTRY)?;
let entry: CaFormatEntry = self.inner.read_item()?; let entry: PxarEntry = self.inner.read_item()?;
Ok(CaDirectoryEntry { Ok(CaDirectoryEntry {
start: entry_start, 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<Vec<CaDirectoryEntry>, Error> { pub fn list_dir(&mut self, dir: &CaDirectoryEntry) -> Result<Vec<CaDirectoryEntry>, Error> {
const GOODBYE_ITEM_SIZE: u64 = std::mem::size_of::<CaFormatGoodbyeItem>() as u64; const GOODBYE_ITEM_SIZE: u64 = std::mem::size_of::<PxarGoodbyeItem>() as u64;
let start = dir.start; let start = dir.start;
let end = dir.end; 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))?; 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); 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))?; 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); 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(); let mut range_list = Vec::new();
for i in 0..goodbye_inner_size/GOODBYE_ITEM_SIZE { 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) { if item.offset > (goodbye_start - start) {
bail!("goodbye entry {} offset out of range [{}..{}] {} {} {}", bail!("goodbye entry {} offset out of range [{}..{}] {} {} {}",

View File

@ -12,7 +12,7 @@ use nix::NixPath;
pub struct PxarDir { pub struct PxarDir {
pub filename: OsString, pub filename: OsString,
pub entry: CaFormatEntry, pub entry: PxarEntry,
pub attr: PxarAttributes, pub attr: PxarAttributes,
pub dir: Option<nix::dir::Dir>, pub dir: Option<nix::dir::Dir>,
} }
@ -23,7 +23,7 @@ pub struct PxarDirBuf {
} }
impl PxarDir { impl PxarDir {
pub fn new(filename: &OsStr, entry: CaFormatEntry, attr: PxarAttributes) -> Self { pub fn new(filename: &OsStr, entry: PxarEntry, attr: PxarAttributes) -> Self {
Self { Self {
filename: filename.to_os_string(), filename: filename.to_os_string(),
entry, entry,

View File

@ -166,8 +166,8 @@ impl <'a, W: Write> Encoder<'a, W> {
fn write_header(&mut self, htype: u64, size: u64) -> Result<(), Error> { fn write_header(&mut self, htype: u64, size: u64) -> Result<(), Error> {
let size = size + (std::mem::size_of::<CaFormatHeader>() as u64); let size = size + (std::mem::size_of::<PxarHeader>() as u64);
self.write_item(CaFormatHeader { size, htype })?; self.write_item(PxarHeader { size, htype })?;
Ok(()) Ok(())
} }
@ -175,13 +175,13 @@ impl <'a, W: Write> Encoder<'a, W> {
fn write_filename(&mut self, name: &CStr) -> Result<(), Error> { fn write_filename(&mut self, name: &CStr) -> Result<(), Error> {
let buffer = name.to_bytes_with_nul(); 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)?; self.write(buffer)?;
Ok(()) Ok(())
} }
fn create_entry(&self, stat: &FileStat) -> Result<CaFormatEntry, Error> { fn create_entry(&self, stat: &FileStat) -> Result<PxarEntry, Error> {
let mode = if is_symlink(&stat) { let mode = if is_symlink(&stat) {
(libc::S_IFLNK | 0o777) as u64 (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, mode: mode,
flags: 0, flags: 0,
uid: stat.st_uid as u64, uid: stat.st_uid as u64,
@ -206,7 +206,7 @@ impl <'a, W: Write> Encoder<'a, W> {
Ok(entry) 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; let mut attr: usize = 0;
@ -224,7 +224,7 @@ impl <'a, W: Write> Encoder<'a, W> {
Ok(()) 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::*; use fs::magic::*;
if magic != MSDOS_SUPER_MAGIC && magic != FUSE_SUPER_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 (self.feature_flags & self.fs_feature_flags & feature_flags) != 0
} }
fn read_xattrs(&self, fd: RawFd, stat: &FileStat) -> Result<(Vec<CaFormatXAttr>, Option<CaFormatFCaps>), Error> { fn read_xattrs(&self, fd: RawFd, stat: &FileStat) -> Result<(Vec<PxarXAttr>, Option<PxarFCaps>), Error> {
let mut xattrs = Vec::new(); let mut xattrs = Vec::new();
let mut fcaps = None; let mut fcaps = None;
@ -295,12 +295,12 @@ impl <'a, W: Write> Encoder<'a, W> {
if xattr::is_security_capability(&name) { if xattr::is_security_capability(&name) {
if self.has_features(flags::WITH_FCAPS) { if self.has_features(flags::WITH_FCAPS) {
// fcaps are stored in own format within the archive // fcaps are stored in own format within the archive
fcaps = Some(CaFormatFCaps { fcaps = Some(PxarFCaps {
data: value, data: value,
}); });
} }
} else if self.has_features(flags::WITH_XATTRS) { } else if self.has_features(flags::WITH_XATTRS) {
xattrs.push(CaFormatXAttr { xattrs.push(PxarXAttr {
name: name.to_vec(), name: name.to_vec(),
value: value, value: value,
}); });
@ -366,13 +366,13 @@ impl <'a, W: Write> Encoder<'a, W> {
acl::ACL_OTHER => other_permissions = Some(permissions), acl::ACL_OTHER => other_permissions = Some(permissions),
acl::ACL_MASK => mask_permissions = Some(permissions), acl::ACL_MASK => mask_permissions = Some(permissions),
acl::ACL_USER => { acl::ACL_USER => {
acl_user.push(CaFormatACLUser { acl_user.push(PxarACLUser {
uid: entry.get_qualifier()?, uid: entry.get_qualifier()?,
permissions: permissions, permissions: permissions,
}); });
}, },
acl::ACL_GROUP => { acl::ACL_GROUP => {
acl_group.push(CaFormatACLGroup { acl_group.push(PxarACLGroup {
gid: entry.get_qualifier()?, gid: entry.get_qualifier()?,
permissions: permissions, permissions: permissions,
}); });
@ -391,7 +391,7 @@ impl <'a, W: Write> Encoder<'a, W> {
// Only in that case we need to store the group permissions, // Only in that case we need to store the group permissions,
// in the other cases they are identical to the stat group permissions. // in the other cases they are identical to the stat group permissions.
if let (Some(gop), Some(_)) = (group_obj_permissions, mask_permissions) { if let (Some(gop), Some(_)) = (group_obj_permissions, mask_permissions) {
acl_group_obj = Some(CaFormatACLGroupObj { acl_group_obj = Some(PxarACLGroupObj {
permissions: gop, permissions: gop,
}); });
} }
@ -402,7 +402,7 @@ impl <'a, W: Write> Encoder<'a, W> {
other_permissions != None || other_permissions != None ||
mask_permissions != None mask_permissions != None
{ {
acl_default = Some(CaFormatACLDefault { acl_default = Some(PxarACLDefault {
// The value is set to UINT64_MAX as placeholder if one // The value is set to UINT64_MAX as placeholder if one
// of the permissions is not set // of the permissions is not set
user_obj_permissions: user_obj_permissions.unwrap_or(std::u64::MAX), 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 /// 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<Option<CaFormatQuotaProjID>, Error> { fn read_quota_project_id(&self, fd: RawFd, magic: i64, stat: &FileStat) -> Result<Option<PxarQuotaProjID>, Error> {
if !(is_directory(&stat) || is_reg_file(&stat)) { if !(is_directory(&stat) || is_reg_file(&stat)) {
return Ok(None); return Ok(None);
} }
@ -459,24 +459,24 @@ impl <'a, W: Write> Encoder<'a, W> {
if projid == 0 { if projid == 0 {
return Ok(None); return Ok(None);
} else { } else {
return Ok(Some(CaFormatQuotaProjID { projid })); return Ok(Some(PxarQuotaProjID { projid }));
} }
}, },
_ => return Ok(None), _ => 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::<CaFormatEntry>() as u64)?; self.write_header(PXAR_ENTRY, std::mem::size_of::<PxarEntry>() as u64)?;
self.write_item(entry)?; self.write_item(entry)?;
Ok(()) 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 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(xattr.name.as_slice())?;
self.write(&[0])?; self.write(&[0])?;
self.write(xattr.value.as_slice())?; self.write(xattr.value.as_slice())?;
@ -484,74 +484,74 @@ impl <'a, W: Write> Encoder<'a, W> {
Ok(()) Ok(())
} }
fn write_fcaps(&mut self, fcaps: Option<CaFormatFCaps>) -> Result<(), Error> { fn write_fcaps(&mut self, fcaps: Option<PxarFCaps>) -> Result<(), Error> {
if let Some(fcaps) = fcaps { if let Some(fcaps) = fcaps {
let size = fcaps.data.len(); 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())?; self.write(fcaps.data.as_slice())?;
} }
Ok(()) Ok(())
} }
fn write_acl_user(&mut self, acl_user: CaFormatACLUser) -> Result<(), Error> { fn write_acl_user(&mut self, acl_user: PxarACLUser) -> Result<(), Error> {
self.write_header(CA_FORMAT_ACL_USER, std::mem::size_of::<CaFormatACLUser>() as u64)?; self.write_header(PXAR_ACL_USER, std::mem::size_of::<PxarACLUser>() as u64)?;
self.write_item(acl_user)?; self.write_item(acl_user)?;
Ok(()) Ok(())
} }
fn write_acl_group(&mut self, acl_group: CaFormatACLGroup) -> Result<(), Error> { fn write_acl_group(&mut self, acl_group: PxarACLGroup) -> Result<(), Error> {
self.write_header(CA_FORMAT_ACL_GROUP, std::mem::size_of::<CaFormatACLGroup>() as u64)?; self.write_header(PXAR_ACL_GROUP, std::mem::size_of::<PxarACLGroup>() as u64)?;
self.write_item(acl_group)?; self.write_item(acl_group)?;
Ok(()) Ok(())
} }
fn write_acl_group_obj(&mut self, acl_group_obj: CaFormatACLGroupObj) -> Result<(), Error> { fn write_acl_group_obj(&mut self, acl_group_obj: PxarACLGroupObj) -> Result<(), Error> {
self.write_header(CA_FORMAT_ACL_GROUP_OBJ, std::mem::size_of::<CaFormatACLGroupObj>() as u64)?; self.write_header(PXAR_ACL_GROUP_OBJ, std::mem::size_of::<PxarACLGroupObj>() as u64)?;
self.write_item(acl_group_obj)?; self.write_item(acl_group_obj)?;
Ok(()) Ok(())
} }
fn write_acl_default(&mut self, acl_default: CaFormatACLDefault) -> Result<(), Error> { fn write_acl_default(&mut self, acl_default: PxarACLDefault) -> Result<(), Error> {
self.write_header(CA_FORMAT_ACL_DEFAULT, std::mem::size_of::<CaFormatACLDefault>() as u64)?; self.write_header(PXAR_ACL_DEFAULT, std::mem::size_of::<PxarACLDefault>() as u64)?;
self.write_item(acl_default)?; self.write_item(acl_default)?;
Ok(()) Ok(())
} }
fn write_acl_default_user(&mut self, acl_default_user: CaFormatACLUser) -> Result<(), Error> { fn write_acl_default_user(&mut self, acl_default_user: PxarACLUser) -> Result<(), Error> {
self.write_header(CA_FORMAT_ACL_DEFAULT_USER, std::mem::size_of::<CaFormatACLUser>() as u64)?; self.write_header(PXAR_ACL_DEFAULT_USER, std::mem::size_of::<PxarACLUser>() as u64)?;
self.write_item(acl_default_user)?; self.write_item(acl_default_user)?;
Ok(()) Ok(())
} }
fn write_acl_default_group(&mut self, acl_default_group: CaFormatACLGroup) -> Result<(), Error> { fn write_acl_default_group(&mut self, acl_default_group: PxarACLGroup) -> Result<(), Error> {
self.write_header(CA_FORMAT_ACL_DEFAULT_GROUP, std::mem::size_of::<CaFormatACLGroup>() as u64)?; self.write_header(PXAR_ACL_DEFAULT_GROUP, std::mem::size_of::<PxarACLGroup>() as u64)?;
self.write_item(acl_default_group)?; self.write_item(acl_default_group)?;
Ok(()) Ok(())
} }
fn write_quota_project_id(&mut self, projid: CaFormatQuotaProjID) -> Result<(), Error> { fn write_quota_project_id(&mut self, projid: PxarQuotaProjID) -> Result<(), Error> {
self.write_header(CA_FORMAT_QUOTA_PROJID, std::mem::size_of::<CaFormatQuotaProjID>() as u64)?; self.write_header(PXAR_QUOTA_PROJID, std::mem::size_of::<PxarQuotaProjID>() as u64)?;
self.write_item(projid)?; self.write_item(projid)?;
Ok(()) 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)); goodbye_items.sort_unstable_by(|a, b| a.hash.cmp(&b.hash));
let item_count = goodbye_items.len(); let item_count = goodbye_items.len();
let goodbye_table_size = (item_count + 1)*std::mem::size_of::<CaFormatGoodbyeItem>(); let goodbye_table_size = (item_count + 1)*std::mem::size_of::<PxarGoodbyeItem>();
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 { if self.file_copy_buffer.len() < goodbye_table_size {
let need = goodbye_table_size - self.file_copy_buffer.len(); 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| { copy_binary_search_tree(item_count, |s, d| {
let item = &goodbye_items[s]; let item = &goodbye_items[s];
let offset = d*std::mem::size_of::<CaFormatGoodbyeItem>(); let offset = d*std::mem::size_of::<PxarGoodbyeItem>();
let dest = crate::tools::map_struct_mut::<CaFormatGoodbyeItem>(&mut buffer[offset..]).unwrap(); let dest = crate::tools::map_struct_mut::<PxarGoodbyeItem>(&mut buffer[offset..]).unwrap();
dest.offset = u64::to_le(item.offset); dest.offset = u64::to_le(item.offset);
dest.size = u64::to_le(item.size); dest.size = u64::to_le(item.size);
dest.hash = u64::to_le(item.hash); dest.hash = u64::to_le(item.hash);
}); });
// append CaFormatGoodbyeTail as last item // append PxarGoodbyeTail as last item
let offset = item_count*std::mem::size_of::<CaFormatGoodbyeItem>(); let offset = item_count*std::mem::size_of::<PxarGoodbyeItem>();
let dest = crate::tools::map_struct_mut::<CaFormatGoodbyeItem>(&mut buffer[offset..]).unwrap(); let dest = crate::tools::map_struct_mut::<PxarGoodbyeItem>(&mut buffer[offset..]).unwrap();
dest.offset = u64::to_le(goodbye_offset as u64); dest.offset = u64::to_le(goodbye_offset as u64);
dest.size = u64::to_le((goodbye_table_size + std::mem::size_of::<CaFormatHeader>()) as u64); dest.size = u64::to_le((goodbye_table_size + std::mem::size_of::<PxarHeader>()) as u64);
dest.hash = u64::to_le(CA_FORMAT_GOODBYE_TAIL_MARKER); dest.hash = u64::to_le(PXAR_GOODBYE_TAIL_MARKER);
self.flush_copy_buffer(goodbye_table_size)?; self.flush_copy_buffer(goodbye_table_size)?;
@ -842,7 +842,7 @@ impl <'a, W: Write> Encoder<'a, W> {
let end_pos = self.writer_pos; let end_pos = self.writer_pos;
goodbye_items.push(CaFormatGoodbyeItem { goodbye_items.push(PxarGoodbyeItem {
offset: start_pos as u64, offset: start_pos as u64,
size: (end_pos - start_pos) as u64, size: (end_pos - start_pos) as u64,
hash: compute_goodbye_hash(filename.to_bytes()), hash: compute_goodbye_hash(filename.to_bytes()),
@ -910,13 +910,13 @@ impl <'a, W: Write> Encoder<'a, W> {
if !include_payload { if !include_payload {
eprintln!("skip content: {:?}", self.full_path()); eprintln!("skip content: {:?}", self.full_path());
self.write_header(CA_FORMAT_PAYLOAD, 0)?; self.write_header(PXAR_PAYLOAD, 0)?;
return Ok(()); return Ok(());
} }
let size = stat.st_size as u64; 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; let mut pos: u64 = 0;
loop { loop {
@ -960,8 +960,8 @@ impl <'a, W: Write> Encoder<'a, W> {
//println!("encode_device: {:?} {} {} {}", self.full_path(), stat.st_rdev, major, minor); //println!("encode_device: {:?} {} {} {}", self.full_path(), stat.st_rdev, major, minor);
self.write_header(CA_FORMAT_DEVICE, std::mem::size_of::<CaFormatDevice>() as u64)?; self.write_header(PXAR_DEVICE, std::mem::size_of::<PxarDevice>() as u64)?;
self.write_item(CaFormatDevice { major, minor })?; self.write_item(PxarDevice { major, minor })?;
Ok(()) Ok(())
} }
@ -983,7 +983,7 @@ impl <'a, W: Write> Encoder<'a, W> {
let entry = self.create_entry(&stat)?; let entry = self.create_entry(&stat)?;
self.write_entry(entry)?; 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)?; self.write(target)?;
Ok(()) Ok(())
@ -1041,12 +1041,12 @@ impl <'a, W: Write> Encoder<'a, W> {
if !include_payload { if !include_payload {
eprintln!("skip content: {:?}", self.full_path()); eprintln!("skip content: {:?}", self.full_path());
self.write_header(CA_FORMAT_PAYLOAD, 0)?; self.write_header(PXAR_PAYLOAD, 0)?;
return Ok(()); return Ok(());
} }
let size = content.len(); 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.write_all(content)?;
self.writer_pos += size; self.writer_pos += size;

View File

@ -3,7 +3,7 @@
//! Please note the all values are stored in little endian ordering. //! Please note the all values are stored in little endian ordering.
//! //!
//! The Archive contains a list of items. Each item starts with a //! 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 failure::*;
use std::cmp::Ordering; use std::cmp::Ordering;
@ -11,43 +11,44 @@ use endian_trait::Endian;
use siphasher::sip::SipHasher24; use siphasher::sip::SipHasher24;
pub const CA_FORMAT_ENTRY: u64 = 0x1396fabcea5bbb51; /// Header types identifying items stored in the archive
pub const CA_FORMAT_FILENAME: u64 = 0x6dbb6ebcb3161f0b; pub const PXAR_ENTRY: u64 = 0x1396fabcea5bbb51;
pub const CA_FORMAT_SYMLINK: u64 = 0x664a6fb6830e0d6c; pub const PXAR_FILENAME: u64 = 0x6dbb6ebcb3161f0b;
pub const CA_FORMAT_DEVICE: u64 = 0xac3dace369dfe643; pub const PXAR_SYMLINK: u64 = 0x664a6fb6830e0d6c;
pub const CA_FORMAT_XATTR: u64 = 0xb8157091f80bc486; pub const PXAR_DEVICE: u64 = 0xac3dace369dfe643;
pub const CA_FORMAT_ACL_USER: u64 = 0x297dc88b2ef12faf; pub const PXAR_XATTR: u64 = 0xb8157091f80bc486;
pub const CA_FORMAT_ACL_GROUP: u64 = 0x36f2acb56cb3dd0b; pub const PXAR_ACL_USER: u64 = 0x297dc88b2ef12faf;
pub const CA_FORMAT_ACL_GROUP_OBJ: u64 = 0x23047110441f38f3; pub const PXAR_ACL_GROUP: u64 = 0x36f2acb56cb3dd0b;
pub const CA_FORMAT_ACL_DEFAULT: u64 = 0xfe3eeda6823c8cd0; pub const PXAR_ACL_GROUP_OBJ: u64 = 0x23047110441f38f3;
pub const CA_FORMAT_ACL_DEFAULT_USER: u64 = 0xbdf03df9bd010a91; pub const PXAR_ACL_DEFAULT: u64 = 0xfe3eeda6823c8cd0;
pub const CA_FORMAT_ACL_DEFAULT_GROUP: u64 = 0xa0cb1168782d1f51; pub const PXAR_ACL_DEFAULT_USER: u64 = 0xbdf03df9bd010a91;
pub const CA_FORMAT_FCAPS: u64 = 0xf7267db0afed0629; pub const PXAR_ACL_DEFAULT_GROUP: u64 = 0xa0cb1168782d1f51;
pub const CA_FORMAT_QUOTA_PROJID:u64 = 0x161baf2d8772a72b; pub const PXAR_FCAPS: u64 = 0xf7267db0afed0629;
pub const PXAR_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;
/// 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(Debug)]
#[derive(Endian)] #[derive(Endian)]
#[repr(C)] #[repr(C)]
pub struct CaFormatHeader { pub struct PxarHeader {
/// The size of the item, including the size of `CaFormatHeader`. /// The size of the item, including the size of `PxarHeader`.
pub size: u64, pub size: u64,
/// The item type (see `CA_FORMAT_` constants). /// The item type (see `PXAR_` constants).
pub htype: u64, pub htype: u64,
} }
#[derive(Endian)] #[derive(Endian)]
#[repr(C)] #[repr(C)]
pub struct CaFormatEntry { pub struct PxarEntry {
pub mode: u64, pub mode: u64,
pub flags: u64, pub flags: u64,
pub uid: u64, pub uid: u64,
@ -57,14 +58,14 @@ pub struct CaFormatEntry {
#[derive(Endian)] #[derive(Endian)]
#[repr(C)] #[repr(C)]
pub struct CaFormatDevice { pub struct PxarDevice {
pub major: u64, pub major: u64,
pub minor: u64, pub minor: u64,
} }
#[derive(Endian)] #[derive(Endian)]
#[repr(C)] #[repr(C)]
pub struct CaFormatGoodbyeItem { pub struct PxarGoodbyeItem {
/// The offset from the start of the GOODBYE object to the start /// The offset from the start of the GOODBYE object to the start
/// of the matching directory item (point to a FILENAME). The last /// of the matching directory item (point to a FILENAME). The last
/// GOODBYE item points to the start of the matching ENTRY /// GOODBYE item points to the start of the matching ENTRY
@ -74,7 +75,7 @@ pub struct CaFormatGoodbyeItem {
/// repeats the size of the GOODBYE item. /// repeats the size of the GOODBYE item.
pub size: u64, pub size: u64,
/// SipHash24 of the directory item name. The last GOODBYE item /// 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, pub hash: u64,
} }
@ -96,46 +97,46 @@ pub fn read_os_string(buffer: &[u8]) -> std::ffi::OsString {
#[derive(Debug, Eq)] #[derive(Debug, Eq)]
#[repr(C)] #[repr(C)]
pub struct CaFormatXAttr { pub struct PxarXAttr {
pub name: Vec<u8>, pub name: Vec<u8>,
pub value: Vec<u8>, pub value: Vec<u8>,
} }
impl Ord for CaFormatXAttr { impl Ord for PxarXAttr {
fn cmp(&self, other: &CaFormatXAttr) -> Ordering { fn cmp(&self, other: &PxarXAttr) -> Ordering {
self.name.cmp(&other.name) self.name.cmp(&other.name)
} }
} }
impl PartialOrd for CaFormatXAttr { impl PartialOrd for PxarXAttr {
fn partial_cmp(&self, other: &CaFormatXAttr) -> Option<Ordering> { fn partial_cmp(&self, other: &PxarXAttr) -> Option<Ordering> {
Some(self.cmp(other)) Some(self.cmp(other))
} }
} }
impl PartialEq for CaFormatXAttr { impl PartialEq for PxarXAttr {
fn eq(&self, other: &CaFormatXAttr) -> bool { fn eq(&self, other: &PxarXAttr) -> bool {
self.name == other.name self.name == other.name
} }
} }
#[derive(Debug)] #[derive(Debug)]
#[repr(C)] #[repr(C)]
pub struct CaFormatFCaps { pub struct PxarFCaps {
pub data: Vec<u8>, pub data: Vec<u8>,
} }
#[derive(Debug, Endian, Eq)] #[derive(Debug, Endian, Eq)]
#[repr(C)] #[repr(C)]
pub struct CaFormatACLUser { pub struct PxarACLUser {
pub uid: u64, pub uid: u64,
pub permissions: u64, pub permissions: u64,
//pub name: Vec<u64>, not impl for now //pub name: Vec<u64>, not impl for now
} }
// TODO if also name is impl, sort by uid, then by name and last by permissions // TODO if also name is impl, sort by uid, then by name and last by permissions
impl Ord for CaFormatACLUser { impl Ord for PxarACLUser {
fn cmp(&self, other: &CaFormatACLUser) -> Ordering { fn cmp(&self, other: &PxarACLUser) -> Ordering {
match self.uid.cmp(&other.uid) { match self.uid.cmp(&other.uid) {
// uids are equal, entries ordered by permissions // uids are equal, entries ordered by permissions
Ordering::Equal => self.permissions.cmp(&other.permissions), Ordering::Equal => self.permissions.cmp(&other.permissions),
@ -145,29 +146,29 @@ impl Ord for CaFormatACLUser {
} }
} }
impl PartialOrd for CaFormatACLUser { impl PartialOrd for PxarACLUser {
fn partial_cmp(&self, other: &CaFormatACLUser) -> Option<Ordering> { fn partial_cmp(&self, other: &PxarACLUser) -> Option<Ordering> {
Some(self.cmp(other)) Some(self.cmp(other))
} }
} }
impl PartialEq for CaFormatACLUser { impl PartialEq for PxarACLUser {
fn eq(&self, other: &CaFormatACLUser) -> bool { fn eq(&self, other: &PxarACLUser) -> bool {
self.uid == other.uid && self.permissions == other.permissions self.uid == other.uid && self.permissions == other.permissions
} }
} }
#[derive(Debug, Endian, Eq)] #[derive(Debug, Endian, Eq)]
#[repr(C)] #[repr(C)]
pub struct CaFormatACLGroup { pub struct PxarACLGroup {
pub gid: u64, pub gid: u64,
pub permissions: u64, pub permissions: u64,
//pub name: Vec<u64>, not impl for now //pub name: Vec<u64>, not impl for now
} }
// TODO if also name is impl, sort by gid, then by name and last by permissions // TODO if also name is impl, sort by gid, then by name and last by permissions
impl Ord for CaFormatACLGroup { impl Ord for PxarACLGroup {
fn cmp(&self, other: &CaFormatACLGroup) -> Ordering { fn cmp(&self, other: &PxarACLGroup) -> Ordering {
match self.gid.cmp(&other.gid) { match self.gid.cmp(&other.gid) {
// gids are equal, entries are ordered by permissions // gids are equal, entries are ordered by permissions
Ordering::Equal => self.permissions.cmp(&other.permissions), Ordering::Equal => self.permissions.cmp(&other.permissions),
@ -177,27 +178,27 @@ impl Ord for CaFormatACLGroup {
} }
} }
impl PartialOrd for CaFormatACLGroup { impl PartialOrd for PxarACLGroup {
fn partial_cmp(&self, other: &CaFormatACLGroup) -> Option<Ordering> { fn partial_cmp(&self, other: &PxarACLGroup) -> Option<Ordering> {
Some(self.cmp(other)) Some(self.cmp(other))
} }
} }
impl PartialEq for CaFormatACLGroup { impl PartialEq for PxarACLGroup {
fn eq(&self, other: &CaFormatACLGroup) -> bool { fn eq(&self, other: &PxarACLGroup) -> bool {
self.gid == other.gid && self.permissions == other.permissions self.gid == other.gid && self.permissions == other.permissions
} }
} }
#[derive(Debug, Endian)] #[derive(Debug, Endian)]
#[repr(C)] #[repr(C)]
pub struct CaFormatACLGroupObj { pub struct PxarACLGroupObj {
pub permissions: u64, pub permissions: u64,
} }
#[derive(Debug, Endian)] #[derive(Debug, Endian)]
#[repr(C)] #[repr(C)]
pub struct CaFormatACLDefault { pub struct PxarACLDefault {
pub user_obj_permissions: u64, pub user_obj_permissions: u64,
pub group_obj_permissions: u64, pub group_obj_permissions: u64,
pub other_permissions: u64, pub other_permissions: u64,
@ -205,33 +206,33 @@ pub struct CaFormatACLDefault {
} }
pub (crate) struct PxarACL { pub (crate) struct PxarACL {
pub users: Vec<CaFormatACLUser>, pub users: Vec<PxarACLUser>,
pub groups: Vec<CaFormatACLGroup>, pub groups: Vec<PxarACLGroup>,
pub group_obj: Option<CaFormatACLGroupObj>, pub group_obj: Option<PxarACLGroupObj>,
pub default: Option<CaFormatACLDefault>, pub default: Option<PxarACLDefault>,
} }
pub const CA_FORMAT_ACL_PERMISSION_READ: u64 = 4; pub const PXAR_ACL_PERMISSION_READ: u64 = 4;
pub const CA_FORMAT_ACL_PERMISSION_WRITE: u64 = 2; pub const PXAR_ACL_PERMISSION_WRITE: u64 = 2;
pub const CA_FORMAT_ACL_PERMISSION_EXECUTE: u64 = 1; pub const PXAR_ACL_PERMISSION_EXECUTE: u64 = 1;
#[derive(Debug, Endian)] #[derive(Debug, Endian)]
#[repr(C)] #[repr(C)]
pub struct CaFormatQuotaProjID { pub struct PxarQuotaProjID {
pub projid: u64, pub projid: u64,
} }
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct PxarAttributes { pub struct PxarAttributes {
pub xattrs: Vec<CaFormatXAttr>, pub xattrs: Vec<PxarXAttr>,
pub fcaps: Option<CaFormatFCaps>, pub fcaps: Option<PxarFCaps>,
pub quota_projid: Option<CaFormatQuotaProjID>, pub quota_projid: Option<PxarQuotaProjID>,
pub acl_user: Vec<CaFormatACLUser>, pub acl_user: Vec<PxarACLUser>,
pub acl_group: Vec<CaFormatACLGroup>, pub acl_group: Vec<PxarACLGroup>,
pub acl_group_obj: Option<CaFormatACLGroupObj>, pub acl_group_obj: Option<PxarACLGroupObj>,
pub acl_default: Option<CaFormatACLDefault>, pub acl_default: Option<PxarACLDefault>,
pub acl_default_user: Vec<CaFormatACLUser>, pub acl_default_user: Vec<PxarACLUser>,
pub acl_default_group: Vec<CaFormatACLGroup>, pub acl_default_group: Vec<PxarACLGroup>,
} }
/// Create SipHash values for goodby tables. /// Create SipHash values for goodby tables.
@ -244,11 +245,11 @@ pub fn compute_goodbye_hash(name: &[u8]) -> u64 {
hasher.finish() hasher.finish()
} }
pub fn check_ca_header<T>(head: &CaFormatHeader, htype: u64) -> Result<(), Error> { pub fn check_ca_header<T>(head: &PxarHeader, htype: u64) -> Result<(), Error> {
if head.htype != htype { if head.htype != htype {
bail!("got wrong header type ({:016x} != {:016x})", head.htype, htype); bail!("got wrong header type ({:016x} != {:016x})", head.htype, htype);
} }
if head.size != (std::mem::size_of::<T>() + std::mem::size_of::<CaFormatHeader>()) as u64 { if head.size != (std::mem::size_of::<T>() + std::mem::size_of::<PxarHeader>()) as u64 {
bail!("got wrong header size for type {:016x}", htype); bail!("got wrong header size for type {:016x}", htype);
} }

View File

@ -41,7 +41,7 @@ pub struct SequentialDecoder<'a, R: Read, F: Fn(&Path) -> Result<(), Error>> {
callback: F, callback: F,
} }
const HEADER_SIZE: u64 = std::mem::size_of::<CaFormatHeader>() as u64; const HEADER_SIZE: u64 = std::mem::size_of::<PxarHeader>() as u64;
impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F> { 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 (self.feature_flags & feature_flags) == feature_flags
} }
fn read_xattr(&mut self, size: usize) -> Result<CaFormatXAttr, Error> { fn read_xattr(&mut self, size: usize) -> Result<PxarXAttr, Error> {
let buffer = self.reader.read_exact_allocated(size)?; let buffer = self.reader.read_exact_allocated(size)?;
let separator = buffer.iter().position(|c| *c == b'\0') 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)); bail!("incorrect xattr name - {}.", String::from_utf8_lossy(name));
} }
Ok(CaFormatXAttr { Ok(PxarXAttr {
name: name.to_vec(), name: name.to_vec(),
value: value[1..].to_vec(), value: value[1..].to_vec(),
}) })
} }
fn read_fcaps(&mut self, size: usize) -> Result<CaFormatFCaps, Error> { fn read_fcaps(&mut self, size: usize) -> Result<PxarFCaps, Error> {
let buffer = self.reader.read_exact_allocated(size)?; 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 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; let mut size = (head.size - HEADER_SIZE) as usize;
loop { loop {
match head.htype { match head.htype {
CA_FORMAT_XATTR => { PXAR_XATTR => {
if self.has_features(flags::WITH_XATTRS) { if self.has_features(flags::WITH_XATTRS) {
attr.xattrs.push(self.read_xattr(size)?); attr.xattrs.push(self.read_xattr(size)?);
} else { } else {
self.skip_bytes(size)?; self.skip_bytes(size)?;
} }
}, },
CA_FORMAT_FCAPS => { PXAR_FCAPS => {
if self.has_features(flags::WITH_FCAPS) { if self.has_features(flags::WITH_FCAPS) {
attr.fcaps = Some(self.read_fcaps(size)?); attr.fcaps = Some(self.read_fcaps(size)?);
} else { } else {
self.skip_bytes(size)?; self.skip_bytes(size)?;
} }
}, },
CA_FORMAT_ACL_USER => { PXAR_ACL_USER => {
if self.has_features(flags::WITH_ACL) { if self.has_features(flags::WITH_ACL) {
attr.acl_user.push(self.read_item::<CaFormatACLUser>()?); attr.acl_user.push(self.read_item::<PxarACLUser>()?);
} else { } else {
self.skip_bytes(size)?; self.skip_bytes(size)?;
} }
}, },
CA_FORMAT_ACL_GROUP => { PXAR_ACL_GROUP => {
if self.has_features(flags::WITH_ACL) { if self.has_features(flags::WITH_ACL) {
attr.acl_group.push(self.read_item::<CaFormatACLGroup>()?); attr.acl_group.push(self.read_item::<PxarACLGroup>()?);
} else { } else {
self.skip_bytes(size)?; self.skip_bytes(size)?;
} }
}, },
CA_FORMAT_ACL_GROUP_OBJ => { PXAR_ACL_GROUP_OBJ => {
if self.has_features(flags::WITH_ACL) { if self.has_features(flags::WITH_ACL) {
attr.acl_group_obj = Some(self.read_item::<CaFormatACLGroupObj>()?); attr.acl_group_obj = Some(self.read_item::<PxarACLGroupObj>()?);
} else { } else {
self.skip_bytes(size)?; self.skip_bytes(size)?;
} }
}, },
CA_FORMAT_ACL_DEFAULT => { PXAR_ACL_DEFAULT => {
if self.has_features(flags::WITH_ACL) { if self.has_features(flags::WITH_ACL) {
attr.acl_default = Some(self.read_item::<CaFormatACLDefault>()?); attr.acl_default = Some(self.read_item::<PxarACLDefault>()?);
} else { } else {
self.skip_bytes(size)?; self.skip_bytes(size)?;
} }
}, },
CA_FORMAT_ACL_DEFAULT_USER => { PXAR_ACL_DEFAULT_USER => {
if self.has_features(flags::WITH_ACL) { if self.has_features(flags::WITH_ACL) {
attr.acl_default_user.push(self.read_item::<CaFormatACLUser>()?); attr.acl_default_user.push(self.read_item::<PxarACLUser>()?);
} else { } else {
self.skip_bytes(size)?; self.skip_bytes(size)?;
} }
}, },
CA_FORMAT_ACL_DEFAULT_GROUP => { PXAR_ACL_DEFAULT_GROUP => {
if self.has_features(flags::WITH_ACL) { if self.has_features(flags::WITH_ACL) {
attr.acl_default_group.push(self.read_item::<CaFormatACLGroup>()?); attr.acl_default_group.push(self.read_item::<PxarACLGroup>()?);
} else { } else {
self.skip_bytes(size)?; self.skip_bytes(size)?;
} }
}, },
CA_FORMAT_QUOTA_PROJID => { PXAR_QUOTA_PROJID => {
if self.has_features(flags::WITH_QUOTA_PROJID) { if self.has_features(flags::WITH_QUOTA_PROJID) {
attr.quota_projid = Some(self.read_item::<CaFormatQuotaProjID>()?); attr.quota_projid = Some(self.read_item::<PxarQuotaProjID>()?);
} else { } else {
self.skip_bytes(size)?; self.skip_bytes(size)?;
} }
@ -262,7 +262,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F
&mut self, &mut self,
fd: RawFd, fd: RawFd,
attr: &PxarAttributes, attr: &PxarAttributes,
entry: &CaFormatEntry, entry: &PxarEntry,
) -> Result<(), Error> { ) -> Result<(), Error> {
self.restore_xattrs_fcaps_fd(fd, &attr.xattrs, &attr.fcaps)?; 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( fn restore_xattrs_fcaps_fd(
&mut self, &mut self,
fd: RawFd, fd: RawFd,
xattrs: &Vec<CaFormatXAttr>, xattrs: &Vec<PxarXAttr>,
fcaps: &Option<CaFormatFCaps> fcaps: &Option<PxarFCaps>
) -> Result<(), Error> { ) -> Result<(), Error> {
for xattr in xattrs { for xattr in xattrs {
if let Err(err) = xattr::fsetxattr(fd, &xattr) { 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( fn restore_quota_projid(
&mut self, &mut self,
fd: RawFd, fd: RawFd,
projid: &Option<CaFormatQuotaProjID> projid: &Option<PxarQuotaProjID>
) -> Result<(), Error> { ) -> Result<(), Error> {
if let Some(projid) = projid { if let Some(projid) = projid {
let mut fsxattr = fs::FSXAttr::default(); let mut fsxattr = fs::FSXAttr::default();
@ -356,7 +356,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F
Ok(()) 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); 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(()) 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); 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(()) 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 uid = entry.uid as u32;
let gid = entry.gid 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(()) 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 uid = entry.uid;
let gid = entry.gid as u32; let gid = entry.gid;
let res = filename.with_nix_path(|cstr| unsafe { let res = filename.with_nix_path(|cstr| unsafe {
libc::fchownat(dirfd, cstr.as_ptr(), uid, gid, libc::AT_SYMLINK_NOFOLLOW) 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(()) 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); 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(()) 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); 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(()) 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 rdev = nix::sys::stat::makedev(device.major, device.minor);
let mode = ((entry.mode as u32) & libc::S_IFMT) | 0o0600; 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, &mut self,
parent_fd: Option<RawFd>, parent_fd: Option<RawFd>,
full_path: &PathBuf, full_path: &PathBuf,
entry: &CaFormatEntry, entry: &PxarEntry,
filename: &OsStr filename: &OsStr
) -> Result<(), Error> { ) -> Result<(), Error> {
//fixme: create symlink //fixme: create symlink
//fixme: restore permission, acls, xattr, ... //fixme: restore permission, acls, xattr, ...
let head: CaFormatHeader = self.read_item()?; let head: PxarHeader = self.read_item()?;
match head.htype { match head.htype {
CA_FORMAT_SYMLINK => { PXAR_SYMLINK => {
let target = self.read_link(head.size)?; let target = self.read_link(head.size)?;
//println!("TARGET: {:?}", target); //println!("TARGET: {:?}", target);
if let Some(fd) = parent_fd { 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( fn restore_socket(
&mut self, &mut self,
parent_fd: Option<RawFd>, parent_fd: Option<RawFd>,
entry: &CaFormatEntry, entry: &PxarEntry,
filename: &OsStr filename: &OsStr
) -> Result<(), Error> { ) -> Result<(), Error> {
if !self.has_features(flags::WITH_SOCKETS) { 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( fn restore_fifo(
&mut self, &mut self,
parent_fd: Option<RawFd>, parent_fd: Option<RawFd>,
entry: &CaFormatEntry, entry: &PxarEntry,
filename: &OsStr filename: &OsStr
) -> Result<(), Error> { ) -> Result<(), Error> {
if !self.has_features(flags::WITH_FIFOS) { 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( fn restore_device(
&mut self, &mut self,
parent_fd: Option<RawFd>, parent_fd: Option<RawFd>,
entry: &CaFormatEntry, entry: &PxarEntry,
filename: &OsStr filename: &OsStr
) -> Result<(), Error> { ) -> Result<(), Error> {
let head: CaFormatHeader = self.read_item()?; let head: PxarHeader = self.read_item()?;
if head.htype != CA_FORMAT_DEVICE { if head.htype != PXAR_DEVICE {
bail!("got unknown header type inside device entry {:016x}", head.htype); 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) { if !self.has_features(flags::WITH_DEVICE_NODES) {
return Ok(()); return Ok(());
} }
@ -573,7 +573,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F
&mut self, &mut self,
parent_fd: Option<RawFd>, parent_fd: Option<RawFd>,
full_path: &PathBuf, full_path: &PathBuf,
entry: &CaFormatEntry, entry: &PxarEntry,
filename: &OsStr filename: &OsStr
) -> Result<(), Error> { ) -> Result<(), Error> {
let mut read_buffer: [u8; 64*1024] = unsafe { std::mem::uninitialized() }; 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) let mut file = file_openat(fd, filename, flags, open_mode)
.map_err(|err| format_err!("open file {:?} failed - {}", full_path, err))?; .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); 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_mode(&entry, file.as_raw_fd())?;
self.restore_mtime(&entry, file.as_raw_fd())?; self.restore_mtime(&entry, file.as_raw_fd())?;
} else { } else {
if head.htype != CA_FORMAT_PAYLOAD { if head.htype != PXAR_PAYLOAD {
bail!("got unknown header type for file entry {:016x}", head.htype); bail!("got unknown header type for file entry {:016x}", head.htype);
} }
if head.size < HEADER_SIZE { if head.size < HEADER_SIZE {
@ -627,7 +627,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F
&mut self, &mut self,
base_path: &Path, base_path: &Path,
dirs: &mut PxarDirBuf, dirs: &mut PxarDirBuf,
entry: CaFormatEntry, entry: PxarEntry,
filename: &OsStr, filename: &OsStr,
matched: MatchType, matched: MatchType,
match_pattern: &Vec<PxarExcludePattern>, match_pattern: &Vec<PxarExcludePattern>,
@ -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)?; 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)?; let name = self.read_filename(head.size)?;
self.restore_dir_entry(base_path, dirs, &name, matched, match_pattern)?; self.restore_dir_entry(base_path, dirs, &name, matched, match_pattern)?;
head = self.read_item()?; 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); 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 MatchType::None
}; };
let header: CaFormatHeader = self.read_item()?; let header: PxarHeader = self.read_item()?;
check_ca_header::<CaFormatEntry>(&header, CA_FORMAT_ENTRY)?; check_ca_header::<PxarEntry>(&header, PXAR_ENTRY)?;
let entry: CaFormatEntry = self.read_item()?; let entry: PxarEntry = self.read_item()?;
let (mut head, attr) = self.read_attributes() let (mut head, attr) = self.read_attributes()
.map_err(|err| format_err!("Reading of directory attributes failed - {}", err))?; .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)?; let name = self.read_filename(head.size)?;
self.restore_dir_entry(path, &mut dirs, &name, matched, match_pattern)?; self.restore_dir_entry(path, &mut dirs, &name, matched, match_pattern)?;
head = self.read_item()?; 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); 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 relative_path = dirs.as_path_buf();
let full_path = base_path.join(&relative_path).join(filename); 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 { if head.htype == PXAR_FORMAT_HARDLINK {
let (target, _offset) = self.read_hardlink(head.size)?; let (target, _offset) = self.read_hardlink(head.size)?;
let target_path = base_path.join(&target); 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(()); return Ok(());
} }
check_ca_header::<CaFormatEntry>(&head, CA_FORMAT_ENTRY)?; check_ca_header::<PxarEntry>(&head, PXAR_ENTRY)?;
let entry: CaFormatEntry = self.read_item()?; let entry: PxarEntry = self.read_item()?;
let mut child_pattern = Vec::new(); let mut child_pattern = Vec::new();
// If parent was a match, then children should be assumed to match too // 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, output: &mut W,
) -> Result<(), Error> { ) -> Result<(), Error> {
let print_head = |head: &CaFormatHeader| { let print_head = |head: &PxarHeader| {
println!("Type: {:016x}", head.htype); println!("Type: {:016x}", head.htype);
println!("Size: {}", head.size); println!("Size: {}", head.size);
}; };
let head: CaFormatHeader = self.read_item()?; let head: PxarHeader = self.read_item()?;
if verbose { if verbose {
println!("Path: {:?}", path); println!("Path: {:?}", path);
print_head(&head); print_head(&head);
@ -821,8 +821,8 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F
return Ok(()); return Ok(());
} }
check_ca_header::<CaFormatEntry>(&head, CA_FORMAT_ENTRY)?; check_ca_header::<PxarEntry>(&head, PXAR_ENTRY)?;
let entry: CaFormatEntry = self.read_item()?; let entry: PxarEntry = self.read_item()?;
if verbose { if verbose {
println!("Mode: {:08x} {:08x}", entry.mode, (entry.mode as u32) & libc::S_IFDIR); 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; let mut entry_count = 0;
loop { loop {
let head: CaFormatHeader = self.read_item()?; let head: PxarHeader = self.read_item()?;
if verbose { if verbose {
print_head(&head); print_head(&head);
} }
@ -849,7 +849,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F
} }
match head.htype { match head.htype {
CA_FORMAT_FILENAME => { PXAR_FILENAME => {
let name = self.read_filename(head.size)?; let name = self.read_filename(head.size)?;
if verbose { println!("Name: {:?}", name); } if verbose { println!("Name: {:?}", name); }
entry_count += 1; 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)?; self.dump_entry(path, verbose, output)?;
path.pop(); path.pop();
}, },
CA_FORMAT_GOODBYE => { PXAR_GOODBYE => {
let table_size = (head.size - HEADER_SIZE) as usize; let table_size = (head.size - HEADER_SIZE) as usize;
if verbose { if verbose {
println!("Goodbye: {:?}", path); 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) (ifmt == libc::S_IFLNK) || (ifmt == libc::S_IFREG)
{ {
loop { loop {
let head: CaFormatHeader = self.read_item()?; let head: PxarHeader = self.read_item()?;
if verbose { if verbose {
print_head(&head); print_head(&head);
} }
@ -888,21 +888,21 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F
} }
match head.htype { match head.htype {
CA_FORMAT_SYMLINK => { PXAR_SYMLINK => {
let target = self.read_link(head.size)?; let target = self.read_link(head.size)?;
if verbose { if verbose {
println!("Symlink: {:?}", target); println!("Symlink: {:?}", target);
} }
break; break;
}, },
CA_FORMAT_DEVICE => { PXAR_DEVICE => {
let device: CaFormatDevice = self.read_item()?; let device: PxarDevice = self.read_item()?;
if verbose { if verbose {
println!("Device: {}, {}", device.major, device.minor); println!("Device: {}, {}", device.major, device.minor);
} }
break; break;
}, },
CA_FORMAT_PAYLOAD => { PXAR_PAYLOAD => {
let payload_size = (head.size - HEADER_SIZE) as usize; let payload_size = (head.size - HEADER_SIZE) as usize;
if verbose { if verbose {
println!("Payload: {}", payload_size); println!("Payload: {}", payload_size);
@ -929,58 +929,58 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F
Ok(()) Ok(())
} }
fn dump_if_attribute(&mut self, header: &CaFormatHeader, verbose: bool) -> Result<bool, Error> { fn dump_if_attribute(&mut self, header: &PxarHeader, verbose: bool) -> Result<bool, Error> {
match header.htype { match header.htype {
CA_FORMAT_XATTR => { PXAR_XATTR => {
let xattr = self.read_xattr((header.size - HEADER_SIZE) as usize)?; let xattr = self.read_xattr((header.size - HEADER_SIZE) as usize)?;
if verbose && self.has_features(flags::WITH_XATTRS) { if verbose && self.has_features(flags::WITH_XATTRS) {
println!("XAttr: {:?}", xattr); println!("XAttr: {:?}", xattr);
} }
}, },
CA_FORMAT_FCAPS => { PXAR_FCAPS => {
let fcaps = self.read_fcaps((header.size - HEADER_SIZE) as usize)?; let fcaps = self.read_fcaps((header.size - HEADER_SIZE) as usize)?;
if verbose && self.has_features(flags::WITH_FCAPS) { if verbose && self.has_features(flags::WITH_FCAPS) {
println!("FCaps: {:?}", fcaps); println!("FCaps: {:?}", fcaps);
} }
}, },
CA_FORMAT_ACL_USER => { PXAR_ACL_USER => {
let user = self.read_item::<CaFormatACLUser>()?; let user = self.read_item::<PxarACLUser>()?;
if verbose && self.has_features(flags::WITH_ACL) { if verbose && self.has_features(flags::WITH_ACL) {
println!("ACLUser: {:?}", user); println!("ACLUser: {:?}", user);
} }
}, },
CA_FORMAT_ACL_GROUP => { PXAR_ACL_GROUP => {
let group = self.read_item::<CaFormatACLGroup>()?; let group = self.read_item::<PxarACLGroup>()?;
if verbose && self.has_features(flags::WITH_ACL) { if verbose && self.has_features(flags::WITH_ACL) {
println!("ACLGroup: {:?}", group); println!("ACLGroup: {:?}", group);
} }
}, },
CA_FORMAT_ACL_GROUP_OBJ => { PXAR_ACL_GROUP_OBJ => {
let group_obj = self.read_item::<CaFormatACLGroupObj>()?; let group_obj = self.read_item::<PxarACLGroupObj>()?;
if verbose && self.has_features(flags::WITH_ACL) { if verbose && self.has_features(flags::WITH_ACL) {
println!("ACLGroupObj: {:?}", group_obj); println!("ACLGroupObj: {:?}", group_obj);
} }
}, },
CA_FORMAT_ACL_DEFAULT => { PXAR_ACL_DEFAULT => {
let default = self.read_item::<CaFormatACLDefault>()?; let default = self.read_item::<PxarACLDefault>()?;
if verbose && self.has_features(flags::WITH_ACL) { if verbose && self.has_features(flags::WITH_ACL) {
println!("ACLDefault: {:?}", default); println!("ACLDefault: {:?}", default);
} }
}, },
CA_FORMAT_ACL_DEFAULT_USER => { PXAR_ACL_DEFAULT_USER => {
let default_user = self.read_item::<CaFormatACLUser>()?; let default_user = self.read_item::<PxarACLUser>()?;
if verbose && self.has_features(flags::WITH_ACL) { if verbose && self.has_features(flags::WITH_ACL) {
println!("ACLDefaultUser: {:?}", default_user); println!("ACLDefaultUser: {:?}", default_user);
} }
}, },
CA_FORMAT_ACL_DEFAULT_GROUP => { PXAR_ACL_DEFAULT_GROUP => {
let default_group = self.read_item::<CaFormatACLGroup>()?; let default_group = self.read_item::<PxarACLGroup>()?;
if verbose && self.has_features(flags::WITH_ACL) { if verbose && self.has_features(flags::WITH_ACL) {
println!("ACLDefaultGroup: {:?}", default_group); println!("ACLDefaultGroup: {:?}", default_group);
} }
}, },
CA_FORMAT_QUOTA_PROJID => { PXAR_QUOTA_PROJID => {
let quota_projid = self.read_item::<CaFormatQuotaProjID>()?; let quota_projid = self.read_item::<PxarQuotaProjID>()?;
if verbose && self.has_features(flags::WITH_QUOTA_PROJID) { if verbose && self.has_features(flags::WITH_QUOTA_PROJID) {
println!("Quota project id: {:?}", 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, table_size: usize,
) -> Result<(), Error> { ) -> Result<(), Error> {
const GOODBYE_ITEM_SIZE: usize = std::mem::size_of::<CaFormatGoodbyeItem>(); const GOODBYE_ITEM_SIZE: usize = std::mem::size_of::<PxarGoodbyeItem>();
if table_size < GOODBYE_ITEM_SIZE { if table_size < GOODBYE_ITEM_SIZE {
bail!("Goodbye table to small ({} < {})", 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; let mut count = 0;
loop { loop {
let item: CaFormatGoodbyeItem = self.read_item()?; let item: PxarGoodbyeItem = self.read_item()?;
count += 1; count += 1;
if item.hash == CA_FORMAT_GOODBYE_TAIL_MARKER { if item.hash == PXAR_GOODBYE_TAIL_MARKER {
if count != entries { if count != entries {
bail!("unexpected goodbye tail marker"); bail!("unexpected goodbye tail marker");
} }

View File

@ -7,7 +7,7 @@ use nix::errno::Errno;
use proxmox::tools::vec; use proxmox::tools::vec;
use crate::pxar::{CaFormatXAttr, CaFormatFCaps}; use crate::pxar::{PxarXAttr, PxarFCaps};
pub fn flistxattr(fd: RawFd) -> Result<Vec<u8>, nix::errno::Errno> { pub fn flistxattr(fd: RawFd) -> Result<Vec<u8>, nix::errno::Errno> {
// Initial buffer size for the attribute list, if content does not fit // Initial buffer size for the attribute list, if content does not fit
@ -64,7 +64,7 @@ pub fn fgetxattr(fd: RawFd, name: &[u8]) -> Result<Vec<u8>, nix::errno::Errno> {
Ok(buffer) 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(); let mut name = xattr.name.clone();
name.push('\0' as u8); name.push('\0' as u8);
let flags = 0 as libc::c_int; let flags = 0 as libc::c_int;
@ -79,7 +79,7 @@ pub fn fsetxattr(fd: RawFd, xattr: &CaFormatXAttr) -> Result<(), nix::errno::Err
Ok(()) 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 // TODO casync checks and removes capabilities if they are set
let name = b"security.capability\0"; let name = b"security.capability\0";
let flags = 0 as libc::c_int; let flags = 0 as libc::c_int;
@ -129,22 +129,22 @@ mod tests {
let fd = file.as_raw_fd(); let fd = file.as_raw_fd();
let valid_user = CaFormatXAttr { let valid_user = PxarXAttr {
name: b"user.attribute0".to_vec(), name: b"user.attribute0".to_vec(),
value: b"value0".to_vec(), value: b"value0".to_vec(),
}; };
let valid_empty_value = CaFormatXAttr { let valid_empty_value = PxarXAttr {
name: b"user.empty".to_vec(), name: b"user.empty".to_vec(),
value: Vec::new(), value: Vec::new(),
}; };
let invalid_trusted = CaFormatXAttr { let invalid_trusted = PxarXAttr {
name: b"trusted.attribute0".to_vec(), name: b"trusted.attribute0".to_vec(),
value: b"value0".to_vec(), value: b"value0".to_vec(),
}; };
let invalid_name_prefix = CaFormatXAttr { let invalid_name_prefix = PxarXAttr {
name: b"users.attribte0".to_vec(), name: b"users.attribte0".to_vec(),
value: b"value".to_vec(), value: b"value".to_vec(),
}; };
@ -154,7 +154,7 @@ mod tests {
name.push(b'a'); name.push(b'a');
} }
let invalid_name_length = CaFormatXAttr { let invalid_name_length = PxarXAttr {
name: name, name: name,
value: b"err".to_vec(), value: b"err".to_vec(),
}; };