SBDP02/io.h
Kacper Donat 22548bbeeb iostats
2018-12-14 21:54:08 +01:00

44 lines
828 B
C

#ifndef IO_H
#define IO_H
#define PAGE_SIZE 512
#define PAGE_NONE 0
#define PAGE_PRESENT 1
#define PAGE_DIRTY 2
#define CACHE_ENTRIES 16
#include <stdio.h>
#include <inttypes.h>
extern unsigned reads, reads_all;
extern unsigned writes, writes_all;
typedef uint64_t page_t;
typedef uint64_t offset_t;
typedef struct {
page_t page;
size_t size;
char data[PAGE_SIZE];
uint8_t flags;
} page_cache_entry_t;
typedef struct {
FILE* file;
char* filename;
page_cache_entry_t cache[CACHE_ENTRIES];
} file_t;
file_t* file_open(const char* filename, const char* mode);
void file_close(file_t* file);
size_t file_read(file_t* file, page_t page, void* buffer, size_t size);
size_t file_write(file_t* file, page_t page, const void* buffer, size_t size);
void file_flush(file_t* file);
#endif