1 /* 2 * Generic accessor 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 "accessor.h" 23 24 #include <string.h> 25 26 27 28 Accessor::Accessor(fileid_t fileid, offset_t size) 29 : _size(size), fileid(fileid) 30 { 31 } 32 33 /* Return the size of the file. */ 34 35 offset_t Accessor::get_size() 36 { 37 return _size; 38 } 39 40 /* Update the size of the file. */ 41 42 void Accessor::set_size(offset_t size) 43 { 44 _size = size; 45 } 46 47 /* Perform any closing operation on the file. */ 48 49 void Accessor::close() 50 { 51 } 52 53 /* Perform any opening operation on the file. */ 54 55 void Accessor::open() 56 { 57 } 58 59 /* Data transfer methods. */ 60 61 void Accessor::fill(Flexpage *flexpage) 62 { 63 /* Filling completely beyond the end of file should produce an empty 64 flexpage. This could potentially be a shared read-only flexpage that 65 would be replaced by an independent writable flexpage if ever written. */ 66 67 if (flexpage->base_offset < _size) 68 fill_populated(flexpage); 69 else 70 memset((void *) flexpage->base_addr, 0, flexpage->size); 71 } 72 73 void Accessor::flush(Flexpage *flexpage) 74 { 75 /* Flushing completely beyond the end of file should discard the 76 flexpage. */ 77 78 if (flexpage->base_offset < _size) 79 flush_populated(flexpage); 80 } 81 82 /* Data transfer helper methods. */ 83 84 void Accessor::fill_populated(Flexpage *flexpage) 85 { 86 (void) flexpage; 87 } 88 89 void Accessor::flush_populated(Flexpage *flexpage) 90 { 91 (void) flexpage; 92 } 93 94 // vim: tabstop=4 expandtab shiftwidth=4