1
0
mirror of https://github.com/fumiama/fumidb.git synced 2026-06-05 16:50:33 +08:00
Files
fumidb/include/page.h
2022-05-01 17:42:11 +08:00

67 lines
1.8 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef _PAGE_H_
#define _PAGE_H_
#include <stdio.h>
#ifndef PAGESZ
#define PAGESZ 4096
#endif
// 获取文件中的第一个空闲页,并将其读到内存
// 如果现有空闲均无整页,则新分配一页
// 返回指针的 -8 字节记录了本页在文件的偏移
// 因此实际上分配了 PAGESZ+8 的空间
// 返回:
// NULL 错误,参见 errno
// page 指针
void* alloc_page(int fd);
// 刷新一页
// 返回:
// EOF lseek 错误,参见 errno
// 0/1 write size != PAGESZ
int sync_page(int fd, void* page);
// 刷新并释放 page
// 返回:
// EOF lseek 错误,参见 errno
// 0/1 write size != PAGESZ
int unmount_page(int fd, void* page);
// 释放分配的页,将其标记为空闲以备使用
// 同时将数据刷新到文件
// 返回:
// EOF 错误,参见 errno
// 0 成功
int free_page(int fd, void* page);
// 获取文件中的第一个满足 size 大小的块的位置
// 返回的块大小一定是 size实际上为 size + 8 + 2
// 开头的 8+2 字节记录了真正的块位置与大小以备释放
// 返回的 ptr 已经跳过这 10 个字节
// 返回:
// NULL 错误,参见 errno
// blk 指针
void* alloc_block(int fd, uint16_t size);
// 刷新 block 到文件
// 返回:
// EOF lseek 错误或 size 过大,参见 errno
// 0/1 write size != PAGESZ
int sync_block(int fd, void* blk);
// 刷新 block 到文件并释放
// 返回:
// EOF lseek 错误或 size 过大,参见 errno
// 0/1 write size != PAGESZ
int unmount_block(int fd, void* blk);
// 释放块,并将其标记为空闲以备使用
// 如果该块前后也有空闲且不跨过4096
// 将会被合并
// 返回:
// EOF 错误,参见 errno
// 0 成功
int free_block(int fd, void* blk);
#endif