|
| kerr_t | file_open (const char *path, uint32_t flags, file_t **out) |
| | open a file or directory through the VFS.
|
| file_t * | file_new_fifo_end (uint32_t flags) |
| | a new end of a named pipe, not yet joined to one (kernel/vfs/fifo.c joins it).
|
| kerr_t | file_open_pipe (file_t **read_end, file_t **write_end) |
| | make the two ends of a new pipe.
|
| file_t * | file_console (void) |
| | the console (keyboard in, screen out).
|
| file_t * | file_new (const file_ops_t *ops, uint32_t flags) |
| | a new description of another kind (a device stream), with one reference.
|
| void | file_ref (file_t *file) |
| | add a reference to a description.
|
| void | file_unref (file_t *file) |
| | drop a reference; the last one releases the description.
|
| bool | file_is_vfs (const file_t *file) |
| | true if the description is a filesystem file (not a pipe or the console).
|
| bool | file_readable (const file_t *file) |
| | true if the description was opened for reading (or writing).
|
| bool | file_writable (const file_t *file) |
| int32_t | file_read (file_t *file, void *buf, uint32_t count) |
| | the operations, with an errno for the unsupported ones: read and write EBADF (wrong access mode, or no op), seek ESPIPE, ioctl ENOTTY, mmap ENODEV, read_entry ENOTDIR, truncate EINVAL.
|
| int32_t | file_write (file_t *file, const void *buf, uint32_t count) |
| int64_t | file_seek (file_t *file, int64_t offset, int whence) |
| int32_t | file_ioctl (file_t *file, uint32_t request, void *arg) |
| int32_t | file_mmap (file_t *file, addr_space_t as, uintptr_t virt, size_t length, int prot, uint64_t offset) |
| int32_t | file_read_entry (file_t *file, fs_dirent_t *entry) |
| int32_t | file_unread_entry (file_t *file, const fs_dirent_t *entry) |
| | give back the entry file_read_entry returned last, so the next call returns it again (getdents, when it does not fit the caller's buffer).
|
| int32_t | file_truncate (file_t *file, uint64_t length) |
| int32_t | file_stat (file_t *file, struct kstat *st) |
| uint32_t | file_poll (file_t *file) |
| | the readiness of a file (kernel/vfs/poll.h).
|
| int32_t | file_pread (file_t *file, void *buf, uint32_t count, int64_t offset) |
| | read or write at an offset without moving the description's offset (pread, pwrite).
|
| int32_t | file_pwrite (file_t *file, const void *buf, uint32_t count, int64_t offset) |
open-file descriptions.
open(), pipe() and the console each make a file_t. a file descriptor is a pointer to one, so dup, dup2, fork and spawn share the description: the same file offset, the same status flags. the description is released (the file closed, the pipe end shut) when its last descriptor closes.
each kind of file (a filesystem file, a pipe end, the console) supplies a file_ops_t, so the syscalls never switch on the kind.
locking: the reference count is guarded by one global spinlock. the operations do their own locking (pipes their spinlock, ext2 its mutex).
the operations, with an errno for the unsupported ones: read and write EBADF (wrong access mode, or no op), seek ESPIPE, ioctl ENOTTY, mmap ENODEV, read_entry ENOTDIR, truncate EINVAL.
the buffers are kernel pointers or user pointers the caller has checked.