1 use super::{LockedSysFSInode, SYS_DEVICES_INODE}; 2 use crate::{filesystem::vfs::IndexNode, syscall::SystemError}; 3 use alloc::sync::Arc; 4 5 /// @brief: 注册device,在sys/devices下生成文件夹 6 /// @parameter device_name: 类文件夹名 7 /// @return: 操作成功,返回inode,操作失败,返回错误码 8 #[inline] 9 #[allow(dead_code)] sys_device_register(device_name: &str) -> Result<Arc<dyn IndexNode>, SystemError>10pub fn sys_device_register(device_name: &str) -> Result<Arc<dyn IndexNode>, SystemError> { 11 let binding: Arc<dyn IndexNode> = SYS_DEVICES_INODE(); 12 binding 13 .as_any_ref() 14 .downcast_ref::<LockedSysFSInode>() 15 .ok_or(SystemError::E2BIG) 16 .unwrap() 17 .add_dir(device_name) 18 } 19 20 /// @brief: 操作bus,在sys/devices删除文件夹 21 /// @parameter device_name: 总线文件夹名 22 /// @return: 操作成功,返回(),操作失败,返回错误码 23 #[inline] 24 #[allow(dead_code)] sys_device_unregister(device_name: &str) -> Result<(), SystemError>25pub fn sys_device_unregister(device_name: &str) -> Result<(), SystemError> { 26 let binding: Arc<dyn IndexNode> = SYS_DEVICES_INODE(); 27 binding 28 .as_any_ref() 29 .downcast_ref::<LockedSysFSInode>() 30 .ok_or(SystemError::E2BIG) 31 .unwrap() 32 .remove(device_name) 33 } 34