cpio::newc

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)
7
8
9
10
11
12
13
14
15
fn load_file(path: &str) -> io::Result<(NewcBuilder, File)> {
	let builder = NewcBuilder::new(path)
		.uid(1000)
		.gid(1000)
		.mode(0o100644);
		
	File::open(path)
		.map(|fp| (builder, fp))
}
More examples
Hide additional examples
examples/other-file-types.rs (line 20)
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
fn main() {
    // Set up our input files
    let data1: &[u8] = b"Hello, World";
    let length1 = data1.len() as u32;
    let mut input1 = io::Cursor::new(data1);

    let data2: &[u8] = b"Hello, World 2";
    let length2 = data2.len() as u32;
    let mut input2 = io::Cursor::new(data2);

    // Set up our output file
    let output = stdout();

    // Set up the descriptor of our input file
    let b = NewcBuilder::new("./hello_world")
        .ino(1)
        .uid(1000)
        .gid(1000)
        .mode(0o100644);
    // and get a writer for that input file
    let mut writer = b.write(output, length1);

    // Copy the input file into our CPIO archive
    io::copy(&mut input1, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    // Set up the descriptor of an empty directory
    let b = NewcBuilder::new("./empty_dir")
        .ino(2)
        .uid(1000)
        .gid(1000)
        .mode(0o000755)
        .set_mode_file_type(cpio::newc::ModeFileType::Directory);
    let writer = b.write(output, 0);
    let output = writer.finish().unwrap();

    // Set up the descriptor of our second input file
    let b = NewcBuilder::new("./hello_world2")
        .ino(3)
        .uid(1000)
        .gid(1000)
        .mode(0o100644);
    // and get a writer for that input file
    let mut writer = b.write(output, length2);

    // Copy the second input file into our CPIO archive
    io::copy(&mut input2, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    let data: &[u8] = b"./hello_world2";
    let length = data.len() as u32;
    let mut input = io::Cursor::new(data);

    // Set up the descriptor for a symlink
    let b = NewcBuilder::new("./hello-link")
        .ino(4)
        .uid(1000)
        .gid(1000)
        .mode(0o100644)
        .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
    let mut writer = b.write(output, length);
    io::copy(&mut input, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    // Finish up by writing the trailer for the archive
    let _ = trailer(output).unwrap();
}
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)
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
fn main() {
    // Set up our input files
    let data1: &[u8] = b"Hello, World";
    let length1 = data1.len() as u32;
    let mut input1 = io::Cursor::new(data1);

    let data2: &[u8] = b"Hello, World 2";
    let length2 = data2.len() as u32;
    let mut input2 = io::Cursor::new(data2);

    // Set up our output file
    let output = stdout();

    // Set up the descriptor of our input file
    let b = NewcBuilder::new("./hello_world")
        .ino(1)
        .uid(1000)
        .gid(1000)
        .mode(0o100644);
    // and get a writer for that input file
    let mut writer = b.write(output, length1);

    // Copy the input file into our CPIO archive
    io::copy(&mut input1, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    // Set up the descriptor of an empty directory
    let b = NewcBuilder::new("./empty_dir")
        .ino(2)
        .uid(1000)
        .gid(1000)
        .mode(0o000755)
        .set_mode_file_type(cpio::newc::ModeFileType::Directory);
    let writer = b.write(output, 0);
    let output = writer.finish().unwrap();

    // Set up the descriptor of our second input file
    let b = NewcBuilder::new("./hello_world2")
        .ino(3)
        .uid(1000)
        .gid(1000)
        .mode(0o100644);
    // and get a writer for that input file
    let mut writer = b.write(output, length2);

    // Copy the second input file into our CPIO archive
    io::copy(&mut input2, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    let data: &[u8] = b"./hello_world2";
    let length = data.len() as u32;
    let mut input = io::Cursor::new(data);

    // Set up the descriptor for a symlink
    let b = NewcBuilder::new("./hello-link")
        .ino(4)
        .uid(1000)
        .gid(1000)
        .mode(0o100644)
        .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
    let mut writer = b.write(output, length);
    io::copy(&mut input, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    // Finish up by writing the trailer for the archive
    let _ = trailer(output).unwrap();
}
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)
7
8
9
10
11
12
13
14
15
fn load_file(path: &str) -> io::Result<(NewcBuilder, File)> {
	let builder = NewcBuilder::new(path)
		.uid(1000)
		.gid(1000)
		.mode(0o100644);
		
	File::open(path)
		.map(|fp| (builder, fp))
}
More examples
Hide additional examples
examples/other-file-types.rs (line 24)
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
fn main() {
    // Set up our input files
    let data1: &[u8] = b"Hello, World";
    let length1 = data1.len() as u32;
    let mut input1 = io::Cursor::new(data1);

    let data2: &[u8] = b"Hello, World 2";
    let length2 = data2.len() as u32;
    let mut input2 = io::Cursor::new(data2);

    // Set up our output file
    let output = stdout();

    // Set up the descriptor of our input file
    let b = NewcBuilder::new("./hello_world")
        .ino(1)
        .uid(1000)
        .gid(1000)
        .mode(0o100644);
    // and get a writer for that input file
    let mut writer = b.write(output, length1);

    // Copy the input file into our CPIO archive
    io::copy(&mut input1, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    // Set up the descriptor of an empty directory
    let b = NewcBuilder::new("./empty_dir")
        .ino(2)
        .uid(1000)
        .gid(1000)
        .mode(0o000755)
        .set_mode_file_type(cpio::newc::ModeFileType::Directory);
    let writer = b.write(output, 0);
    let output = writer.finish().unwrap();

    // Set up the descriptor of our second input file
    let b = NewcBuilder::new("./hello_world2")
        .ino(3)
        .uid(1000)
        .gid(1000)
        .mode(0o100644);
    // and get a writer for that input file
    let mut writer = b.write(output, length2);

    // Copy the second input file into our CPIO archive
    io::copy(&mut input2, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    let data: &[u8] = b"./hello_world2";
    let length = data.len() as u32;
    let mut input = io::Cursor::new(data);

    // Set up the descriptor for a symlink
    let b = NewcBuilder::new("./hello-link")
        .ino(4)
        .uid(1000)
        .gid(1000)
        .mode(0o100644)
        .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
    let mut writer = b.write(output, length);
    io::copy(&mut input, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    // Finish up by writing the trailer for the archive
    let _ = trailer(output).unwrap();
}
Source

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

Set this file’s UID.

Examples found in repository?
examples/createcpio.rs (line 9)
7
8
9
10
11
12
13
14
15
fn load_file(path: &str) -> io::Result<(NewcBuilder, File)> {
	let builder = NewcBuilder::new(path)
		.uid(1000)
		.gid(1000)
		.mode(0o100644);
		
	File::open(path)
		.map(|fp| (builder, fp))
}
More examples
Hide additional examples
examples/other-file-types.rs (line 22)
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
fn main() {
    // Set up our input files
    let data1: &[u8] = b"Hello, World";
    let length1 = data1.len() as u32;
    let mut input1 = io::Cursor::new(data1);

    let data2: &[u8] = b"Hello, World 2";
    let length2 = data2.len() as u32;
    let mut input2 = io::Cursor::new(data2);

    // Set up our output file
    let output = stdout();

    // Set up the descriptor of our input file
    let b = NewcBuilder::new("./hello_world")
        .ino(1)
        .uid(1000)
        .gid(1000)
        .mode(0o100644);
    // and get a writer for that input file
    let mut writer = b.write(output, length1);

    // Copy the input file into our CPIO archive
    io::copy(&mut input1, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    // Set up the descriptor of an empty directory
    let b = NewcBuilder::new("./empty_dir")
        .ino(2)
        .uid(1000)
        .gid(1000)
        .mode(0o000755)
        .set_mode_file_type(cpio::newc::ModeFileType::Directory);
    let writer = b.write(output, 0);
    let output = writer.finish().unwrap();

    // Set up the descriptor of our second input file
    let b = NewcBuilder::new("./hello_world2")
        .ino(3)
        .uid(1000)
        .gid(1000)
        .mode(0o100644);
    // and get a writer for that input file
    let mut writer = b.write(output, length2);

    // Copy the second input file into our CPIO archive
    io::copy(&mut input2, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    let data: &[u8] = b"./hello_world2";
    let length = data.len() as u32;
    let mut input = io::Cursor::new(data);

    // Set up the descriptor for a symlink
    let b = NewcBuilder::new("./hello-link")
        .ino(4)
        .uid(1000)
        .gid(1000)
        .mode(0o100644)
        .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
    let mut writer = b.write(output, length);
    io::copy(&mut input, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    // Finish up by writing the trailer for the archive
    let _ = trailer(output).unwrap();
}
Source

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

Set this file’s GID.

Examples found in repository?
examples/createcpio.rs (line 10)
7
8
9
10
11
12
13
14
15
fn load_file(path: &str) -> io::Result<(NewcBuilder, File)> {
	let builder = NewcBuilder::new(path)
		.uid(1000)
		.gid(1000)
		.mode(0o100644);
		
	File::open(path)
		.map(|fp| (builder, fp))
}
More examples
Hide additional examples
examples/other-file-types.rs (line 23)
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
fn main() {
    // Set up our input files
    let data1: &[u8] = b"Hello, World";
    let length1 = data1.len() as u32;
    let mut input1 = io::Cursor::new(data1);

    let data2: &[u8] = b"Hello, World 2";
    let length2 = data2.len() as u32;
    let mut input2 = io::Cursor::new(data2);

    // Set up our output file
    let output = stdout();

    // Set up the descriptor of our input file
    let b = NewcBuilder::new("./hello_world")
        .ino(1)
        .uid(1000)
        .gid(1000)
        .mode(0o100644);
    // and get a writer for that input file
    let mut writer = b.write(output, length1);

    // Copy the input file into our CPIO archive
    io::copy(&mut input1, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    // Set up the descriptor of an empty directory
    let b = NewcBuilder::new("./empty_dir")
        .ino(2)
        .uid(1000)
        .gid(1000)
        .mode(0o000755)
        .set_mode_file_type(cpio::newc::ModeFileType::Directory);
    let writer = b.write(output, 0);
    let output = writer.finish().unwrap();

    // Set up the descriptor of our second input file
    let b = NewcBuilder::new("./hello_world2")
        .ino(3)
        .uid(1000)
        .gid(1000)
        .mode(0o100644);
    // and get a writer for that input file
    let mut writer = b.write(output, length2);

    // Copy the second input file into our CPIO archive
    io::copy(&mut input2, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    let data: &[u8] = b"./hello_world2";
    let length = data.len() as u32;
    let mut input = io::Cursor::new(data);

    // Set up the descriptor for a symlink
    let b = NewcBuilder::new("./hello-link")
        .ino(4)
        .uid(1000)
        .gid(1000)
        .mode(0o100644)
        .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
    let mut writer = b.write(output, length);
    io::copy(&mut input, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    // Finish up by writing the trailer for the archive
    let _ = trailer(output).unwrap();
}

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)
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
fn main() {
    // Set up our input files
    let data1: &[u8] = b"Hello, World";
    let length1 = data1.len() as u32;
    let mut input1 = io::Cursor::new(data1);

    let data2: &[u8] = b"Hello, World 2";
    let length2 = data2.len() as u32;
    let mut input2 = io::Cursor::new(data2);

    // Set up our output file
    let output = stdout();

    // Set up the descriptor of our input file
    let b = NewcBuilder::new("./hello_world")
        .ino(1)
        .uid(1000)
        .gid(1000)
        .mode(0o100644);
    // and get a writer for that input file
    let mut writer = b.write(output, length1);

    // Copy the input file into our CPIO archive
    io::copy(&mut input1, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    // Set up the descriptor of an empty directory
    let b = NewcBuilder::new("./empty_dir")
        .ino(2)
        .uid(1000)
        .gid(1000)
        .mode(0o000755)
        .set_mode_file_type(cpio::newc::ModeFileType::Directory);
    let writer = b.write(output, 0);
    let output = writer.finish().unwrap();

    // Set up the descriptor of our second input file
    let b = NewcBuilder::new("./hello_world2")
        .ino(3)
        .uid(1000)
        .gid(1000)
        .mode(0o100644);
    // and get a writer for that input file
    let mut writer = b.write(output, length2);

    // Copy the second input file into our CPIO archive
    io::copy(&mut input2, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    let data: &[u8] = b"./hello_world2";
    let length = data.len() as u32;
    let mut input = io::Cursor::new(data);

    // Set up the descriptor for a symlink
    let b = NewcBuilder::new("./hello-link")
        .ino(4)
        .uid(1000)
        .gid(1000)
        .mode(0o100644)
        .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
    let mut writer = b.write(output, length);
    io::copy(&mut input, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    // Finish up by writing the trailer for the archive
    let _ = trailer(output).unwrap();
}
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)
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
fn main() {
    // Set up our input files
    let data1: &[u8] = b"Hello, World";
    let length1 = data1.len() as u32;
    let mut input1 = io::Cursor::new(data1);

    let data2: &[u8] = b"Hello, World 2";
    let length2 = data2.len() as u32;
    let mut input2 = io::Cursor::new(data2);

    // Set up our output file
    let output = stdout();

    // Set up the descriptor of our input file
    let b = NewcBuilder::new("./hello_world")
        .ino(1)
        .uid(1000)
        .gid(1000)
        .mode(0o100644);
    // and get a writer for that input file
    let mut writer = b.write(output, length1);

    // Copy the input file into our CPIO archive
    io::copy(&mut input1, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    // Set up the descriptor of an empty directory
    let b = NewcBuilder::new("./empty_dir")
        .ino(2)
        .uid(1000)
        .gid(1000)
        .mode(0o000755)
        .set_mode_file_type(cpio::newc::ModeFileType::Directory);
    let writer = b.write(output, 0);
    let output = writer.finish().unwrap();

    // Set up the descriptor of our second input file
    let b = NewcBuilder::new("./hello_world2")
        .ino(3)
        .uid(1000)
        .gid(1000)
        .mode(0o100644);
    // and get a writer for that input file
    let mut writer = b.write(output, length2);

    // Copy the second input file into our CPIO archive
    io::copy(&mut input2, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    let data: &[u8] = b"./hello_world2";
    let length = data.len() as u32;
    let mut input = io::Cursor::new(data);

    // Set up the descriptor for a symlink
    let b = NewcBuilder::new("./hello-link")
        .ino(4)
        .uid(1000)
        .gid(1000)
        .mode(0o100644)
        .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
    let mut writer = b.write(output, length);
    io::copy(&mut input, &mut writer).unwrap();
    let output = writer.finish().unwrap();

    // Finish up by writing the trailer for the archive
    let _ = trailer(output).unwrap();
}
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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.