@@ -82,21 +82,21 @@ struct Directory<'a> {
8282}
8383
8484#[ derive( Debug ) ]
85- struct Leaf < ' a > {
86- content : & ' a image:: LeafContent ,
85+ struct Leaf < ' a , ObjectID : FsVerityHashValue > {
86+ content : & ' a image:: LeafContent < ObjectID > ,
8787 nlink : usize ,
8888}
8989
9090#[ derive( Debug ) ]
91- enum InodeContent < ' a > {
91+ enum InodeContent < ' a , ObjectID : FsVerityHashValue > {
9292 Directory ( Directory < ' a > ) ,
93- Leaf ( Leaf < ' a > ) ,
93+ Leaf ( Leaf < ' a , ObjectID > ) ,
9494}
9595
96- struct Inode < ' a > {
96+ struct Inode < ' a , ObjectID : FsVerityHashValue > {
9797 stat : & ' a image:: Stat ,
9898 xattrs : InodeXAttrs ,
99- content : InodeContent < ' a > ,
99+ content : InodeContent < ' a , ObjectID > ,
100100}
101101
102102impl XAttr {
@@ -263,7 +263,7 @@ impl<'a> Directory<'a> {
263263 }
264264}
265265
266- impl Leaf < ' _ > {
266+ impl < ObjectID : FsVerityHashValue > Leaf < ' _ , ObjectID > {
267267 fn inode_meta ( & self ) -> ( format:: DataLayout , u32 , u64 , usize ) {
268268 let ( layout, u, size) = match & self . content {
269269 image:: LeafContent :: Regular ( image:: RegularFile :: Inline ( data) ) => {
@@ -299,7 +299,7 @@ impl Leaf<'_> {
299299 }
300300}
301301
302- impl Inode < ' _ > {
302+ impl < ObjectID : FsVerityHashValue > Inode < ' _ , ObjectID > {
303303 fn file_type ( & self ) -> format:: FileType {
304304 match & self . content {
305305 InodeContent :: Directory ( ..) => format:: FileType :: Directory ,
@@ -395,13 +395,13 @@ impl Inode<'_> {
395395 }
396396}
397397
398- struct InodeCollector < ' a > {
399- inodes : Vec < Inode < ' a > > ,
400- hardlinks : HashMap < * const image:: Leaf , usize > ,
398+ struct InodeCollector < ' a , ObjectID : FsVerityHashValue > {
399+ inodes : Vec < Inode < ' a , ObjectID > > ,
400+ hardlinks : HashMap < * const image:: Leaf < ObjectID > , usize > ,
401401}
402402
403- impl < ' a > InodeCollector < ' a > {
404- fn push_inode ( & mut self , stat : & ' a image:: Stat , content : InodeContent < ' a > ) -> usize {
403+ impl < ' a , ObjectID : FsVerityHashValue > InodeCollector < ' a , ObjectID > {
404+ fn push_inode ( & mut self , stat : & ' a image:: 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.
@@ -442,7 +442,7 @@ impl<'a> InodeCollector<'a> {
442442 inode
443443 }
444444
445- fn collect_leaf ( & mut self , leaf : & ' a Rc < image:: Leaf > ) -> usize {
445+ fn collect_leaf ( & mut self , leaf : & ' a Rc < image:: Leaf < ObjectID > > ) -> usize {
446446 let nlink = Rc :: strong_count ( leaf) ;
447447
448448 if nlink > 1 {
@@ -481,7 +481,7 @@ impl<'a> InodeCollector<'a> {
481481 entries. insert ( point, entry) ;
482482 }
483483
484- fn collect_dir ( & mut self , dir : & ' a image:: Directory , parent : usize ) -> usize {
484+ fn collect_dir ( & mut self , dir : & ' a image:: 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 ( ) ) ) ;
@@ -509,7 +509,7 @@ impl<'a> InodeCollector<'a> {
509509 me
510510 }
511511
512- pub fn collect ( fs : & ' a image:: FileSystem ) -> Vec < Inode < ' a > > {
512+ pub fn collect ( fs : & ' a image:: FileSystem < ObjectID > ) -> Vec < Inode < ' a , ObjectID > > {
513513 let mut this = Self {
514514 inodes : vec ! [ ] ,
515515 hardlinks : HashMap :: new ( ) ,
@@ -525,7 +525,7 @@ impl<'a> InodeCollector<'a> {
525525
526526/// Takes a list of inodes where each inode contains only local xattr values, determines which
527527/// xattrs (key, value) pairs appear more than once, and shares them.
528- fn share_xattrs ( inodes : & mut [ Inode ] ) -> Vec < XAttr > {
528+ fn share_xattrs < ObjectID : FsVerityHashValue > ( inodes : & mut [ Inode < ObjectID > ] ) -> Vec < XAttr > {
529529 let mut xattrs: BTreeMap < XAttr , usize > = BTreeMap :: new ( ) ;
530530
531531 // Collect all xattrs from the inodes
@@ -563,7 +563,11 @@ fn share_xattrs(inodes: &mut [Inode]) -> Vec<XAttr> {
563563 xattrs. into_keys ( ) . collect ( )
564564}
565565
566- fn write_erofs ( output : & mut impl Output , inodes : & [ Inode ] , xattrs : & [ XAttr ] ) {
566+ fn write_erofs < ObjectID : FsVerityHashValue > (
567+ output : & mut impl Output ,
568+ inodes : & [ Inode < ObjectID > ] ,
569+ xattrs : & [ XAttr ] ,
570+ ) {
567571 // Write composefs header
568572 output. note_offset ( Offset :: Header ) ;
569573 output. write_struct ( format:: ComposefsHeader {
@@ -684,7 +688,7 @@ impl Output for FirstPass {
684688 }
685689}
686690
687- pub fn mkfs_erofs ( fs : & image:: FileSystem ) -> Box < [ u8 ] > {
691+ pub fn mkfs_erofs < ObjectID : FsVerityHashValue > ( fs : & image:: FileSystem < ObjectID > ) -> Box < [ u8 ] > {
688692 // Create the intermediate representation: flattened inodes and shared xattrs
689693 let mut inodes = InodeCollector :: collect ( fs) ;
690694 let xattrs = share_xattrs ( & mut inodes) ;
0 commit comments