1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pkg/landfall-examples/msc_block_server/msc_region_opener.cc Tue Feb 27 17:27:25 2024 +0100
1.3 @@ -0,0 +1,148 @@
1.4 +/*
1.5 + * An opener for regions of a memory card.
1.6 + *
1.7 + * Copyright (C) 2021, 2022, 2024 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License as
1.11 + * published by the Free Software Foundation; either version 2 of
1.12 + * the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 + * Boston, MA 02110-1301, USA
1.23 + */
1.24 +
1.25 +#include <dirent.h>
1.26 +#include <stdio.h>
1.27 +#include <string.h>
1.28 +#include <sys/stat.h>
1.29 +#include <unistd.h>
1.30 +
1.31 +#include <resource/resource_server.h>
1.32 +
1.33 +#include "msc_region_accessor.h"
1.34 +#include "msc_region_opener.h"
1.35 +
1.36 +
1.37 +
1.38 +MscRegionOpener::~MscRegionOpener()
1.39 +{
1.40 +}
1.41 +
1.42 +bool MscRegionOpener::accessing_directory(flags_t flags, fileid_t fileid)
1.43 +{
1.44 + (void) flags; (void) fileid;
1.45 + return false;
1.46 +}
1.47 +
1.48 +bool MscRegionOpener::accessing_file(flags_t flags, fileid_t fileid)
1.49 +{
1.50 + (void) flags; (void) fileid;
1.51 + return true;
1.52 +}
1.53 +
1.54 +/* Test if a directory is empty. */
1.55 +
1.56 +bool MscRegionOpener::directory_is_empty(fileid_t fileid)
1.57 +{
1.58 + (void) fileid;
1.59 + return false;
1.60 +}
1.61 +
1.62 +/* Return a file identifier for the given 'path'. */
1.63 +
1.64 +long MscRegionOpener::get_fileid(const char *path, flags_t flags, fileid_t *fileid)
1.65 +{
1.66 + (void) flags;
1.67 +
1.68 + // Convert the path to an integer for use as the file identifier.
1.69 +
1.70 + if (!(strlen(path) && isdigit(path[0])))
1.71 + return -L4_ENOENT;
1.72 +
1.73 + *fileid = atoi(path);
1.74 + return L4_EOK;
1.75 +}
1.76 +
1.77 +/* Return a new accessor for 'fileid'. */
1.78 +
1.79 +long MscRegionOpener::make_accessor(flags_t flags, fileid_t fileid,
1.80 + Accessor **accessor)
1.81 +{
1.82 + // NOTE: Not testing for create or write flags.
1.83 +
1.84 + (void) flags;
1.85 +
1.86 + // Find the given partition and initialise the accessor with the appropriate
1.87 + // details.
1.88 +
1.89 + uint32_t start_block, num_blocks;
1.90 +
1.91 + if (_ops->get_partition(fileid, &start_block, &num_blocks))
1.92 + return -L4_ENOENT;
1.93 +
1.94 + *accessor = new MscRegionAccessor(_ops, start_block, num_blocks, fileid);
1.95 + return L4_EOK;
1.96 +}
1.97 +
1.98 +/* Return a directory accessor for 'fileid'.
1.99 + NOTE: Currently unimplemented. */
1.100 +
1.101 +long MscRegionOpener::make_directory_accessor(flags_t flags, fileid_t fileid,
1.102 + DirectoryAccessor **accessor)
1.103 +{
1.104 + (void) flags; (void) fileid; (void) accessor;
1.105 + return -L4_EPERM;
1.106 +}
1.107 +
1.108 +
1.109 +
1.110 +/* Make a new directory. */
1.111 +
1.112 +long MscRegionOpener::make_directory_object(const char *path, sys_mode_t mode)
1.113 +{
1.114 + (void) path; (void) mode;
1.115 + return -L4_EPERM;
1.116 +}
1.117 +
1.118 +/* Remove a filesystem object. */
1.119 +
1.120 +long MscRegionOpener::remove_object(fileid_t fileid)
1.121 +{
1.122 + (void) fileid;
1.123 + return -L4_EPERM;
1.124 +}
1.125 +
1.126 +/* Rename a filesystem object, placing source inside the parent of target. */
1.127 +
1.128 +long MscRegionOpener::rename_object(const char *source, const char *target)
1.129 +{
1.130 + (void) source; (void) target;
1.131 + return -L4_EPERM;
1.132 +}
1.133 +
1.134 +/* Populate a memory region with statistics metadata for a filesystem object.
1.135 + NOTE: Currently unimplemented. */
1.136 +
1.137 +long MscRegionOpener::stat_object(const char *path, void *base, offset_t size)
1.138 +{
1.139 + (void) path; (void) base; (void) size;
1.140 + return -L4_EPERM;
1.141 +}
1.142 +
1.143 +/* Unlink a filesystem object. */
1.144 +
1.145 +long MscRegionOpener::unlink_object(fileid_t parent_fileid, fileid_t fileid)
1.146 +{
1.147 + (void) parent_fileid; (void) fileid;
1.148 + return -L4_EPERM;
1.149 +}
1.150 +
1.151 +// vim: tabstop=4 expandtab shiftwidth=4