]> git.proxmox.com Git - proxmox-backup.git/blame - src/catar/format_definition.rs
catar cleanups ...
[proxmox-backup.git] / src / catar / format_definition.rs
CommitLineData
4fa71e05
DM
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
b62b6cad
DM
8use failure::*;
9
0866748d
DM
10use siphasher::sip::SipHasher24;
11
3192ae96
DM
12pub const CA_FORMAT_ENTRY: u64 = 0x1396fabcea5bbb51;
13pub const CA_FORMAT_FILENAME: u64 = 0x6dbb6ebcb3161f0b;
14pub const CA_FORMAT_SYMLINK: u64 = 0x664a6fb6830e0d6c;
2e4ae0e2
DM
15pub const CA_FORMAT_PAYLOAD: u64 = 0x8b9e1d93d6dcffc9;
16
3192ae96 17pub const CA_FORMAT_GOODBYE: u64 = 0xdfd35c5e8327c403;
b62b6cad 18/* The end marker used in the GOODBYE object */
3192ae96 19pub const CA_FORMAT_GOODBYE_TAIL_MARKER: u64 = 0x57446fa533702943;
b62b6cad 20
a0cc09b5
DM
21pub const CA_FORMAT_FEATURE_FLAGS_MAX: u64 = 0xb000_0001_ffef_fe26; // fixme: ?
22
b62b6cad
DM
23#[repr(C)]
24pub struct CaFormatHeader {
4fa71e05 25 /// The size of the item, including the size of `CaFormatHeader`.
3192ae96 26 pub size: u64,
4fa71e05 27 /// The item type (see `CA_FORMAT_` constants).
3192ae96 28 pub htype: u64,
b62b6cad
DM
29}
30
31#[repr(C)]
32pub struct CaFormatEntry {
3192ae96
DM
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,
b62b6cad
DM
39}
40
41#[repr(C)]
42pub struct CaFormatGoodbyeItem {
4fa71e05
DM
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`
3192ae96 47 pub offset: u64,
4fa71e05
DM
48 /// The overall size of the directory item. The last GOODBYE item
49 /// repeats the size of the GOODBYE item.
3192ae96 50 pub size: u64,
4fa71e05
DM
51 /// SipHash24 of the directory item name. The last GOODBYE item
52 /// uses the special hash value `CA_FORMAT_GOODBYE_TAIL_MARKER`.
3192ae96 53 pub hash: u64,
b62b6cad
DM
54}
55
0866748d
DM
56
57/// Helper function to extract file names from binary archive.
58pub fn read_os_string(buffer: &[u8]) -> std::ffi::OsString {
b62b6cad
DM
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}
0866748d
DM
71
72/// Create SipHash values for goodby tables.
73//pub fn compute_goodbye_hash(name: &std::ffi::CStr) -> u64 {
74pub 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}