SimpleKernel 1.17.0
Loading...
Searching...
No Matches
ramfs.cpp
Go to the documentation of this file.
1
5#include "ramfs.hpp"
6
7#include "kernel_log.hpp"
8#include "kstd_cstring"
9#include "vfs.hpp"
10
11namespace ramfs {
12
13using namespace vfs;
14
16 : inodes_{},
17 free_list_(nullptr),
18 root_inode_(nullptr),
19 used_inodes_(0),
20 mounted_(false),
21 file_data_pool_{},
22 file_data_pool_used_(0),
23 dir_data_pool_{},
24 dir_data_pool_used_(0),
25 inode_ops_(this),
26 file_ops_(this) {}
27
29 if (mounted_) {
30 Unmount();
31 }
32}
33
34auto RamFs::GetName() const -> const char* { return "ramfs"; }
35
37 if (mounted_) {
38 return std::unexpected(Error(ErrorCode::kFsAlreadyMounted));
39 }
40
41 if (device != nullptr) {
42 return std::unexpected(Error(ErrorCode::kInvalidArgument));
43 }
44
45 klog::Info("RamFs: mounting...");
46
47 // 初始化 inode 空闲链表
48 free_list_ = nullptr;
49 for (int i = kMaxInodes - 1; i >= 0; --i) {
50 inodes_[i].next_free = free_list_;
51 free_list_ = &inodes_[i];
52 }
53
54 // 分配根目录 inode
55 auto root_result = AllocateInode();
56 if (!root_result.has_value()) {
57 return std::unexpected(root_result.error());
58 }
59
60 root_inode_ = root_result.value();
61 root_inode_->type = FileType::kDirectory;
62 root_inode_->permissions = 0755;
63
64 // 初始化根目录数据
65 RamInode* ram_root = static_cast<RamInode*>(root_inode_->fs_private);
66 ram_root->data = nullptr;
67 ram_root->capacity = 0;
68 ram_root->child_count = 0;
69
70 used_inodes_ = 1;
71 mounted_ = true;
72
73 klog::Info("RamFs: mounted successfully");
74 return root_inode_;
75}
76
78 if (!mounted_) {
79 return std::unexpected(Error(ErrorCode::kFsNotMounted));
80 }
81
82 klog::Info("RamFs: unmounting...");
83
84 // Clear all inode data pointers (data lives in static pools)
85 for (size_t i = 0; i < kMaxInodes; ++i) {
86 if (inodes_[i].inode.type != FileType::kUnknown &&
87 inodes_[i].data != nullptr) {
88 inodes_[i].data = nullptr;
89 }
90 }
91
92 // 重置状态并释放静态池
93 free_list_ = nullptr;
94 root_inode_ = nullptr;
95 used_inodes_ = 0;
96 mounted_ = false;
97 file_data_pool_used_ = 0;
98 dir_data_pool_used_ = 0;
99
100 klog::Info("RamFs: unmounted");
101 return {};
102}
103
105 // ramfs 是纯内存文件系统,无需同步
106 return {};
107}
108
110 if (free_list_ == nullptr) {
111 return std::unexpected(Error(ErrorCode::kOutOfMemory));
112 }
113
114 RamInode* ram_inode = free_list_;
115 free_list_ = free_list_->next_free;
116
117 // 初始化 inode
118 ram_inode->inode.ino = reinterpret_cast<uint64_t>(&ram_inode->inode);
119 ram_inode->inode.type = FileType::kUnknown;
120 ram_inode->inode.size = 0;
121 ram_inode->inode.permissions = 0644;
122 ram_inode->inode.link_count = 1;
123 ram_inode->inode.fs_private = ram_inode;
124 ram_inode->inode.fs = this;
125 ram_inode->inode.ops = &inode_ops_;
126
127 ram_inode->data = nullptr;
128 ram_inode->capacity = 0;
129 ram_inode->child_count = 0;
130 ram_inode->next_free = nullptr;
131
132 ++used_inodes_;
133 return &ram_inode->inode;
134}
135
137 if (inode == nullptr) {
138 return std::unexpected(Error(ErrorCode::kInvalidArgument));
139 }
140
141 RamInode* ram_inode = static_cast<RamInode*>(inode->fs_private);
142
143 // Data lives in static pools; just clear the pointer (no individual reclaim)
144 if (ram_inode->data != nullptr) {
145 ram_inode->data = nullptr;
146 }
147
148 // 重置 inode
149 ram_inode->inode.type = FileType::kUnknown;
150 ram_inode->inode.size = 0;
151 ram_inode->inode.fs_private = nullptr;
152 ram_inode->inode.ops = nullptr;
153
154 ram_inode->capacity = 0;
155 ram_inode->child_count = 0;
156
157 // 加入空闲链表
158 ram_inode->next_free = free_list_;
159 free_list_ = ram_inode;
160
161 --used_inodes_;
162 return {};
163}
164
165auto RamFs::GetRootInode() const -> Inode* { return root_inode_; }
166
167auto RamFs::GetFileOps() -> FileOps* { return &file_ops_; }
168
169// InodeOps 实现
170
171auto RamFs::RamFsInodeOps::Lookup(Inode* dir, const char* name)
173 if (dir == nullptr || name == nullptr) {
174 return std::unexpected(Error(ErrorCode::kInvalidArgument));
175 }
176
177 RamInode* ram_dir = static_cast<RamInode*>(dir->fs_private);
178
179 RamDirEntry* entry = fs_->FindInDirectory(ram_dir, name);
180
181 if (entry == nullptr) {
182 return std::unexpected(Error(ErrorCode::kFsFileNotFound));
183 }
184
185 return entry->inode;
186}
187
188auto RamFs::RamFsInodeOps::Create(Inode* dir, const char* name, FileType type)
190 if (dir == nullptr || name == nullptr) {
191 return std::unexpected(Error(ErrorCode::kInvalidArgument));
192 }
193
194 if (type != FileType::kRegular && type != FileType::kDirectory) {
195 return std::unexpected(Error(ErrorCode::kInvalidArgument));
196 }
197
198 RamInode* ram_dir = static_cast<RamInode*>(dir->fs_private);
199
200 // 分配新 inode
201 auto alloc_result = fs_->AllocateInode();
202 if (!alloc_result.has_value()) {
203 return std::unexpected(alloc_result.error());
204 }
205
206 Inode* new_inode = alloc_result.value();
207 new_inode->type = type;
208
209 // 添加到目录
210 auto add_result = fs_->AddToDirectory(ram_dir, name, new_inode);
211 if (!add_result.has_value()) {
212 fs_->FreeInode(new_inode);
213 return std::unexpected(add_result.error());
214 }
215
216 return new_inode;
217}
218
219auto RamFs::RamFsInodeOps::Unlink(Inode* dir, const char* name)
220 -> Expected<void> {
221 if (dir == nullptr || name == nullptr) {
222 return std::unexpected(Error(ErrorCode::kInvalidArgument));
223 }
224
225 RamInode* ram_dir = static_cast<RamInode*>(dir->fs_private);
226
227 // 查找目标
228 RamDirEntry* entry = fs_->FindInDirectory(ram_dir, name);
229 if (entry == nullptr) {
230 return std::unexpected(Error(ErrorCode::kFsFileNotFound));
231 }
232
233 // 不能删除目录
234 if (entry->inode != nullptr && entry->inode->type == FileType::kDirectory) {
235 return std::unexpected(Error(ErrorCode::kFsIsADirectory));
236 }
237
238 // 从目录中移除
239 auto remove_result = fs_->RemoveFromDirectory(ram_dir, name);
240 if (!remove_result.has_value()) {
241 return remove_result;
242 }
243
244 // 如果链接计数为 0,释放 inode
245 if (entry->inode != nullptr && entry->inode->link_count == 0) {
246 fs_->FreeInode(entry->inode);
247 }
248
249 return {};
250}
251
252auto RamFs::RamFsInodeOps::Mkdir(Inode* dir, const char* name)
254 // 复用 Create,但指定类型为目录
255 return Create(dir, name, FileType::kDirectory);
256}
257
258auto RamFs::RamFsInodeOps::Rmdir(Inode* dir, const char* name)
259 -> Expected<void> {
260 if (dir == nullptr || name == nullptr) {
261 return std::unexpected(Error(ErrorCode::kInvalidArgument));
262 }
263
264 RamInode* ram_dir = static_cast<RamInode*>(dir->fs_private);
265
266 // 查找目标
267 RamDirEntry* entry = fs_->FindInDirectory(ram_dir, name);
268 if (entry == nullptr) {
269 return std::unexpected(Error(ErrorCode::kFsFileNotFound));
270 }
271
272 // 必须是目录
273 if (entry->inode == nullptr || entry->inode->type != FileType::kDirectory) {
274 return std::unexpected(Error(ErrorCode::kFsNotADirectory));
275 }
276
277 // 检查目录是否为空
278 RamInode* target = static_cast<RamInode*>(entry->inode->fs_private);
279 if (!fs_->IsDirectoryEmpty(target)) {
280 return std::unexpected(Error(ErrorCode::kFsNotEmpty));
281 }
282
283 // 从目录中移除
284 auto remove_result = fs_->RemoveFromDirectory(ram_dir, name);
285 if (!remove_result.has_value()) {
286 return remove_result;
287 }
288
289 // 释放 inode
290 if (entry->inode->link_count == 0) {
291 fs_->FreeInode(entry->inode);
292 }
293
294 return {};
295}
296
297// FileOps 实现
298
299auto RamFs::RamFsFileOps::Read(File* file, void* buf, size_t count)
301 if (file == nullptr || buf == nullptr) {
302 return std::unexpected(Error(ErrorCode::kInvalidArgument));
303 }
304
305 if (file->inode == nullptr) {
306 return std::unexpected(Error(ErrorCode::kFsCorrupted));
307 }
308
309 if (file->inode->type != FileType::kRegular) {
310 return std::unexpected(Error(ErrorCode::kFsIsADirectory));
311 }
312
313 RamInode* ram_inode = static_cast<RamInode*>(file->inode->fs_private);
314
315 // 计算可读字节数
316 if (file->offset >= file->inode->size) {
317 return 0; // EOF
318 }
319
320 size_t available = file->inode->size - file->offset;
321 size_t to_read = (count < available) ? count : available;
322
323 if (to_read == 0) {
324 return 0;
325 }
326
327 // 复制数据
328 memcpy(buf, static_cast<uint8_t*>(ram_inode->data) + file->offset, to_read);
329
330 file->offset += to_read;
331 return to_read;
332}
333
334auto RamFs::RamFsFileOps::Write(File* file, const void* buf, size_t count)
336 if (file == nullptr || buf == nullptr) {
337 return std::unexpected(Error(ErrorCode::kInvalidArgument));
338 }
339
340 if (file->inode == nullptr) {
341 return std::unexpected(Error(ErrorCode::kFsCorrupted));
342 }
343
344 if (file->inode->type != FileType::kRegular) {
345 return std::unexpected(Error(ErrorCode::kFsIsADirectory));
346 }
347
348 RamInode* ram_inode = static_cast<RamInode*>(file->inode->fs_private);
349
350 // 检查是否需要扩展文件
351 size_t new_size = file->offset + count;
352 if (new_size > ram_inode->capacity) {
353 auto expand_result = fs_->ExpandFile(ram_inode, new_size);
354 if (!expand_result.has_value()) {
355 return std::unexpected(expand_result.error());
356 }
357 }
358
359 // 写入数据
360 memcpy(static_cast<uint8_t*>(ram_inode->data) + file->offset, buf, count);
361
362 file->offset += count;
363
364 // 更新文件大小
365 if (file->offset > file->inode->size) {
366 file->inode->size = file->offset;
367 }
368
369 return count;
370}
371
372auto RamFs::RamFsFileOps::Seek(File* file, int64_t offset, SeekWhence whence)
374 if (file == nullptr) {
375 return std::unexpected(Error(ErrorCode::kInvalidArgument));
376 }
377
378 uint64_t new_offset = 0;
379
380 switch (whence) {
381 case SeekWhence::kSet:
382 if (offset < 0) {
383 return std::unexpected(Error(ErrorCode::kInvalidArgument));
384 }
385 new_offset = static_cast<uint64_t>(offset);
386 break;
387
388 case SeekWhence::kCur:
389 if (offset < 0 && static_cast<uint64_t>(-offset) > file->offset) {
390 return std::unexpected(Error(ErrorCode::kInvalidArgument));
391 }
392 new_offset =
393 static_cast<uint64_t>(static_cast<int64_t>(file->offset) + offset);
394 break;
395
396 case SeekWhence::kEnd:
397 if (file->inode == nullptr) {
398 return std::unexpected(Error(ErrorCode::kFsCorrupted));
399 }
400 if (offset < 0 && static_cast<uint64_t>(-offset) > file->inode->size) {
401 return std::unexpected(Error(ErrorCode::kInvalidArgument));
402 }
403 new_offset = static_cast<uint64_t>(
404 static_cast<int64_t>(file->inode->size) + offset);
405 break;
406
407 default:
408 return std::unexpected(Error(ErrorCode::kInvalidArgument));
409 }
410
411 file->offset = new_offset;
412 return new_offset;
413}
414
416 if (file == nullptr) {
417 return std::unexpected(Error(ErrorCode::kInvalidArgument));
418 }
419
420 // ramfs 没有特殊的关闭操作
421 // File 对象由调用者释放
422 return {};
423}
424
425auto RamFs::RamFsFileOps::ReadDir(File* file, DirEntry* dirent, size_t count)
427 if (file == nullptr || dirent == nullptr) {
428 return std::unexpected(Error(ErrorCode::kInvalidArgument));
429 }
430
431 if (file->inode == nullptr || file->inode->type != FileType::kDirectory) {
432 return std::unexpected(Error(ErrorCode::kFsNotADirectory));
433 }
434
435 RamInode* ram_dir = static_cast<RamInode*>(file->inode->fs_private);
436
437 RamDirEntry* entries = static_cast<RamDirEntry*>(ram_dir->data);
438
439 size_t read_count = 0;
440 size_t offset = file->offset;
441
442 // 添加 . 和 .. 条目
443 if (offset == 0 && read_count < count) {
444 dirent[read_count].ino = file->inode->ino;
445 dirent[read_count].type = static_cast<uint8_t>(FileType::kDirectory);
446 strncpy(dirent[read_count].name, ".", sizeof(dirent[read_count].name));
447 ++read_count;
448 ++offset;
449 }
450
451 if (offset == 1 && read_count < count) {
452 Inode* parent_inode =
453 (file->dentry != nullptr && file->dentry->parent != nullptr)
454 ? file->dentry->parent->inode
455 : file->inode;
456 dirent[read_count].ino = parent_inode->ino;
457 dirent[read_count].type = static_cast<uint8_t>(FileType::kDirectory);
458 strncpy(dirent[read_count].name, "..", sizeof(dirent[read_count].name));
459 ++read_count;
460 ++offset;
461 }
462
463 // 读取实际目录项(跳过 . 和 .. 的偏移)
464 size_t entry_idx = (offset > 2) ? offset - 2 : 0;
465 while (read_count < count && entry_idx < ram_dir->child_count) {
466 dirent[read_count].ino = entries[entry_idx].inode->ino;
467 dirent[read_count].type =
468 static_cast<uint8_t>(entries[entry_idx].inode->type);
469 strncpy(dirent[read_count].name, entries[entry_idx].name,
470 sizeof(dirent[read_count].name));
471 ++read_count;
472 ++entry_idx;
473 }
474
475 file->offset = offset + read_count;
476 return read_count;
477}
478
479// 辅助函数实现
480
481auto RamFs::FindInDirectory(RamInode* dir, const char* name) -> RamDirEntry* {
482 if (dir == nullptr || dir->inode.type != FileType::kDirectory ||
483 dir->data == nullptr) {
484 return nullptr;
485 }
486
487 RamDirEntry* entries = static_cast<RamDirEntry*>(dir->data);
488 for (size_t i = 0; i < dir->child_count; ++i) {
489 if (strcmp(entries[i].name, name) == 0) {
490 return &entries[i];
491 }
492 }
493
494 return nullptr;
495}
496
497auto RamFs::AddToDirectory(RamInode* dir, const char* name, Inode* inode)
498 -> Expected<void> {
499 if (dir == nullptr || name == nullptr || inode == nullptr) {
500 return std::unexpected(Error(ErrorCode::kInvalidArgument));
501 }
502
503 if (dir->inode.type != FileType::kDirectory) {
504 return std::unexpected(Error(ErrorCode::kFsNotADirectory));
505 }
506
507 // 检查是否已存在
508 if (FindInDirectory(dir, name) != nullptr) {
509 return std::unexpected(Error(ErrorCode::kFsFileExists));
510 }
511
512 // 扩展目录容量
513 size_t current_entries = dir->capacity / sizeof(RamDirEntry);
514 if (dir->child_count >= current_entries) {
515 size_t new_capacity = (current_entries == 0) ? 16 : current_entries * 2;
516 RamDirEntry* new_data = AllocateDirEntries(new_capacity);
517 if (new_data == nullptr) {
518 return std::unexpected(Error(ErrorCode::kOutOfMemory));
519 }
520
521 // 复制旧数据
522 if (dir->data != nullptr) {
523 memcpy(new_data, dir->data, dir->child_count * sizeof(RamDirEntry));
524 // Old allocation stays in pool (bump allocator — no per-entry free)
525 }
526
527 dir->data = new_data;
528 dir->capacity = new_capacity * sizeof(RamDirEntry);
529 }
530
531 // 添加新条目
532 RamDirEntry* entries = static_cast<RamDirEntry*>(dir->data);
533 RamDirEntry* new_entry = &entries[dir->child_count];
534 strncpy(new_entry->name, name, sizeof(new_entry->name) - 1);
535 new_entry->name[sizeof(new_entry->name) - 1] = '\0';
536 new_entry->inode = inode;
537
538 ++dir->child_count;
539 ++inode->link_count;
540
541 return {};
542}
543
544auto RamFs::RemoveFromDirectory(RamInode* dir, const char* name)
545 -> Expected<void> {
546 if (dir == nullptr || name == nullptr) {
547 return std::unexpected(Error(ErrorCode::kInvalidArgument));
548 }
549
550 RamDirEntry* entry = FindInDirectory(dir, name);
551 if (entry == nullptr) {
552 return std::unexpected(Error(ErrorCode::kFsFileNotFound));
553 }
554
555 // 减少链接计数
556 if (entry->inode != nullptr) {
557 --entry->inode->link_count;
558 }
559
560 // 移除条目(将最后一个条目移到此处)
561 RamDirEntry* entries = static_cast<RamDirEntry*>(dir->data);
562 size_t last_idx = dir->child_count - 1;
563 if (entry != &entries[last_idx]) {
564 *entry = entries[last_idx];
565 }
566
567 --dir->child_count;
568 return {};
569}
570
572 if (dir == nullptr || dir->inode.type != FileType::kDirectory) {
573 return true;
574 }
575
576 // 只包含 . 和 .. 的目录也是空的
577 return dir->child_count == 0;
578}
579
580auto RamFs::ExpandFile(RamInode* inode, size_t new_size) -> Expected<void> {
581 if (inode == nullptr) {
582 return std::unexpected(Error(ErrorCode::kInvalidArgument));
583 }
584
585 if (new_size <= inode->capacity) {
586 return {};
587 }
588
589 // 计算新容量(按 256 字节对齐)
590 size_t new_capacity = ((new_size + 255) / 256) * 256;
591
592 uint8_t* new_data = static_cast<uint8_t*>(AllocateFileData(new_capacity));
593 if (new_data == nullptr) {
594 return std::unexpected(Error(ErrorCode::kOutOfMemory));
595 }
596
597 // 复制旧数据
598 if (inode->data != nullptr) {
599 memcpy(new_data, inode->data, inode->inode.size);
600 // Old allocation stays in pool (bump allocator — no per-block free)
601 }
602
603 inode->data = new_data;
604 inode->capacity = new_capacity;
605
606 return {};
607}
608
609auto RamFs::AllocateFileData(size_t size) -> void* {
610 // Align up to 16 bytes
611 size_t aligned = (size + 15UL) & ~15UL;
612 if (file_data_pool_used_ + aligned > kFileDataPoolSize) {
613 return nullptr;
614 }
615 void* ptr = &file_data_pool_[file_data_pool_used_];
616 file_data_pool_used_ += aligned;
617 return ptr;
618}
619
621 size_t bytes = count * sizeof(RamDirEntry);
622 // Align up to alignof(RamDirEntry)
623 static constexpr size_t kAlign = alignof(RamDirEntry);
624 size_t aligned = (bytes + kAlign - 1UL) & ~(kAlign - 1UL);
625 if (dir_data_pool_used_ + aligned > kDirDataPoolSize) {
626 return nullptr;
627 }
628 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
629 auto* ptr =
630 reinterpret_cast<RamDirEntry*>(&dir_data_pool_[dir_data_pool_used_]);
631 dir_data_pool_used_ += aligned;
632 return ptr;
633}
634
635} // namespace ramfs
auto Read(vfs::File *file, void *buf, size_t count) -> Expected< size_t > override
从文件读取数据
Definition ramfs.cpp:299
auto Write(vfs::File *file, const void *buf, size_t count) -> Expected< size_t > override
向文件写入数据
Definition ramfs.cpp:334
auto Close(vfs::File *file) -> Expected< void > override
关闭文件
Definition ramfs.cpp:415
auto ReadDir(vfs::File *file, vfs::DirEntry *dirent, size_t count) -> Expected< size_t > override
读取目录项
Definition ramfs.cpp:425
auto Seek(vfs::File *file, int64_t offset, vfs::SeekWhence whence) -> Expected< uint64_t > override
调整文件偏移量
Definition ramfs.cpp:372
auto Unlink(vfs::Inode *dir, const char *name) -> Expected< void > override
删除文件(解除链接)
Definition ramfs.cpp:219
auto Rmdir(vfs::Inode *dir, const char *name) -> Expected< void > override
删除目录
Definition ramfs.cpp:258
auto Create(vfs::Inode *dir, const char *name, vfs::FileType type) -> Expected< vfs::Inode * > override
在目录中创建新文件
Definition ramfs.cpp:188
auto Mkdir(vfs::Inode *dir, const char *name) -> Expected< vfs::Inode * > override
创建目录
Definition ramfs.cpp:252
auto Lookup(vfs::Inode *dir, const char *name) -> Expected< vfs::Inode * > override
在目录中查找指定名称的 inode
Definition ramfs.cpp:171
vfs::Inode * root_inode_
根目录 inode
Definition ramfs.hpp:162
auto IsDirectoryEmpty(RamInode *dir) -> bool
Definition ramfs.cpp:571
auto AllocateFileData(size_t size) -> void *
Bump-allocate size bytes from the file data pool.
Definition ramfs.cpp:609
auto AllocateInode() -> Expected< vfs::Inode * > override
分配新 inode
Definition ramfs.cpp:109
auto Unmount() -> Expected< void > override
卸载 ramfs
Definition ramfs.cpp:77
auto FindInDirectory(RamInode *dir, const char *name) -> RamDirEntry *
Definition ramfs.cpp:481
~RamFs() override
析构函数
Definition ramfs.cpp:28
auto Sync() -> Expected< void > override
同步数据到磁盘(ramfs 无操作)
Definition ramfs.cpp:104
auto Mount(vfs::BlockDevice *device) -> Expected< vfs::Inode * > override
挂载 ramfs
Definition ramfs.cpp:36
auto GetFileOps() -> vfs::FileOps *
获取文件操作实例
Definition ramfs.cpp:167
auto AddToDirectory(RamInode *dir, const char *name, vfs::Inode *inode) -> Expected< void >
Definition ramfs.cpp:497
auto GetRootInode() const -> vfs::Inode *
获取根 inode
Definition ramfs.cpp:165
auto GetName() const -> const char *override
获取文件系统类型名
Definition ramfs.cpp:34
auto ExpandFile(RamInode *inode, size_t new_size) -> Expected< void >
Definition ramfs.cpp:580
auto FreeInode(vfs::Inode *inode) -> Expected< void > override
释放 inode
Definition ramfs.cpp:136
auto AllocateDirEntries(size_t count) -> RamDirEntry *
Bump-allocate space for count RamDirEntry from the dir pool.
Definition ramfs.cpp:620
RamFs()
构造函数
Definition ramfs.cpp:15
bool mounted_
是否已挂载
Definition ramfs.hpp:166
auto RemoveFromDirectory(RamInode *dir, const char *name) -> Expected< void >
Definition ramfs.cpp:544
块设备抽象基类
File 操作接口
@ kInvalidArgument
@ kFsAlreadyMounted
@ kFsNotADirectory
std::expected< T, Error > Expected
std::expected 别名模板
Definition expected.hpp:365
auto Info(etl::format_string< Args... > fmt, Args &&... args) -> void
以 INFO 级别记录日志
FileType
文件类型
Definition vfs_types.hpp:22
SeekWhence
文件 seek 基准
Definition vfs_types.hpp:94
#define memcpy
#define strncpy
#define strcmp
错误类型,用于 std::expected
Definition expected.hpp:343
目录项结构(存储在目录的 data 中)
Definition ramfs.hpp:143
ramfs 内部 inode 数据
Definition ramfs.hpp:130
RamInode * next_free
空闲链表指针
Definition ramfs.hpp:139
void * data
文件数据(普通文件)或子项列表(目录)
Definition ramfs.hpp:133
size_t capacity
数据缓冲区容量
Definition ramfs.hpp:135
size_t child_count
子项数量(仅目录)
Definition ramfs.hpp:137
目录项结构(用于 readdir)
File — 打开的文件实例(每次 open 产生一个)
Definition vfs.hpp:65
Inode — 文件元数据(独立于路径名)
Definition vfs.hpp:16
FileSystem * fs
所属文件系统
Definition vfs.hpp:30
uint32_t link_count
硬链接计数
Definition vfs.hpp:26
uint32_t permissions
权限位(简化版)
Definition vfs.hpp:24
uint64_t size
文件大小(字节)
Definition vfs.hpp:22
FileType type
文件类型
Definition vfs.hpp:20
InodeOps * ops
文件操作接口
Definition vfs.hpp:33
uint64_t ino
inode 编号(文件系统内唯一)
Definition vfs.hpp:18
void * fs_private
文件系统私有数据指针
Definition vfs.hpp:28