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

Method OpenFil

src/filesystem/fatfs/fatfs.cpp:264–299  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

262}
263
264auto FatFsFileSystem::OpenFil(vfs::Inode* inode, vfs::OpenFlags open_flags)
265 -> Expected<void> {
266 auto* fi = static_cast<FatInode*>(inode->fs_private);
267 if (fi->fil != nullptr) {
268 // 已打开
269 return {};
270 }
271 FIL* fil = AllocateFil();
272 if (fil == nullptr) {
273 return std::unexpected(Error{ErrorCode::kFsFdTableFull});
274 }
275 BYTE fa_mode = 0;
276 // kOReadOnly == 0,需单独检查
277 if (open_flags == vfs::OpenFlags::kOReadOnly) {
278 fa_mode = FA_READ;
279 }
280 if ((open_flags & vfs::OpenFlags::kOWriteOnly) != 0U) {
281 fa_mode = FA_WRITE;
282 }
283 if ((open_flags & vfs::OpenFlags::kOReadWrite) != 0U) {
284 fa_mode = FA_READ | FA_WRITE;
285 }
286 if ((open_flags & vfs::OpenFlags::kOCreate) != 0U) {
287 fa_mode |= FA_OPEN_ALWAYS;
288 }
289 if ((open_flags & vfs::OpenFlags::kOTruncate) != 0U) {
290 fa_mode |= FA_CREATE_ALWAYS;
291 }
292 FRESULT fr = f_open(fil, fi->path.data(), fa_mode);
293 if (fr != FR_OK) {
294 FreeFil(fil);
295 return std::unexpected(Error{FresultToErrorCode(fr)});
296 }
297 fi->fil = fil;
298 return {};
299}
300
301auto FatFsFileSystem::FatFsInodeOps::Lookup(vfs::Inode* dir, const char* name)
302 -> Expected<vfs::Inode*> {

Callers 1

OpenMethod · 0.80

Calls 1

FresultToErrorCodeFunction · 0.85

Tested by

no test coverage detected