in fs/extfs/extfs.cpp [70:105]
static ext2_file_t do_ext2fs_open_file(ext2_filsys fs, const char *path, unsigned int flags, unsigned int mode) {
DEFER(LOG_DEBUG("open_file" , VALUE(path)));
ext2_ino_t ino = string_to_inode(fs, path, !(flags & O_NOFOLLOW));
errcode_t ret;
if (ino == 0) {
if (!(flags & O_CREAT)) {
errno = ENOENT;
return nullptr;
}
ret = create_file(fs, path, mode, &ino);
if (ret) {
LOG_ERROR_RETURN(-ret, nullptr, "failed to create file ", VALUE(ret), VALUE(path));
}
} else if (flags & O_EXCL) {
errno = EEXIST;
return nullptr;
}
if ((flags & O_DIRECTORY) && ext2fs_check_directory(fs, ino)) {
errno = ENOTDIR;
return nullptr;
}
ext2_file_t file;
ret = ext2fs_file_open(fs, ino, extfs_open_flags(flags), &file);
if (ret) {
errno = -parse_extfs_error(fs, ino, ret);
return nullptr;
}
if (flags & O_TRUNC) {
ret = ext2fs_file_set_size2(file, 0);
if (ret) {
errno = -parse_extfs_error(fs, ino, ret);
return nullptr;
}
}
return file;
}