1 /* 2 * Access a filesystem. 3 * 4 * Copyright (C) 2019, 2022 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 <stdio.h> 23 24 #include "ops.h" 25 26 27 28 /* Help message. */ 29 30 char help_text[] = "\ 31 Usage: %s [ <options> ] <operation> <filename>...\n\ 32 \n\ 33 File ownership options:\n\ 34 \n\ 35 -g GID Set group identifier for new files\n\ 36 -u UID Set user identifier for new files\n\ 37 \n\ 38 File permission options:\n\ 39 \n\ 40 -m MASK Set mode/permissions mask for new directories\n\ 41 \n\ 42 Transfer operations:\n\ 43 \n\ 44 copy-in Copy files into a directory within the image\n\ 45 copy-out Copy files from the image into a directory\n\ 46 \n\ 47 Image operations:\n\ 48 \n\ 49 ls List files and directories within the image\n\ 50 mkdir Make directories within the image\n\ 51 rm Remove non-directory objects from the image\n\ 52 rmdir Remove directories from the image\n\ 53 stat Show statistics for files and directories\n\ 54 \n\ 55 Script operations:\n\ 56 \n\ 57 script Read operations from a script file\n\ 58 "; 59 60 /* Operations exposed by the program. */ 61 62 struct operation operations[] = { 63 #if 0 64 {"copy-in", copy_in}, 65 {"copy-out", copy_out}, 66 #endif 67 {"ls", list_objects}, 68 #if 0 69 {"mkdir", make_dirs}, 70 {"rm", remove_non_dirs}, 71 {"rmdir", remove_dirs}, 72 {"script", run_script}, 73 {"stat", stat_objects}, 74 #endif 75 {NULL, NULL}, 76 }; 77 78 /* Main program. */ 79 80 int main(int argc, char *argv[]) 81 { 82 /* Program argument details. */ 83 84 char **args; 85 int num_args; 86 enum op_results op_result; 87 88 args = &argv[1]; 89 num_args = argc - 1; 90 91 if (num_args < 2) 92 { 93 fprintf(stderr, help_text, argv[0]); 94 return 1; 95 } 96 97 /* Perform the requested operation. */ 98 99 op_result = run_operation(args[0], num_args - 1, &args[1]); 100 return handle_op_result(args[0], op_result); 101 } 102 103 /* vim: tabstop=4 expandtab shiftwidth=4 104 */