1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
5#include "mos/filesystem/vfs_types.h"
6#include "mos/mm/physical/pmm.h"
7
8/**
9 * @brief Get a page from the page cache
10 *
11 * @param cache The inode cache
12 * @param pgoff The page offset
13 * @return phyframe_t* The page, or NULL if it doesn't exist
14 * @note Caller must hold the cache's lock
15 */
16phyframe_t *pagecache_get_page_for_read(inode_cache_t *cache, off_t pgoff);
17
18/**
19 * @brief Get a page from the page cache for writing
20 *
21 * @param cache The inode cache
22 * @param pgoff The page offset
23 * @return phyframe_t* The page
24 */
25phyframe_t *pagecache_get_page_for_write(inode_cache_t *cache, off_t pgoff);
26
27ssize_t vfs_read_pagecache(inode_cache_t *icache, void *buf, size_t size, off_t offset);
28ssize_t vfs_write_pagecache(inode_cache_t *icache, const void *buf, size_t total_size, off_t offset);
29
30/**
31 * @brief Flush or drop a range of pages from the page cache
32 *
33 * @param icache The inode cache
34 * @param pgoff The starting page offset
35 * @param npages The number of pages to flush or drop
36 * @param drop_page Whether to drop the pages, or just flush them
37 * @return long
38 */
39long pagecache_flush_or_drop(inode_cache_t *icache, off_t pgoff, size_t npages, bool drop_page);
40
41/**
42 * @brief Flush or drop all pages in the page cache
43 *
44 * @param icache The inode cache
45 * @param drop_page Whether to drop the pages, or just flush them
46 * @return long
47 */
48long pagecache_flush_or_drop_all(inode_cache_t *icache, bool drop_page);
49