From faf574364aa213d584da2ead432c25595b43a153 Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Wed, 22 Mar 2023 18:50:20 -0400 Subject: [PATCH] Add basic data structures to represent Tar archives --- Cargo.lock | 5 +++++ Cargo.toml | 4 ++++ tar/Cargo.toml | 5 +++++ tar/src/header.rs | 21 +++++++++++++++++++++ tar/src/lib.rs | 7 +++++++ tar/src/node.rs | 6 ++++++ 6 files changed, 48 insertions(+) create mode 100644 tar/Cargo.toml create mode 100644 tar/src/header.rs create mode 100644 tar/src/lib.rs create mode 100644 tar/src/node.rs diff --git a/Cargo.lock b/Cargo.lock index 4b25e32..9d44710 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -202,6 +202,7 @@ dependencies = [ "ron", "serde", "sha2", + "tar", "walkdir", ] @@ -393,6 +394,10 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tar" +version = "0.1.0" + [[package]] name = "termcolor" version = "1.2.0" diff --git a/Cargo.toml b/Cargo.toml index c69535e..abb3070 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,11 +5,15 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[workspace] +members = [ "tar" ] + [dependencies] clap = "4.1" rayon = "1.7" ron = "0.8" sha2 = "0.10" +tar = { path = "tar" } walkdir = "2.3" [dependencies.serde] diff --git a/tar/Cargo.toml b/tar/Cargo.toml new file mode 100644 index 0000000..3b4d893 --- /dev/null +++ b/tar/Cargo.toml @@ -0,0 +1,5 @@ +[package] +name = "tar" +version = "0.1.0" +edition = "2021" + diff --git a/tar/src/header.rs b/tar/src/header.rs new file mode 100644 index 0000000..317f519 --- /dev/null +++ b/tar/src/header.rs @@ -0,0 +1,21 @@ +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct Header { + pub fname: [u8; 100], + pub mode: [u8; 8], + pub uid: [u8; 8], + pub gid: [u8; 8], + pub size: [u8; 12], + pub mtime: [u8; 12], + pub header_checksum: [u8; 8], + pub link_indicator: [u8; 1], + pub link_name: [u8; 100], + pub ustar_magic: [u8; 6], + pub ustar_version: [u8; 2], + pub username: [u8; 32], + pub groupname: [u8; 32], + pub device_major: [u8; 8], + pub device_minor: [u8; 8], + pub file_prefix: [u8; 155], + pub reserved: [u8; 12], +} + diff --git a/tar/src/lib.rs b/tar/src/lib.rs new file mode 100644 index 0000000..dadf0e4 --- /dev/null +++ b/tar/src/lib.rs @@ -0,0 +1,7 @@ +mod header; +mod node; +pub use {header::Header, node::Node}; + +pub struct Archive { + pub nodes: Vec, +} diff --git a/tar/src/node.rs b/tar/src/node.rs new file mode 100644 index 0000000..9d4a683 --- /dev/null +++ b/tar/src/node.rs @@ -0,0 +1,6 @@ +use crate::Header; + +pub struct Node { + pub header: Header, + pub data: Vec<[u8; 512]>, +}