mirror of
https://github.com/hexagonal-sun/moss-kernel.git
synced 2026-05-24 08:55:20 -04:00
libkernel: Add support for xattr in ext4
This commit is contained in:
@@ -35,7 +35,7 @@ tock-registers = { version = "0.10.1", optional = true }
|
||||
|
||||
# fs
|
||||
async-trait = { workspace = true, optional = true }
|
||||
ext4plus = { version = "0.1.0-beta.1", optional = true }
|
||||
ext4plus = { version = "0.1.0-beta.3", optional = true }
|
||||
|
||||
# proc_vm
|
||||
object = { version = "0.38.0", default-features = false, features = ["core", "elf", "read_core"], optional = true }
|
||||
|
||||
@@ -19,11 +19,12 @@ use crate::{
|
||||
blk::buffer::BlockBuffer,
|
||||
},
|
||||
};
|
||||
use alloc::string::ToString;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec::Vec;
|
||||
use alloc::{
|
||||
boxed::Box,
|
||||
sync::{Arc, Weak},
|
||||
vec,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use core::any::Any;
|
||||
@@ -583,6 +584,49 @@ where
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
async fn getxattr(&self, name: &str) -> Result<Vec<u8>> {
|
||||
let inner = self.inner.lock().await;
|
||||
let fs = self.fs_ref.upgrade().ok_or(FsError::InvalidFs)?;
|
||||
Ok(inner
|
||||
.get_xattr(&fs.inner, name)
|
||||
.await?
|
||||
.ok_or(FsError::NotFound)?)
|
||||
}
|
||||
|
||||
async fn listxattr(&self) -> Result<Vec<String>> {
|
||||
let inner = self.inner.lock().await;
|
||||
let fs = self.fs_ref.upgrade().ok_or(FsError::InvalidFs)?;
|
||||
let mut xattrs = vec![];
|
||||
for attr in inner.list_xattrs(&fs.inner).await? {
|
||||
let str_attr = String::from_utf8_lossy(&attr).to_string();
|
||||
xattrs.push(str_attr);
|
||||
}
|
||||
Ok(xattrs)
|
||||
}
|
||||
|
||||
async fn setxattr(&self, name: &str, buf: &[u8], create: bool, replace: bool) -> Result<()> {
|
||||
let mut inner = self.inner.lock().await;
|
||||
let fs = self.fs_ref.upgrade().ok_or(FsError::InvalidFs)?;
|
||||
if inner.get_xattr(&fs.inner, name).await?.is_some() {
|
||||
if create {
|
||||
return Err(KernelError::Fs(FsError::AlreadyExists));
|
||||
}
|
||||
} else {
|
||||
if replace {
|
||||
return Err(KernelError::Fs(FsError::NotFound));
|
||||
}
|
||||
}
|
||||
inner.set_xattr(&fs.inner, name, buf).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn removexattr(&self, name: &str) -> Result<()> {
|
||||
let mut inner = self.inner.lock().await;
|
||||
let fs = self.fs_ref.upgrade().ok_or(FsError::InvalidFs)?;
|
||||
inner.remove_xattr(&fs.inner, name).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// An EXT4 filesystem instance.
|
||||
|
||||
Reference in New Issue
Block a user