MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / Alloc

Method Alloc

src/filesystem/file_descriptor.cpp:61–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59}
60
61auto FileDescriptorTable::Alloc(vfs::File* file) -> Expected<int> {
62 if (file == nullptr) {
63 return std::unexpected(Error(ErrorCode::kInvalidArgument));
64 }
65
66 LockGuard guard(lock_);
67
68 // 从 3 开始查找(0/1/2 预留给标准流)
69 for (int fd = 3; fd < kMaxFd; ++fd) {
70 if (table_[fd] == nullptr) {
71 table_[fd] = file;
72 ++open_count_;
73 return fd;
74 }
75 }
76
77 return std::unexpected(Error(ErrorCode::kFsFdTableFull));
78}
79
80auto FileDescriptorTable::Get(int fd) -> vfs::File* {
81 if (fd < 0 || fd >= kMaxFd) {

Callers 1

TEST_FFunction · 0.80

Calls 1

ErrorClass · 0.85

Tested by 1

TEST_FFunction · 0.64