]> git.proxmox.com Git - proxmox-backup.git/commitdiff
catar/encoder.rs: cleanups
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 11 Jan 2019 09:01:51 +0000 (10:01 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 11 Jan 2019 09:01:51 +0000 (10:01 +0100)
src/catar/encoder.rs
src/catar/format_definition.rs

index ff4617d80e7e24a91ba4523a0df3a97de9106ff8..c1d4c078d37fedb49b4bda8d830a36018c502b7a 100644 (file)
@@ -74,11 +74,9 @@ impl <'a, W: Write> CaTarEncoder<'a, W> {
         Ok(())
     }
 
-    fn write_item<T: Endian + Clone>(&mut self, item: &T) ->  Result<(), Error> {
+    fn write_item<T: Endian>(&mut self, item: T) ->  Result<(), Error> {
 
-        let mut data: T = unsafe { std::mem::uninitialized() };
-
-        data = (*item).clone().to_le();
+        let data = item.to_le();
 
         let buffer = unsafe { std::slice::from_raw_parts(
             &data as *const T as *const u8,
@@ -99,7 +97,7 @@ impl <'a, W: Write> CaTarEncoder<'a, W> {
     fn write_header(&mut self, htype: u64, size: u64) -> Result<(), Error> {
 
         let size = size + (std::mem::size_of::<CaFormatHeader>() as u64);
-        self.write_item(&CaFormatHeader { size, htype })?;
+        self.write_item(CaFormatHeader { size, htype })?;
 
         Ok(())
     }
@@ -149,7 +147,7 @@ impl <'a, W: Write> CaTarEncoder<'a, W> {
         Ok(())
     }
 
-    fn write_entry(&mut self, entry: &CaFormatEntry) -> Result<(), Error> {
+    fn write_entry(&mut self, entry: CaFormatEntry) -> Result<(), Error> {
 
         self.write_header(CA_FORMAT_ENTRY, std::mem::size_of::<CaFormatEntry>() as u64)?;
         self.write_item(entry)?;
@@ -210,7 +208,7 @@ impl <'a, W: Write> CaTarEncoder<'a, W> {
 
         self.read_chattr(rawfd, &mut dir_entry)?;
 
-        self.write_entry(&dir_entry)?;
+        self.write_entry(dir_entry)?;
 
         let mut dir_count = 0;
 
@@ -327,7 +325,7 @@ impl <'a, W: Write> CaTarEncoder<'a, W> {
 
         self.read_chattr(filefd, &mut entry)?;
 
-        self.write_entry(&entry)?;
+        self.write_entry(entry)?;
 
         let size = stat.st_size as u64;
 
@@ -369,7 +367,7 @@ impl <'a, W: Write> CaTarEncoder<'a, W> {
         //println!("encode_symlink: {:?} -> {:?}", self.current_path, target);
 
         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(target)?;
@@ -398,6 +396,7 @@ fn errno_is_unsupported(errno: Errno) -> bool {
 }
 
 use nix::{convert_ioctl_res, request_code_read, ioc};
+
 // /usr/include/linux/fs.h: #define FS_IOC_GETFLAGS _IOR('f', 1, long)
 /// read Linux file system attributes (see man chattr)
 nix::ioctl_read!(read_attr_fd, b'f', 1, usize);
index cb44cf20c2bf67e74c19f3dd7ba4cd5d087e82c9..6534510f555ca128a00232f3a798c2955acce7dd 100644 (file)
@@ -22,26 +22,38 @@ pub const CA_FORMAT_GOODBYE_TAIL_MARKER: u64 = 0x57446fa533702943;
 
 // Feature flags
 
-// DOS file flags
+/// DOS file flag `HIDDEN`
 pub const CA_FORMAT_WITH_FLAG_HIDDEN: u64      = 0x2000;
+/// DOS file flag `SYSTEM`
 pub const CA_FORMAT_WITH_FLAG_SYSTEM: u64      = 0x4000;
+/// DOS file flag `ARCHIVE`
 pub const CA_FORMAT_WITH_FLAG_ARCHIVE: u64     = 0x8000;
 
-// chattr() flags
+// chattr() flags#
+/// Linux file attribute `APPEND`
 pub const CA_FORMAT_WITH_FLAG_APPEND: u64      = 0x10000;
+/// Linux file attribute `NOATIME`
 pub const CA_FORMAT_WITH_FLAG_NOATIME: u64     = 0x20000;
+/// Linux file attribute `COMPR`
 pub const CA_FORMAT_WITH_FLAG_COMPR: u64       = 0x40000;
+/// Linux file attribute `NOCOW`
 pub const CA_FORMAT_WITH_FLAG_NOCOW: u64       = 0x80000;
+/// Linux file attribute `NODUMP`
 pub const CA_FORMAT_WITH_FLAG_NODUMP: u64      = 0x100000;
+/// Linux file attribute `DIRSYNC`
 pub const CA_FORMAT_WITH_FLAG_DIRSYNC: u64     = 0x200000;
+/// Linux file attribute `IMMUTABLE`
 pub const CA_FORMAT_WITH_FLAG_IMMUTABLE: u64   = 0x400000;
+/// Linux file attribute `SYNC`
 pub const CA_FORMAT_WITH_FLAG_SYNC: u64        = 0x800000;
+/// Linux file attribute `NOCOMP`
 pub const CA_FORMAT_WITH_FLAG_NOCOMP: u64      = 0x1000000;
+/// Linux file attribute `PROJINHERIT`
 pub const CA_FORMAT_WITH_FLAG_PROJINHERIT: u64 = 0x2000000;
 
 pub const CA_FORMAT_FEATURE_FLAGS_MAX: u64 = 0xb000_0001_ffef_fe26; // fixme: ?
 
-#[derive(Endian,Clone)]
+#[derive(Endian)]
 #[repr(C)]
 pub struct CaFormatHeader {
     /// The size of the item, including the size of `CaFormatHeader`.
@@ -50,7 +62,7 @@ pub struct CaFormatHeader {
     pub htype: u64,
 }
 
-#[derive(Endian,Clone)]
+#[derive(Endian)]
 #[repr(C)]
 pub struct CaFormatEntry {
     pub feature_flags: u64,
@@ -147,6 +159,5 @@ pub fn ca_feature_flags_from_chattr(attr: u32) -> u64 {
         if (attr & fs_flag) != 0 { flags = flags | ca_flag; }
     }
 
-
     flags
 }