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