1 /* 2 * An opener for regions of a memory card. 3 * 4 * Copyright (C) 2021, 2022, 2024 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 <dirent.h> 23 #include <stdio.h> 24 #include <string.h> 25 #include <sys/stat.h> 26 #include <unistd.h> 27 28 #include <resource/resource_server.h> 29 30 #include "msc_region_accessor.h" 31 #include "msc_region_opener.h" 32 33 34 35 MscRegionOpener::~MscRegionOpener() 36 { 37 } 38 39 bool MscRegionOpener::accessing_directory(flags_t flags, fileid_t fileid) 40 { 41 (void) flags; (void) fileid; 42 return false; 43 } 44 45 bool MscRegionOpener::accessing_file(flags_t flags, fileid_t fileid) 46 { 47 (void) flags; (void) fileid; 48 return true; 49 } 50 51 /* Test if a directory is empty. */ 52 53 bool MscRegionOpener::directory_is_empty(fileid_t fileid) 54 { 55 (void) fileid; 56 return false; 57 } 58 59 /* Return a file identifier for the given 'path'. */ 60 61 long MscRegionOpener::get_fileid(const char *path, flags_t flags, fileid_t *fileid) 62 { 63 (void) flags; 64 65 // Convert the path to an integer for use as the file identifier. 66 67 if (!(strlen(path) && isdigit(path[0]))) 68 return -L4_ENOENT; 69 70 *fileid = atoi(path); 71 return L4_EOK; 72 } 73 74 /* Return a new accessor for 'fileid'. */ 75 76 long MscRegionOpener::make_accessor(flags_t flags, fileid_t fileid, 77 Accessor **accessor) 78 { 79 // NOTE: Not testing for create or write flags. 80 81 (void) flags; 82 83 // Find the given partition and initialise the accessor with the appropriate 84 // details. 85 86 uint32_t start_block, num_blocks; 87 88 if (_ops->get_partition(fileid, &start_block, &num_blocks)) 89 return -L4_ENOENT; 90 91 *accessor = new MscRegionAccessor(_ops, start_block, num_blocks, fileid); 92 return L4_EOK; 93 } 94 95 /* Return a directory accessor for 'fileid'. 96 NOTE: Currently unimplemented. */ 97 98 long MscRegionOpener::make_directory_accessor(flags_t flags, fileid_t fileid, 99 DirectoryAccessor **accessor) 100 { 101 (void) flags; (void) fileid; (void) accessor; 102 return -L4_EPERM; 103 } 104 105 106 107 /* Make a new directory. */ 108 109 long MscRegionOpener::make_directory_object(const char *path, sys_mode_t mode) 110 { 111 (void) path; (void) mode; 112 return -L4_EPERM; 113 } 114 115 /* Remove a filesystem object. */ 116 117 long MscRegionOpener::remove_object(fileid_t fileid) 118 { 119 (void) fileid; 120 return -L4_EPERM; 121 } 122 123 /* Rename a filesystem object, placing source inside the parent of target. */ 124 125 long MscRegionOpener::rename_object(const char *source, const char *target) 126 { 127 (void) source; (void) target; 128 return -L4_EPERM; 129 } 130 131 /* Populate a memory region with statistics metadata for a filesystem object. 132 NOTE: Currently unimplemented. */ 133 134 long MscRegionOpener::stat_object(const char *path, void *base, offset_t size) 135 { 136 (void) path; (void) base; (void) size; 137 return -L4_EPERM; 138 } 139 140 /* Unlink a filesystem object. */ 141 142 long MscRegionOpener::unlink_object(fileid_t parent_fileid, fileid_t fileid) 143 { 144 (void) parent_fileid; (void) fileid; 145 return -L4_EPERM; 146 } 147 148 // vim: tabstop=4 expandtab shiftwidth=4