Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

文件、目录与元数据

查看此模块的 Doxygen 逐项接口:签名、形参、返回值与重载 →

faio::fs 覆盖已打开文件的读写、路径级操作、属性查询和目录枚举。File 与 OpenOptions 来自 <faio/fs/file.hpp>,按路径调用的函数和元数据类型来自 <faio/fs/path.hpp>,目录枚举使用 <faio/fs/directory.hpp>。

接口

类别接口行为
文件对象File::open(context, path, options)按 OpenOptions 打开;无 options 等价于只读打开
File::create(context, path)使用 write + create + truncate 创建文件
OpenOptionsread/write/append/truncate/create/create_new;矛盾组合返回 EINVAL
read / write允许短读短写;非空缓冲区读到 0 表示文件结束
read_exact / write_all分块完成;提前 EOF 或零进展分别返回 UnexpectedEOF、WriteZero,并带进度
read_at / write_at显式偏移,不改逻辑游标;append 模式下 write_at 返回 EINVAL
seek / seek_from返回新偏移;结果越界或落到起点之前返回 EINVAL
metadata / permissions打开文件的属性快照与权限位
set_len / set_permissionsftruncate / fchmod
sync_data / sync_all / flush数据同步 / 连元数据一起同步 / 只等待写操作完成
close / try_clone / native_handle关闭并等在途操作 / dup 复制句柄 / 借用原生描述符
元数据与权限Metadatalen/is_file/is_dir/is_symlink/permissions/same_file/file_type/modified/accessed
Permissionsbits()/readonly()/set_readonly(),包装 std::filesystem::perms
路径操作metadata / symlink_metadata前者跟随符号链接,后者查询链接本身
canonicalize规范化绝对路径,解析符号链接并要求路径存在
hard_link / symlink / rename创建硬链接、符号链接或重命名
remove_file / remove_dir删除文件或空目录
create_dir / create_dir_all创建目录;权限参数只作用于新建目录
DirBuilderrecursive() 与 permissions() 选项,create() 按选项创建
remove_dir_all返回删除条目数;选项含 max_depth、max_state_bytes、batch_size
copy复制普通文件并返回字节数;目标截断,失败不回滚
read / read_to_string / write整体读写;read 默认上限 256 MiB,超限返回 EFBIG
目录枚举read_dir(context, path)打开目录返回 ReadDir;省略 context 时使用当前上下文
next_entry()返回 expected<optional<DirEntry>>;空 optional 表示枚举结束
DirEntryfile_name()、path()、metadata()、file_type()
close()等待在途批次结束并关闭目录句柄