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