paul@93 | 1 | /* |
paul@93 | 2 | * File-specific pager functionality. |
paul@93 | 3 | * |
paul@475 | 4 | * Copyright (C) 2021, 2022, 2023 Paul Boddie <paul@boddie.org.uk> |
paul@93 | 5 | * |
paul@93 | 6 | * This program is free software; you can redistribute it and/or |
paul@93 | 7 | * modify it under the terms of the GNU General Public License as |
paul@93 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@93 | 9 | * the License, or (at your option) any later version. |
paul@93 | 10 | * |
paul@93 | 11 | * This program is distributed in the hope that it will be useful, |
paul@93 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@93 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@93 | 14 | * GNU General Public License for more details. |
paul@93 | 15 | * |
paul@93 | 16 | * You should have received a copy of the GNU General Public License |
paul@93 | 17 | * along with this program; if not, write to the Free Software |
paul@93 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@93 | 19 | * Boston, MA 02110-1301, USA |
paul@93 | 20 | */ |
paul@93 | 21 | |
paul@8 | 22 | #pragma once |
paul@8 | 23 | |
paul@94 | 24 | #include <fsserver/mapped_file_object_interface.h> |
paul@94 | 25 | #include <fsserver/pager.h> |
paul@202 | 26 | #include <fsserver/file_provider.h> |
paul@8 | 27 | |
paul@93 | 28 | |
paul@93 | 29 | |
paul@8 | 30 | /* A pager abstraction for a file. */ |
paul@8 | 31 | |
paul@9 | 32 | class FilePager : public Pager, public MappedFileObject |
paul@8 | 33 | { |
paul@79 | 34 | protected: |
paul@200 | 35 | FileProvider *_provider; |
paul@346 | 36 | flags_t _flags; |
paul@79 | 37 | |
paul@141 | 38 | /* Notification endpoint for event subscription. */ |
paul@141 | 39 | |
paul@485 | 40 | l4_cap_idx_t _notifier = L4_INVALID_CAP; |
paul@141 | 41 | |
paul@141 | 42 | /* Resize flag for notification. */ |
paul@141 | 43 | |
paul@141 | 44 | bool _resized = false; |
paul@141 | 45 | |
paul@346 | 46 | /* Helper methods. */ |
paul@346 | 47 | |
paul@346 | 48 | bool copy_on_write(); |
paul@346 | 49 | |
paul@8 | 50 | public: |
paul@8 | 51 | fileid_t fileid; |
paul@8 | 52 | |
paul@346 | 53 | explicit FilePager(fileid_t fileid, FileProvider *provider, flags_t flags); |
paul@79 | 54 | |
paul@79 | 55 | virtual void close(); |
paul@8 | 56 | |
paul@10 | 57 | /* Server details. */ |
paul@10 | 58 | |
paul@459 | 59 | ipc_server_default_config_type config(); |
paul@10 | 60 | |
paul@10 | 61 | void *interface() |
paul@10 | 62 | { return static_cast<MappedFileObject *>(this); } |
paul@10 | 63 | |
paul@53 | 64 | /* File methods. */ |
paul@53 | 65 | |
paul@53 | 66 | virtual long flush(offset_t populated_size, offset_t *size); |
paul@53 | 67 | |
paul@475 | 68 | virtual long reopen(flags_t flags, offset_t *size, l4_cap_idx_t *file, |
paul@475 | 69 | object_flags_t *object_flags); |
paul@475 | 70 | |
paul@55 | 71 | virtual long resize(offset_t *size); |
paul@55 | 72 | |
paul@10 | 73 | /* Pager and mapped file methods. */ |
paul@10 | 74 | |
paul@410 | 75 | virtual long map(offset_t offset, map_address_t hot_spot, map_flags_t flags, |
paul@90 | 76 | l4_snd_fpage_t *region); |
paul@9 | 77 | |
paul@339 | 78 | virtual long mmap(offset_t position, offset_t length, |
paul@339 | 79 | offset_t start_visible, offset_t end_visible, |
paul@332 | 80 | offset_t *start_pos, offset_t *end_pos, offset_t *size); |
paul@141 | 81 | |
paul@141 | 82 | /* Notification methods. */ |
paul@141 | 83 | |
paul@290 | 84 | virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags); |
paul@290 | 85 | |
paul@488 | 86 | virtual long unsubscribe(l4_cap_idx_t notifier); |
paul@8 | 87 | }; |
paul@8 | 88 | |
paul@8 | 89 | // vim: tabstop=4 expandtab shiftwidth=4 |