PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
fs.h
Go to the documentation of this file.
1#ifndef _SYS_IO_H
2#define _SYS_IO_H 1
3
4#include <alloca.h>
5#include <assert.h>
6#include <errno.h>
7#include <stdarg.h>
8#include <stdint.h>
9#include <stdlib.h>
10
11#if defined(__cplusplus)
12extern "C"
13{
14#endif
15
16#include "_libstd/ERR.h"
17#include "_libstd/MAX_NAME.h"
18#include "_libstd/MAX_PATH.h"
19#include "_libstd/NULL.h"
20#include "_libstd/SEEK.h"
21#include "_libstd/clock_t.h"
22#include "_libstd/config.h"
23#include "_libstd/fd_t.h"
24#include "_libstd/ssize_t.h"
25#include "_libstd/time_t.h"
26
27/**
28 * @brief Filesystem header.
29 * @defgroup libstd_sys_fs Filesystem IO
30 * @ingroup libstd
31 *
32 * @{
33 */
34
35#define STDIN_FILENO 0 ///< Standard input file descriptor.
36#define STDOUT_FILENO 1 ///< Standard output file descriptor.
37#define STDERR_FILENO 2 ///< Standard error file descriptor.
38
39/**
40 * @brief Pipe read end.
41 *
42 * The `PIPE_READ` constant defines which file descriptor in `fd` from a `open2` call on the `/dev/pipe` file will
43 * be the read end of the pipe.
44 *
45 */
46#define PIPE_READ 0
47
48/**
49 * @brief Pipe write end.
50 *
51 * The `PIPE_WRITE` constant defines which file descriptor in `fd` from a `open2` call on the `/dev/pipe` file will
52 * be the write end of the pipe.
53 *
54 */
55#define PIPE_WRITE 1
56
57/**
58 * @brief Maximum buffer size for the `F()` macro.
59 */
60#define F_MAX_SIZE 512
61
62/**
63 * @brief Allocates a formatted string on the stack.
64 *
65 * @warning Will terminate the program if the size of the formatted string is too large or if an encoding error occurs.
66 */
67#define F(format, ...) \
68 ({ \
69 char* _buffer = alloca(F_MAX_SIZE); \
70 int _len = snprintf(_buffer, F_MAX_SIZE, format, __VA_ARGS__); \
71 if (_len < 0 || _len >= F_MAX_SIZE) \
72 { \
73 abort(); \
74 } \
75 _buffer; \
76 })
77
78/**
79 * @brief System call for opening files.
80 *
81 * The `open()` function opens a file located at a given path.
82 *
83 * @param path The path to the desired file.
84 * @return On success, the file descriptor, on failure returns `ERR` and `errno` is set.
85 */
86fd_t open(const char* path);
87
88/**
89 * @brief System call for opening 2 file descriptors from one file.
90
91 * This is intended as a more generic
92 implementation
93 * of system calls like pipe() in POSIX systems. One example use case of this system call is pipes, if
94 * `open2` is called on `/dev/pipe` then `fd[0]` will store the read end of the pipe and `fd[1]` will store the
95 write
96 * end of the pipe. But if `open()` is called on `/dev/pipe` then the returned file descriptor would be both
97 * ends.
98 *
99 * @param path The path to the desired file.
100 * @param fd An array of two `fd_t` where the new file descriptors will be stored.
101 * @return On success, 0, on failure returns `ERR` and `errno` is set.
102 */
103uint64_t open2(const char* path, fd_t fd[2]);
104
105/**
106 * @brief System call for opening files relative to another file descriptor.
107 *
108 * @param from The file descriptor to open the file relative to, or `FD_NONE` to open from the current working
109 * directory.
110 * @param path The path to the desired file.
111 * @return On success, the file descriptor, on failure returns `ERR` and `errno` is set.
112 */
113fd_t openat(fd_t from, const char* path);
114
115/**
116 * @brief System call for closing files.
117 *
118 * @param fd The file descriptor to close.
119 * @return On success, 0, on failure returns `ERR` and `errno` is set.
120 */
122
123/**
124 * @brief System call for reading from files.
125 *
126 * @param fd The file descriptor to read from.
127 * @param buffer A pointer to the buffer where the data will be stored.
128 * @param count The maximum number of bytes to read.
129 * @return On success, the number of bytes read. On end-of-file, 0. On failure, `ERR` and `errno`
130 * is set.
131 */
132size_t read(fd_t fd, void* buffer, size_t count);
133
134/**
135 * @brief Wrapper for reading a file directly into a null-terminated string.
136 *
137 * The `reads()` function reads the entire contents of a file into a newly allocated null-terminated string.
138 * The caller is responsible for freeing the returned string.
139 *
140 * @param fd The file descriptor to read from.
141 * @return On success, a pointer to the null-terminated string. On failure, `NULL` and `errno` is set.
142 */
143char* reads(fd_t fd);
144
145/**
146 * @brief Wrapper for reading a file directly using a path.
147 *
148 * Equivalent to calling `open()`, `seek()`, `read()`, and `close()` in sequence.
149 *
150 * @param path The path to the file.
151 * @param buffer A pointer to the buffer where the data will be stored.
152 * @param count The maximum number of bytes to read.
153 * @param offset The offset in the file to start reading from.
154 * @return On success, the number of bytes read. On end-of-file, 0. On failure, `ERR` and `errno` is set.
155 */
156size_t readfile(const char* path, void* buffer, size_t count, size_t offset);
157
158/**
159 * @brief Wrapper for reading an entire file directly into a null-terminated string.
160 *
161 * The `readfiles()` function reads the entire contents of a file into a newly allocated null-terminated string.
162 * The caller is responsible for freeing the returned string.
163 *
164 * Equivalent to calling `open()`, `reads()`, and `close()` in sequence.
165 *
166 * @param path The path to the file.
167 * @return On success, a pointer to the null-terminated string. On failure, `NULL` and `errno` is set.
168 */
169char* readfiles(const char* path);
170
171/**
172 * @brief System call for writing to files.
173 *
174 * @param fd The file descriptor to write to.
175 * @param buffer A pointer to the buffer containing the data to write.
176 * @param count The number of bytes to write.
177 * @return On success, the number of bytes written. On failure, `ERR` and `errno` is set.
178 */
179size_t write(fd_t fd, const void* buffer, size_t count);
180
181/**
182 * @brief Wrapper for writing a null-terminated string to a file.
183 *
184 * @param fd The file descriptor to write to.
185 * @param string The null-terminated string to write.
186 * @return On success, the number of bytes written. On failure, `ERR` and `errno` is set.
187 */
188size_t writes(fd_t fd, const char* string);
189
190/**
191 * @brief Wrapper for writing to a file directly using a path.
192 *
193 * Equivalent to calling `open()`, `seek()`, `write()`, and `close()` in sequence.
194 *
195 * @param path The path to the file.
196 * @param buffer A pointer to the buffer containing the data to write.
197 * @param count The number of bytes to write.
198 * @param offset The offset in the file to start writing to.
199 * @return On success, the number of bytes written. On failure, `ERR` and `errno` is set.
200 */
201size_t writefile(const char* path, const void* buffer, size_t count, size_t offset);
202
203/**
204 * @brief Wrapper for writing a null-terminated string directly to a file using a path.
205 *
206 * Equivalent to calling `open()`, `writes()`, and `close()` in sequence.
207 *
208 * @param path The path to the file.
209 * @param string The null-terminated string to write.
210 * @return On success, the number of bytes written. On failure, `ERR` and `errno` is set.
211 */
212size_t writefiles(const char* path, const char* string);
213
214/**
215 * @brief Wrapper for reading from a file descriptor using scan formatting.
216 *
217 * @param fd The file descriptor to read from.
218 * @param format The format string.
219 * @return On success, the number of input items successfully matched and assigned. On failure, `ERR`.
220 */
221uint64_t scan(fd_t fd, const char* format, ...);
222
223/**
224 * @brief Wrapper for reading from a file descriptor using scan formatting with `va_list`.
225 *
226 * @param fd The file descriptor to read from.
227 * @param format The format string.
228 * @param args The va_list of arguments.
229 * @return On success, the number of input items successfully matched and assigned. On failure, `ERR`.
230 */
231uint64_t vscan(fd_t fd, const char* format, va_list args);
232
233/**
234 * @brief Wrapper for reading from a file path using scan formatting.
235 *
236 * Equivalent to calling `open()`, `scan()`, and `close()` in sequence.
237 *
238 * @param path The path to the file.
239 * @param format The format string.
240 * @return On success, the number of input items successfully matched and assigned. On failure, `ERR`.
241 */
242uint64_t scanfile(const char* path, const char* format, ...);
243
244/**
245 * @brief Wrapper for reading from a file path using scan formatting with `va_list`.
246 *
247 * Equivalent to calling `open()`, `vscan()`, and `close()` in sequence.
248 *
249 * @param path The path to the file.
250 * @param format The format string.
251 * @param args The va_list of arguments.
252 * @return On success, the number of input items successfully matched and assigned. On failure, `ERR`.
253 */
254uint64_t vscanfile(const char* path, const char* format, va_list args);
255
256/**
257 * @brief Type for the `seek()` origin argument.
258 *
259 */
261
262/**
263 * @brief System call for changing the file offset.
264 *
265 * @param fd The file descriptor.
266 * @param offset The offset to move the file pointer.
267 * @param origin The origin that the offset is relative to (e.g., `SEEK_SET`, `SEEK_CUR`, `SEEK_END`).
268 * @return On success, the new offset from the beginning of the file. On failure, `ERR` and `errno` is
269 * set.
270 */
271size_t seek(fd_t fd, ssize_t offset, seek_origin_t origin);
272
273/**
274 * @brief System call for changing the cwd.
275 *
276 * @param path The path to the new directory.
277 * @return On success, 0. On failure, `ERR` and `errno` is set.
278 */
279uint64_t chdir(const char* path);
280
281/**
282 * @brief Poll events type.
283 *
284 */
285typedef enum
286{
287 POLLNONE = 0, ///< None
288 POLLIN = (1 << 0), ///< File descriptor is ready to read.
289 POLLOUT = (1 << 1), ///< File descriptor is ready to write.
290 POLLERR = (1 << 2), ///< File descriptor caused an error.
291 POLLHUP = (1 << 3), ///< Stream socket peer closed connection, or shut down writing of connection.
292 POLLNVAL = (1 << 4), ///< Invalid file descriptor.
294
295/**
296 * @brief Poll event values that will always be checked and included even if not specified.
297 */
298#define POLL_SPECIAL (POLLERR | POLLHUP | POLLNVAL)
299
300/**
301 * @brief Poll file descriptor structure.
302 *
303 */
304typedef struct pollfd
305{
306 fd_t fd; ///< The file descriptor to poll.
307 poll_events_t events; ///< The events to wait for.
308 poll_events_t revents; ///< The events that occurred.
309} pollfd_t;
310
311/**
312 * @brief System call for polling files.
313 *
314 * @param fds An array of `pollfd_t` structures, each specifying a file descriptor to poll in pollfd_t::fd and the
315 * events to wait for in pollfd_t::events.
316 * @param amount The number of `pollfd_t` structures in the `fds` array.
317 * @param timeout The maximum time (in clock ticks) to wait for an event. If `CLOCKS_NEVER`, it waits forever.
318 * @return On success, the number of file descriptors for which the events occurred. On timeout, 0. On
319 * failure, `ERR` and `errno` is set.
320 */
321uint64_t poll(pollfd_t* fds, uint64_t amount, clock_t timeout);
322
323/**
324 * @brief Wrapper for polling one file.
325 *
326 * The `poll1()` function waits for events on a single file descriptor. Otherwise it is identical to `poll()` and exists
327 * simply for convenience.
328 *
329 * @param fd The file descriptor to poll.
330 * @param events The events to wait for (e.g., `POLLIN`, `POLLOUT`).
331 * @param timeout The maximum time (in clock ticks) to wait for an event. If `CLOCKS_NEVER`, it waits forever.
332 * @return On success, the events that occurred. On timeout, 0. On failure, the `POLLERR` event bit is
333 * set and `errno` is set.
334 */
335poll_events_t poll1(fd_t fd, poll_events_t events, clock_t timeout);
336
337/**
338 * @brief Vnode type enum.
339 * @enum vtype_t
340 */
341typedef enum
342{
343 VREG, ///< Is a regular file.
344 VDIR, ///< Is a directory.
345 VSYMLINK, ///< Is a symbolic link.
346} vtype_t;
347
348/**
349 * @brief A suberblock identifier that uniquely identifies a superblock within the system.
350 *
351 * When combined with a vnode number, this can uniquely identify an vnode within the entire system.
352 */
354
355/**
356 * @brief Vnode attributes structure.
357 * @struct vattr_t
358 */
359typedef struct vattr
360{
370 uint8_t padding[64]; ///< Padding to leave space for future expansion.
371} vattr_t;
372
373/**
374 * @brief Stat type.
375 * @struct stat_t
376 */
377typedef struct
378{
379 sbid_t sbid; ///< The superblock ID of the filesystem containing the entry.
380 uint64_t number; ///< The number of the entries vnode.
381 vtype_t type; ///< The type of the entries vnode.
382 uint64_t size; ///< The size of the file that is visible outside the filesystem.
383 uint64_t blocks; ///< The amount of blocks used on disk to store the file.
384 uint64_t blockSize; ///< The preferred block size of the filesystem.
385 uint64_t maxFileSize; ///< The maximum size of a file on this filesystem.
386 uint64_t linkAmount; ///< The amount of times the vnode appears in dentries.
387 time_t accessTime; ///< Unix time stamp for the last vnode access.
388 time_t modifyTime; ///< Unix time stamp for last file content alteration.
389 time_t changeTime; ///< Unix time stamp for the last file metadata alteration.
390 time_t createTime; ///< Unix time stamp for the creation of the vnode.
391 char name[MAX_PATH]; ///< The name of the entry, not the full filepath. Includes the flags of the paths mount.
392 uint8_t padding[64]; ///< Padding to leave space for future expansion.
393} stat_t;
394
395#ifdef static_assert
396static_assert(sizeof(stat_t) == 416, "invalid stat_t size");
397#endif
398
399/**
400 * @brief System call for retrieving info about a file or directory.
401 *
402 * @param path The path to the file or directory.
403 * @param stat A pointer to a `stat_t` structure where the file information will be stored.
404 * @return On success, 0. On failure, `ERR` and `errno` is set.
405 */
406uint64_t stat(const char* path, stat_t* stat);
407
408/**
409 * @brief System call for extended driver behaviour.
410 *
411 * The `ioctl()` function allows drivers to implement unusual behaviour that would be impossible or impractical with a
412 * normal file-based API.
413 *
414 * @param fd The file descriptor of the file.
415 * @param request The driver-dependent request code.
416 * @param argp A pointer to an argument that depends on the request, can be `NULL` if size is 0.
417 * @param size The size of the argument pointed to by `argp`.
418 * @return On success, the return value depends on the driver but is usually 0. On failure, `ERR` and `errno` is
419 * set.
420 */
421uint64_t ioctl(fd_t fd, uint64_t request, void* argp, size_t size);
422
423/**
424 * @brief System call for duplicating file descriptors.
425 *
426 * @param oldFd The open file descriptor to duplicate.
427 * @return On success, the new file descriptor. On failure, `ERR` and `errno` is set.
428 */
429fd_t dup(fd_t oldFd);
430
431/**
432 * @brief System call for duplicating file descriptors, with a destination.
433 *
434 * @param oldFd The open file descriptor to duplicate.
435 * @param newFd The desired new file descriptor.
436 * @return On success, the new file descriptor. On failure, `ERR` and `errno` is set.
437 */
438fd_t dup2(fd_t oldFd, fd_t newFd);
439
440/**
441 * @brief Directory entry flags.
442 * @enum dirent_flags_t
443 */
444typedef enum
445{
447 DIRENT_MOUNTED = 1 << 0, ///< The directory entry is a mountpoint.
449
450/**
451 * @brief Directory entry struct.
452 *
453 */
454typedef struct
455{
458 char path[MAX_PATH]; ///< The relative path of the entry.
459 char mode[MAX_PATH]; ///< The flags of the paths mount.
460} dirent_t;
461
462/**
463 * @brief System call for reading directory entires.
464 *
465 * @param fd The file descriptor of the directory to read.
466 * @param buffer The destination buffer.
467 * @param count The size of the buffer in bytes.
468 * @return On success, the total number of bytes written to the buffer. On failure,
469 * returns `ERR` and `errno` is set.
470 */
472
473/**
474 * @brief Helper for reading all directory entries.
475 *
476 * The caller is responsible for freeing the returned pointer.
477 *
478 * @param fd The file descriptor of the directory to read.
479 * @param buffer Output pointer to store the allocated buffer containing the directory entries.
480 * @param count Output pointer to store the number of bytes written to the buffer.
481 * @return On success, `0`. On failure, `ERR` and `errno` is set.
482 */
483size_t readdir(fd_t fd, dirent_t** buffer, uint64_t* count);
484
485/**
486 * @brief Wrapper for creating a directory.
487 *
488 * @param path The path of the directory to create.
489 * @return On success, 0. On failure, `ERR` and `errno` is set.
490 */
491uint64_t mkdir(const char* path);
492
493/**
494 * @brief Wrapper for removing a directory.
495 *
496 * @param path The path of the directory to remove.
497 * @return On success, 0. On failure, `ERR` and `errno` is set.
498 */
499uint64_t rmdir(const char* path);
500
501/**
502 * @brief System call for creating a hardlink.
503 *
504 * @param oldPath
505 * @param newPath
506 * @return On success, 0. On failure, `ERR` and `errno` is set.
507 */
508uint64_t link(const char* oldPath, const char* newPath);
509
510/**
511 * @brief Wrapper for removing a file.
512 *
513 * @param path The path of the file to remove.
514 * @return On success, 0. On failure, `ERR` and `errno` is set.
515 */
516uint64_t unlink(const char* path);
517
518#define KEY_MAX 128 ///< Maximum size of a key generated by `share()`.
519
520#define KEY_128BIT 25 ///< The size of a buffer needed to hold a 128-bit key.
521
522#define KEY_256BIT 45 ///< The size of a buffer needed to hold a 256-bit key.
523
524#define KEY_512BIT 89 ///< The size of a buffer needed to hold a 512-bit key.
525
526/**
527 * @brief System call for sharing a file descriptor with another process.
528 *
529 * @param key Output buffer to store the generated key.
530 * @param size The size of the output buffer.
531 * @param fd The file descriptor to share.
532 * @param timeout The time until the shared file descriptor expires. If `CLOCKS_NEVER`, it never expires.
533 * @return On success, `0`. On failure, `ERR` and `errno` is set.
534 */
535uint64_t share(char* key, uint64_t size, fd_t fd, clock_t timeout);
536
537/**
538 * @brief Helper for sharing a file by its path.
539 *
540 * @param key Output buffer to store the generated key.
541 * @param size The size of the output buffer.
542 * @param path The path to the file to share.
543 * @param timeout The time until the shared file descriptor expires. If `CLOCKS_NEVER`, it never expires.
544 * @return On success, `0`. On failure, `ERR` and `errno` is set.
545 */
546uint64_t sharefile(char* key, uint64_t size, const char* path, clock_t timeout);
547
548/**
549 * @brief System call for claiming a shared file descriptor.
550 *
551 * After claiming a shared file descriptor, the key is no longer valid and cannot be used again.
552 *
553 * @param key The key identifying the shared file descriptor.
554 * @return On success, the claimed file descriptor. On failure, `ERR` and `errno` is set.
555 */
556fd_t claim(const char* key);
557
558/**
559 * @brief System call for binding a file descriptor to a mountpoint.
560 *
561 * The created mount will inherit permissions from the source while the mount behaviour will follow the flags specified
562 * in `mountpoint`.
563 *
564 * @param mountpoint The mountpoint path.
565 * @param source The file descriptor to bind, must represent a directory.
566 * @return On success, `0`. On failure, `ERR` and `errno` is set.
567 */
568uint64_t bind(const char* mountpoint, fd_t source);
569
570/**
571 * @brief System call for mounting a filesystem.
572 *
573 * @param mountpoint The target path to mount to.
574 * @param fs The path to the desired filesystem in the `fs` sysfs directory.
575 * @param options A string containing filesystem defined `key=value` pairs, with multiple options separated by commas,
576 * or `NULL`.
577 * @return On success, `0`. On failure, `ERR` and `errno` is set.
578 */
579uint64_t mount(const char* mountpoint, const char* fs, const char* options);
580
581/**
582 * @brief System call for unmounting a filesystem.
583 *
584 * @param mountpoint The target path to unmount.
585 * @return On success, `0`. On failure, `ERR` and `errno` is set.
586 */
587uint64_t unmount(const char* mountpoint);
588
589/**
590 * @brief System call for reading the target of a symbolic link.
591 *
592 * @param path The path to the symbolic link.
593 * @param buffer A buffer to store the target path.
594 * @param count The size of the buffer.
595 * @return On success, the number of bytes read. On failure, `ERR` and `errno` is set.
596 */
597size_t readlink(const char* path, char* buffer, uint64_t count);
598
599/**
600 * @brief System call for creating a symbolic link.
601 *
602 * @param target The target path of the symbolic link.
603 * @param linkpath The path where the symbolic link will be created.
604 * @return On success, 0. On failure, `ERR` and `errno` is set.
605 */
606uint64_t symlink(const char* target, const char* linkpath);
607
608/**
609 * @brief Macro to automatically retry a function that returns an integer if it errors and `errno == EINTR`.
610 *
611 * @param expr The expression to evaluate.
612 */
613#define RETRY_EINTR(expr) \
614 ({ \
615 uint64_t _result; \
616 do \
617 { \
618 _result = (expr); \
619 } while (_result == ERR && errno == EINTR); \
620 _result; \
621 })
622
623/**
624 * @brief Macro to automatically retry a function that returns a pointer if it errors and `errno == EINTR`.
625 *
626 * @param expr The expression to evaluate.
627 */
628#define RETRY_EINTR_PTR(expr) \
629 ({ \
630 void* _result; \
631 do \
632 { \
633 _result = (expr); \
634 } while (_result == NULL && errno == EINTR); \
635 _result; \
636 })
637
638/** @} */
639
640#if defined(__cplusplus)
641}
642#endif
643
644#endif
#define MAX_PATH
Maximum length of filepaths.
Definition MAX_PATH.h:11
EFI_PHYSICAL_ADDRESS buffer
Definition main.c:237
static char format[MAX_NAME]
Definition screen.c:17
static clock_source_t source
Structure to describe the HPET to the sys time subsystem.
Definition hpet.c:193
fd_t dup2(fd_t oldFd, fd_t newFd)
System call for duplicating file descriptors, with a destination.
Definition dup2.c:8
uint64_t stat(const char *path, stat_t *stat)
System call for retrieving info about a file or directory.
Definition stat.c:8
size_t getdents(fd_t fd, dirent_t *buffer, uint64_t count)
System call for reading directory entires.
Definition getdents.c:8
size_t writefile(const char *path, const void *buffer, size_t count, size_t offset)
Wrapper for writing to a file directly using a path.
Definition writefile.c:3
fd_t open(const char *path)
System call for opening files.
Definition open.c:8
vtype_t
Vnode type enum.
Definition fs.h:342
uint64_t sbid_t
A suberblock identifier that uniquely identifies a superblock within the system.
Definition fs.h:353
uint64_t scanfile(const char *path, const char *format,...)
Wrapper for reading from a file path using scan formatting.
Definition scanfile.c:6
char * reads(fd_t fd)
Wrapper for reading a file directly into a null-terminated string.
Definition sread.c:5
uint64_t unmount(const char *mountpoint)
System call for unmounting a filesystem.
Definition unmount.c:5
poll_events_t poll1(fd_t fd, poll_events_t events, clock_t timeout)
Wrapper for polling one file.
Definition poll1.c:8
size_t writefiles(const char *path, const char *string)
Wrapper for writing a null-terminated string directly to a file using a path.
Definition swritefile.c:4
uint64_t close(fd_t fd)
System call for closing files.
Definition close.c:8
size_t readlink(const char *path, char *buffer, uint64_t count)
System call for reading the target of a symbolic link.
Definition readlink.c:8
char * readfiles(const char *path)
Wrapper for reading an entire file directly into a null-terminated string.
Definition sreadfile.c:3
fd_t dup(fd_t oldFd)
System call for duplicating file descriptors.
Definition dup.c:8
uint64_t vscan(fd_t fd, const char *format, va_list args)
Wrapper for reading from a file descriptor using scan formatting with va_list.
Definition vscan.c:29
size_t write(fd_t fd, const void *buffer, size_t count)
System call for writing to files.
Definition write.c:8
size_t seek(fd_t fd, ssize_t offset, seek_origin_t origin)
System call for changing the file offset.
Definition seek.c:8
uint64_t mkdir(const char *path)
Wrapper for creating a directory.
Definition mkdir.c:9
fd_t openat(fd_t from, const char *path)
System call for opening files relative to another file descriptor.
Definition openat.c:8
size_t readfile(const char *path, void *buffer, size_t count, size_t offset)
Wrapper for reading a file directly using a path.
Definition readfile.c:3
uint64_t poll(pollfd_t *fds, uint64_t amount, clock_t timeout)
System call for polling files.
Definition poll.c:8
size_t read(fd_t fd, void *buffer, size_t count)
System call for reading from files.
Definition read.c:8
uint64_t chdir(const char *path)
System call for changing the cwd.
Definition chdir.c:8
dirent_flags_t
Directory entry flags.
Definition fs.h:445
uint64_t mount(const char *mountpoint, const char *fs, const char *options)
System call for mounting a filesystem.
Definition mount.c:5
fd_t claim(const char *key)
System call for claiming a shared file descriptor.
Definition claim.c:6
uint64_t bind(const char *mountpoint, fd_t source)
System call for binding a file descriptor to a mountpoint.
Definition bind.c:5
uint64_t symlink(const char *target, const char *linkpath)
System call for creating a symbolic link.
Definition symlink.c:8
uint64_t vscanfile(const char *path, const char *format, va_list args)
Wrapper for reading from a file path using scan formatting with va_list.
Definition vscanfile.c:6
uint64_t unlink(const char *path)
Wrapper for removing a file.
Definition unlink.c:5
uint8_t seek_origin_t
Type for the seek() origin argument.
Definition fs.h:260
poll_events_t
Poll events type.
Definition fs.h:286
size_t writes(fd_t fd, const char *string)
Wrapper for writing a null-terminated string to a file.
Definition swrite.c:4
uint64_t open2(const char *path, fd_t fd[2])
System call for opening 2 file descriptors from one file.
Definition open2.c:8
uint64_t scan(fd_t fd, const char *format,...)
Wrapper for reading from a file descriptor using scan formatting.
Definition scan.c:6
size_t readdir(fd_t fd, dirent_t **buffer, uint64_t *count)
Helper for reading all directory entries.
Definition readdir.c:8
uint64_t share(char *key, uint64_t size, fd_t fd, clock_t timeout)
System call for sharing a file descriptor with another process.
Definition share.c:6
uint64_t sharefile(char *key, uint64_t size, const char *path, clock_t timeout)
Helper for sharing a file by its path.
Definition sharefile.c:4
uint64_t rmdir(const char *path)
Wrapper for removing a directory.
Definition rmdir.c:6
uint64_t link(const char *oldPath, const char *newPath)
System call for creating a hardlink.
Definition link.c:8
uint64_t ioctl(fd_t fd, uint64_t request, void *argp, size_t size)
System call for extended driver behaviour.
Definition ioctl.c:8
@ VSYMLINK
Is a symbolic link.
Definition fs.h:345
@ VREG
Is a regular file.
Definition fs.h:343
@ VDIR
Is a directory.
Definition fs.h:344
@ DIRENT_MOUNTED
The directory entry is a mountpoint.
Definition fs.h:447
@ DIRENT_NONE
Definition fs.h:446
@ POLLIN
File descriptor is ready to read.
Definition fs.h:288
@ POLLNONE
None.
Definition fs.h:287
@ POLLHUP
Stream socket peer closed connection, or shut down writing of connection.
Definition fs.h:291
@ POLLNVAL
Invalid file descriptor.
Definition fs.h:292
@ POLLOUT
File descriptor is ready to write.
Definition fs.h:289
@ POLLERR
File descriptor caused an error.
Definition fs.h:290
__INT64_TYPE__ ssize_t
Signed size type.
Definition ssize_t.h:11
__UINT64_TYPE__ fd_t
File descriptor type.
Definition fd_t.h:10
__UINT64_TYPE__ clock_t
A nanosecond time.
Definition clock_t.h:13
static uint64_t offset
Definition screen.c:19
static atomic_long count
Definition main.c:11
__builtin_va_list va_list
Definition stdarg.h:11
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
Directory entry struct.
Definition fs.h:455
dirent_flags_t flags
Definition fs.h:457
vtype_t type
Definition fs.h:456
Poll file descriptor structure.
Definition fs.h:305
poll_events_t revents
The events that occurred.
Definition fs.h:308
poll_events_t events
The events to wait for.
Definition fs.h:307
fd_t fd
The file descriptor to poll.
Definition fs.h:306
Stat type.
Definition fs.h:378
time_t accessTime
Unix time stamp for the last vnode access.
Definition fs.h:387
sbid_t sbid
The superblock ID of the filesystem containing the entry.
Definition fs.h:379
uint64_t blockSize
The preferred block size of the filesystem.
Definition fs.h:384
uint64_t linkAmount
The amount of times the vnode appears in dentries.
Definition fs.h:386
uint64_t size
The size of the file that is visible outside the filesystem.
Definition fs.h:382
uint64_t number
The number of the entries vnode.
Definition fs.h:380
uint64_t maxFileSize
The maximum size of a file on this filesystem.
Definition fs.h:385
time_t modifyTime
Unix time stamp for last file content alteration.
Definition fs.h:388
time_t changeTime
Unix time stamp for the last file metadata alteration.
Definition fs.h:389
uint64_t blocks
The amount of blocks used on disk to store the file.
Definition fs.h:383
vtype_t type
The type of the entries vnode.
Definition fs.h:381
time_t createTime
Unix time stamp for the creation of the vnode.
Definition fs.h:390
Vnode attributes structure.
Definition fs.h:360
uint64_t blockSize
Definition fs.h:366
uint64_t nlink
Definition fs.h:362
vtype_t type
Definition fs.h:361
time_t atime
Definition fs.h:367
time_t mtime
Definition fs.h:368
uint64_t blocks
Definition fs.h:365
uint64_t id
Definition fs.h:363
uint64_t size
Definition fs.h:364
time_t ctime
Definition fs.h:369
long long unsigned time_t
Definition time_t.h:4