1 /* 2 * File-specific pager functionality. 3 * 4 * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include "file_pager.h" 23 #include "mapped_file_object_server.h" 24 25 26 27 /* Initialise a pager for a file with a unique file identifier, file provider, 28 mapping flags and a file paging coordinator. The provider offers a shared 29 page mapper for moderating access to loaded pages. */ 30 31 FilePager::FilePager(fileid_t fileid, FileProvider *provider, map_flags_t flags, 32 FilePaging *paging) 33 : Pager(provider->mapper(), flags), 34 _paging(paging), _provider(provider), fileid(fileid) 35 { 36 } 37 38 int FilePager::expected_items() 39 { 40 return MappedFileObject_expected_items; 41 } 42 43 ipc_server_handler_type FilePager::handler() 44 { 45 return (ipc_server_handler_type) handle_MappedFileObject; 46 } 47 48 49 50 /* Close the pager, removing the mapper from the paging registry if 51 appropriate. */ 52 53 void FilePager::close() 54 { 55 /* Notify other users of the file. */ 56 57 _provider->notify_others(_endpoint, NOTIFY_PEER_CLOSED); 58 59 /* Detach the pager, potentially removing the file provider. */ 60 61 _paging->detach_pager(fileid, _provider); 62 } 63 64 65 66 /* File-specific operations. */ 67 68 long FilePager::flush(offset_t populated_size, offset_t *size) 69 { 70 long err = Pager::flush(populated_size, size); 71 72 if (_resized) 73 { 74 _provider->notify_others(_endpoint, NOTIFY_CONTENT_AVAILABLE); 75 _resized = false; 76 } 77 78 return err; 79 } 80 81 long FilePager::resize(offset_t *size) 82 { 83 offset_t old_size = get_data_size(); 84 long err = Pager::resize(size); 85 86 /* If the size has changed, notify other users, but only after data has been 87 flushed. */ 88 89 if (old_size < get_data_size()) 90 _resized = true; 91 92 return err; 93 } 94 95 long FilePager::mmap(offset_t position, offset_t length, offset_t *start_pos, 96 offset_t *end_pos, offset_t *size) 97 { 98 /* Set the limits of the paged region. */ 99 100 return Pager::mmap(position, length, start_pos, end_pos, size); 101 } 102 103 104 105 /* Generic pager operations. */ 106 107 long FilePager::map(offset_t offset, address_t hot_spot, map_flags_t flags, l4_snd_fpage_t *region) 108 { 109 return Pager::map(offset, hot_spot, flags, region); 110 } 111 112 113 114 /* Subscribe to notifications. */ 115 116 long FilePager::subscribe(l4_cap_idx_t endpoint, notify_flags_t flags) 117 { 118 /* Readers can subscribe to new data (at end), and pipe closed events. 119 Writers can subscribe to new space and pipe closed events. */ 120 121 _endpoint = _provider->subscribe(endpoint, flags); 122 return L4_EOK; 123 } 124 125 long FilePager::unsubscribe(l4_cap_idx_t endpoint) 126 { 127 _provider->unsubscribe(_endpoint, endpoint); 128 return L4_EOK; 129 } 130 131 // vim: tabstop=4 expandtab shiftwidth=4