KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
fs.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 kos/fs.h
4 Copyright (C) 2000, 2001, 2002, 2003 Megan Potter
5 Copyright (C) 2012, 2013, 2014, 2016 Lawrence Sebald
6
7*/
8
9/** \file kos/fs.h
10 \brief Virtual filesystem support.
11 \ingroup vfs_generic
12
13 This file contains the interface to the virtual filesystem (VFS) of KOS. The
14 functions defined in this file make up the base of the filesystem operations
15 that can be performed by programs. The functions in here are abstracted by
16 various other layers in libc, and shouldn't be necessarily used (for
17 portability reasons). However, if you want only to interact with KOS in your
18 programs, feel free to use them to your heart's content!
19
20 \author Megan Potter
21 \author Lawrence Sebald
22*/
23
24#ifndef __KOS_FS_H
25#define __KOS_FS_H
26
27#include <kos/cdefs.h>
28__BEGIN_DECLS
29
30#include <sys/types.h>
31#include <kos/limits.h>
32#include <kos/opts.h>
33#include <time.h>
34#include <sys/queue.h>
35#include <stdarg.h>
36#include <sys/stat.h>
37
38#include <kos/nmmgr.h>
39
40/** \defgroup vfs_generic Generic
41 \brief Generic, uniform access to a virtual filesystems
42 \ingroup vfs
43 @{
44*/
45
46/** \brief Directory entry.
47
48 All VFS handlers must conform to this interface in their directory entries.
49
50 \headerfile kos/fs.h
51*/
52typedef struct kos_dirent {
53 int size; /**< \brief Size of the file in bytes. */
54 char name[NAME_MAX]; /**< \brief Name of the file. */
55 time_t time; /**< \brief Last access/mod/change time (depends on VFS) */
56 uint32_t attr; /**< \brief Attributes of the file. */
57} dirent_t;
58
59/* Forward declaration */
60struct vfs_handler;
61
62/* stat_t.unique */
63/** \brief stat_t.unique: Constant to use denoting file has no unique ID */
64#define STAT_UNIQUE_NONE 0
65
66/* stat_t.type */
67/** \brief stat_t.type: Unknown / undefined / not relevant */
68#define STAT_TYPE_NONE 0
69
70/** \brief stat_t.type: Standard file */
71#define STAT_TYPE_FILE 1
72
73/** \brief stat_t.type: Standard directory */
74#define STAT_TYPE_DIR 2
75
76/** \brief stat_t.type: A virtual device of some sort (pipe, socket, etc) */
77#define STAT_TYPE_PIPE 3
78
79/** \brief stat_t.type: Meta data */
80#define STAT_TYPE_META 4
81
82/** \brief stat_t.type: Symbolic link */
83#define STAT_TYPE_SYMLINK 5
84
85/* stat_t.attr */
86#define STAT_ATTR_NONE 0x00 /**< \brief stat_t.attr: No attributes */
87#define STAT_ATTR_R 0x01 /**< \brief stat_t.attr: Read-capable */
88#define STAT_ATTR_W 0x02 /**< \brief stat_t.attr: Write-capable */
89
90/** \brief stat_t.attr: Read/Write capable */
91#define STAT_ATTR_RW (STAT_ATTR_R | STAT_ATTR_W)
92
93/** \brief File descriptor type */
94typedef int file_t;
95
96/** \brief Invalid file handle constant (for open failure, etc) */
97#define FILEHND_INVALID ((file_t)-1)
98
99/** \brief VFS handler interface.
100
101 All VFS handlers must implement this interface.
102
103 \headerfile kos/fs.h
104*/
105typedef struct vfs_handler {
106 /** \brief Name manager handler header */
108
109 /* Some VFS-specific pieces */
110 /** \brief Allow VFS caching; 0=no, 1=yes */
111 int cache;
112 /** \brief Pointer to private data for the handler */
113 void *privdata;
114
115 /** \brief Open a file on the given VFS; return a unique identifier */
116 void *(*open)(struct vfs_handler *vfs, const char *fn, int mode);
117
118 /** \brief Close a previously opened file */
119 int (*close)(void *hnd);
120
121 /** \brief Read from a previously opened file */
122 ssize_t (*read)(void *hnd, void *buffer, size_t cnt);
123
124 /** \brief Write to a previously opened file */
125 ssize_t (*write)(void *hnd, const void *buffer, size_t cnt);
126
127 /** \brief Seek in a previously opened file */
128 off_t (*seek)(void *hnd, off_t offset, int whence);
129
130 /** \brief Return the current position in a previously opened file */
131 off_t (*tell)(void *hnd);
132
133 /** \brief Return the total size of a previously opened file */
134 size_t (*total)(void *hnd);
135
136 /** \brief Read the next directory entry in a directory opened with O_DIR */
137 const dirent_t *(*readdir)(void *hnd);
138
139 /** \brief Execute a device-specific call on a previously opened file */
140 int (*ioctl)(void *hnd, int cmd, va_list ap);
141
142 /** \brief Rename/move a file on the given VFS */
143 int (*rename)(struct vfs_handler *vfs, const char *fn1, const char *fn2);
144
145 /** \brief Delete a file from the given VFS */
146 int (*unlink)(struct vfs_handler *vfs, const char *fn);
147
148 /** \brief "Memory map" a previously opened file */
149 void *(*mmap)(void *fd);
150
151 /** \brief Perform an I/O completion (async I/O) for a previously opened
152 file */
153 int (*complete)(void *fd, ssize_t *rv);
154
155 /** \brief Get status information on a file on the given VFS
156 \note path will not be passed through realpath() before calling the
157 filesystem-level function. It is also important to not call
158 realpath() in any implementation of this function as it is
159 possible that realpath() will call this function. */
160 int (*stat)(struct vfs_handler *vfs, const char *path, struct stat *buf,
161 int flag);
162
163 /** \brief Make a directory on the given VFS */
164 int (*mkdir)(struct vfs_handler *vfs, const char *fn);
165
166 /** \brief Remove a directory from the given VFS */
167 int (*rmdir)(struct vfs_handler *vfs, const char *fn);
168
169 /** \brief Manipulate file control flags on the given file */
170 int (*fcntl)(void *fd, int cmd, va_list ap);
171
172 /** \brief Check if an event is pending on the given file */
173 short (*poll)(void *fd, short events);
174
175 /** \brief Create a hard link */
176 int (*link)(struct vfs_handler *vfs, const char *path1, const char *path2);
177
178 /** \brief Create a symbolic link */
179 int (*symlink)(struct vfs_handler *vfs, const char *path1,
180 const char *path2);
181
182 /* 64-bit file access functions. Generally, you should only define one of
183 the 64-bit or 32-bit versions of these functions. */
184
185 /** \brief Seek in a previously opened file (64-bit offsets) */
186 _off64_t (*seek64)(void *hnd, _off64_t offset, int whence);
187
188 /** \brief Return the current position in an opened file (64-bit offset) */
189 _off64_t (*tell64)(void *hnd);
190
191 /** \brief Return the size of an opened file as a 64-bit integer */
192 uint64_t (*total64)(void *hnd);
193
194 /** \brief Read the value of a symbolic link
195 \note path will not be passed through realpath() before calling the
196 filesystem-level function. It is also important to not call
197 realpath() in any implementation of this function as it is
198 possible that realpath() will call this function. */
199 ssize_t (*readlink)(struct vfs_handler *vfs, const char *path, char *buf,
200 size_t bufsize);
201
202 /** \brief Rewind a directory stream to the start */
203 int (*rewinddir)(void *hnd);
204
205 /** \brief Get status information on an already opened file. */
206 int (*fstat)(void *hnd, struct stat *st);
208
209/** \cond */
210/* This is the private struct that will be used as raw file handles
211 underlying descriptors. */
212struct fs_hnd;
213
214/* The kernel-wide file descriptor table. These will reference to open files. */
215extern struct fs_hnd *fd_table[FD_SETSIZE];
216/** \endcond */
217
218/* Open modes */
219#include <sys/fcntl.h>
220
221/** \anchor vfs_fopen_modes
222 \name File Open Modes
223 @{
224*/
225#define O_MODE_MASK 0x0f /**< \brief Mask for mode numbers */
226//#define O_TRUNC 0x0100 /* Truncate */
227#define O_ASYNC 0x0200 /**< \brief Open for asynchronous I/O */
228//#define O_NONBLOCK 0x0400 /* Open for non-blocking I/O */
229#define O_DIR 0x1000 /**< \brief Open as directory */
230#define O_META 0x2000 /**< \brief Open as metadata */
231/** @} */
232
233/** \anchor vfs_seek_modes
234 \name Seek Modes
235
236 These are the values you can pass for the whence parameter to fs_seek().
237
238 @{
239*/
240#define SEEK_SET 0 /**< \brief Set position to offset. */
241#define SEEK_CUR 1 /**< \brief Seek from current position. */
242#define SEEK_END 2 /**< \brief Seek from end of file. */
243/** @} */
244
245/* Standard file descriptor functions */
246/** \brief Open a file on the VFS.
247
248 This function opens the specified file, returning a new file descriptor to
249 access the file.
250
251 \param fn The path to open.
252 \param mode The mode to use with opening the file. This may
253 include the standard open modes (O_RDONLY, O_WRONLY,
254 etc), as well as values from the \ref vfs_fopen_modes
255 "File Open Modes" list. Multiple values can be ORed
256 together.
257
258 \return The new file descriptor on success, FILEHND_INVALID on error.
259*/
260file_t fs_open(const char *fn, int mode);
261
262/** \brief Close an opened file.
263
264 This function closes the specified file descriptor, releasing all resources
265 associated with the descriptor.
266
267 \param hnd The file descriptor to close.
268
269 \return 0 for success, -1 for error
270*/
272
273/** \brief Read from an opened file.
274
275 This function reads into the specified buffer from the file at its current
276 file pointer.
277
278 \param hnd The file descriptor to read from.
279 \param buffer The buffer to read into.
280 \param cnt The size of the buffer (or the number of bytes
281 requested).
282
283 \return The number of bytes read, or -1 on error. Note that
284 this may not be the full number of bytes requested.
285*/
286ssize_t fs_read(file_t hnd, void *buffer, size_t cnt);
287
288/** \brief Write to an opened file.
289
290 This function writes the specified buffer into the file at the current file
291 pointer.
292
293 \param hnd The file descriptor to write into.
294 \param buffer The data to write into the file.
295 \param cnt The size of the buffer, in bytes.
296
297 \return The number of bytes written, or -1 on failure. Note
298 that the number of bytes written may be less than
299 what was requested.
300*/
301ssize_t fs_write(file_t hnd, const void *buffer, size_t cnt);
302
303/** \brief Seek to a new position within a file.
304
305 This function moves the file pointer to the specified position within the
306 file (the base of this position is determined by the whence parameter).
307
308 \param hnd The file descriptor to move the pointer for.
309 \param offset The offset in bytes from the specified base.
310 \param whence The base of the pointer move. This should be one of
311 the \ref vfs_seek_modes "Seek Modes" values.
312
313 \return The new position of the file pointer.
314*/
315off_t fs_seek(file_t hnd, off_t offset, int whence);
316
317/** \brief Seek to a new position within a file (64-bit offsets).
318
319 This function moves the file pointer to the specified position within the
320 file (the base of this position is determined by the whence parameter).
321
322 \param hnd The file descriptor to move the pointer for.
323 \param offset The offset in bytes from the specified base.
324 \param whence The base of the pointer move. This should be one of
325 the \ref vfs_seek_modes "Seek Modes" values.
326
327 \return The new position of the file pointer.
328*/
329_off64_t fs_seek64(file_t hnd, _off64_t offset, int whence);
330
331/** \brief Retrieve the position of the pointer within a file.
332
333 This function retrieves the current location of the file pointer within an
334 opened file. This is an offset in bytes from the start of the file.
335
336 \param hnd The file descriptor to retrieve the pointer from.
337
338 \return The offset within the file for the pointer.
339*/
341
342/** \brief Retrieve the position of the 64-bit pointer within a file.
343
344 This function retrieves the current location of the file pointer within an
345 opened file. This is an offset in bytes from the start of the file.
346
347 \param hnd The file descriptor to retrieve the pointer from.
348
349 \return The offset within the file for the pointer.
350*/
352
353/** \brief Retrieve the length of an opened file.
354
355 This file retrieves the length of the file associated with the given file
356 descriptor.
357
358 \param hnd The file descriptor to retrieve the size from.
359
360 \return The length of the file on success, -1 on failure.
361*/
363
364/** \brief Retrieve the length of an opened file as a 64-bit integer.
365
366 This file retrieves the length of the file associated with the given file
367 descriptor.
368
369 \note uint64_t is unsigned, so the error return value is
370 not less than 0.
371
372 \param hnd The file descriptor to retrieve the size from.
373
374 \return The length of the file on success, -1 on failure.
375*/
377
378
379/** \brief Read an entry from an opened directory.
380
381 This function reads the next entry from the directory specified by the given
382 file descriptor.
383
384 \param hnd The opened directory's file descriptor.
385
386 \return The next entry, or NULL on failure.
387*/
389
390/** \brief Execute a device-specific command on a file descriptor.
391
392 The types and formats of the commands are device/filesystem specific, and
393 are not documented here. Each filesystem may define any commands that are
394 specific to it with its implementation of this function.
395
396 \param hnd The file descriptor to use.
397 \param cmd The command to run.
398 \param ... Arguments for the command specified.
399
400 \return -1 on error.
401*/
402int fs_ioctl(file_t hnd, int cmd, ...);
403
404/** \brief Rename the specified file to the given filename.
405
406 This function renames the file specified by the first argument to the second
407 argument. The two paths should be on the same filesystem.
408
409 \param fn1 The existing file to rename.
410 \param fn2 The new filename to rename to.
411
412 \return 0 on success, -1 on failure.
413*/
414int fs_rename(const char *fn1, const char *fn2);
415
416/** \brief Delete the specified file.
417
418 This function deletes the specified file from the filesystem. This should
419 only be used for files, not for directories. For directories, use fs_rmdir()
420 instead of this function.
421
422 \param fn The path to remove.
423
424 \return 0 on success, -1 on failure.
425*/
426int fs_unlink(const char *fn);
427
428/** \brief Change the current working directory of the current thread.
429
430 This function changes the current working directory for the current thread.
431 Any relative paths passed into file-related functions will be relative to
432 the path that is changed to.
433
434 \param fn The path to set as the current working directory.
435
436 \return 0 on success, -1 on failure.
437*/
438int fs_chdir(const char *fn);
439
440/** \brief Memory-map a previously opened file.
441
442 This file "maps" the opened file into memory, reading the whole file into a
443 buffer, and returning that buffer. The returned buffer should not be freed,
444 as it will be freed when the file is closed. Bytes written into the buffer,
445 up to the original length of the file, will be written back to the file when
446 it is closed, assuming that the file is opened for writing.
447
448 \note Some of the filesystems in KallistiOS do not support
449 this operation. If you attempt to use this function
450 on a filesystem that does not support it, the
451 function will return NULL and set errno to EINVAL.
452
453 \param hnd The descriptor to memory map.
454
455 \return The memory mapped buffer, or NULL on failure.
456*/
458
459/** \brief Perform an I/O completion on the given file descriptor.
460
461 This function is used with asynchronous I/O to perform an I/O completion on
462 the given file descriptor.
463
464 \note Most of the filesystems in KallistiOS do not support
465 this operation. If you attempt to use this function
466 on a filesystem that does not support it, the
467 function will return -1 and set errno to EINVAL.
468
469 \param fd The descriptor to complete I/O on.
470 \param rv A buffer to store the size of the I/O in.
471
472 \return 0 on success, -1 on failure.
473*/
474int fs_complete(file_t fd, ssize_t *rv);
475
476/** \brief Create a directory.
477
478 This function creates the specified directory, if possible.
479
480 \param fn The path of the directory to create.
481 \return 0 on success, -1 on failure.
482*/
483int fs_mkdir(const char *fn);
484
485/** \brief Remove a directory by name.
486
487 This function removes the specified directory. The directory shall only be
488 removed if it is empty.
489
490 \param fn The path of the directory to remove.
491
492 \return 0 on success, -1 on failure.
493*/
494int fs_rmdir(const char *fn);
495
496/** \brief Manipulate file control flags.
497
498 This function implements the standard C fcntl function.
499
500 \param fd The file descriptor to use.
501 \param cmd The command to run.
502 \param ... Arguments for the command specified.
503
504 \return -1 on error (generally).
505*/
506int fs_fcntl(file_t fd, int cmd, ...);
507
508/** \brief Create a hard link.
509
510 This function implements the POSIX function link(), which creates a hard
511 link for an existing file.
512
513 \note Most filesystems in KallistiOS do not support hard
514 links. If you call this function on a filesystem
515 that does not support hard links, the function will
516 return -1 and set errno to EMLINK.
517
518 \param path1 An existing file to create a new link to.
519 \param path2 The pathname of the new link to be created.
520
521 \return 0 on success, -1 on failure.
522*/
523int fs_link(const char *path1, const char *path2);
524
525/** \brief Create a symbolic link.
526
527 This function implements the POSIX function symlink(), which creates a
528 symbolic link on the filesystem. Symbolic links are not required to point to
529 an existing file (per POSIX) and may result in circular links if care is not
530 taken. For now, symbolic links cannot cross filesystem boundaries in KOS.
531
532 \note Most filesystems in KallistiOS do not support
533 symbolic links. Filesystems that do not support
534 symlinks will simply set errno to ENOSYS and return
535 -1.
536
537 \param path1 The content of the link (i.e, what to point at).
538 \param path2 The pathname of the new link to be created.
539
540 \return 0 on success, -1 on failure.
541*/
542int fs_symlink(const char *path1, const char *path2);
543
544/** \brief Read the value of a symbolic link.
545
546 This function implements the POSIX function readlink(), which simply reads
547 the value of the symbolic link at the end of a path. This does not resolve
548 any internal links and it does not canonicalize the path either.
549
550 \note Most filesystems in KallistiOS do not support
551 symbolic links. Filesystems that do not support
552 symlinks will simply set errno to ENOSYS and return
553 -1.
554
555 \param path The symbolic link to read.
556 \param buf The buffer to place the link's contents in.
557 \param bufsize The number of bytes allocated to buf.
558
559 \return -1 on failure, the number of bytes placed into buf
560 on success. If the return value is equal to bufsize,
561 you may not have the whole link -- provide a larger
562 buffer and try again.
563*/
564ssize_t fs_readlink(const char *path, char *buf, size_t bufsize);
565
566/** \brief Retrieve information about the specified path.
567
568 This function retrieves status information on the given path. This function
569 now returns the normal POSIX-style struct stat, rather than the old KOS
570 stat_t structure. In addition, you can specify whether or not this function
571 should resolve symbolic links on filesystems that support symlinks.
572
573 \param path The path to retrieve information about.
574 \param buf The buffer to store stat information in.
575 \param flag Specifies whether or not to resolve a symbolic link.
576 If you don't want to resolve any symbolic links at
577 the end of the path, pass AT_SYMLINK_NOFOLLOW,
578 otherwise pass 0.
579
580 \return 0 on success, -1 on failure.
581*/
582int fs_stat(const char *path, struct stat *buf, int flag);
583
584/** \brief Rewind a directory to the start.
585
586 This function rewinds the position of a directory stream to the beginning of
587 the directory.
588
589 \note Some filesystems may not support this function. If a
590 filesystem doesn't support it, errno will be set to
591 ENOSYS and -1 will be returned.
592
593 \param hnd The opened directory's file descriptor.
594
595 \return 0 on success, -1 on failure.
596*/
598
599/** \brief Retrieve information about an opened file.
600
601 This function retrieves status information on the given file descriptor,
602 which must correspond to an already opened file.
603
604 \note Some filesystems may not support this function. If a
605 filesystem doesn't support it, errno will be set to
606 ENOSYS and -1 will be returned.
607
608 \param hnd The file descriptor to retrieve information about.
609 \param buf The buffer to store stat information in.
610
611 \return 0 on success, -1 on failure.
612*/
613int fs_fstat(file_t hnd, struct stat *buf);
614
615/** \brief Duplicate a file descriptor.
616
617 This function duplicates the specified file descriptor, returning a new file
618 descriptor that can be used to access the file. This is equivalent to the
619 standard POSIX function dup().
620
621 \param oldfd The old file descriptor to duplicate.
622
623 \return The new file descriptor on success, FILEHND_INVALID on failure.
624*/
626
627/** \brief Duplicate a file descriptor onto the specified descriptor.
628
629 This function duplicates the specified file descriptor onto the other file
630 descriptor provided. If the newfd parameter represents an open file, that
631 file will be closed before the old descriptor is duplicated onto it. This is
632 equivalent to the standard POSIX function dup2().
633
634 \param oldfd The old file descriptor to duplicate.
635 \param newfd The descriptor to copy into.
636
637 \return The new file descriptor on success, FILEHND_INVALID on failure.
638*/
640
641/** \brief Create a "transient" file descriptor.
642
643 This function creates and opens a new file descriptor that isn't associated
644 directly with a file on the filesystem. This is used internally to actually
645 open files, and should (in general) not be called by user code. Effectively,
646 if you're trying to implement your own filesystem handler in your code, you
647 may need this function, otherwise you should just ignore it.
648
649 \param vfs The VFS handler structure to use for the file.
650 \param hnd Internal handle data for the file.
651
652 \return The opened descriptor on success, FILEHND_INVALID on failure.
653*/
655
656/** \brief Retrieve the VFS Handler for a file descriptor.
657
658 This function retrieves the Handler structure for the VFS of the specified
659 file descriptor. There is generally no reason to call this function in user
660 code, as it is meant for use internally.
661
662 \param fd The file descriptor to retrieve the handler for.
663
664 \return The VFS' handler structure.
665*/
667
668/** \brief Retrieve the internal handle for a file descriptor.
669
670 This function retrieves the internal file handle data of the specified file
671 descriptor. There is generally no reason to call this function in user code,
672 as it is meant for use internally.
673
674 \param fd The file descriptor to retrieve the handler for.
675
676 \return The internal handle for the file descriptor.
677*/
679
680/** \brief Get the current working directory of the running thread.
681
682 \return The current working directory.
683*/
684const char *fs_getwd(void);
685
686/* Couple of util functions */
687
688/** \brief Copy a file.
689
690 This function copies the file at src to dst on the filesystem.
691
692 \param src The filename to copy from.
693 \param dst The filename to copy to.
694
695 \return The number of bytes copied successfully.
696*/
697ssize_t fs_copy(const char *src, const char *dst);
698
699/** \brief Open and read a whole file into RAM.
700
701 This function opens the specified file, reads it into memory (allocating the
702 necessary space with malloc), and closes the file. The caller is responsible
703 for freeing the memory when they are done with it.
704
705 \param src The filename to open and read.
706 \param out_ptr A pointer to the buffer on success, NULL otherwise.
707
708 \return The size of the file on success, -1 otherwise.
709*/
710ssize_t fs_load(const char *src, void **out_ptr);
711
712/** \brief Append a path component to a string.
713
714 This function acts mostly like the function strncat(), with a few slight
715 differences. First, if the destination string doesn't end in a '/'
716 character, this function will add it. Second, it returns the length of the
717 resulting string, including the NUL terminator. Finally, no modification of
718 the destination string will occur if there isn't enough space left in the
719 string to do so.
720
721 \param dst The string to modify.
722 \param src The path component to append.
723 \param len The length allocated for dst.
724
725 \return The length of the new string (including the NUL
726 terminator) on success, -1 otherwise.
727
728 \par Error Conditions:
729 \em EFAULT - src or dst is a NULL pointer \n
730 \em EINVAL - len is zero \n
731 \em ENAMETOOLONG - the resulting path would be longer than len bytes \n
732*/
733ssize_t fs_path_append(char *dst, const char *src, size_t len);
734
735/** \brief Normalize the specified path.
736 This function acts mostly like the function realpath() but it only simplifies
737 a path by resolving . and .. components and removing redundant slashes. It
738 doesn't check if the path exists or resolve symbolic links.
739 \param path The path to normalize.
740 \param resolved The buffer to store resolved normalized path. It has
741 to be PATH_MAX bytes in size.
742
743 \return A pointer to the normalized path on success,
744 or NULL on failure, in which case the path which
745 caused trouble is left in resolved.
746 \par Error Conditions:
747 \em EINVAL - path or resolved is a NULL pointer \n
748 \em ENAMETOOLONG - the resulting path would be longer than PATH_MAX bytes \n
749*/
750char *fs_normalize_path(const char *__RESTRICT path, char *__RESTRICT resolved);
751
752/** \brief Initialize the virtual filesystem.
753
754 This is normally done for you by default when KOS starts. In general, there
755 should be no reason for you to call this function.
756*/
757void fs_init(void);
758
759/** \brief Shut down the virtual filesystem.
760
761 This is done for you by the normal shutdown procedure of KOS. There should
762 not really be any reason for you to call this function yourself.
763*/
764void fs_shutdown(void);
765
766/** @} */
767
768__END_DECLS
769
770#endif /* __KOS_FS_H */
int mode
Definition 2ndmix.c:539
void hnd(const char *file, int line, const char *expr, const char *msg, const char *func)
Definition asserthnd.c:52
Various common macros used throughout the codebase.
#define FD_SETSIZE
The number of distinct file descriptors, including files and network sockets, that can be in use at a...
Definition opts.h:137
#define __RESTRICT
Definition cdefs.h:98
#define NAME_MAX
Max filename length.
Definition limits.h:25
int poll(struct pollfd fds[], nfds_t nfds, int timeout)
Poll a group of file descriptors for activity.
ssize_t fs_write(file_t hnd, const void *buffer, size_t cnt)
Write to an opened file.
const dirent_t * fs_readdir(file_t hnd)
Read an entry from an opened directory.
int fs_rmdir(const char *fn)
Remove a directory by name.
file_t fs_open_handle(vfs_handler_t *vfs, void *hnd)
Create a "transient" file descriptor.
int fs_rewinddir(file_t hnd)
Rewind a directory to the start.
file_t fs_open(const char *fn, int mode)
Open a file on the VFS.
int fs_chdir(const char *fn)
Change the current working directory of the current thread.
off_t fs_tell(file_t hnd)
Retrieve the position of the pointer within a file.
ssize_t fs_total(file_t hnd)
Retrieve the length of an opened file.
const char * fs_getwd(void)
Get the current working directory of the running thread.
_off64_t fs_tell64(file_t hnd)
Retrieve the position of the 64-bit pointer within a file.
vfs_handler_t * fs_get_handler(file_t fd)
Retrieve the VFS Handler for a file descriptor.
ssize_t fs_load(const char *src, void **out_ptr)
Open and read a whole file into RAM.
void * fs_mmap(file_t hnd)
Memory-map a previously opened file.
int fs_link(const char *path1, const char *path2)
Create a hard link.
int fs_close(file_t hnd)
Close an opened file.
void * fs_get_handle(file_t fd)
Retrieve the internal handle for a file descriptor.
int fs_fstat(file_t hnd, struct stat *buf)
Retrieve information about an opened file.
int fs_rename(const char *fn1, const char *fn2)
Rename the specified file to the given filename.
ssize_t fs_readlink(const char *path, char *buf, size_t bufsize)
Read the value of a symbolic link.
void fs_shutdown(void)
Shut down the virtual filesystem.
int fs_symlink(const char *path1, const char *path2)
Create a symbolic link.
int fs_fcntl(file_t fd, int cmd,...)
Manipulate file control flags.
int fs_ioctl(file_t hnd, int cmd,...)
Execute a device-specific command on a file descriptor.
int fs_unlink(const char *fn)
Delete the specified file.
file_t fs_dup(file_t oldfd)
Duplicate a file descriptor.
off_t fs_seek(file_t hnd, off_t offset, int whence)
Seek to a new position within a file.
ssize_t fs_read(file_t hnd, void *buffer, size_t cnt)
Read from an opened file.
_off64_t fs_seek64(file_t hnd, _off64_t offset, int whence)
Seek to a new position within a file (64-bit offsets).
ssize_t fs_copy(const char *src, const char *dst)
Copy a file.
int file_t
File descriptor type.
Definition fs.h:94
int fs_stat(const char *path, struct stat *buf, int flag)
Retrieve information about the specified path.
ssize_t fs_path_append(char *dst, const char *src, size_t len)
Append a path component to a string.
file_t fs_dup2(file_t oldfd, file_t newfd)
Duplicate a file descriptor onto the specified descriptor.
int64_t fs_total64(file_t hnd)
Retrieve the length of an opened file as a 64-bit integer.
int fs_complete(file_t fd, ssize_t *rv)
Perform an I/O completion on the given file descriptor.
int fs_mkdir(const char *fn)
Create a directory.
void fs_init(void)
Initialize the virtual filesystem.
char * fs_normalize_path(const char *__RESTRICT path, char *__RESTRICT resolved)
Normalize the specified path.
#define ioctl
Definition ioctl.h:41
Limits.
Name manager.
Compile-time options regarding debugging and other topics.
static char buffer[256]
Definition porthelper.c:11
Directory entry.
Definition fs.h:52
time_t time
Last access/mod/change time (depends on VFS)
Definition fs.h:55
int size
Size of the file in bytes.
Definition fs.h:53
uint32_t attr
Attributes of the file.
Definition fs.h:56
Name handler interface.
Definition nmmgr.h:61
VFS handler interface.
Definition fs.h:105
void * privdata
Pointer to private data for the handler.
Definition fs.h:113
nmmgr_handler_t nmmgr
Name manager handler header.
Definition fs.h:107
int cache
Allow VFS caching; 0=no, 1=yes.
Definition fs.h:111
KOS-implementation of select C11 and POSIX extensions.