Struct Builder

Source
pub struct Builder { /* private fields */ }
Expand description

Builds metadata for one entry to be written into an archive.

Implementations§

Source§

impl Builder

Source

pub fn new(name: &str) -> Self

Create the metadata for one CPIO entry

Examples found in repository?
examples/createcpio.rs (line 8)
7fn load_file(path: &str) -> io::Result<(NewcBuilder, File)> {
8	let builder = NewcBuilder::new(path)
9		.uid(1000)
10		.gid(1000)
11		.mode(0o100644);
12		
13	File::open(path)
14		.map(|fp| (builder, fp))
15}
More examples
Hide additional examples
examples/other-file-types.rs (line 20)
6fn main() {
7    // Set up our input files
8    let data1: &[u8] = b"Hello, World";
9    let length1 = data1.len() as u32;
10    let mut input1 = io::Cursor::new(data1);
11
12    let data2: &[u8] = b"Hello, World 2";
13    let length2 = data2.len() as u32;
14    let mut input2 = io::Cursor::new(data2);
15
16    // Set up our output file
17    let output = stdout();
18
19    // Set up the descriptor of our input file
20    let b = NewcBuilder::new("./hello_world")
21        .ino(1)
22        .uid(1000)
23        .gid(1000)
24        .mode(0o100644);
25    // and get a writer for that input file
26    let mut writer = b.write(output, length1);
27
28    // Copy the input file into our CPIO archive
29    io::copy(&mut input1, &mut writer).unwrap();
30    let output = writer.finish().unwrap();
31
32    // Set up the descriptor of an empty directory
33    let b = NewcBuilder::new("./empty_dir")
34        .ino(2)
35        .uid(1000)
36        .gid(1000)
37        .mode(0o000755)
38        .set_mode_file_type(cpio::newc::ModeFileType::Directory);
39    let writer = b.write(output, 0);
40    let output = writer.finish().unwrap();
41
42    // Set up the descriptor of our second input file
43    let b = NewcBuilder::new("./hello_world2")
44        .ino(3)
45        .uid(1000)
46        .gid(1000)
47        .mode(0o100644);
48    // and get a writer for that input file
49    let mut writer = b.write(output, length2);
50
51    // Copy the second input file into our CPIO archive
52    io::copy(&mut input2, &mut writer).unwrap();
53    let output = writer.finish().unwrap();
54
55    let data: &[u8] = b"./hello_world2";
56    let length = data.len() as u32;
57    let mut input = io::Cursor::new(data);
58
59    // Set up the descriptor for a symlink
60    let b = NewcBuilder::new("./hello-link")
61        .ino(4)
62        .uid(1000)
63        .gid(1000)
64        .mode(0o100644)
65        .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
66    let mut writer = b.write(output, length);
67    io::copy(&mut input, &mut writer).unwrap();
68    let output = writer.finish().unwrap();
69
70    // Finish up by writing the trailer for the archive
71    let _ = trailer(output).unwrap();
72}
Source

pub fn ino(self, ino: u32) -> Self

Set the inode number for this file. In modern times however, typically this is just a a unique index ID for the file, rather than the actual inode number.

Examples found in repository?
examples/other-file-types.rs (line 21)
6fn main() {
7    // Set up our input files
8    let data1: &[u8] = b"Hello, World";
9    let length1 = data1.len() as u32;
10    let mut input1 = io::Cursor::new(data1);
11
12    let data2: &[u8] = b"Hello, World 2";
13    let length2 = data2.len() as u32;
14    let mut input2 = io::Cursor::new(data2);
15
16    // Set up our output file
17    let output = stdout();
18
19    // Set up the descriptor of our input file
20    let b = NewcBuilder::new("./hello_world")
21        .ino(1)
22        .uid(1000)
23        .gid(1000)
24        .mode(0o100644);
25    // and get a writer for that input file
26    let mut writer = b.write(output, length1);
27
28    // Copy the input file into our CPIO archive
29    io::copy(&mut input1, &mut writer).unwrap();
30    let output = writer.finish().unwrap();
31
32    // Set up the descriptor of an empty directory
33    let b = NewcBuilder::new("./empty_dir")
34        .ino(2)
35        .uid(1000)
36        .gid(1000)
37        .mode(0o000755)
38        .set_mode_file_type(cpio::newc::ModeFileType::Directory);
39    let writer = b.write(output, 0);
40    let output = writer.finish().unwrap();
41
42    // Set up the descriptor of our second input file
43    let b = NewcBuilder::new("./hello_world2")
44        .ino(3)
45        .uid(1000)
46        .gid(1000)
47        .mode(0o100644);
48    // and get a writer for that input file
49    let mut writer = b.write(output, length2);
50
51    // Copy the second input file into our CPIO archive
52    io::copy(&mut input2, &mut writer).unwrap();
53    let output = writer.finish().unwrap();
54
55    let data: &[u8] = b"./hello_world2";
56    let length = data.len() as u32;
57    let mut input = io::Cursor::new(data);
58
59    // Set up the descriptor for a symlink
60    let b = NewcBuilder::new("./hello-link")
61        .ino(4)
62        .uid(1000)
63        .gid(1000)
64        .mode(0o100644)
65        .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
66    let mut writer = b.write(output, length);
67    io::copy(&mut input, &mut writer).unwrap();
68    let output = writer.finish().unwrap();
69
70    // Finish up by writing the trailer for the archive
71    let _ = trailer(output).unwrap();
72}
Source

pub fn mode(self, mode: u32) -> Self

Set the file’s “mode” - the same as an inode “mode” field - containing permission bits and a bit of metadata about the type of file represented.

Examples found in repository?
examples/createcpio.rs (line 11)
7fn load_file(path: &str) -> io::Result<(NewcBuilder, File)> {
8	let builder = NewcBuilder::new(path)
9		.uid(1000)
10		.gid(1000)
11		.mode(0o100644);
12		
13	File::open(path)
14		.map(|fp| (builder, fp))
15}
More examples
Hide additional examples
examples/other-file-types.rs (line 24)
6fn main() {
7    // Set up our input files
8    let data1: &[u8] = b"Hello, World";
9    let length1 = data1.len() as u32;
10    let mut input1 = io::Cursor::new(data1);
11
12    let data2: &[u8] = b"Hello, World 2";
13    let length2 = data2.len() as u32;
14    let mut input2 = io::Cursor::new(data2);
15
16    // Set up our output file
17    let output = stdout();
18
19    // Set up the descriptor of our input file
20    let b = NewcBuilder::new("./hello_world")
21        .ino(1)
22        .uid(1000)
23        .gid(1000)
24        .mode(0o100644);
25    // and get a writer for that input file
26    let mut writer = b.write(output, length1);
27
28    // Copy the input file into our CPIO archive
29    io::copy(&mut input1, &mut writer).unwrap();
30    let output = writer.finish().unwrap();
31
32    // Set up the descriptor of an empty directory
33    let b = NewcBuilder::new("./empty_dir")
34        .ino(2)
35        .uid(1000)
36        .gid(1000)
37        .mode(0o000755)
38        .set_mode_file_type(cpio::newc::ModeFileType::Directory);
39    let writer = b.write(output, 0);
40    let output = writer.finish().unwrap();
41
42    // Set up the descriptor of our second input file
43    let b = NewcBuilder::new("./hello_world2")
44        .ino(3)
45        .uid(1000)
46        .gid(1000)
47        .mode(0o100644);
48    // and get a writer for that input file
49    let mut writer = b.write(output, length2);
50
51    // Copy the second input file into our CPIO archive
52    io::copy(&mut input2, &mut writer).unwrap();
53    let output = writer.finish().unwrap();
54
55    let data: &[u8] = b"./hello_world2";
56    let length = data.len() as u32;
57    let mut input = io::Cursor::new(data);
58
59    // Set up the descriptor for a symlink
60    let b = NewcBuilder::new("./hello-link")
61        .ino(4)
62        .uid(1000)
63        .gid(1000)
64        .mode(0o100644)
65        .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
66    let mut writer = b.write(output, length);
67    io::copy(&mut input, &mut writer).unwrap();
68    let output = writer.finish().unwrap();
69
70    // Finish up by writing the trailer for the archive
71    let _ = trailer(output).unwrap();
72}
Source

pub fn uid(self, uid: u32) -> Self

Set this file’s UID.

Examples found in repository?
examples/createcpio.rs (line 9)
7fn load_file(path: &str) -> io::Result<(NewcBuilder, File)> {
8	let builder = NewcBuilder::new(path)
9		.uid(1000)
10		.gid(1000)
11		.mode(0o100644);
12		
13	File::open(path)
14		.map(|fp| (builder, fp))
15}
More examples
Hide additional examples
examples/other-file-types.rs (line 22)
6fn main() {
7    // Set up our input files
8    let data1: &[u8] = b"Hello, World";
9    let length1 = data1.len() as u32;
10    let mut input1 = io::Cursor::new(data1);
11
12    let data2: &[u8] = b"Hello, World 2";
13    let length2 = data2.len() as u32;
14    let mut input2 = io::Cursor::new(data2);
15
16    // Set up our output file
17    let output = stdout();
18
19    // Set up the descriptor of our input file
20    let b = NewcBuilder::new("./hello_world")
21        .ino(1)
22        .uid(1000)
23        .gid(1000)
24        .mode(0o100644);
25    // and get a writer for that input file
26    let mut writer = b.write(output, length1);
27
28    // Copy the input file into our CPIO archive
29    io::copy(&mut input1, &mut writer).unwrap();
30    let output = writer.finish().unwrap();
31
32    // Set up the descriptor of an empty directory
33    let b = NewcBuilder::new("./empty_dir")
34        .ino(2)
35        .uid(1000)
36        .gid(1000)
37        .mode(0o000755)
38        .set_mode_file_type(cpio::newc::ModeFileType::Directory);
39    let writer = b.write(output, 0);
40    let output = writer.finish().unwrap();
41
42    // Set up the descriptor of our second input file
43    let b = NewcBuilder::new("./hello_world2")
44        .ino(3)
45        .uid(1000)
46        .gid(1000)
47        .mode(0o100644);
48    // and get a writer for that input file
49    let mut writer = b.write(output, length2);
50
51    // Copy the second input file into our CPIO archive
52    io::copy(&mut input2, &mut writer).unwrap();
53    let output = writer.finish().unwrap();
54
55    let data: &[u8] = b"./hello_world2";
56    let length = data.len() as u32;
57    let mut input = io::Cursor::new(data);
58
59    // Set up the descriptor for a symlink
60    let b = NewcBuilder::new("./hello-link")
61        .ino(4)
62        .uid(1000)
63        .gid(1000)
64        .mode(0o100644)
65        .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
66    let mut writer = b.write(output, length);
67    io::copy(&mut input, &mut writer).unwrap();
68    let output = writer.finish().unwrap();
69
70    // Finish up by writing the trailer for the archive
71    let _ = trailer(output).unwrap();
72}
Source

pub fn gid(self, gid: u32) -> Self

Set this file’s GID.

Examples found in repository?
examples/createcpio.rs (line 10)
7fn load_file(path: &str) -> io::Result<(NewcBuilder, File)> {
8	let builder = NewcBuilder::new(path)
9		.uid(1000)
10		.gid(1000)
11		.mode(0o100644);
12		
13	File::open(path)
14		.map(|fp| (builder, fp))
15}
More examples
Hide additional examples
examples/other-file-types.rs (line 23)
6fn main() {
7    // Set up our input files
8    let data1: &[u8] = b"Hello, World";
9    let length1 = data1.len() as u32;
10    let mut input1 = io::Cursor::new(data1);
11
12    let data2: &[u8] = b"Hello, World 2";
13    let length2 = data2.len() as u32;
14    let mut input2 = io::Cursor::new(data2);
15
16    // Set up our output file
17    let output = stdout();
18
19    // Set up the descriptor of our input file
20    let b = NewcBuilder::new("./hello_world")
21        .ino(1)
22        .uid(1000)
23        .gid(1000)
24        .mode(0o100644);
25    // and get a writer for that input file
26    let mut writer = b.write(output, length1);
27
28    // Copy the input file into our CPIO archive
29    io::copy(&mut input1, &mut writer).unwrap();
30    let output = writer.finish().unwrap();
31
32    // Set up the descriptor of an empty directory
33    let b = NewcBuilder::new("./empty_dir")
34        .ino(2)
35        .uid(1000)
36        .gid(1000)
37        .mode(0o000755)
38        .set_mode_file_type(cpio::newc::ModeFileType::Directory);
39    let writer = b.write(output, 0);
40    let output = writer.finish().unwrap();
41
42    // Set up the descriptor of our second input file
43    let b = NewcBuilder::new("./hello_world2")
44        .ino(3)
45        .uid(1000)
46        .gid(1000)
47        .mode(0o100644);
48    // and get a writer for that input file
49    let mut writer = b.write(output, length2);
50
51    // Copy the second input file into our CPIO archive
52    io::copy(&mut input2, &mut writer).unwrap();
53    let output = writer.finish().unwrap();
54
55    let data: &[u8] = b"./hello_world2";
56    let length = data.len() as u32;
57    let mut input = io::Cursor::new(data);
58
59    // Set up the descriptor for a symlink
60    let b = NewcBuilder::new("./hello-link")
61        .ino(4)
62        .uid(1000)
63        .gid(1000)
64        .mode(0o100644)
65        .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
66    let mut writer = b.write(output, length);
67    io::copy(&mut input, &mut writer).unwrap();
68    let output = writer.finish().unwrap();
69
70    // Finish up by writing the trailer for the archive
71    let _ = trailer(output).unwrap();
72}

Set the number of links associated with this file.

Source

pub fn mtime(self, mtime: u32) -> Self

Set the modification time of this file.

Source

pub fn dev_major(self, dev_major: u32) -> Self

Set the major component of the device ID, describing the device on which this file resides.

Device IDs are comprised of a major and minor component. The major component identifies the class of device, while the minor component identifies a specific device of that class.

Source

pub fn dev_minor(self, dev_minor: u32) -> Self

Set the minor component of the device ID, describing the device on which this file resides.

Device IDs are comprised of a major and minor component. The major component identifies the class of device, while the minor component identifies a specific device of that class.

Source

pub fn rdev_major(self, rdev_major: u32) -> Self

Set the major component of the rdev ID, describes the device that this file (inode) represents.

Device IDs are comprised of a major and minor component. The major component identifies the class of device, while the minor component identifies a specific device of that class.

Source

pub fn rdev_minor(self, rdev_minor: u32) -> Self

Set the minor component of the rdev ID, field describes the device that this file (inode) represents.

Device IDs are comprised of a major and minor component. The major component identifies the class of device, while the minor component identifies a specific device of that class.

Source

pub fn set_mode_file_type(self, file_type: ModeFileType) -> Self

Set the mode file type of the entry

Examples found in repository?
examples/other-file-types.rs (line 38)
6fn main() {
7    // Set up our input files
8    let data1: &[u8] = b"Hello, World";
9    let length1 = data1.len() as u32;
10    let mut input1 = io::Cursor::new(data1);
11
12    let data2: &[u8] = b"Hello, World 2";
13    let length2 = data2.len() as u32;
14    let mut input2 = io::Cursor::new(data2);
15
16    // Set up our output file
17    let output = stdout();
18
19    // Set up the descriptor of our input file
20    let b = NewcBuilder::new("./hello_world")
21        .ino(1)
22        .uid(1000)
23        .gid(1000)
24        .mode(0o100644);
25    // and get a writer for that input file
26    let mut writer = b.write(output, length1);
27
28    // Copy the input file into our CPIO archive
29    io::copy(&mut input1, &mut writer).unwrap();
30    let output = writer.finish().unwrap();
31
32    // Set up the descriptor of an empty directory
33    let b = NewcBuilder::new("./empty_dir")
34        .ino(2)
35        .uid(1000)
36        .gid(1000)
37        .mode(0o000755)
38        .set_mode_file_type(cpio::newc::ModeFileType::Directory);
39    let writer = b.write(output, 0);
40    let output = writer.finish().unwrap();
41
42    // Set up the descriptor of our second input file
43    let b = NewcBuilder::new("./hello_world2")
44        .ino(3)
45        .uid(1000)
46        .gid(1000)
47        .mode(0o100644);
48    // and get a writer for that input file
49    let mut writer = b.write(output, length2);
50
51    // Copy the second input file into our CPIO archive
52    io::copy(&mut input2, &mut writer).unwrap();
53    let output = writer.finish().unwrap();
54
55    let data: &[u8] = b"./hello_world2";
56    let length = data.len() as u32;
57    let mut input = io::Cursor::new(data);
58
59    // Set up the descriptor for a symlink
60    let b = NewcBuilder::new("./hello-link")
61        .ino(4)
62        .uid(1000)
63        .gid(1000)
64        .mode(0o100644)
65        .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
66    let mut writer = b.write(output, length);
67    io::copy(&mut input, &mut writer).unwrap();
68    let output = writer.finish().unwrap();
69
70    // Finish up by writing the trailer for the archive
71    let _ = trailer(output).unwrap();
72}
Source

pub fn write<W: Write>(self, w: W, file_size: u32) -> Writer<W>

Write out an entry to the provided writer in SVR4 “new ascii” CPIO format.

Examples found in repository?
examples/other-file-types.rs (line 26)
6fn main() {
7    // Set up our input files
8    let data1: &[u8] = b"Hello, World";
9    let length1 = data1.len() as u32;
10    let mut input1 = io::Cursor::new(data1);
11
12    let data2: &[u8] = b"Hello, World 2";
13    let length2 = data2.len() as u32;
14    let mut input2 = io::Cursor::new(data2);
15
16    // Set up our output file
17    let output = stdout();
18
19    // Set up the descriptor of our input file
20    let b = NewcBuilder::new("./hello_world")
21        .ino(1)
22        .uid(1000)
23        .gid(1000)
24        .mode(0o100644);
25    // and get a writer for that input file
26    let mut writer = b.write(output, length1);
27
28    // Copy the input file into our CPIO archive
29    io::copy(&mut input1, &mut writer).unwrap();
30    let output = writer.finish().unwrap();
31
32    // Set up the descriptor of an empty directory
33    let b = NewcBuilder::new("./empty_dir")
34        .ino(2)
35        .uid(1000)
36        .gid(1000)
37        .mode(0o000755)
38        .set_mode_file_type(cpio::newc::ModeFileType::Directory);
39    let writer = b.write(output, 0);
40    let output = writer.finish().unwrap();
41
42    // Set up the descriptor of our second input file
43    let b = NewcBuilder::new("./hello_world2")
44        .ino(3)
45        .uid(1000)
46        .gid(1000)
47        .mode(0o100644);
48    // and get a writer for that input file
49    let mut writer = b.write(output, length2);
50
51    // Copy the second input file into our CPIO archive
52    io::copy(&mut input2, &mut writer).unwrap();
53    let output = writer.finish().unwrap();
54
55    let data: &[u8] = b"./hello_world2";
56    let length = data.len() as u32;
57    let mut input = io::Cursor::new(data);
58
59    // Set up the descriptor for a symlink
60    let b = NewcBuilder::new("./hello-link")
61        .ino(4)
62        .uid(1000)
63        .gid(1000)
64        .mode(0o100644)
65        .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
66    let mut writer = b.write(output, length);
67    io::copy(&mut input, &mut writer).unwrap();
68    let output = writer.finish().unwrap();
69
70    // Finish up by writing the trailer for the archive
71    let _ = trailer(output).unwrap();
72}
Source

pub fn write_crc<W: Write>( self, w: W, file_size: u32, file_checksum: u32, ) -> Writer<W>

Write out an entry to the provided writer in SVR4 “new crc” CPIO format.

Trait Implementations§

Source§

impl Clone for Builder

Source§

fn clone(&self) -> Builder

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.