Skip to content

Commit 154f31a

Browse files
committed
comment: 将kernel代码注释国际化
1 parent afa4a69 commit 154f31a

File tree

13 files changed

+180
-179
lines changed

13 files changed

+180
-179
lines changed

kernel/src/drivers/char/serial.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ impl SerialDevice {
2424
}
2525
}
2626

27-
/// 创建一个串口字符设备实例,并封装为通用的 `Device` 结构。
28-
/// 用户需要手动指定 major/minor 号。
27+
/// Create a serial char device object and uses [`Device`] sturct.
28+
/// The user must specify major/minor number manually.
2929
pub fn create_device(major: u16, minor: u16, port_address: u16) -> Device {
3030
let serial = Arc::new(SerialDevice::new(port_address));
3131
Device::new(
@@ -36,7 +36,7 @@ impl SerialDevice {
3636
)
3737
}
3838

39-
/// 创建一个串口字符设备实例,并让 `DeviceManager` 自动分配 major/minor 号。
39+
/// Create a serial char device object and let [`DeviceManager`] auto assign major/minor number.
4040
pub fn create_device_auto_assign(port_address: u16) -> Device {
4141
let serial = Arc::new(SerialDevice::new(port_address));
4242
Device::new_auto_assign(serial.name().to_string(), DeviceInner::Char(serial))

kernel/src/drivers/device.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ pub enum DeviceError {
4040

4141
#[derive(Debug, Clone, PartialEq, Eq)]
4242
pub struct ScanInfo {
43-
pub device_id: String, // 设备唯一标识
44-
pub protocol_type: String, // 通信协议类型(如USB/PCI/I2C
45-
pub vendor_id: Option<u16>, // 供应商ID
46-
pub product_id: Option<u16>, // 产品ID
47-
pub additional_data: Option<BTreeMap<String, String>>, // 附加数据
43+
pub device_id: String, // Device ID
44+
pub protocol_type: String, // Communication protocol type (e.g. USB/PCI/I2C)
45+
pub vendor_id: Option<u16>, // Vendor ID
46+
pub product_id: Option<u16>, // Product ID
47+
pub additional_data: Option<BTreeMap<String, String>>, // Additional data
4848
}
4949

5050
pub trait SharedDeviceOps: Send + Sync {
@@ -81,7 +81,6 @@ pub trait BlockDevice: SharedDeviceOps {
8181
buf: &[u8],
8282
) -> Result<usize, DeviceError>;
8383

84-
// 新增擦除块操作
8584
fn erase_blocks(&self, start_block: usize, num_blocks: usize) -> Result<usize, DeviceError> {
8685
let _ = (start_block, num_blocks);
8786
Err(DeviceError::NotSupported)

kernel/src/fs/fs_impl/kernfs.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ pub type ReadCallback = Box<dyn Fn(u64, &mut [u8]) -> Result<usize, VfsError> +
1515
pub type WriteCallback = Box<dyn Fn(u64, &[u8]) -> Result<usize, VfsError> + Send + Sync>;
1616

1717
pub enum KernNodeContent {
18-
/// 目录
18+
/// Directory node
1919
Dir(RwLock<BTreeMap<String, Arc<KernInode>>>),
20-
/// 读写函数
20+
/// Read-write function node
2121
File {
2222
read: Option<ReadCallback>,
2323
write: Option<WriteCallback>,
2424
size: u64,
2525
},
26-
/// 设备映射
26+
/// Device mapping
2727
Device { device: Arc<Device> },
2828
}
2929

30-
/// 内核文件系统节点
30+
/// Kernel file system node
3131
pub struct KernInode {
3232
node_type: VNodeType,
3333
content: KernNodeContent,
@@ -42,15 +42,15 @@ impl core::fmt::Debug for KernInode {
4242
}
4343

4444
impl KernInode {
45-
/// 创建目录节点
45+
/// Create dir node
4646
pub fn new_dir() -> Arc<Self> {
4747
Arc::new(Self {
4848
node_type: VNodeType::Dir,
4949
content: KernNodeContent::Dir(RwLock::new(BTreeMap::new())),
5050
})
5151
}
5252

53-
/// 创建文件节点
53+
/// Create file node
5454
pub fn new_file(read: Option<ReadCallback>, write: Option<WriteCallback>) -> Arc<Self> {
5555
Arc::new(Self {
5656
node_type: VNodeType::File,
@@ -61,15 +61,15 @@ impl KernInode {
6161
},
6262
})
6363
}
64-
/// 创建设备节点
64+
/// Create device node
6565
pub fn new_device(device: Arc<Device>) -> Arc<Self> {
6666
Arc::new(Self {
6767
node_type: VNodeType::Device,
6868
content: KernNodeContent::Device { device },
6969
})
7070
}
7171

72-
/// 添加子节点(仅目录节点可用)
72+
/// Add child node to directory
7373
pub fn add_child(&self, name: &str, child: Arc<KernInode>) -> Result<(), VfsError> {
7474
match &self.content {
7575
KernNodeContent::Dir(entries) => {

kernel/src/fs/vfs.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@ lazy_static! {
1818

1919
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
2020
pub enum VfsError {
21-
/// 文件或目录不存在
21+
/// Directory/File not exist
2222
NotFound,
23-
/// 文件或目录已存在
23+
/// File/Directory already exists
2424
AlreadyExists,
25-
/// 路径不是目录
25+
/// Path is not directory
2626
NotADirectory,
27-
/// 路径不是文件
27+
/// Path is not file
2828
NotAFile,
29-
/// 权限不足
29+
/// Permission denied
3030
PermissionDenied,
31-
/// 设备错误
31+
/// Device error
3232
DeviceError(DeviceError),
33-
/// 无效的参数
33+
/// Invalid argument
3434
InvalidArgument,
35-
/// IO 错误
35+
/// IO error
3636
IoError,
37-
/// 符号链接深度过深
37+
/// Symlink too deep
3838
MaxSymlinkDepth,
39-
/// 文件系统类型不支持
39+
/// File system type not supported
4040
FsTypeNotSupported,
41-
/// 路径为空
41+
/// Path is empty
4242
EmptyPath,
43-
/// 功能未实现
43+
/// Function not implemented
4444
NotImplemented,
45-
/// 目录非空
45+
/// Directory is not empty
4646
DirectoryNotEmpty,
4747
}
4848

@@ -54,34 +54,34 @@ impl From<DeviceError> for VfsError {
5454

5555
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5656
pub enum VNodeType {
57-
/// 文件
57+
/// File
5858
File,
59-
/// 目录
59+
/// Directory
6060
Dir,
61-
/// 符号链接
61+
/// Symbol link
6262
SymLink,
63-
/// 设备
63+
/// Device
6464
Device,
6565
}
6666

67-
/// 文件或目录的元数据
67+
/// File/Directory's metadata
6868
#[derive(Debug, Clone, Eq, PartialEq, Default)]
6969
pub struct Metadata {
70-
/// 文件大小
70+
/// File size
7171
pub size: u64,
72-
/// UNIX权限位,如0o755
72+
/// UNIX permission, such as 0o755
7373
pub permissions: u32,
74-
/// 用户ID
74+
/// User ID
7575
pub uid: u32,
76-
/// 组ID
76+
/// Group ID
7777
pub gid: u32,
78-
/// 创建时间 (秒)
78+
/// Create time (s)
7979
pub ctime: u64,
80-
/// 最后修改时间 (秒)
80+
/// Last edited time ()
8181
pub mtime: u64,
82-
/// 占用的块数
82+
/// Used blocks
8383
pub blocks: u64,
84-
/// 硬链接数量
84+
/// Hard link numbers
8585
pub nlinks: u64,
8686
}
8787

0 commit comments

Comments
 (0)