paul@342 | 1 | /* |
paul@342 | 2 | * A page mapper providing memory pages to satisfy file accesses, masking the |
paul@342 | 3 | * limits of a visible region of the file's contents. |
paul@342 | 4 | * |
paul@342 | 5 | * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk> |
paul@342 | 6 | * |
paul@342 | 7 | * This program is free software; you can redistribute it and/or |
paul@342 | 8 | * modify it under the terms of the GNU General Public License as |
paul@342 | 9 | * published by the Free Software Foundation; either version 2 of |
paul@342 | 10 | * the License, or (at your option) any later version. |
paul@342 | 11 | * |
paul@342 | 12 | * This program is distributed in the hope that it will be useful, |
paul@342 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@342 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@342 | 15 | * GNU General Public License for more details. |
paul@342 | 16 | * |
paul@342 | 17 | * You should have received a copy of the GNU General Public License |
paul@342 | 18 | * along with this program; if not, write to the Free Software |
paul@342 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@342 | 20 | * Boston, MA 02110-1301, USA |
paul@342 | 21 | */ |
paul@342 | 22 | |
paul@342 | 23 | #pragma once |
paul@342 | 24 | |
paul@342 | 25 | #include <fsserver/generic_page_mapper.h> |
paul@342 | 26 | #include <mem/memory_incremental.h> |
paul@342 | 27 | |
paul@342 | 28 | |
paul@342 | 29 | |
paul@342 | 30 | /* A special flexpage class for masked flexpages. */ |
paul@342 | 31 | |
paul@342 | 32 | class MaskedFlexpage : public Flexpage |
paul@342 | 33 | { |
paul@342 | 34 | public: |
paul@342 | 35 | explicit MaskedFlexpage(Region *region = NULL); |
paul@342 | 36 | }; |
paul@342 | 37 | |
paul@342 | 38 | |
paul@342 | 39 | |
paul@342 | 40 | /* A file mapper, associating flexpages with file regions. */ |
paul@342 | 41 | |
paul@342 | 42 | class MaskedPageMapper : public GenericPageMapper |
paul@342 | 43 | { |
paul@342 | 44 | protected: |
paul@342 | 45 | GenericPageMapper *_mapper; |
paul@342 | 46 | offset_t _size; |
paul@342 | 47 | |
paul@342 | 48 | /* Masked region support. */ |
paul@342 | 49 | |
paul@342 | 50 | MemoryIncremental _memory; |
paul@342 | 51 | offset_t _start_visible, _end_visible; |
paul@342 | 52 | MaskedFlexpage _start_flexpage, _end_flexpage, _zero_flexpage; |
paul@342 | 53 | |
paul@342 | 54 | /* Internal flexpage retrieval methods. */ |
paul@342 | 55 | |
paul@342 | 56 | Flexpage *get_masked_flexpage(Flexpage *flexpage); |
paul@342 | 57 | |
paul@342 | 58 | void allocate_region(Flexpage *flexpage, Flexpage &masked); |
paul@342 | 59 | |
paul@342 | 60 | void populate_region(Flexpage *flexpage, Flexpage &masked, |
paul@342 | 61 | bool has_start, bool has_end); |
paul@342 | 62 | |
paul@342 | 63 | public: |
paul@342 | 64 | explicit MaskedPageMapper(GenericPageMapper *mapper, offset_t start_visible, |
paul@342 | 65 | offset_t end_visible); |
paul@342 | 66 | |
paul@342 | 67 | virtual ~MaskedPageMapper(); |
paul@342 | 68 | |
paul@342 | 69 | /* Interface for the pager, implementing GenericPageMapper. */ |
paul@342 | 70 | |
paul@342 | 71 | Flexpage *get(offset_t offset, map_flags_t flags); |
paul@342 | 72 | |
paul@342 | 73 | void queue(Flexpage *flexpage); |
paul@342 | 74 | |
paul@342 | 75 | void flush_all(offset_t start, offset_t size); |
paul@342 | 76 | |
paul@342 | 77 | offset_t get_data_size(); |
paul@342 | 78 | |
paul@342 | 79 | void set_data_size(offset_t size); |
paul@342 | 80 | }; |
paul@342 | 81 | |
paul@342 | 82 | // vim: tabstop=4 expandtab shiftwidth=4 |