|
| 1 | +# API 参考索引 |
| 2 | + |
| 3 | +<cite> |
| 4 | +**Referenced Files in This Document ** |
| 5 | +- [axfs_vfs/src/lib.rs](file://axfs_vfs/src/lib.rs) |
| 6 | +- [axfs_vfs/src/structs.rs](file://axfs_vfs/src/structs.rs) |
| 7 | +- [axfs_vfs/src/macros.rs](file://axfs_vfs/src/macros.rs) |
| 8 | +- [axfs_devfs/src/lib.rs](file://axfs_devfs/src/lib.rs) |
| 9 | +- [axfs_devfs/src/null.rs](file://axfs_devfs/src/null.rs) |
| 10 | +- [axfs_devfs/src/zero.rs](file://axfs_devfs/src/zero.rs) |
| 11 | +- [axfs_devfs/src/urandom.rs](file://axfs_devfs/src/urandom.rs) |
| 12 | +- [axfs_devfs/src/dir.rs](file://axfs_devfs/src/dir.rs) |
| 13 | +- [axfs_ramfs/src/lib.rs](file://axfs_ramfs/src/lib.rs) |
| 14 | +- [axfs_ramfs/src/file.rs](file://axfs_ramfs/src/file.rs) |
| 15 | +- [axfs_ramfs/src/dir.rs](file://axfs_ramfs/src/dir.rs) |
| 16 | +</cite> |
| 17 | + |
| 18 | +## 目录 |
| 19 | +1. [axfs_vfs 核心接口与数据结构](#axfs_vfs-核心接口与数据结构) |
| 20 | + - [VfsOps](#vfsops) |
| 21 | + - [VfsNodeOps](#vfsnodeops) |
| 22 | + - [VfsNodeAttr](#vfsnodeattr) |
| 23 | + - [VfsNodePerm](#vfsnodeperm) |
| 24 | + - [VfsNodeType](#vfsnodetype) |
| 25 | +2. [axfs_devfs 设备实现](#axfs_devfs-设备实现) |
| 26 | + - [DeviceFileSystem](#devicefilesystem) |
| 27 | + - [NullDev](#nulldev) |
| 28 | + - [ZeroDev](#zerodev) |
| 29 | + - [UrandomDev](#urandomdev) |
| 30 | +3. [axfs_ramfs 可变节点类型](#axfs_ramfs-可变节点类型) |
| 31 | + - [RamFileSystem](#ramfilesystem) |
| 32 | + - [FileNode](#filenode) |
| 33 | + - [DirNode](#dirnode) |
| 34 | +4. [宏说明](#宏说明) |
| 35 | + - [impl_vfs_dir_default!](#impl_vfs_dir_default) |
| 36 | + - [impl_vfs_non_dir_default!](#impl_vfs_non_dir_default) |
| 37 | + |
| 38 | +## axfs_vfs 核心接口与数据结构 |
| 39 | + |
| 40 | +### VfsOps |
| 41 | +[VfsOps](file://axfs_vfs/src/lib.rs#L65-L90) 是文件系统操作的核心 trait,定义了文件系统的生命周期和属性查询方法。 |
| 42 | + |
| 43 | +**方法列表:** |
| 44 | +- `mount(&self, _path: &str, _mount_point: VfsNodeRef) -> VfsResult` |
| 45 | + 文件系统挂载时调用。默认实现为空。 |
| 46 | +- `umount(&self) -> VfsResult` |
| 47 | + 文件系统卸载时调用。默认实现为空。 |
| 48 | +- `format(&self) -> VfsResult` |
| 49 | + 格式化文件系统。默认返回 `Unsupported` 错误。 |
| 50 | +- `statfs(&self) -> VfsResult<FileSystemInfo>` |
| 51 | + 获取文件系统属性。默认返回 `Unsupported` 错误。 |
| 52 | +- `root_dir(&self) -> VfsNodeRef` |
| 53 | + 获取文件系统的根目录节点(必须由具体类型实现)。 |
| 54 | + |
| 55 | +**Section sources** |
| 56 | +- [axfs_vfs/src/lib.rs](file://axfs_vfs/src/lib.rs#L65-L90) |
| 57 | + |
| 58 | +### VfsNodeOps |
| 59 | +[VfsNodeOps](file://axfs_vfs/src/lib.rs#L93-L177) 是节点(文件/目录)操作的核心 trait,定义了对文件或目录的各种操作。 |
| 60 | + |
| 61 | +**通用操作(文件与目录均支持):** |
| 62 | +- `open(&self) -> VfsResult` |
| 63 | + 节点打开时调用。默认实现为空。 |
| 64 | +- `release(&self) -> VfsResult` |
| 65 | + 节点关闭时调用。默认实现为空。 |
| 66 | +- `get_attr(&self) -> VfsResult<VfsNodeAttr>` |
| 67 | + 获取节点属性。默认返回 `Unsupported` 错误。 |
| 68 | + |
| 69 | +**文件专有操作:** |
| 70 | +- `read_at(&self, _offset: u64, _buf: &mut [u8]) -> VfsResult<usize>` |
| 71 | + 从指定偏移读取数据。默认返回 `InvalidInput` 错误。 |
| 72 | +- `write_at(&self, _offset: u64, _buf: &[u8]) -> VfsResult<usize>` |
| 73 | + 向指定偏移写入数据。默认返回 `InvalidInput` 错误。 |
| 74 | +- `fsync(&self) -> VfsResult` |
| 75 | + 同步文件数据到存储。默认返回 `InvalidInput` 错误。 |
| 76 | +- `truncate(&self, _size: u64) -> VfsResult` |
| 77 | + 截断文件至指定大小。默认返回 `InvalidInput` 错误。 |
| 78 | + |
| 79 | +**目录专有操作:** |
| 80 | +- `parent(&self) -> Option<VfsNodeRef>` |
| 81 | + 获取父目录。默认返回 `None`。 |
| 82 | +- `lookup(self: Arc<Self>, _path: &str) -> VfsResult<VfsNodeRef>` |
| 83 | + 在目录中查找路径对应的节点。默认返回 `Unsupported` 错误。 |
| 84 | +- `create(&self, _path: &str, _ty: VfsNodeType) -> VfsResult` |
| 85 | + 创建新节点。默认返回 `Unsupported` 错误。 |
| 86 | +- `remove(&self, _path: &str) -> VfsResult` |
| 87 | + 删除指定路径的节点。默认返回 `Unsupported` 错误。 |
| 88 | +- `read_dir(&self, _start_idx: usize, _dirents: &mut [VfsDirEntry]) -> VfsResult<usize>` |
| 89 | + 读取目录条目。默认返回 `Unsupported` 错误。 |
| 90 | +- `rename(&self, _src_path: &str, _dst_path: &str) -> VfsResult` |
| 91 | + 重命名或移动节点。默认返回 `Unsupported` 错误。 |
| 92 | +- `as_any(&self) -> &dyn core::any::Any` |
| 93 | + 将自身转换为 `Any` 类型以支持向下转型。默认未实现。 |
| 94 | + |
| 95 | +**Section sources** |
| 96 | +- [axfs_vfs/src/lib.rs](file://axfs_vfs/src/lib.rs#L93-L177) |
| 97 | + |
| 98 | +### VfsNodeAttr |
| 99 | +[VfsNodeAttr](file://axfs_vfs/src/structs.rs#L13-L38) 表示节点(文件/目录)的属性。 |
| 100 | + |
| 101 | +**字段:** |
| 102 | +- `mode: VfsNodePerm` - 文件权限模式 |
| 103 | +- `ty: VfsNodeType` - 文件类型 |
| 104 | +- `size: u64` - 总大小(字节) |
| 105 | +- `blocks: u64` - 分配的 512B 块数量 |
| 106 | + |
| 107 | +**构造方法:** |
| 108 | +- `new(mode: VfsNodePerm, ty: VfsNodeType, size: u64, blocks: u64)` - 创建具有指定属性的新实例 |
| 109 | +- `new_file(size: u64, blocks: u64)` - 为文件创建新实例,默认权限为 `0o666` |
| 110 | +- `new_dir(size: u64, blocks: u64)` - 为目录创建新实例,默认权限为 `0o755` |
| 111 | + |
| 112 | +**访问器方法:** |
| 113 | +- `size()`, `blocks()`, `perm()`, `file_type()` - 获取对应属性 |
| 114 | +- `set_perm(perm: VfsNodePerm)` - 设置权限 |
| 115 | +- `is_file()`, `is_dir()` - 判断是否为文件或目录 |
| 116 | + |
| 117 | +**Section sources** |
| 118 | +- [axfs_vfs/src/structs.rs](file://axfs_vfs/src/structs.rs#L13-L38) |
| 119 | + |
| 120 | +### VfsNodePerm |
| 121 | +[VfsNodePerm](file://axfs_vfs/src/structs.rs#L40-L82) 使用 bitflags 宏定义节点权限模式。 |
| 122 | + |
| 123 | +**权限位:** |
| 124 | +- 所有者:`OWNER_READ (0o400)`, `OWNER_WRITE (0o200)`, `OWNER_EXEC (0o100)` |
| 125 | +- 组:`GROUP_READ (0o40)`, `GROUP_WRITE (0o20)`, `GROUP_EXEC (0o10)` |
| 126 | +- 其他:`OTHER_READ (0o4)`, `OTHER_WRITE (0o2)`, `OTHER_EXEC (0o1)` |
| 127 | + |
| 128 | +**常量方法:** |
| 129 | +- `default_file()` - 返回文件默认权限 `0o666` |
| 130 | +- `default_dir()` - 返回目录默认权限 `0o755` |
| 131 | + |
| 132 | +**实用方法:** |
| 133 | +- `mode()` - 返回底层原始位 |
| 134 | +- `rwx_buf()` - 返回 9 字节字符串表示(如 `rwxr-xr-x`) |
| 135 | +- `owner_readable()`, `owner_writable()`, `owner_executable()` - 检查所有者权限 |
| 136 | + |
| 137 | +**Section sources** |
| 138 | +- [axfs_vfs/src/structs.rs](file://axfs_vfs/src/structs.rs#L40-L82) |
| 139 | + |
| 140 | +### VfsNodeType |
| 141 | +[VfsNodeType](file://axfs_vfs/src/structs.rs#L84-L114) 枚举定义节点类型。 |
| 142 | + |
| 143 | +**成员:** |
| 144 | +- `Fifo = 0o1` - FIFO(命名管道) |
| 145 | +- `CharDevice = 0o2` - 字符设备 |
| 146 | +- `Dir = 0o4` - 目录 |
| 147 | +- `BlockDevice = 0o6` - 块设备 |
| 148 | +- `File = 0o10` - 普通文件 |
| 149 | +- `SymLink = 0o12` - 符号链接 |
| 150 | +- `Socket = 0o14` - 套接字 |
| 151 | + |
| 152 | +**判断方法:** |
| 153 | +- `is_file()`, `is_dir()`, `is_symlink()`, `is_block_device()`, `is_char_device()`, `is_fifo()`, `is_socket()` - 检查类型 |
| 154 | +- `as_char()` - 返回字符表示(如 `d` 表示目录,`-` 表示普通文件) |
| 155 | + |
| 156 | +**Section sources** |
| 157 | +- [axfs_vfs/src/structs.rs](file://axfs_vfs/src/structs.rs#L84-L114) |
| 158 | + |
| 159 | +## axfs_devfs 设备实现 |
| 160 | + |
| 161 | +### DeviceFileSystem |
| 162 | +[DeviceFileSystem](file://axfs_devfs/src/lib.rs#L38-L73) 是基于 `axfs_vfs` 实现的设备文件系统。 |
| 163 | + |
| 164 | +**字段:** |
| 165 | +- `parent: Once<VfsNodeRef>` - 父节点引用(惰性初始化) |
| 166 | +- `root: Arc<DirNode>` - 根目录节点 |
| 167 | + |
| 168 | +**方法:** |
| 169 | +- `new() -> Self` - 创建新实例 |
| 170 | +- `mkdir(&self, name: &'static str) -> Arc<DirNode>` - 在根目录创建子目录 |
| 171 | +- `add(&self, name: &'static str, node: VfsNodeRef)` - 向根目录添加节点 |
| 172 | +- `default()` - 默认构造函数 |
| 173 | + |
| 174 | +**实现的 VfsOps:** |
| 175 | +- `mount()` - 设置根目录的父节点 |
| 176 | +- `root_dir()` - 返回根目录节点 |
| 177 | + |
| 178 | +**Section sources** |
| 179 | +- [axfs_devfs/src/lib.rs](file://axfs_devfs/src/lib.rs#L38-L73) |
| 180 | + |
| 181 | +### NullDev |
| 182 | +[NullDev](file://axfs_devfs/src/null.rs#L5-L31) 实现类似 `/dev/null` 的空设备。 |
| 183 | + |
| 184 | +**行为:** |
| 185 | +- 读取时返回 0 字节 |
| 186 | +- 写入时丢弃所有数据并返回写入长度 |
| 187 | + |
| 188 | +**实现的方法:** |
| 189 | +- `get_attr()` - 返回字符设备属性 |
| 190 | +- `read_at()` - 返回 `Ok(0)` |
| 191 | +- `write_at()` - 返回 `Ok(buf.len())` |
| 192 | +- `truncate()` - 返回 `Ok(())` |
| 193 | +- 使用 `impl_vfs_non_dir_default!` 宏填充其他方法 |
| 194 | + |
| 195 | +**Section sources** |
| 196 | +- [axfs_devfs/src/null.rs](file://axfs_devfs/src/null.rs#L5-L31) |
| 197 | + |
| 198 | +### ZeroDev |
| 199 | +[ZeroDev](file://axfs_devfs/src/zero.rs#L5-L32) 实现类似 `/dev/zero` 的零设备。 |
| 200 | + |
| 201 | +**行为:** |
| 202 | +- 读取时返回全 `\0` 字节 |
| 203 | +- 写入时丢弃所有数据并返回写入长度 |
| 204 | + |
| 205 | +**实现的方法:** |
| 206 | +- `get_attr()` - 返回字符设备属性 |
| 207 | +- `read_at()` - 填充缓冲区为 0 并返回长度 |
| 208 | +- `write_at()` - 返回 `Ok(buf.len())` |
| 209 | +- `truncate()` - 返回 `Ok(())` |
| 210 | +- 使用 `impl_vfs_non_dir_default!` 宏填充其他方法 |
| 211 | + |
| 212 | +**Section sources** |
| 213 | +- [axfs_devfs/src/zero.rs](file://axfs_devfs/src/zero.rs#L5-L32) |
| 214 | + |
| 215 | +### UrandomDev |
0 commit comments