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