1 use super::{LockedSysFSInode, SYS_CLASS_INODE};
2 use crate::{filesystem::vfs::IndexNode, syscall::SystemError};
3 use alloc::sync::Arc;
4 
5 /// @brief: 注册class,在sys/class下生成文件夹
6 /// @parameter class_name: 类文件夹名
7 /// @return: 操作成功,返回inode,操作失败,返回错误码
8 #[inline]
9 #[allow(dead_code)]
sys_class_register(class_name: &str) -> Result<Arc<dyn IndexNode>, SystemError>10 pub fn sys_class_register(class_name: &str) -> Result<Arc<dyn IndexNode>, SystemError> {
11     let binding: Arc<dyn IndexNode> = SYS_CLASS_INODE();
12     binding
13         .as_any_ref()
14         .downcast_ref::<LockedSysFSInode>()
15         .ok_or(SystemError::E2BIG)
16         .unwrap()
17         .add_dir(class_name)
18 }
19 
20 /// @brief: 注销class,在sys/class删除文件夹
21 /// @parameter class_name: 总线文件夹名
22 /// @return: 操作成功,返回(),操作失败,返回错误码
23 #[inline]
24 #[allow(dead_code)]
sys_class_unregister(class_name: &str) -> Result<(), SystemError>25 pub fn sys_class_unregister(class_name: &str) -> Result<(), SystemError> {
26     let binding: Arc<dyn IndexNode> = SYS_CLASS_INODE();
27     binding
28         .as_any_ref()
29         .downcast_ref::<LockedSysFSInode>()
30         .ok_or(SystemError::E2BIG)
31         .unwrap()
32         .remove(class_name)
33 }
34 
35 /// @brief: 注册device,在对应类下操作设备文件夹
36 /// @parameter class: 类文件夹inode
37 /// @parameter device_name: 设备文件夹名
38 /// @return: 操作成功,返回inode,操作失败,返回错误码
39 #[inline]
40 #[allow(dead_code)]
class_device_register( class: Arc<dyn IndexNode>, device_name: &str, ) -> Result<Arc<dyn IndexNode>, SystemError>41 pub fn class_device_register(
42     class: Arc<dyn IndexNode>,
43     device_name: &str,
44 ) -> Result<Arc<dyn IndexNode>, SystemError> {
45     class
46         .as_any_ref()
47         .downcast_ref::<LockedSysFSInode>()
48         .ok_or(SystemError::E2BIG)
49         .unwrap()
50         .add_dir(device_name)
51 }
52 
53 /// @brief: 操作device,在对应类下删除设备文件夹
54 /// @parameter class: 类文件夹inode
55 /// @parameter device_name: 设备文件夹名
56 /// @return: 操作成功,返回(),操作失败,返回错误码
57 #[inline]
58 #[allow(dead_code)]
class_device_unregister( class: Arc<dyn IndexNode>, device_name: &str, ) -> Result<(), SystemError>59 pub fn class_device_unregister(
60     class: Arc<dyn IndexNode>,
61     device_name: &str,
62 ) -> Result<(), SystemError> {
63     class
64         .as_any_ref()
65         .downcast_ref::<LockedSysFSInode>()
66         .ok_or(SystemError::E2BIG)
67         .unwrap()
68         .remove(device_name)
69 }
70