TingHuang dd9f1fc1a4
新增SysFS (#250)
* 添加sysfs

* 注册sysfs

* 添加sysfs相关

* 添加rust-anlyzer辅助配置

* 将设备与sysfs相关联

* 添加单独的文件管理sysfs下的文件夹
2023-04-21 16:03:42 +08:00

34 lines
1.1 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use super::{LockedSysFSInode, SYS_DEVICES_INODE};
use crate::{filesystem::vfs::IndexNode, syscall::SystemError};
use alloc::sync::Arc;
/// @brief: 注册device在sys/devices下生成文件夹
/// @parameter device_name: 类文件夹名
/// @return: 操作成功返回inode操作失败返回错误码
#[inline]
#[allow(dead_code)]
pub fn device_register(device_name: &str) -> Result<Arc<dyn IndexNode>, SystemError> {
let binding: Arc<dyn IndexNode> = SYS_DEVICES_INODE();
binding
.as_any_ref()
.downcast_ref::<LockedSysFSInode>()
.ok_or(SystemError::E2BIG)
.unwrap()
.add_dir(device_name)
}
/// @brief: 操作bus在sys/devices删除文件夹
/// @parameter device_name: 总线文件夹名
/// @return: 操作成功,返回(),操作失败,返回错误码
#[inline]
#[allow(dead_code)]
pub fn device_unregister(device_name: &str) -> Result<(), SystemError> {
let binding: Arc<dyn IndexNode> = SYS_DEVICES_INODE();
binding
.as_any_ref()
.downcast_ref::<LockedSysFSInode>()
.ok_or(SystemError::E2BIG)
.unwrap()
.remove(device_name)
}