1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/conf/dstest_fsaccess.cfg Mon Mar 07 23:54:48 2022 +0100
1.3 @@ -0,0 +1,51 @@
1.4 +-- vim:set ft=lua:
1.5 +
1.6 +local L4 = require("L4");
1.7 +
1.8 +local l = L4.default_loader;
1.9 +
1.10 +local pipe_server = l:new_channel();
1.11 +
1.12 +l:startv({
1.13 + caps = {
1.14 + server = pipe_server:svr(),
1.15 + },
1.16 + log = { "pipes", "r" },
1.17 + },
1.18 + "rom/dstest_pipe_server", "10");
1.19 +
1.20 +local block_server = l:new_channel();
1.21 +
1.22 +l:startv({
1.23 + caps = {
1.24 + server = block_server:svr(),
1.25 + },
1.26 + log = { "blocksvr", "r" },
1.27 + },
1.28 + "rom/dstest_block_server", "10");
1.29 +
1.30 +local ext2svr = l:new_channel();
1.31 +
1.32 +l:startv({
1.33 + caps = {
1.34 + blocksvr = block_server,
1.35 + pipes = pipe_server,
1.36 + ext2svr = ext2svr:svr(),
1.37 + },
1.38 + log = { "ext2svr", "y" },
1.39 + },
1.40 + "rom/dstest_ext2_server", "blocksvr", "rom/e2test.fs", "10", "ext2svr");
1.41 +
1.42 +-- Obtain user filesystems with umask 0022 (18).
1.43 +
1.44 +local open_for_user = 6;
1.45 +local ext2svr_paulb = L4.cast(L4.Proto.Factory, ext2svr):create(open_for_user, 1000, 1000, 18);
1.46 +
1.47 +l:startv({
1.48 + caps = {
1.49 + server = ext2svr_paulb,
1.50 + },
1.51 + log = { "client", "g" },
1.52 + },
1.53 + -- program, directory to read
1.54 + "rom/dstest_fsaccess", "ls", "home/paulb/many");
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/conf/dstest_fsaccess.list Mon Mar 07 23:54:48 2022 +0100
2.3 @@ -0,0 +1,28 @@
2.4 +entry dstest_fsaccess
2.5 +roottask moe rom/dstest_fsaccess.cfg
2.6 +module dstest_fsaccess.cfg
2.7 +module e2test.fs
2.8 +module l4re
2.9 +module ned
2.10 +module dstest_fsaccess
2.11 +module dstest_ext2_server
2.12 +module dstest_block_server
2.13 +module dstest_pipe_server
2.14 +module lib4re-c.so
2.15 +module lib4re-c-util.so
2.16 +module lib4re.so
2.17 +module lib4re-util.so
2.18 +module libc_be_l4refile.so
2.19 +module libc_be_l4re.so
2.20 +module libc_be_socket_noop.so
2.21 +module libc_support_misc.so
2.22 +module libdl.so
2.23 +module libipc.so
2.24 +module libl4sys-direct.so
2.25 +module libl4sys.so
2.26 +module libl4util.so
2.27 +module libld-l4.so
2.28 +module libpthread.so
2.29 +module libstdc++.so
2.30 +module libsupc++.so
2.31 +module libuc_c.so
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/fsaccess/Control Mon Mar 07 23:54:48 2022 +0100
3.3 @@ -0,0 +1,3 @@
3.4 +requires: libc libipc libfsclient libmem libext2fs libext2fs_blockserver libe2access_blockserver
3.5 +provides: fsaccess
3.6 +maintainer: paul@boddie.org.uk
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/fsaccess/Makefile Mon Mar 07 23:54:48 2022 +0100
4.3 @@ -0,0 +1,12 @@
4.4 +PKGDIR ?= .
4.5 +L4DIR ?= $(PKGDIR)/../../..
4.6 +
4.7 +TARGET = dstest_fsaccess
4.8 +
4.9 +MODE = static
4.10 +
4.11 +SRC_C = fsaccess.c ops.c op_list_objects.c
4.12 +
4.13 +REQUIRES_LIBS = l4re_c-util libfsclient libmem libipc libsystypes libe2access_blockserver
4.14 +
4.15 +include $(L4DIR)/mk/prog.mk
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/fsaccess/fsaccess.c Mon Mar 07 23:54:48 2022 +0100
5.3 @@ -0,0 +1,104 @@
5.4 +/*
5.5 + * Access a filesystem.
5.6 + *
5.7 + * Copyright (C) 2019, 2022 Paul Boddie <paul@boddie.org.uk>
5.8 + *
5.9 + * This program is free software; you can redistribute it and/or
5.10 + * modify it under the terms of the GNU General Public License as
5.11 + * published by the Free Software Foundation; either version 2 of
5.12 + * the License, or (at your option) any later version.
5.13 + *
5.14 + * This program is distributed in the hope that it will be useful,
5.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5.17 + * GNU General Public License for more details.
5.18 + *
5.19 + * You should have received a copy of the GNU General Public License
5.20 + * along with this program; if not, write to the Free Software
5.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
5.22 + * Boston, MA 02110-1301, USA
5.23 + */
5.24 +
5.25 +#include <stdio.h>
5.26 +
5.27 +#include "ops.h"
5.28 +
5.29 +
5.30 +
5.31 +/* Help message. */
5.32 +
5.33 +char help_text[] = "\
5.34 +Usage: %s [ <options> ] <operation> <filename>...\n\
5.35 +\n\
5.36 +File ownership options:\n\
5.37 +\n\
5.38 + -g GID Set group identifier for new files\n\
5.39 + -u UID Set user identifier for new files\n\
5.40 +\n\
5.41 +File permission options:\n\
5.42 +\n\
5.43 + -m MASK Set mode/permissions mask for new directories\n\
5.44 +\n\
5.45 +Transfer operations:\n\
5.46 +\n\
5.47 + copy-in Copy files into a directory within the image\n\
5.48 + copy-out Copy files from the image into a directory\n\
5.49 +\n\
5.50 +Image operations:\n\
5.51 +\n\
5.52 + ls List files and directories within the image\n\
5.53 + mkdir Make directories within the image\n\
5.54 + rm Remove non-directory objects from the image\n\
5.55 + rmdir Remove directories from the image\n\
5.56 + stat Show statistics for files and directories\n\
5.57 +\n\
5.58 +Script operations:\n\
5.59 +\n\
5.60 + script Read operations from a script file\n\
5.61 +";
5.62 +
5.63 +/* Operations exposed by the program. */
5.64 +
5.65 +struct operation operations[] = {
5.66 +#if 0
5.67 + {"copy-in", copy_in},
5.68 + {"copy-out", copy_out},
5.69 +#endif
5.70 + {"ls", list_objects},
5.71 +#if 0
5.72 + {"mkdir", make_dirs},
5.73 + {"rm", remove_non_dirs},
5.74 + {"rmdir", remove_dirs},
5.75 + {"script", run_script},
5.76 + {"stat", stat_objects},
5.77 +#endif
5.78 + {NULL, NULL},
5.79 + };
5.80 +
5.81 +/* Main program. */
5.82 +
5.83 +int main(int argc, char *argv[])
5.84 +{
5.85 + /* Program argument details. */
5.86 +
5.87 + char **args;
5.88 + int num_args;
5.89 + enum op_results op_result;
5.90 +
5.91 + args = &argv[1];
5.92 + num_args = argc - 1;
5.93 +
5.94 + if (num_args < 2)
5.95 + {
5.96 + fprintf(stderr, help_text, argv[0]);
5.97 + return 1;
5.98 + }
5.99 +
5.100 + /* Perform the requested operation. */
5.101 +
5.102 + op_result = run_operation(args[0], num_args - 1, &args[1]);
5.103 + return handle_op_result(args[0], op_result);
5.104 +}
5.105 +
5.106 +/* vim: tabstop=4 expandtab shiftwidth=4
5.107 +*/
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/fsaccess/op_list_objects.c Mon Mar 07 23:54:48 2022 +0100
6.3 @@ -0,0 +1,133 @@
6.4 +/*
6.5 + * List filesystem objects using the client library.
6.6 + *
6.7 + * Copyright (C) 2019, 2022 Paul Boddie <paul@boddie.org.uk>
6.8 + *
6.9 + * This program is free software; you can redistribute it and/or
6.10 + * modify it under the terms of the GNU General Public License as
6.11 + * published by the Free Software Foundation; either version 2 of
6.12 + * the License, or (at your option) any later version.
6.13 + *
6.14 + * This program is distributed in the hope that it will be useful,
6.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6.17 + * GNU General Public License for more details.
6.18 + *
6.19 + * You should have received a copy of the GNU General Public License
6.20 + * along with this program; if not, write to the Free Software
6.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
6.22 + * Boston, MA 02110-1301, USA
6.23 + */
6.24 +
6.25 +#include <stdio.h>
6.26 +#include <stdlib.h>
6.27 +#include <string.h>
6.28 +
6.29 +#include <sys/stat.h>
6.30 +#include <sys/types.h>
6.31 +
6.32 +#include <e2access/format.h> /* get_permission_string */
6.33 +#include <e2access/path.h>
6.34 +#include <fsclient/client.h>
6.35 +
6.36 +#include "ops.h"
6.37 +
6.38 +
6.39 +
6.40 +/* Show object details. */
6.41 +
6.42 +static void _show_object(const char *basename, struct stat *st)
6.43 +{
6.44 + printf("%s%s %5d %5d %6ld %6ld %s\n",
6.45 + S_ISDIR(st->st_mode) ? "d" : "-",
6.46 + get_permission_string(st->st_mode),
6.47 + st->st_uid,
6.48 + st->st_gid,
6.49 + st->st_size,
6.50 + st->st_nlink,
6.51 + basename);
6.52 +}
6.53 +
6.54 +/* Show an object in a directory. */
6.55 +
6.56 +static int _show_dirent(const char *dirname, struct dirent *dirent)
6.57 +{
6.58 + struct stat st;
6.59 + char path[strlen(dirname) + 1 + strlen(dirent->d_name) + 1];
6.60 +
6.61 + sprintf(path, "%s/%s", dirname, dirent->d_name);
6.62 +
6.63 + if (client_stat(path, &st))
6.64 + return 1;
6.65 +
6.66 + _show_object(dirent->d_name, &st);
6.67 +
6.68 + return 0;
6.69 +}
6.70 +
6.71 +/* List a directory or file. */
6.72 +
6.73 +static int _list_object(const char *path)
6.74 +{
6.75 + struct stat st;
6.76 + file_t *reader;
6.77 + struct dirent *dirent;
6.78 +
6.79 + if (client_stat(path, &st))
6.80 + return 1;
6.81 +
6.82 + if (S_ISDIR(st.st_mode))
6.83 + {
6.84 + reader = client_opendir(path);
6.85 +
6.86 + if (reader == NULL)
6.87 + return 1;
6.88 +
6.89 + /* Show the directory entries. */
6.90 +
6.91 + while ((dirent = client_readdir(reader)) != NULL)
6.92 + {
6.93 + if (_show_dirent(path, dirent))
6.94 + {
6.95 + free(dirent);
6.96 + return 1;
6.97 + }
6.98 +
6.99 + free(dirent);
6.100 + }
6.101 + }
6.102 + else
6.103 + _show_object(path_basename(path), &st);
6.104 +
6.105 + return 0;
6.106 +}
6.107 +
6.108 +/* List objects in the filesystem image. */
6.109 +
6.110 +int list_objects(int argc, char *argv[])
6.111 +{
6.112 + int i;
6.113 + char *path;
6.114 +
6.115 + for (i = 0; i < argc; i++)
6.116 + {
6.117 + path = argv[i];
6.118 +
6.119 + /* Emit each object. */
6.120 +
6.121 + puts(path);
6.122 +
6.123 + /* List individual files or directories. */
6.124 +
6.125 + if (_list_object(path))
6.126 + {
6.127 + fprintf(stderr, "Failed to list object: %s\n", path);
6.128 + return 1;
6.129 + }
6.130 + }
6.131 +
6.132 + return 0;
6.133 +}
6.134 +
6.135 +/* vim: tabstop=4 expandtab shiftwidth=4
6.136 +*/
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/fsaccess/ops.c Mon Mar 07 23:54:48 2022 +0100
7.3 @@ -0,0 +1,78 @@
7.4 +/*
7.5 + * Operation invocation.
7.6 + *
7.7 + * Copyright (C) 2019, 2022 Paul Boddie <paul@boddie.org.uk>
7.8 + *
7.9 + * This program is free software; you can redistribute it and/or
7.10 + * modify it under the terms of the GNU General Public License as
7.11 + * published by the Free Software Foundation; either version 2 of
7.12 + * the License, or (at your option) any later version.
7.13 + *
7.14 + * This program is distributed in the hope that it will be useful,
7.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.17 + * GNU General Public License for more details.
7.18 + *
7.19 + * You should have received a copy of the GNU General Public License
7.20 + * along with this program; if not, write to the Free Software
7.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
7.22 + * Boston, MA 02110-1301, USA
7.23 + */
7.24 +
7.25 +#include <stdio.h>
7.26 +#include <string.h>
7.27 +
7.28 +#include "ops.h"
7.29 +
7.30 +
7.31 +
7.32 +/* Operations exposed by the program. */
7.33 +
7.34 +extern struct operation operations[];
7.35 +
7.36 +
7.37 +
7.38 +/* Produce a general result condition from the invocation of an operation. */
7.39 +
7.40 +int handle_op_result(const char *operation, enum op_results op_result)
7.41 +{
7.42 + if (op_result == OP_UNKNOWN)
7.43 + {
7.44 + fprintf(stderr, "Operation not recognised: %s\n", operation);
7.45 + return 1;
7.46 + }
7.47 + else if (op_result == OP_FAILED)
7.48 + {
7.49 + fprintf(stderr, "Operation failed: %s\n", operation);
7.50 + return 1;
7.51 + }
7.52 + else
7.53 + return 0;
7.54 +}
7.55 +
7.56 +/* Invocation of operations. */
7.57 +
7.58 +enum op_results run_operation(const char *operation, int argc, char *argv[])
7.59 +{
7.60 + struct operation *op;
7.61 + int exitcode;
7.62 +
7.63 + for (op = &operations[0]; op->name != NULL; op++)
7.64 + {
7.65 + if (!strcmp(operation, op->name))
7.66 + {
7.67 + exitcode = op->fn(argc, argv);
7.68 + if (exitcode)
7.69 + return OP_FAILED;
7.70 + break;
7.71 + }
7.72 + }
7.73 +
7.74 + if (op->name == NULL)
7.75 + return OP_UNKNOWN;
7.76 +
7.77 + return OP_SUCCESS;
7.78 +}
7.79 +
7.80 +/* vim: tabstop=4 expandtab shiftwidth=4
7.81 +*/
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/fsaccess/ops.h Mon Mar 07 23:54:48 2022 +0100
8.3 @@ -0,0 +1,56 @@
8.4 +/*
8.5 + * Operations and their invocation.
8.6 + *
8.7 + * Copyright (C) 2022 Paul Boddie <paul@boddie.org.uk>
8.8 + *
8.9 + * This program is free software; you can redistribute it and/or
8.10 + * modify it under the terms of the GNU General Public License as
8.11 + * published by the Free Software Foundation; either version 2 of
8.12 + * the License, or (at your option) any later version.
8.13 + *
8.14 + * This program is distributed in the hope that it will be useful,
8.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8.17 + * GNU General Public License for more details.
8.18 + *
8.19 + * You should have received a copy of the GNU General Public License
8.20 + * along with this program; if not, write to the Free Software
8.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
8.22 + * Boston, MA 02110-1301, USA
8.23 + */
8.24 +
8.25 +#pragma once
8.26 +
8.27 +/* Invocation support. */
8.28 +
8.29 +enum op_results
8.30 +{
8.31 + OP_SUCCESS = 0,
8.32 + OP_FAILED = 1,
8.33 + OP_UNKNOWN = 2,
8.34 +};
8.35 +
8.36 +int handle_op_result(const char *operation, enum op_results op_result);
8.37 +enum op_results run_operation(const char *operation, int argc, char *argv[]);
8.38 +
8.39 +/* Operations exposed by the program. */
8.40 +
8.41 +typedef int (*op_sig)(int, char *[]);
8.42 +
8.43 +struct operation
8.44 +{
8.45 + const char *name;
8.46 + op_sig fn;
8.47 +};
8.48 +
8.49 +int copy_in(int argc, char *argv[]);
8.50 +int copy_out(int argc, char *argv[]);
8.51 +int list_objects(int argc, char *argv[]);
8.52 +int make_dirs(int argc, char *argv[]);
8.53 +int remove_dirs(int argc, char *argv[]);
8.54 +int remove_non_dirs(int argc, char *argv[]);
8.55 +int run_script(int argc, char *argv[]);
8.56 +int stat_objects(int argc, char *argv[]);
8.57 +
8.58 +/* vim: tabstop=4 expandtab shiftwidth=4
8.59 +*/