1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/libfsserver/include/fsserver/masked_page_mapper.h Sat May 28 00:59:04 2022 +0200
1.3 @@ -0,0 +1,82 @@
1.4 +/*
1.5 + * A page mapper providing memory pages to satisfy file accesses, masking the
1.6 + * limits of a visible region of the file's contents.
1.7 + *
1.8 + * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
1.9 + *
1.10 + * This program is free software; you can redistribute it and/or
1.11 + * modify it under the terms of the GNU General Public License as
1.12 + * published by the Free Software Foundation; either version 2 of
1.13 + * the License, or (at your option) any later version.
1.14 + *
1.15 + * This program is distributed in the hope that it will be useful,
1.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.18 + * GNU General Public License for more details.
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License
1.21 + * along with this program; if not, write to the Free Software
1.22 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.23 + * Boston, MA 02110-1301, USA
1.24 + */
1.25 +
1.26 +#pragma once
1.27 +
1.28 +#include <fsserver/generic_page_mapper.h>
1.29 +#include <mem/memory_incremental.h>
1.30 +
1.31 +
1.32 +
1.33 +/* A special flexpage class for masked flexpages. */
1.34 +
1.35 +class MaskedFlexpage : public Flexpage
1.36 +{
1.37 +public:
1.38 + explicit MaskedFlexpage(Region *region = NULL);
1.39 +};
1.40 +
1.41 +
1.42 +
1.43 +/* A file mapper, associating flexpages with file regions. */
1.44 +
1.45 +class MaskedPageMapper : public GenericPageMapper
1.46 +{
1.47 +protected:
1.48 + GenericPageMapper *_mapper;
1.49 + offset_t _size;
1.50 +
1.51 + /* Masked region support. */
1.52 +
1.53 + MemoryIncremental _memory;
1.54 + offset_t _start_visible, _end_visible;
1.55 + MaskedFlexpage _start_flexpage, _end_flexpage, _zero_flexpage;
1.56 +
1.57 + /* Internal flexpage retrieval methods. */
1.58 +
1.59 + Flexpage *get_masked_flexpage(Flexpage *flexpage);
1.60 +
1.61 + void allocate_region(Flexpage *flexpage, Flexpage &masked);
1.62 +
1.63 + void populate_region(Flexpage *flexpage, Flexpage &masked,
1.64 + bool has_start, bool has_end);
1.65 +
1.66 +public:
1.67 + explicit MaskedPageMapper(GenericPageMapper *mapper, offset_t start_visible,
1.68 + offset_t end_visible);
1.69 +
1.70 + virtual ~MaskedPageMapper();
1.71 +
1.72 + /* Interface for the pager, implementing GenericPageMapper. */
1.73 +
1.74 + Flexpage *get(offset_t offset, map_flags_t flags);
1.75 +
1.76 + void queue(Flexpage *flexpage);
1.77 +
1.78 + void flush_all(offset_t start, offset_t size);
1.79 +
1.80 + offset_t get_data_size();
1.81 +
1.82 + void set_data_size(offset_t size);
1.83 +};
1.84 +
1.85 +// vim: tabstop=4 expandtab shiftwidth=4