paul@93 | 1 | /* |
paul@93 | 2 | * File-specific pager functionality. |
paul@93 | 3 | * |
paul@93 | 4 | * Copyright (C) 2021 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@94 | 26 | #include <fsserver/file_paging.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@81 | 35 | FilePaging *_paging; |
paul@79 | 36 | |
paul@141 | 37 | /* Notification endpoint for event subscription. */ |
paul@141 | 38 | |
paul@141 | 39 | unsigned int _endpoint; |
paul@141 | 40 | |
paul@141 | 41 | /* Resize flag for notification. */ |
paul@141 | 42 | |
paul@141 | 43 | bool _resized = false; |
paul@141 | 44 | |
paul@8 | 45 | public: |
paul@8 | 46 | fileid_t fileid; |
paul@8 | 47 | |
paul@121 | 48 | explicit FilePager(fileid_t fileid, PageMapper *mapper, map_flags_t flags, |
paul@81 | 49 | FilePaging *paging); |
paul@79 | 50 | |
paul@79 | 51 | virtual void close(); |
paul@8 | 52 | |
paul@10 | 53 | /* Server details. */ |
paul@10 | 54 | |
paul@10 | 55 | int expected_items(); |
paul@10 | 56 | |
paul@10 | 57 | ipc_server_handler_type handler(); |
paul@10 | 58 | |
paul@10 | 59 | void *interface() |
paul@10 | 60 | { return static_cast<MappedFileObject *>(this); } |
paul@10 | 61 | |
paul@53 | 62 | /* File methods. */ |
paul@53 | 63 | |
paul@53 | 64 | virtual long flush(offset_t populated_size, offset_t *size); |
paul@53 | 65 | |
paul@55 | 66 | virtual long resize(offset_t *size); |
paul@55 | 67 | |
paul@10 | 68 | /* Pager and mapped file methods. */ |
paul@10 | 69 | |
paul@121 | 70 | virtual long map(offset_t offset, address_t hot_spot, map_flags_t flags, |
paul@90 | 71 | l4_snd_fpage_t *region); |
paul@9 | 72 | |
paul@90 | 73 | virtual long mmap(offset_t position, offset_t length, offset_t *start_pos, |
paul@90 | 74 | offset_t *end_pos, offset_t *size); |
paul@141 | 75 | |
paul@141 | 76 | /* Notification methods. */ |
paul@141 | 77 | |
paul@193 | 78 | virtual long subscribe(l4_cap_idx_t endpoint, notify_flags_t flags); |
paul@141 | 79 | |
paul@193 | 80 | virtual long unsubscribe(l4_cap_idx_t endpoint); |
paul@8 | 81 | }; |
paul@8 | 82 | |
paul@8 | 83 | // vim: tabstop=4 expandtab shiftwidth=4 |