paul@93 | 1 | /* |
paul@93 | 2 | * File-specific pager functionality. |
paul@93 | 3 | * |
paul@665 | 4 | * Copyright (C) 2021, 2022, 2023, 2024 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@675 | 37 | object_flags_t _object_flags; |
paul@673 | 38 | offset_t _data_current; |
paul@79 | 39 | |
paul@141 | 40 | /* Notification endpoint for event subscription. */ |
paul@141 | 41 | |
paul@485 | 42 | l4_cap_idx_t _notifier = L4_INVALID_CAP; |
paul@141 | 43 | |
paul@141 | 44 | /* Resize flag for notification. */ |
paul@141 | 45 | |
paul@141 | 46 | bool _resized = false; |
paul@141 | 47 | |
paul@346 | 48 | /* Helper methods. */ |
paul@346 | 49 | |
paul@346 | 50 | bool copy_on_write(); |
paul@346 | 51 | |
paul@8 | 52 | public: |
paul@8 | 53 | fileid_t fileid; |
paul@8 | 54 | |
paul@675 | 55 | explicit FilePager(fileid_t fileid, FileProvider *provider, flags_t flags, |
paul@675 | 56 | object_flags_t object_flags); |
paul@79 | 57 | |
paul@79 | 58 | virtual void close(); |
paul@8 | 59 | |
paul@10 | 60 | /* Server details. */ |
paul@10 | 61 | |
paul@459 | 62 | ipc_server_default_config_type config(); |
paul@10 | 63 | |
paul@10 | 64 | void *interface() |
paul@10 | 65 | { return static_cast<MappedFileObject *>(this); } |
paul@10 | 66 | |
paul@673 | 67 | /* Flush methods. */ |
paul@53 | 68 | |
paul@665 | 69 | virtual long flush(offset_t position, offset_t *size); |
paul@53 | 70 | |
paul@675 | 71 | virtual long refresh(offset_t *position, offset_t *start_pos, |
paul@675 | 72 | offset_t *end_pos, offset_t *size, |
paul@675 | 73 | object_flags_t *object_flags); |
paul@673 | 74 | |
paul@673 | 75 | /* File methods. */ |
paul@673 | 76 | |
paul@475 | 77 | virtual long reopen(flags_t flags, offset_t *size, l4_cap_idx_t *file, |
paul@475 | 78 | object_flags_t *object_flags); |
paul@475 | 79 | |
paul@55 | 80 | virtual long resize(offset_t *size); |
paul@55 | 81 | |
paul@10 | 82 | /* Pager and mapped file methods. */ |
paul@10 | 83 | |
paul@410 | 84 | virtual long map(offset_t offset, map_address_t hot_spot, map_flags_t flags, |
paul@90 | 85 | l4_snd_fpage_t *region); |
paul@9 | 86 | |
paul@339 | 87 | virtual long mmap(offset_t position, offset_t length, |
paul@339 | 88 | offset_t start_visible, offset_t end_visible, |
paul@332 | 89 | offset_t *start_pos, offset_t *end_pos, offset_t *size); |
paul@141 | 90 | |
paul@141 | 91 | /* Notification methods. */ |
paul@141 | 92 | |
paul@290 | 93 | virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags); |
paul@290 | 94 | |
paul@548 | 95 | virtual long unsubscribe(); |
paul@8 | 96 | }; |
paul@8 | 97 | |
paul@8 | 98 | // vim: tabstop=4 expandtab shiftwidth=4 |