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