]> git.proxmox.com Git - proxmox-backup.git/blob - src/catar/format_definition.rs
catar cleanups ...
[proxmox-backup.git] / src / catar / format_definition.rs
1 //! *catar* binary format definition
2 //!
3 //! Please note the all values are stored in little endian ordering.
4 //!
5 //! The Archive contains a list of items. Each item starts with a
6 //! `CaFormatHeader`, followed by the item data.
7
8 use failure::*;
9
10 use siphasher::sip::SipHasher24;
11
12 pub const CA_FORMAT_ENTRY: u64 = 0x1396fabcea5bbb51;
13 pub const CA_FORMAT_FILENAME: u64 = 0x6dbb6ebcb3161f0b;
14 pub const CA_FORMAT_SYMLINK: u64 = 0x664a6fb6830e0d6c;
15 pub const CA_FORMAT_PAYLOAD: u64 = 0x8b9e1d93d6dcffc9;
16
17 pub const CA_FORMAT_GOODBYE: u64 = 0xdfd35c5e8327c403;
18 /* The end marker used in the GOODBYE object */
19 pub const CA_FORMAT_GOODBYE_TAIL_MARKER: u64 = 0x57446fa533702943;
20
21 pub const CA_FORMAT_FEATURE_FLAGS_MAX: u64 = 0xb000_0001_ffef_fe26; // fixme: ?
22
23 #[repr(C)]
24 pub struct CaFormatHeader {
25 /// The size of the item, including the size of `CaFormatHeader`.
26 pub size: u64,
27 /// The item type (see `CA_FORMAT_` constants).
28 pub htype: u64,
29 }
30
31 #[repr(C)]
32 pub struct CaFormatEntry {
33 pub feature_flags: u64,
34 pub mode: u64,
35 pub flags: u64,
36 pub uid: u64,
37 pub gid: u64,
38 pub mtime: u64,
39 }
40
41 #[repr(C)]
42 pub struct CaFormatGoodbyeItem {
43 /// The offset from the start of the GOODBYE object to the start
44 /// of the matching directory item (point to a FILENAME). The last
45 /// GOODBYE item points to the start of the matching ENTRY
46 /// object. repeats the `size`
47 pub offset: u64,
48 /// The overall size of the directory item. The last GOODBYE item
49 /// repeats the size of the GOODBYE item.
50 pub size: u64,
51 /// SipHash24 of the directory item name. The last GOODBYE item
52 /// uses the special hash value `CA_FORMAT_GOODBYE_TAIL_MARKER`.
53 pub hash: u64,
54 }
55
56
57 /// Helper function to extract file names from binary archive.
58 pub fn read_os_string(buffer: &[u8]) -> std::ffi::OsString {
59 let len = buffer.len();
60
61 use std::os::unix::ffi::OsStrExt;
62
63 let name = if len > 0 && buffer[len-1] == 0 {
64 std::ffi::OsStr::from_bytes(&buffer[0..len-1])
65 } else {
66 std::ffi::OsStr::from_bytes(&buffer)
67 };
68
69 name.into()
70 }
71
72 /// Create SipHash values for goodby tables.
73 //pub fn compute_goodbye_hash(name: &std::ffi::CStr) -> u64 {
74 pub fn compute_goodbye_hash(name: &[u8]) -> u64 {
75
76 use std::hash::Hasher;
77 let mut hasher = SipHasher24::new_with_keys(0x8574442b0f1d84b3, 0x2736ed30d1c22ec1);
78 hasher.write(name);
79 hasher.finish()
80 }