paul@272 | 1 | /* |
paul@272 | 2 | * An opener for regions of a memory card. |
paul@272 | 3 | * |
paul@272 | 4 | * Copyright (C) 2021, 2022, 2024 Paul Boddie <paul@boddie.org.uk> |
paul@272 | 5 | * |
paul@272 | 6 | * This program is free software; you can redistribute it and/or |
paul@272 | 7 | * modify it under the terms of the GNU General Public License as |
paul@272 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@272 | 9 | * the License, or (at your option) any later version. |
paul@272 | 10 | * |
paul@272 | 11 | * This program is distributed in the hope that it will be useful, |
paul@272 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@272 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@272 | 14 | * GNU General Public License for more details. |
paul@272 | 15 | * |
paul@272 | 16 | * You should have received a copy of the GNU General Public License |
paul@272 | 17 | * along with this program; if not, write to the Free Software |
paul@272 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@272 | 19 | * Boston, MA 02110-1301, USA |
paul@272 | 20 | */ |
paul@272 | 21 | |
paul@272 | 22 | #include <dirent.h> |
paul@272 | 23 | #include <stdio.h> |
paul@272 | 24 | #include <string.h> |
paul@272 | 25 | #include <sys/stat.h> |
paul@272 | 26 | #include <unistd.h> |
paul@272 | 27 | |
paul@272 | 28 | #include <resource/resource_server.h> |
paul@272 | 29 | |
paul@272 | 30 | #include "msc_region_accessor.h" |
paul@272 | 31 | #include "msc_region_opener.h" |
paul@272 | 32 | |
paul@272 | 33 | |
paul@272 | 34 | |
paul@272 | 35 | MscRegionOpener::~MscRegionOpener() |
paul@272 | 36 | { |
paul@272 | 37 | } |
paul@272 | 38 | |
paul@272 | 39 | bool MscRegionOpener::accessing_directory(flags_t flags, fileid_t fileid) |
paul@272 | 40 | { |
paul@272 | 41 | (void) flags; (void) fileid; |
paul@272 | 42 | return false; |
paul@272 | 43 | } |
paul@272 | 44 | |
paul@272 | 45 | bool MscRegionOpener::accessing_file(flags_t flags, fileid_t fileid) |
paul@272 | 46 | { |
paul@272 | 47 | (void) flags; (void) fileid; |
paul@272 | 48 | return true; |
paul@272 | 49 | } |
paul@272 | 50 | |
paul@272 | 51 | /* Test if a directory is empty. */ |
paul@272 | 52 | |
paul@272 | 53 | bool MscRegionOpener::directory_is_empty(fileid_t fileid) |
paul@272 | 54 | { |
paul@272 | 55 | (void) fileid; |
paul@272 | 56 | return false; |
paul@272 | 57 | } |
paul@272 | 58 | |
paul@272 | 59 | /* Return a file identifier for the given 'path'. */ |
paul@272 | 60 | |
paul@272 | 61 | long MscRegionOpener::get_fileid(const char *path, flags_t flags, fileid_t *fileid) |
paul@272 | 62 | { |
paul@272 | 63 | (void) flags; |
paul@272 | 64 | |
paul@272 | 65 | // Convert the path to an integer for use as the file identifier. |
paul@272 | 66 | |
paul@272 | 67 | if (!(strlen(path) && isdigit(path[0]))) |
paul@272 | 68 | return -L4_ENOENT; |
paul@272 | 69 | |
paul@272 | 70 | *fileid = atoi(path); |
paul@272 | 71 | return L4_EOK; |
paul@272 | 72 | } |
paul@272 | 73 | |
paul@272 | 74 | /* Return a new accessor for 'fileid'. */ |
paul@272 | 75 | |
paul@272 | 76 | long MscRegionOpener::make_accessor(flags_t flags, fileid_t fileid, |
paul@272 | 77 | Accessor **accessor) |
paul@272 | 78 | { |
paul@272 | 79 | // NOTE: Not testing for create or write flags. |
paul@272 | 80 | |
paul@272 | 81 | (void) flags; |
paul@272 | 82 | |
paul@272 | 83 | // Find the given partition and initialise the accessor with the appropriate |
paul@272 | 84 | // details. |
paul@272 | 85 | |
paul@272 | 86 | uint32_t start_block, num_blocks; |
paul@272 | 87 | |
paul@272 | 88 | if (_ops->get_partition(fileid, &start_block, &num_blocks)) |
paul@272 | 89 | return -L4_ENOENT; |
paul@272 | 90 | |
paul@272 | 91 | *accessor = new MscRegionAccessor(_ops, start_block, num_blocks, fileid); |
paul@272 | 92 | return L4_EOK; |
paul@272 | 93 | } |
paul@272 | 94 | |
paul@272 | 95 | /* Return a directory accessor for 'fileid'. |
paul@272 | 96 | NOTE: Currently unimplemented. */ |
paul@272 | 97 | |
paul@272 | 98 | long MscRegionOpener::make_directory_accessor(flags_t flags, fileid_t fileid, |
paul@272 | 99 | DirectoryAccessor **accessor) |
paul@272 | 100 | { |
paul@272 | 101 | (void) flags; (void) fileid; (void) accessor; |
paul@272 | 102 | return -L4_EPERM; |
paul@272 | 103 | } |
paul@272 | 104 | |
paul@272 | 105 | |
paul@272 | 106 | |
paul@272 | 107 | /* Make a new directory. */ |
paul@272 | 108 | |
paul@272 | 109 | long MscRegionOpener::make_directory_object(const char *path, sys_mode_t mode) |
paul@272 | 110 | { |
paul@272 | 111 | (void) path; (void) mode; |
paul@272 | 112 | return -L4_EPERM; |
paul@272 | 113 | } |
paul@272 | 114 | |
paul@272 | 115 | /* Remove a filesystem object. */ |
paul@272 | 116 | |
paul@272 | 117 | long MscRegionOpener::remove_object(fileid_t fileid) |
paul@272 | 118 | { |
paul@272 | 119 | (void) fileid; |
paul@272 | 120 | return -L4_EPERM; |
paul@272 | 121 | } |
paul@272 | 122 | |
paul@272 | 123 | /* Rename a filesystem object, placing source inside the parent of target. */ |
paul@272 | 124 | |
paul@272 | 125 | long MscRegionOpener::rename_object(const char *source, const char *target) |
paul@272 | 126 | { |
paul@272 | 127 | (void) source; (void) target; |
paul@272 | 128 | return -L4_EPERM; |
paul@272 | 129 | } |
paul@272 | 130 | |
paul@272 | 131 | /* Populate a memory region with statistics metadata for a filesystem object. |
paul@272 | 132 | NOTE: Currently unimplemented. */ |
paul@272 | 133 | |
paul@272 | 134 | long MscRegionOpener::stat_object(const char *path, void *base, offset_t size) |
paul@272 | 135 | { |
paul@272 | 136 | (void) path; (void) base; (void) size; |
paul@272 | 137 | return -L4_EPERM; |
paul@272 | 138 | } |
paul@272 | 139 | |
paul@272 | 140 | /* Unlink a filesystem object. */ |
paul@272 | 141 | |
paul@272 | 142 | long MscRegionOpener::unlink_object(fileid_t parent_fileid, fileid_t fileid) |
paul@272 | 143 | { |
paul@272 | 144 | (void) parent_fileid; (void) fileid; |
paul@272 | 145 | return -L4_EPERM; |
paul@272 | 146 | } |
paul@272 | 147 | |
paul@272 | 148 | // vim: tabstop=4 expandtab shiftwidth=4 |