52typedef struct kos_dirent {
64#define STAT_UNIQUE_NONE 0
68#define STAT_TYPE_NONE 0
71#define STAT_TYPE_FILE 1
74#define STAT_TYPE_DIR 2
77#define STAT_TYPE_PIPE 3
80#define STAT_TYPE_META 4
83#define STAT_TYPE_SYMLINK 5
86#define STAT_ATTR_NONE 0x00
87#define STAT_ATTR_R 0x01
88#define STAT_ATTR_W 0x02
91#define STAT_ATTR_RW (STAT_ATTR_R | STAT_ATTR_W)
97#define FILEHND_INVALID ((file_t)-1)
105typedef struct vfs_handler {
116 void *(*open)(
struct vfs_handler *vfs,
const char *fn,
int mode);
119 int (*close)(
void *hnd);
122 ssize_t (*read)(
void *hnd,
void *buffer,
size_t cnt);
125 ssize_t (*write)(
void *hnd,
const void *buffer,
size_t cnt);
128 off_t (*seek)(
void *hnd, off_t offset,
int whence);
131 off_t (*tell)(
void *hnd);
134 size_t (*total)(
void *hnd);
140 int (*
ioctl)(
void *hnd,
int cmd, va_list ap);
143 int (*rename)(
struct vfs_handler *vfs,
const char *fn1,
const char *fn2);
146 int (*unlink)(
struct vfs_handler *vfs,
const char *fn);
149 void *(*mmap)(
void *fd);
153 int (*complete)(
void *fd, ssize_t *rv);
160 int (*stat)(
struct vfs_handler *vfs,
const char *path,
struct stat *buf,
164 int (*mkdir)(
struct vfs_handler *vfs,
const char *fn);
167 int (*rmdir)(
struct vfs_handler *vfs,
const char *fn);
170 int (*fcntl)(
void *fd,
int cmd, va_list ap);
173 short (*
poll)(
void *fd,
short events);
176 int (*link)(
struct vfs_handler *vfs,
const char *path1,
const char *path2);
179 int (*symlink)(
struct vfs_handler *vfs,
const char *path1,
199 ssize_t (*readlink)(
struct vfs_handler *vfs,
const char *path,
char *buf,
206 int (*fstat)(
void *hnd,
struct stat *st);
219#include <sys/fcntl.h>
225#define O_MODE_MASK 0x0f
227#define O_ASYNC 0x0200
526int fs_link(
const char *path1,
const char *path2);
585int fs_stat(
const char *path,
struct stat *buf,
int flag);
700ssize_t
fs_copy(
const char *src,
const char *dst);
713ssize_t
fs_load(
const char *src,
void **out_ptr);
#define FD_SETSIZE
The number of distinct file descriptors, including files and network sockets, that can be in use at a...
Definition opts.h:136
#define __RESTRICT
Definition cdefs.h:176
#define NAME_MAX
Max filename length.
Definition limits.h:25
unsigned long long uint64
64-bit unsigned integer
Definition types.h:32
long long _off64_t
64-bit file offset type.
Definition _types.h:46
unsigned long uint32
32-bit unsigned integer
Definition types.h:33
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.
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_init(void)
Initialize the virtual filesystem.
size_t fs_total(file_t hnd)
Retrieve the length of an opened file.
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.
dirent_t * fs_readdir(file_t hnd)
Read an entry from an opened directory.
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.
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.
uint64 fs_total64(file_t hnd)
Retrieve the length of an opened file as a 64-bit integer.
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.
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.
char * fs_normalize_path(const char *__RESTRICT path, char *__RESTRICT resolved)
Normalize the specified path.
void rewinddir(DIR *dir)
Rewind a directory stream to the start of the directory.
#define ioctl
Definition ioctl.h:39
Compile-time options regarding debugging and other topics.
Directory entry.
Definition fs.h:52
uint32 attr
Attributes of the file.
Definition fs.h:56
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
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.