12 #include <sys/cdefs.h>
15 #include <sys/types.h>
18 #include <sys/queue.h>
56 #define STAT_UNIQUE_NONE 0
60 #define STAT_TYPE_NONE 0
63 #define STAT_TYPE_FILE 1
66 #define STAT_TYPE_DIR 2
69 #define STAT_TYPE_PIPE 3
72 #define STAT_TYPE_META 4
75 #define STAT_TYPE_SYMLINK 5
78 #define STAT_ATTR_NONE 0x00
79 #define STAT_ATTR_R 0x01
80 #define STAT_ATTR_W 0x02
83 #define STAT_ATTR_RW (STAT_ATTR_R | STAT_ATTR_W)
89 #define FILEHND_INVALID ((file_t)-1)
114 ssize_t (*
read)(
void *hnd,
void *buffer,
size_t cnt);
117 ssize_t (*
write)(
void *hnd,
const void *buffer,
size_t cnt);
120 off_t (*
seek)(
void *hnd, off_t offset,
int whence);
132 int (*
ioctl)(
void *hnd,
void *data,
size_t size);
141 void *(*mmap)(
void *fd);
162 int (*
fcntl)(
void *fd,
int cmd, va_list ap);
165 short (*
poll)(
void *fd,
short events);
201 #define FD_SETSIZE 1024
213 #include <sys/fcntl.h>
218 #define O_MODE_MASK 0x0f
220 #define O_ASYNC 0x0200
223 #define O_META 0x2000
389 int fs_rename(
const char *fn1,
const char *fn2);
491 int fs_link(
const char *path1,
const char *path2);
509 int fs_symlink(
const char *path1,
const char *path2);
530 ssize_t
fs_readlink(
const char *path,
char *buf,
size_t bufsize);
547 int fs_stat(
const char *path,
struct stat *buf,
int flag);
638 ssize_t
fs_copy(
const char *src,
const char *dst);
650 ssize_t
fs_load(
const char *src,
void **out_ptr);
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.
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
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.