1 use super::{LockedSysFSInode, SYS_BUS_INODE};
2 use crate::{filesystem::vfs::IndexNode, kdebug, syscall::SystemError};
3 use alloc::sync::Arc;
4 
5 /// @brief: 注册bus,在sys/bus下生成文件夹
6 /// @parameter bus_name: 总线文件夹名
7 /// @return: 操作成功,返回inode,操作失败,返回错误码
8 #[inline]
9 #[allow(dead_code)]
sys_bus_register(bus_name: &str) -> Result<Arc<dyn IndexNode>, SystemError>10 pub fn sys_bus_register(bus_name: &str) -> Result<Arc<dyn IndexNode>, SystemError> {
11     let binding: Arc<dyn IndexNode> = SYS_BUS_INODE();
12     kdebug!("Before bus_register: ls /sys/bus/: {:?}", binding.list());
13     binding
14         .as_any_ref()
15         .downcast_ref::<LockedSysFSInode>()
16         .ok_or(SystemError::E2BIG)
17         .unwrap()
18         .add_dir(bus_name)
19 }
20 
21 /// @brief: 注销bus,在sys/bus删除文件夹
22 /// @parameter bus_name: 总线文件夹名
23 /// @return: 操作成功,返回(),操作失败,返回错误码
24 #[allow(dead_code)]
sys_bus_unregister(bus_name: &str) -> Result<(), SystemError>25 pub fn sys_bus_unregister(bus_name: &str) -> Result<(), SystemError> {
26     let binding: Arc<dyn IndexNode> = SYS_BUS_INODE();
27     binding
28         .as_any_ref()
29         .downcast_ref::<LockedSysFSInode>()
30         .ok_or(SystemError::E2BIG)
31         .unwrap()
32         .remove(bus_name)
33 }
34 
35 /// @brief: 在相应总线文件夹下生成devices和drivers文件夹
36 /// @parameter inode: 总线文件夹inode
37 /// @return: 操作成功,返回devices inode和drivers inode,操作失败,返回错误码
sys_bus_init( inode: &Arc<dyn IndexNode>, ) -> Result<(Arc<dyn IndexNode>, Arc<dyn IndexNode>), SystemError>38 pub fn sys_bus_init(
39     inode: &Arc<dyn IndexNode>,
40 ) -> Result<(Arc<dyn IndexNode>, Arc<dyn IndexNode>), SystemError> {
41     match inode.as_any_ref().downcast_ref::<LockedSysFSInode>() {
42         Some(lock_bus) => match lock_bus.add_dir("devices") {
43             Ok(devices) => match lock_bus.add_dir("drivers") {
44                 Ok(drivers) => Ok((devices, drivers)),
45                 Err(err) => Err(err),
46             },
47             Err(err) => Err(err),
48         },
49         None => Err(SystemError::E2BIG),
50     }
51 }
52