Skip to content

Commit 1ebdad3

Browse files
src/image.rs: rename to tree.rs
This file has always had a bad name. Conceptually it represents the content of an image, but the word "image" has way too many meanings in this crate. When I talk to other people about this code I usually find myself calling it "the in-memory filesystem tree", so let's rename it to "tree". This commit was completely automated thanks to LSP tooling and rust-fmt. Signed-off-by: Allison Karlitskaya <[email protected]>
1 parent bb0eddb commit 1ebdad3

File tree

10 files changed

+36
-36
lines changed

10 files changed

+36
-36
lines changed

src/dumpfile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustix::fs::FileType;
1313

1414
use crate::{
1515
fsverity::FsVerityHashValue,
16-
image::{Directory, FileSystem, Inode, Leaf, LeafContent, RegularFile, Stat},
16+
tree::{Directory, FileSystem, Inode, Leaf, LeafContent, RegularFile, Stat},
1717
};
1818

1919
fn write_empty(writer: &mut impl fmt::Write) -> fmt::Result {

src/erofs/writer.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use zerocopy::{Immutable, IntoBytes};
1313
use crate::{
1414
erofs::{composefs::OverlayMetacopy, format, reader::round_up},
1515
fsverity::FsVerityHashValue,
16-
image,
16+
tree,
1717
};
1818

1919
#[derive(Clone, Copy, Debug)]
@@ -83,7 +83,7 @@ struct Directory<'a> {
8383

8484
#[derive(Debug)]
8585
struct Leaf<'a, ObjectID: FsVerityHashValue> {
86-
content: &'a image::LeafContent<ObjectID>,
86+
content: &'a tree::LeafContent<ObjectID>,
8787
nlink: usize,
8888
}
8989

@@ -94,7 +94,7 @@ enum InodeContent<'a, ObjectID: FsVerityHashValue> {
9494
}
9595

9696
struct Inode<'a, ObjectID: FsVerityHashValue> {
97-
stat: &'a image::Stat,
97+
stat: &'a tree::Stat,
9898
xattrs: InodeXAttrs,
9999
content: InodeContent<'a, ObjectID>,
100100
}
@@ -266,23 +266,23 @@ impl<'a> Directory<'a> {
266266
impl<ObjectID: FsVerityHashValue> Leaf<'_, ObjectID> {
267267
fn inode_meta(&self) -> (format::DataLayout, u32, u64, usize) {
268268
let (layout, u, size) = match &self.content {
269-
image::LeafContent::Regular(image::RegularFile::Inline(data)) => {
269+
tree::LeafContent::Regular(tree::RegularFile::Inline(data)) => {
270270
if data.is_empty() {
271271
(format::DataLayout::FlatPlain, 0, data.len() as u64)
272272
} else {
273273
(format::DataLayout::FlatInline, 0, data.len() as u64)
274274
}
275275
}
276-
image::LeafContent::Regular(image::RegularFile::External(.., size)) => {
276+
tree::LeafContent::Regular(tree::RegularFile::External(.., size)) => {
277277
(format::DataLayout::ChunkBased, 31, *size)
278278
}
279-
image::LeafContent::CharacterDevice(rdev) | image::LeafContent::BlockDevice(rdev) => {
279+
tree::LeafContent::CharacterDevice(rdev) | tree::LeafContent::BlockDevice(rdev) => {
280280
(format::DataLayout::FlatPlain, *rdev as u32, 0)
281281
}
282-
image::LeafContent::Fifo | image::LeafContent::Socket => {
282+
tree::LeafContent::Fifo | tree::LeafContent::Socket => {
283283
(format::DataLayout::FlatPlain, 0, 0)
284284
}
285-
image::LeafContent::Symlink(target) => {
285+
tree::LeafContent::Symlink(target) => {
286286
(format::DataLayout::FlatInline, 0, target.len() as u64)
287287
}
288288
};
@@ -291,9 +291,9 @@ impl<ObjectID: FsVerityHashValue> Leaf<'_, ObjectID> {
291291

292292
fn write_inline(&self, output: &mut impl Output) {
293293
output.write(match self.content {
294-
image::LeafContent::Regular(image::RegularFile::Inline(data)) => data,
295-
image::LeafContent::Regular(image::RegularFile::External(..)) => b"\xff\xff\xff\xff", // null chunk
296-
image::LeafContent::Symlink(target) => target.as_bytes(),
294+
tree::LeafContent::Regular(tree::RegularFile::Inline(data)) => data,
295+
tree::LeafContent::Regular(tree::RegularFile::External(..)) => b"\xff\xff\xff\xff", // null chunk
296+
tree::LeafContent::Symlink(target) => target.as_bytes(),
297297
_ => &[],
298298
});
299299
}
@@ -304,12 +304,12 @@ impl<ObjectID: FsVerityHashValue> Inode<'_, ObjectID> {
304304
match &self.content {
305305
InodeContent::Directory(..) => format::FileType::Directory,
306306
InodeContent::Leaf(leaf) => match &leaf.content {
307-
image::LeafContent::Regular(..) => format::FileType::RegularFile,
308-
image::LeafContent::CharacterDevice(..) => format::FileType::CharacterDevice,
309-
image::LeafContent::BlockDevice(..) => format::FileType::BlockDevice,
310-
image::LeafContent::Fifo => format::FileType::Fifo,
311-
image::LeafContent::Socket => format::FileType::Socket,
312-
image::LeafContent::Symlink(..) => format::FileType::Symlink,
307+
tree::LeafContent::Regular(..) => format::FileType::RegularFile,
308+
tree::LeafContent::CharacterDevice(..) => format::FileType::CharacterDevice,
309+
tree::LeafContent::BlockDevice(..) => format::FileType::BlockDevice,
310+
tree::LeafContent::Fifo => format::FileType::Fifo,
311+
tree::LeafContent::Socket => format::FileType::Socket,
312+
tree::LeafContent::Symlink(..) => format::FileType::Symlink,
313313
},
314314
}
315315
}
@@ -397,16 +397,16 @@ impl<ObjectID: FsVerityHashValue> Inode<'_, ObjectID> {
397397

398398
struct InodeCollector<'a, ObjectID: FsVerityHashValue> {
399399
inodes: Vec<Inode<'a, ObjectID>>,
400-
hardlinks: HashMap<*const image::Leaf<ObjectID>, usize>,
400+
hardlinks: HashMap<*const tree::Leaf<ObjectID>, usize>,
401401
}
402402

403403
impl<'a, ObjectID: FsVerityHashValue> InodeCollector<'a, ObjectID> {
404-
fn push_inode(&mut self, stat: &'a image::Stat, content: InodeContent<'a, ObjectID>) -> usize {
404+
fn push_inode(&mut self, stat: &'a tree::Stat, content: InodeContent<'a, ObjectID>) -> usize {
405405
let mut xattrs = InodeXAttrs::default();
406406

407407
// We need to record extra xattrs for some files. These come first.
408408
if let InodeContent::Leaf(Leaf {
409-
content: image::LeafContent::Regular(image::RegularFile::External(id, ..)),
409+
content: tree::LeafContent::Regular(tree::RegularFile::External(id, ..)),
410410
..
411411
}) = content
412412
{
@@ -442,7 +442,7 @@ impl<'a, ObjectID: FsVerityHashValue> InodeCollector<'a, ObjectID> {
442442
inode
443443
}
444444

445-
fn collect_leaf(&mut self, leaf: &'a Rc<image::Leaf<ObjectID>>) -> usize {
445+
fn collect_leaf(&mut self, leaf: &'a Rc<tree::Leaf<ObjectID>>) -> usize {
446446
let nlink = Rc::strong_count(leaf);
447447

448448
if nlink > 1 {
@@ -481,7 +481,7 @@ impl<'a, ObjectID: FsVerityHashValue> InodeCollector<'a, ObjectID> {
481481
entries.insert(point, entry);
482482
}
483483

484-
fn collect_dir(&mut self, dir: &'a image::Directory<ObjectID>, parent: usize) -> usize {
484+
fn collect_dir(&mut self, dir: &'a tree::Directory<ObjectID>, parent: usize) -> usize {
485485
// The root inode number needs to fit in a u16. That more or less compels us to write the
486486
// directory inode before the inode of the children of the directory. Reserve a slot.
487487
let me = self.push_inode(&dir.stat, InodeContent::Directory(Directory::default()));
@@ -490,8 +490,8 @@ impl<'a, ObjectID: FsVerityHashValue> InodeCollector<'a, ObjectID> {
490490

491491
for (name, inode) in dir.sorted_entries() {
492492
let child = match inode {
493-
image::Inode::Directory(dir) => self.collect_dir(dir, me),
494-
image::Inode::Leaf(leaf) => self.collect_leaf(leaf),
493+
tree::Inode::Directory(dir) => self.collect_dir(dir, me),
494+
tree::Inode::Leaf(leaf) => self.collect_leaf(leaf),
495495
};
496496
entries.push(DirEnt {
497497
name: name.as_bytes(),
@@ -509,7 +509,7 @@ impl<'a, ObjectID: FsVerityHashValue> InodeCollector<'a, ObjectID> {
509509
me
510510
}
511511

512-
pub fn collect(fs: &'a image::FileSystem<ObjectID>) -> Vec<Inode<'a, ObjectID>> {
512+
pub fn collect(fs: &'a tree::FileSystem<ObjectID>) -> Vec<Inode<'a, ObjectID>> {
513513
let mut this = Self {
514514
inodes: vec![],
515515
hardlinks: HashMap::new(),
@@ -688,7 +688,7 @@ impl Output for FirstPass {
688688
}
689689
}
690690

691-
pub fn mkfs_erofs<ObjectID: FsVerityHashValue>(fs: &image::FileSystem<ObjectID>) -> Box<[u8]> {
691+
pub fn mkfs_erofs<ObjectID: FsVerityHashValue>(fs: &tree::FileSystem<ObjectID>) -> Box<[u8]> {
692692
// Create the intermediate representation: flattened inodes and shared xattrs
693693
let mut inodes = InodeCollector::collect(fs);
694694
let xattrs = share_xattrs(&mut inodes);

src/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ use zerocopy::IntoBytes;
2525

2626
use crate::{
2727
fsverity::{compute_verity, FsVerityHashValue},
28-
image::{Directory, FileSystem, Inode, Leaf, LeafContent, RegularFile, Stat},
2928
repository::Repository,
3029
selabel::selabel,
30+
tree::{Directory, FileSystem, Inode, Leaf, LeafContent, RegularFile, Stat},
3131
util::proc_self_fd,
3232
INLINE_CONTENT_MAX,
3333
};

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ pub mod dumpfile_parse;
55
pub mod erofs;
66
pub mod fs;
77
pub mod fsverity;
8-
pub mod image;
98
pub mod mount;
109
pub mod mountcompat;
1110
pub mod oci;
1211
pub mod repository;
1312
pub mod selabel;
1413
pub mod splitstream;
14+
pub mod tree;
1515
pub mod uki;
1616
pub mod util;
1717

src/oci/image.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ use crate::{
77
dumpfile::write_dumpfile,
88
erofs::writer::mkfs_erofs,
99
fsverity::FsVerityHashValue,
10-
image::{Directory, FileSystem, Inode, Leaf},
1110
oci::{
1211
self,
1312
tar::{TarEntry, TarItem},
1413
},
1514
repository::Repository,
1615
selabel::selabel,
16+
tree::{Directory, FileSystem, Inode, Leaf},
1717
};
1818

1919
pub fn process_entry<ObjectID: FsVerityHashValue>(
@@ -107,7 +107,7 @@ pub fn create_image<ObjectID: FsVerityHashValue>(
107107
mod test {
108108
use crate::{
109109
fsverity::Sha256HashValue,
110-
image::{LeafContent, RegularFile, Stat},
110+
tree::{LeafContent, RegularFile, Stat},
111111
};
112112
use std::{cell::RefCell, collections::BTreeMap, io::BufRead, path::PathBuf};
113113

src/oci/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ pub fn prepare_boot<ObjectID: FsVerityHashValue>(
391391
.with_context(|| "Attachments layer {layer} is not connected to image {name}")?;
392392

393393
// read the layer into a FileSystem object
394-
let mut filesystem = crate::image::FileSystem::new();
394+
let mut filesystem = crate::tree::FileSystem::new();
395395
let mut split_stream = repo.open_stream(&hex::encode(layer_sha256), Some(layer_verity))?;
396396
while let Some(entry) = tar::get_entry(&mut split_stream)? {
397397
image::process_entry(&mut filesystem, entry)?;

src/oci/tar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use tokio::io::{AsyncRead, AsyncReadExt};
1616
use crate::{
1717
dumpfile,
1818
fsverity::FsVerityHashValue,
19-
image::{LeafContent, RegularFile, Stat},
2019
splitstream::{SplitStreamData, SplitStreamReader, SplitStreamWriter},
20+
tree::{LeafContent, RegularFile, Stat},
2121
util::{read_exactish, read_exactish_async},
2222
INLINE_CONTENT_MAX,
2323
};

src/selabel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use regex_automata::{hybrid::dfa, util::syntax, Anchored, Input};
1212

1313
use crate::{
1414
fsverity::FsVerityHashValue,
15-
image::{Directory, FileSystem, ImageError, Inode, Leaf, LeafContent, RegularFile, Stat},
1615
repository::Repository,
16+
tree::{Directory, FileSystem, ImageError, Inode, Leaf, LeafContent, RegularFile, Stat},
1717
};
1818

1919
/* We build the entire SELinux policy into a single "lazy DFA" such that:

src/image.rs renamed to src/tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<ObjectID: FsVerityHashValue> Directory<ObjectID> {
9696
/// point.
9797
///
9898
/// ```
99-
/// use composefs::{image::FileSystem, fsverity::Sha256HashValue};
99+
/// use composefs::{tree::FileSystem, fsverity::Sha256HashValue};
100100
/// let fs = FileSystem::<Sha256HashValue>::new();
101101
///
102102
/// // populate the fs...

tests/mkfs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use composefs::{
1414
dumpfile::write_dumpfile,
1515
erofs::{debug::debug_img, writer::mkfs_erofs},
1616
fsverity::{FsVerityHashValue, Sha256HashValue},
17-
image::{Directory, FileSystem, Inode, Leaf, LeafContent, RegularFile, Stat},
17+
tree::{Directory, FileSystem, Inode, Leaf, LeafContent, RegularFile, Stat},
1818
};
1919

2020
fn debug_fs(mut fs: FileSystem<impl FsVerityHashValue>) -> String {

0 commit comments

Comments
 (0)