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@101 | 28 | Accessor::Accessor(fileid_t fileid) |
paul@101 | 29 | : 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 | /* Perform any closing operation on the file. */ |
paul@6 | 38 | |
paul@6 | 39 | void Accessor::close() |
paul@6 | 40 | { |
paul@6 | 41 | } |
paul@6 | 42 | |
paul@56 | 43 | /* Data transfer methods. */ |
paul@56 | 44 | |
paul@56 | 45 | void Accessor::fill(Flexpage *flexpage) |
paul@56 | 46 | { |
paul@56 | 47 | /* Filling completely beyond the end of file should produce an empty |
paul@56 | 48 | flexpage. This could potentially be a shared read-only flexpage that |
paul@56 | 49 | would be replaced by an independent writable flexpage if ever written. */ |
paul@56 | 50 | |
paul@101 | 51 | if (flexpage->base_offset < get_size()) |
paul@56 | 52 | fill_populated(flexpage); |
paul@56 | 53 | else |
paul@56 | 54 | memset((void *) flexpage->base_addr, 0, flexpage->size); |
paul@56 | 55 | } |
paul@56 | 56 | |
paul@56 | 57 | void Accessor::flush(Flexpage *flexpage) |
paul@56 | 58 | { |
paul@56 | 59 | /* Flushing completely beyond the end of file should discard the |
paul@56 | 60 | flexpage. */ |
paul@56 | 61 | |
paul@101 | 62 | if (flexpage->base_offset < get_size()) |
paul@56 | 63 | flush_populated(flexpage); |
paul@56 | 64 | } |
paul@56 | 65 | |
paul@56 | 66 | /* Data transfer helper methods. */ |
paul@56 | 67 | |
paul@56 | 68 | void Accessor::fill_populated(Flexpage *flexpage) |
paul@56 | 69 | { |
paul@57 | 70 | (void) flexpage; |
paul@56 | 71 | } |
paul@56 | 72 | |
paul@56 | 73 | void Accessor::flush_populated(Flexpage *flexpage) |
paul@56 | 74 | { |
paul@57 | 75 | (void) flexpage; |
paul@56 | 76 | } |
paul@56 | 77 | |
paul@6 | 78 | // vim: tabstop=4 expandtab shiftwidth=4 |