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 and shared page 28 mapper for moderating access to loaded pages. */ 29 30 FilePager::FilePager(fileid_t fileid, PageMapper *mapper, map_flags_t flags, 31 FilePaging *paging) 32 : Pager(mapper, flags), _paging(paging), fileid(fileid) 33 { 34 } 35 36 int FilePager::expected_items() 37 { 38 return MappedFileObject_expected_items; 39 } 40 41 ipc_server_handler_type FilePager::handler() 42 { 43 return (ipc_server_handler_type) handle_MappedFileObject; 44 } 45 46 47 48 /* Close the pager, removing the mapper from the paging registry if 49 appropriate. */ 50 51 void FilePager::close() 52 { 53 _paging->detach_pager(fileid, _mapper); 54 55 /* Notify other users of the file. */ 56 57 _paging->notify_others(_endpoint, NOTIFY_PEER_CLOSED); 58 } 59 60 61 62 /* File-specific operations. */ 63 64 long FilePager::flush(offset_t populated_size, offset_t *size) 65 { 66 long err = Pager::flush(populated_size, size); 67 68 if (_resized) 69 { 70 _paging->notify_others(_endpoint, NOTIFY_CONTENT_AVAILABLE); 71 _resized = false; 72 } 73 74 return err; 75 } 76 77 long FilePager::resize(offset_t *size) 78 { 79 offset_t old_size = get_data_size(); 80 long err = Pager::resize(size); 81 82 /* If the size has changed, notify other users, but only after data has been 83 flushed. */ 84 85 if (old_size < get_data_size()) 86 _resized = true; 87 88 return err; 89 } 90 91 long FilePager::mmap(offset_t position, offset_t length, offset_t *start_pos, 92 offset_t *end_pos, offset_t *size) 93 { 94 /* Set the limits of the paged region. */ 95 96 return Pager::mmap(position, length, start_pos, end_pos, size); 97 } 98 99 100 101 /* Generic pager operations. */ 102 103 long FilePager::map(offset_t offset, address_t hot_spot, map_flags_t flags, l4_snd_fpage_t *region) 104 { 105 return Pager::map(offset, hot_spot, flags, region); 106 } 107 108 109 110 /* Subscribe to notifications. */ 111 112 long FilePager::subscribe(l4_cap_idx_t notifier, notify_flags_t flags) 113 { 114 /* Readers can subscribe to new data (at end), and pipe closed events. 115 Writers can subscribe to new space and pipe closed events. */ 116 117 _endpoint = _paging->subscribe(notifier, flags); 118 return L4_EOK; 119 } 120 121 long FilePager::unsubscribe(l4_cap_idx_t notifier) 122 { 123 _paging->unsubscribe(_endpoint, notifier); 124 return L4_EOK; 125 } 126 127 // vim: tabstop=4 expandtab shiftwidth=4