MOS Source Code
Loading...
Searching...
No Matches
io.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
6
7#include <mos/io/io_types.h>
8#include <mos/mm/mm_types.h>
9#include <mos/types.hpp>
10
11typedef struct _io io_t;
12struct vmap_t; // forward declaration
13
14typedef enum
15{
16 IO_NULL, // null io port
17 IO_FILE, // a file
18 IO_DIR, // a directory (i.e. readdir())
19 IO_IPC, // an IPC channel
20 IO_PIPE, // an end of a pipe
21 IO_CONSOLE, // a console
22} io_type_t;
23
24typedef enum
25{
30 IO_SEEKABLE = 1 << 3,
31 IO_MMAPABLE = 1 << 4,
33
35
36typedef struct
37{
38 size_t (*read)(io_t *io, void *buf, size_t count);
39 size_t (*write)(io_t *io, const void *buf, size_t count);
41 off_t (*seek)(io_t *io, off_t offset, io_seek_whence_t whence);
42 bool (*mmap)(io_t *io, vmap_t *vmap, off_t offset);
43 bool (*munmap)(io_t *io, vmap_t *vmap, bool *unmapped);
44 void (*get_name)(const io_t *io, char *buf, size_t size);
45} io_op_t;
46
47typedef struct _io
48{
49 bool closed;
53 const io_op_t *ops;
54} io_t;
55
56extern io_t *const io_null;
57
58void io_init(io_t *io, io_type_t type, io_flags_t flags, const io_op_t *ops);
59
60io_t *io_ref(io_t *io);
61io_t *io_unref(io_t *io);
62__nodiscard bool io_valid(const io_t *io);
63
64size_t io_read(io_t *io, void *buf, size_t count);
65size_t io_pread(io_t *io, void *buf, size_t count, off_t offset);
66size_t io_write(io_t *io, const void *buf, size_t count);
67off_t io_seek(io_t *io, off_t offset, io_seek_whence_t whence);
68off_t io_tell(io_t *io);
69bool io_mmap_perm_check(io_t *io, vm_flags flags, bool is_private);
70bool io_mmap(io_t *io, vmap_t *vmap, off_t offset);
71bool io_munmap(io_t *io, vmap_t *vmap, bool *unmapped);
72void io_get_name(const io_t *io, char *buf, size_t size);
MOSAPI void(1, 2) fatal_abort(const char *fmt
static const io_op_t ops
Definition io.cpp:29
bool io_mmap_perm_check(io_t *io, vm_flags flags, bool is_private)
Definition io.cpp:225
off_t io_tell(io_t *io)
Definition io.cpp:219
size_t io_pread(io_t *io, void *buf, size_t count, off_t offset)
Definition io.cpp:152
bool io_munmap(io_t *io, vmap_t *vmap, bool *unmapped)
Definition io.cpp:274
void io_init(io_t *io, io_type_t type, io_flags_t flags, const io_op_t *ops)
Definition io.cpp:45
io_t * io_ref(io_t *io)
Definition io.cpp:74
io_flags_t
Definition io.hpp:25
@ IO_MMAPABLE
Definition io.hpp:31
@ IO_EXECUTABLE
Definition io.hpp:29
@ IO_READABLE
Definition io.hpp:27
@ IO_SEEKABLE
Definition io.hpp:30
@ IO_WRITABLE
Definition io.hpp:28
@ IO_NONE
Definition io.hpp:26
bool io_mmap(io_t *io, vmap_t *vmap, off_t offset)
Definition io.cpp:255
__nodiscard bool io_valid(const io_t *io)
Definition io.cpp:128
off_t io_seek(io_t *io, off_t offset, io_seek_whence_t whence)
Definition io.cpp:200
io_t * io_unref(io_t *io)
Definition io.cpp:93
io_type_t
Definition io.hpp:15
@ IO_IPC
Definition io.hpp:19
@ IO_PIPE
Definition io.hpp:20
@ IO_CONSOLE
Definition io.hpp:21
@ IO_FILE
Definition io.hpp:17
@ IO_NULL
Definition io.hpp:16
@ IO_DIR
Definition io.hpp:18
io_t *const io_null
Definition io.cpp:43
size_t io_write(io_t *io, const void *buf, size_t count)
Definition io.cpp:181
size_t io_read(io_t *io, void *buf, size_t count)
Definition io.cpp:133
void io_get_name(const io_t *io, char *buf, size_t size)
Definition io.cpp:308
io_seek_whence_t
Definition io_types.h:6
@ MEM_PERM_NONE
Definition mm_types.h:8
@ MEM_PERM_EXEC
Definition mm_types.h:11
@ MEM_PERM_READ
Definition mm_types.h:9
@ MEM_PERM_WRITE
Definition mm_types.h:10
#define __nodiscard
Definition mos_global.h:35
int bool
Definition pb_syshdr.h:57
uint32_t size_t
Definition pb_syshdr.h:42
vm_flags
Definition platform.hpp:42
size_t size
Definition slab.cpp:34
Definition io.hpp:37
size_t(* read)(io_t *io, void *buf, size_t count)
Definition io.hpp:38
off_t(* seek)(io_t *io, off_t offset, io_seek_whence_t whence)
Definition io.hpp:41
void(* close)(io_t *io)
Definition io.hpp:40
bool(* mmap)(io_t *io, vmap_t *vmap, off_t offset)
Definition io.hpp:42
bool(* munmap)(io_t *io, vmap_t *vmap, bool *unmapped)
Definition io.hpp:43
void(* get_name)(const io_t *io, char *buf, size_t size)
Definition io.hpp:44
size_t(* write)(io_t *io, const void *buf, size_t count)
Definition io.hpp:39
Definition io.hpp:48
io_type_t type
Definition io.hpp:52
io_flags_t flags
Definition io.hpp:51
bool closed
Definition io.hpp:49
atomic_t refcount
Definition io.hpp:50
const io_op_t * ops
Definition io.hpp:53
Definition mm.hpp:59
io_t * io
Definition mm.hpp:68
ssize_t off_t
Definition types.h:80
#define MOS_ENUM_OPERATORS(_enum)
Definition types.hpp:113
std::atomic_size_t atomic_t
Definition types.hpp:11