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