# HG changeset patch # User Paul Boddie # Date 1648156307 -3600 # Node ID 69806f7995c8bd5407c92ed3401e15478f75aa37 # Parent f36ec8bda6080087b759c0c7f105ca1a28e33666 Added object removal support to fsaccess. diff -r f36ec8bda608 -r 69806f7995c8 conf/fsaccess.txt --- a/conf/fsaccess.txt Wed Mar 23 22:58:37 2022 +0100 +++ b/conf/fsaccess.txt Thu Mar 24 22:11:47 2022 +0100 @@ -11,3 +11,9 @@ copy-in rom/fsaccess.txt home/paulb/fsaccess/script.txt ls home/paulb/fsaccess stat home/paulb/fsaccess/script.txt +rm home/paulb/fsaccess/script.txt +ls home/paulb/fsaccess +rm home/paulb/fsaccess/fsaccess.txt +ls home/paulb/fsaccess +rmdir home/paulb/fsaccess +ls home/paulb diff -r f36ec8bda608 -r 69806f7995c8 fsaccess/Makefile --- a/fsaccess/Makefile Wed Mar 23 22:58:37 2022 +0100 +++ b/fsaccess/Makefile Thu Mar 24 22:11:47 2022 +0100 @@ -7,8 +7,8 @@ SRC_C = \ file.c fsaccess.c input.c session.c ops.c \ - op_copy_in.c op_list_objects.c op_make_dirs.c op_script.c \ - op_stat_objects.c + op_copy_in.c op_list_objects.c op_make_dirs.c op_remove.c \ + op_script.c op_stat_objects.c REQUIRES_LIBS = l4re_c-util libfsclient libmem libipc libsystypes libe2access libe2access_blockserver diff -r f36ec8bda608 -r 69806f7995c8 fsaccess/fsaccess.c --- a/fsaccess/fsaccess.c Wed Mar 23 22:58:37 2022 +0100 +++ b/fsaccess/fsaccess.c Thu Mar 24 22:11:47 2022 +0100 @@ -39,7 +39,6 @@ Transfer operations:\n\ \n\ copy-in Copy files into a directory within the image\n\ - copy-out Copy files from the image into a directory\n\ \n\ Image operations:\n\ \n\ @@ -58,15 +57,10 @@ struct operation operations[] = { {"copy-in", copy_in}, -#if 0 - {"copy-out", copy_out}, -#endif {"ls", list_objects}, {"mkdir", make_dirs}, -#if 0 {"rm", remove_non_dirs}, {"rmdir", remove_dirs}, -#endif {"script", run_script}, {"stat", stat_objects}, {NULL, NULL}, diff -r f36ec8bda608 -r 69806f7995c8 fsaccess/op_remove.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fsaccess/op_remove.c Thu Mar 24 22:11:47 2022 +0100 @@ -0,0 +1,102 @@ +/* + * Remove objects from a filesystem. + * + * Copyright (C) 2019, 2022 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#include +#include + +#include + +#include "ops.h" + + + +/* Remove objects from the filesystem image. */ + +static int _remove(int argc, char *argv[], int dir_only) +{ + int i; + const char *path; + long err; + struct stat st; + + /* Remove each directory with the given pathname. */ + + for (i = 0; i < argc; i++) + { + path = argv[i]; + + /* Detect missing objects. */ + + err = client_stat(path, &st); + + if (err) + { + fprintf(stderr, "Could not stat object: %s\n", path); + return 1; + } + + /* Insist on a directory if specified. */ + + if (dir_only) + { + if (!S_ISDIR(st.st_mode)) + { + fprintf(stderr, "Not a directory: %s\n", path); + return 1; + } + } + + /* Otherwise, insist on a non-directory. */ + + else if (S_ISDIR(st.st_mode)) + { + fprintf(stderr, "Cannot remove a directory: %s\n", path); + return 1; + } + + /* Remove the object. */ + + if (client_remove(path)) + { + fprintf(stderr, "Could not remove object: %s\n", path); + return 1; + } + } + + return 0; +} + +/* Remove directories from the filesystem image. */ + +int remove_dirs(int argc, char *argv[]) +{ + return _remove(argc, argv, 1); +} + +/* Remove non-directories from the filesystem image. */ + +int remove_non_dirs(int argc, char *argv[]) +{ + return _remove(argc, argv, 0); +} + +/* vim: tabstop=4 expandtab shiftwidth=4 +*/