1 /* 2 * Access a filesystem. 3 * 4 * Copyright (C) 2019, 2022, 2024 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 #include <unistd.h> 24 25 #include "ops.h" 26 #include "session.h" 27 28 29 30 /* Help message. */ 31 32 char help_text[] = "\ 33 Usage: %s [ <options> ] <operation> <filename>...\n\ 34 \n\ 35 File permission options:\n\ 36 \n\ 37 -m MASK Set mode/permissions mask for new directories\n\ 38 \n\ 39 Transfer operations:\n\ 40 \n\ 41 copy-in Copy files into a directory within the image\n\ 42 \n\ 43 Image operations:\n\ 44 \n\ 45 ls List files and directories within the image\n\ 46 mkdir Make directories within the image\n\ 47 rm Remove non-directory objects from the image\n\ 48 rmdir Remove directories from the image\n\ 49 stat Show statistics for files and directories\n\ 50 \n\ 51 Script operations:\n\ 52 \n\ 53 script Read operations from a script file (or stdin)\n\ 54 Execution operations:\n\ 55 \n\ 56 file Send a file to a program\n\ 57 jobs Show initiated programs\n\ 58 pipe Connect a running program to a new program\n\ 59 run Run a program from the filesystem and wait for it to finish\n\ 60 spawn Run a program in the background\n\ 61 wait Wait for a spawned program to finish\n\ 62 "; 63 64 /* Operations exposed by the program. */ 65 66 struct operation operations[] = { 67 {"copy-in", copy_in}, 68 {"file", file_to_program}, 69 {"jobs", show_programs}, 70 {"ls", list_objects}, 71 {"mkdir", make_dirs}, 72 {"pipe", pipe_to_program}, 73 {"rm", remove_non_dirs}, 74 {"rmdir", remove_dirs}, 75 {"run", run_program}, 76 {"spawn", spawn_program}, 77 {"script", run_script}, 78 {"stat", stat_objects}, 79 {"wait", wait_program}, 80 {NULL, NULL}, 81 }; 82 83 /* Main program. */ 84 85 int main(int argc, char *argv[]) 86 { 87 /* Program argument details. */ 88 89 char **args; 90 int num_args; 91 int exitcode; 92 enum op_results op_result; 93 94 /* Parse program options and initialise the argument details. */ 95 96 if (parse_options(argc, argv)) 97 return 1; 98 99 args = &argv[optind]; 100 num_args = argc - optind; 101 102 if (num_args < 2) 103 { 104 fprintf(stderr, help_text, argv[0]); 105 return 1; 106 } 107 108 /* Perform the requested operation. */ 109 110 op_result = run_operation(args[0], num_args - 1, &args[1], &exitcode); 111 return handle_op_result(args[0], op_result); 112 } 113 114 /* vim: tabstop=4 expandtab shiftwidth=4 115 */