paul@283 | 1 | /* |
paul@283 | 2 | * Access a filesystem. |
paul@283 | 3 | * |
paul@283 | 4 | * Copyright (C) 2019, 2022 Paul Boddie <paul@boddie.org.uk> |
paul@283 | 5 | * |
paul@283 | 6 | * This program is free software; you can redistribute it and/or |
paul@283 | 7 | * modify it under the terms of the GNU General Public License as |
paul@283 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@283 | 9 | * the License, or (at your option) any later version. |
paul@283 | 10 | * |
paul@283 | 11 | * This program is distributed in the hope that it will be useful, |
paul@283 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@283 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@283 | 14 | * GNU General Public License for more details. |
paul@283 | 15 | * |
paul@283 | 16 | * You should have received a copy of the GNU General Public License |
paul@283 | 17 | * along with this program; if not, write to the Free Software |
paul@283 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@283 | 19 | * Boston, MA 02110-1301, USA |
paul@283 | 20 | */ |
paul@283 | 21 | |
paul@283 | 22 | #include <stdio.h> |
paul@283 | 23 | |
paul@283 | 24 | #include "ops.h" |
paul@283 | 25 | |
paul@283 | 26 | |
paul@283 | 27 | |
paul@283 | 28 | /* Help message. */ |
paul@283 | 29 | |
paul@283 | 30 | char help_text[] = "\ |
paul@283 | 31 | Usage: %s [ <options> ] <operation> <filename>...\n\ |
paul@283 | 32 | \n\ |
paul@283 | 33 | File ownership options:\n\ |
paul@283 | 34 | \n\ |
paul@283 | 35 | -g GID Set group identifier for new files\n\ |
paul@283 | 36 | -u UID Set user identifier for new files\n\ |
paul@283 | 37 | \n\ |
paul@283 | 38 | File permission options:\n\ |
paul@283 | 39 | \n\ |
paul@283 | 40 | -m MASK Set mode/permissions mask for new directories\n\ |
paul@283 | 41 | \n\ |
paul@283 | 42 | Transfer operations:\n\ |
paul@283 | 43 | \n\ |
paul@283 | 44 | copy-in Copy files into a directory within the image\n\ |
paul@283 | 45 | copy-out Copy files from the image into a directory\n\ |
paul@283 | 46 | \n\ |
paul@283 | 47 | Image operations:\n\ |
paul@283 | 48 | \n\ |
paul@283 | 49 | ls List files and directories within the image\n\ |
paul@283 | 50 | mkdir Make directories within the image\n\ |
paul@283 | 51 | rm Remove non-directory objects from the image\n\ |
paul@283 | 52 | rmdir Remove directories from the image\n\ |
paul@283 | 53 | stat Show statistics for files and directories\n\ |
paul@283 | 54 | \n\ |
paul@283 | 55 | Script operations:\n\ |
paul@283 | 56 | \n\ |
paul@283 | 57 | script Read operations from a script file\n\ |
paul@283 | 58 | "; |
paul@283 | 59 | |
paul@283 | 60 | /* Operations exposed by the program. */ |
paul@283 | 61 | |
paul@283 | 62 | struct operation operations[] = { |
paul@283 | 63 | #if 0 |
paul@283 | 64 | {"copy-in", copy_in}, |
paul@283 | 65 | {"copy-out", copy_out}, |
paul@283 | 66 | #endif |
paul@283 | 67 | {"ls", list_objects}, |
paul@283 | 68 | #if 0 |
paul@283 | 69 | {"mkdir", make_dirs}, |
paul@283 | 70 | {"rm", remove_non_dirs}, |
paul@283 | 71 | {"rmdir", remove_dirs}, |
paul@283 | 72 | {"script", run_script}, |
paul@283 | 73 | {"stat", stat_objects}, |
paul@283 | 74 | #endif |
paul@283 | 75 | {NULL, NULL}, |
paul@283 | 76 | }; |
paul@283 | 77 | |
paul@283 | 78 | /* Main program. */ |
paul@283 | 79 | |
paul@283 | 80 | int main(int argc, char *argv[]) |
paul@283 | 81 | { |
paul@283 | 82 | /* Program argument details. */ |
paul@283 | 83 | |
paul@283 | 84 | char **args; |
paul@283 | 85 | int num_args; |
paul@283 | 86 | enum op_results op_result; |
paul@283 | 87 | |
paul@283 | 88 | args = &argv[1]; |
paul@283 | 89 | num_args = argc - 1; |
paul@283 | 90 | |
paul@283 | 91 | if (num_args < 2) |
paul@283 | 92 | { |
paul@283 | 93 | fprintf(stderr, help_text, argv[0]); |
paul@283 | 94 | return 1; |
paul@283 | 95 | } |
paul@283 | 96 | |
paul@283 | 97 | /* Perform the requested operation. */ |
paul@283 | 98 | |
paul@283 | 99 | op_result = run_operation(args[0], num_args - 1, &args[1]); |
paul@283 | 100 | return handle_op_result(args[0], op_result); |
paul@283 | 101 | } |
paul@283 | 102 | |
paul@283 | 103 | /* vim: tabstop=4 expandtab shiftwidth=4 |
paul@283 | 104 | */ |