libc: io: implement file io buffering and internal locking for concurrency

This commit is contained in:
2026-04-01 18:51:13 +01:00
parent f2e650d368
commit 548387c43a
23 changed files with 948 additions and 73 deletions
+19 -6
View File
@@ -1,25 +1,38 @@
#ifndef _LIBC_IO_FILE_H_
#define _LIBC_IO_FILE_H_
#include "ringbuf.h"
#include <mango/types.h>
#include <stddef.h>
enum file_flags {
FILE_EOF = 0x01u,
FILE_ERR = 0x02u,
FILE_BIN = 0x04u,
FILE_STATIC = 0x08u,
};
struct __opaque_file {
enum file_flags f_flags;
kern_futex_t f_lock;
int f_prev;
int f_buffer_mode;
int f_fd;
char f_unget;
char *f_buf;
size_t f_buf_datalen, f_buf_max;
size_t f_buf_readptr;
/* the current seek position of the buffered data (i.e. the offset of
* the data that would be returned by reading f_buf). */
size_t f_seek;
struct ringbuf f_buf;
};
extern int __libc_file_refill(struct __opaque_file *f);
extern int __libc_file_read(struct __opaque_file *f, void *out, size_t count);
extern size_t __libc_file_available(struct __opaque_file *f);
extern void __libc_file_lock(struct __opaque_file *f);
extern void __libc_file_unlock(struct __opaque_file *f);
extern long __libc_file_read(struct __opaque_file *f, void *p, size_t count);
extern long __libc_file_write(
struct __opaque_file *f,
const void *p,
size_t count);
#endif