Skip to content

Commit 0e2d52f

Browse files
committed
Add read-only xattr support to the API.
1 parent ec41a9c commit 0e2d52f

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

fal-backend-apfs/src/filesystem.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,4 +681,12 @@ impl<D: fal::DeviceMut> fal::Filesystem<D> for Filesystem<D> {
681681
fn write(&mut self, _fh: u64, _offset: u64, _buffer: &[u8]) -> Result<u64> {
682682
unimplemented!()
683683
}
684+
fn get_xattr(&mut self, _inode: &Inode, _name: &[u8]) -> Result<Vec<u8>> {
685+
// TODO: This shouldn't be too hard to implement since the xattrs are already stored in th
686+
// tree, and used internally (for symlinks).
687+
unimplemented!("getting extended attributes")
688+
}
689+
fn list_xattrs(&mut self, _inode: &Inode) -> Result<Vec<Vec<u8>>> {
690+
unimplemented!("listing extended attributes")
691+
}
684692
}

fal-backend-ext4/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub use superblock::Superblock;
2323

2424
use disk::Disk;
2525
use inode::InodeIoError;
26+
use xattr::XattrEntry;
2627

2728
pub fn allocate_block_bytes(superblock: &Superblock) -> Box<[u8]> {
2829
vec![0u8; superblock.block_size() as usize].into_boxed_slice()
@@ -388,6 +389,19 @@ impl<D: fal::DeviceMut> fal::Filesystem<D> for Filesystem<D> {
388389
fn unlink(&mut self, _parent: u32, _name: &[u8]) -> fal::Result<()> {
389390
unimplemented!()
390391
}
392+
fn get_xattr(&mut self, inode: &Inode, name: &[u8]) -> fal::Result<Vec<u8>> {
393+
match inode.xattrs {
394+
Some(ref x) => x.entries.iter().find(|(k, _)| k.name == name).ok_or(fal::Error::NoEntity).map(|(_, v)| v.clone()),
395+
None => Err(fal::Error::NoEntity),
396+
}
397+
}
398+
fn list_xattrs(&mut self, inode: &Inode) -> fal::Result<Vec<Vec<u8>>> {
399+
// TODO: Support block-based xattrs as well.
400+
match inode.xattrs {
401+
Some(ref x) => Ok(x.entries.iter().map(|(entry, _)| &entry.name).cloned().collect()),
402+
None => Ok(vec! []),
403+
}
404+
}
391405
}
392406

393407
pub fn calculate_crc32c(value: u32, bytes: &[u8]) -> u32 {

fal/src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,11 @@ where
366366

367367
// XXX: Rust's type system doesn't support associated types with lifetimes. If a backend wants
368368
// to use a concurrent hashmap for storing the file handles, then there won't be a direct
369-
// reference, but an RAII guard. Basically all RAII guards store their owner, and to replace the
370-
// return type with a guard, an associated type with a lifetime is required. On the other hand,
371-
// inodes aren't typically that slow to clone. However with generic associated types, this
372-
// problem will likely be easily solved.
369+
// reference, but an RAII guard. Basically all RAII guards store their owner as a reference,
370+
// and to replace the return type with a guard, an associated type with a lifetime is required.
371+
// On the other hand, inodes aren't typically that slow to clone. However with generic associated
372+
// types, this problem will likely be easily solved, as Self::InodeStruct can have an
373+
// untethered lifetime.
373374
//
374375
// https://github.com/rust-lang/rust/issues/44265
375376
//
@@ -389,6 +390,13 @@ where
389390
/// entry reaches zero, the inode is deleted and its space is freed. However, if that inode is
390391
/// still open, it won't be removed until that.
391392
fn unlink(&mut self, parent: Self::InodeAddr, name: &[u8]) -> Result<()>;
393+
394+
/// Get a named extended attribute from an inode.
395+
fn get_xattr(&mut self, inode: &Self::InodeStruct, name: &[u8]) -> Result<Vec<u8>>;
396+
397+
/// List the extended attribute names (keys) from an inode.
398+
// TODO: Perhaps this double vector should be a null-separated u8 vector instead.
399+
fn list_xattrs(&mut self, inode: &Self::InodeStruct) -> Result<Vec<Vec<u8>>>;
392400
}
393401

394402
#[derive(Debug)]

0 commit comments

Comments
 (0)