summaryrefslogtreecommitdiffstats
path: root/third_party/rust/object/src/archive.rs
blob: 6271d073601f40c669eaba881706606532273f8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! Archive definitions.
//!
//! These definitions are independent of read/write support, although we do implement
//! some traits useful for those.

use crate::pod::Pod;

/// File identification bytes stored at the beginning of the file.
pub const MAGIC: [u8; 8] = *b"!<arch>\n";

/// File identification bytes at the beginning of AIX big archive.
pub const AIX_BIG_MAGIC: [u8; 8] = *b"<bigaf>\n";

/// File identification bytes stored at the beginning of a thin archive.
///
/// A thin archive only contains a symbol table and file names.
pub const THIN_MAGIC: [u8; 8] = *b"!<thin>\n";

/// The terminator for each archive member header.
pub const TERMINATOR: [u8; 2] = *b"`\n";

/// The header at the start of an archive member.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Header {
    /// The file name.
    pub name: [u8; 16],
    /// File modification timestamp in decimal.
    pub date: [u8; 12],
    /// User ID in decimal.
    pub uid: [u8; 6],
    /// Group ID in decimal.
    pub gid: [u8; 6],
    /// File mode in octal.
    pub mode: [u8; 8],
    /// File size in decimal.
    pub size: [u8; 10],
    /// Must be equal to `TERMINATOR`.
    pub terminator: [u8; 2],
}

/// The header at the start of an AIX big archive member, without name.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct AixHeader {
    /// File member size in decimal.
    pub size: [u8; 20],
    /// Next member offset in decimal.
    pub nxtmem: [u8; 20],
    /// Previous member offset in decimal.
    pub prvmem: [u8; 20],
    /// File member date in decimal.
    pub date: [u8; 12],
    /// File member user id in decimal.
    pub uid: [u8; 12],
    /// File member group id in decimal.
    pub gid: [u8; 12],
    /// File member mode in octal.
    pub mode: [u8; 12],
    /// File member name length in decimal.
    pub namlen: [u8; 4],
}

/// The AIX big archive's fixed length header at file beginning.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct AixFileHeader {
    /// Archive magic string.
    pub magic: [u8; 8],
    /// Offset of member table.
    pub memoff: [u8; 20],
    /// Offset of global symbol table.
    pub gstoff: [u8; 20],
    /// Offset of global symbol table for 64-bit objects.
    pub gst64off: [u8; 20],
    /// Offset of first member.
    pub fstmoff: [u8; 20],
    /// Offset of last member.
    pub lstmoff: [u8; 20],
    /// Offset of first member on free list.
    pub freeoff: [u8; 20],
}

/// Offset of a member in an AIX big archive.
///
/// This is used in the member index.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct AixMemberOffset(pub [u8; 20]);

unsafe_impl_pod!(Header, AixHeader, AixFileHeader, AixMemberOffset,);