|
ginnOS
The reference: libc, the libraries and the kernel
|
#include "file.h"#include "kernel/errno.h"#include "kernel/vfs/poll.h"#include "kernel/device/device.h"#include "kernel/fs/devfs.h"#include "kernel/vfs/flock.h"#include "kernel/vfs/fifo.h"#include "kernel/memory/heap.h"#include "kernel/sync/spinlock.h"#include "kernel/assert.h"#include "common/memory.h"#include "common/string.h"Functions | |
| 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_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) |
| uint32_t | file_poll (file_t *file) |
| the readiness of a file (kernel/vfs/poll.h). | |
| int32_t | file_stat (file_t *file, struct kstat *st) |
| 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) |
| bool | file_is_vfs (const file_t *file) |
| true if the description is a filesystem file (not a pipe or the console). | |
| 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_new | ( | const file_ops_t * | ops, |
| uint32_t | flags ) |
a new description of another kind (a device stream), with one reference.
its ops release it, and free it with kfree.
| void file_ref | ( | file_t * | file | ) |
add a reference to a description.
| file | the description. |
| void file_unref | ( | file_t * | file | ) |
drop a reference; the last one releases the description.
may sleep (closing a filesystem file takes its mutex).
| file | the description (NULL is ignored). |
true if the description was opened for reading (or writing).
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.
| 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).
the readiness of a file (kernel/vfs/poll.h).
a file without a poll op (a regular file) is always ready to read and write.
read or write at an offset without moving the description's offset (pread, pwrite).
only for files that can seek (ESPIPE otherwise). not atomic against another process using the same description.
true if the description is a filesystem file (not a pipe or the console).
open a file or directory through the VFS.
| path | absolute path. |
| flags | O_ access mode and status flags to keep in the description. |
| out | receives the new description (one reference). |
a new end of a named pipe, not yet joined to one (kernel/vfs/fifo.c joins it).
its release leaves the named pipe.
| flags | the open flags. |