Cthulhu  0.2.10
Cthulhu compiler collection
fs.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-only
2 
3 #pragma once
4 
5 #include <ctu_fs_api.h>
6 
7 #include "os/core.h"
8 
9 #include <stdbool.h>
10 
12 
13 typedef struct arena_t arena_t;
14 typedef struct io_t io_t;
15 typedef struct vector_t vector_t;
16 
21 
22 typedef struct fs_t fs_t;
23 typedef struct fs_inode_t fs_inode_t;
24 typedef struct fs_iter_t fs_iter_t;
25 
29 CT_FS_API void fs_delete(STA_RELEASE fs_t *fs);
30 
38 CT_FS_API fs_t *fs_physical(IN_STRING const char *root, IN_NOTNULL arena_t *arena);
39 
47 CT_FS_API fs_t *fs_virtual(IN_STRING const char *name, IN_NOTNULL arena_t *arena);
48 
56 CT_FS_API os_error_t fs_dir_create(IN_NOTNULL fs_t *fs, IN_STRING const char *path);
57 
65 CT_FS_API void fs_file_create(IN_NOTNULL fs_t *fs, IN_STRING const char *path);
66 
76 CT_FS_API io_t *fs_open(IN_NOTNULL fs_t *fs, IN_STRING const char *path, os_access_t flags);
77 
85 CT_FS_API bool fs_dir_exists(IN_NOTNULL fs_t *fs, IN_STRING const char *path);
86 
94 CT_FS_API bool fs_file_exists(IN_NOTNULL fs_t *fs, IN_STRING const char *path);
95 
103 CT_FS_API os_error_t fs_dir_delete(IN_NOTNULL fs_t *fs, IN_STRING const char *path);
104 
111 CT_FS_API os_error_t fs_file_delete(IN_NOTNULL fs_t *fs, IN_STRING const char *path);
112 
115 typedef struct sync_result_t
116 {
119  const char *path;
120 } sync_result_t;
121 
127 CT_FS_API sync_result_t fs_sync(IN_NOTNULL fs_t *dst, IN_NOTNULL fs_t *src);
128 
134 CT_PUREFN
135 CT_FS_API os_dirent_t fs_inode_type(IN_NOTNULL const fs_inode_t *inode);
136 
143 CT_PUREFN
144 CT_FS_API bool fs_inode_is(IN_NOTNULL const fs_inode_t *inode, os_dirent_t type);
145 
152 CT_PUREFN
153 CT_FS_API const char *fs_inode_name(IN_NOTNULL const fs_inode_t *inode);
154 
161 CT_FS_API fs_inode_t *fs_find_inode(IN_NOTNULL fs_t *fs, IN_STRING const char *path);
162 
168 CT_PUREFN
169 CT_FS_API fs_inode_t *fs_root_inode(IN_NOTNULL fs_t *fs);
170 
178 CT_FS_API os_error_t fs_iter_begin(
179  IN_NOTNULL fs_t *fs,
180  IN_NOTNULL const fs_inode_t *node,
181  OUT_NOTNULL fs_iter_t **iter);
182 
188 CT_FS_API os_error_t fs_iter_end(
189  IN_NOTNULL fs_iter_t *iter);
190 
198 CT_FS_API os_error_t fs_iter_next(
199  IN_NOTNULL fs_iter_t *iter,
200  OUT_NOTNULL fs_inode_t **inode);
201 
203 
os_dirent_t
directory entry type
Definition: core.h:56
os_access_t
file access mode
Definition: core.h:38
#define STA_RELEASE
annotate a pointer as invalid after the function returns
#define CT_PUREFN
mark a function as pure, always returns the same value for the same arguments
Definition: analyze.h:228
#define CT_NODISCARD
mark a function as returning a value that must be used
#define IN_NOTNULL
annotate a parameter as not being null
#define IN_STRING
annotate a parameter as being a null terminated string
#define OUT_NOTNULL
Definition: analyze.h:99
#define CT_BEGIN_API
Definition: compiler.h:129
#define CT_END_API
Definition: compiler.h:130
CT_NODISCARD CT_FS_API fs_t * fs_virtual(const char *name, arena_t *arena)
create a virtual filesystem interface
Definition: virtual.c:273
CT_PUREFN CT_FS_API os_dirent_t fs_inode_type(const fs_inode_t *inode)
get the type of an inode
Definition: fs.c:520
CT_FS_API void fs_delete(STA_RELEASE fs_t *fs)
delete a filesystem handle
CT_NODISCARD CT_FS_API bool fs_dir_exists(fs_t *fs, const char *path)
query if a directory exists
Definition: fs.c:368
CT_FS_API os_error_t fs_iter_begin(fs_t *fs, const fs_inode_t *node, OUT_NOTNULL fs_iter_t **iter)
begin iterating over a directory
CT_FS_API os_error_t fs_file_delete(fs_t *fs, const char *path)
delete a file
Definition: fs.c:219
CT_NODISCARD CT_FS_API fs_t * fs_physical(const char *root, arena_t *arena)
create a filesystem interface to a physical location on disk
Definition: physical.c:215
CT_NODISCARD CT_FS_API bool fs_file_exists(fs_t *fs, const char *path)
query if a file exists
Definition: fs.c:197
CT_FS_API os_error_t fs_dir_delete(fs_t *fs, const char *path)
delete a directory delete a directory and all contained files and folders
Definition: fs.c:397
CT_FS_API os_error_t fs_dir_create(fs_t *fs, const char *path)
create a directory create a directory and all child directories inside a filesystem
Definition: fs.c:333
CT_FS_API fs_inode_t * fs_find_inode(fs_t *fs, const char *path)
find an inode in a filesystem
Definition: fs.c:544
CT_FS_API os_error_t fs_iter_next(fs_iter_t *iter, OUT_NOTNULL fs_inode_t **inode)
get the next inode in an iteration
CT_NODISCARD CT_FS_API io_t * fs_open(fs_t *fs, const char *path, os_access_t flags)
open a file at a given location in the filesystem
Definition: fs.c:254
CT_FS_API os_error_t fs_iter_end(fs_iter_t *iter)
end an iteration
Definition: fs.c:590
CT_FS_API void fs_file_create(fs_t *fs, const char *path)
create a file
Definition: fs.c:176
CT_PUREFN CT_FS_API bool fs_inode_is(const fs_inode_t *inode, os_dirent_t type)
check if a given inode is of a certain type
Definition: fs.c:528
CT_PUREFN CT_FS_API const char * fs_inode_name(const fs_inode_t *inode)
get the name of an inode
Definition: fs.c:536
CT_FS_API sync_result_t fs_sync(fs_t *dst, fs_t *src)
synchronize 2 filesystems copies all folders and files from src to dst
Definition: fs.c:511
CT_PUREFN CT_FS_API fs_inode_t * fs_root_inode(fs_t *fs)
get the root inode of a filesystem
Definition: fs.c:553
an allocator object
Definition: arena.h:86
fs_t * fs
Definition: common.h:21
Definition: common.h:72
io object implementation
Definition: impl.h:122
the result of a fs_sync call this is here because we cant use Compiler message notification in the fs...
Definition: fs.h:116
const char * path
the file that failed to sync
Definition: fs.h:119
a generic vector of pointers
Definition: vector.c:16