Thomas Heijligen | d1e0457 | 2023-11-27 14:28:55 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
Thomas Heijligen | b00b316 | 2023-11-29 10:02:31 +0000 | [diff] [blame^] | 2 | #include <stdbool.h> |
| 3 | #include <getopt.h> |
Thomas Heijligen | d1e0457 | 2023-11-27 14:28:55 +0000 | [diff] [blame] | 4 | |
Thomas Heijligen | 62268ee | 2023-11-27 15:10:41 +0000 | [diff] [blame] | 5 | #include "blockdev.h" |
| 6 | |
Thomas Heijligen | b00b316 | 2023-11-29 10:02:31 +0000 | [diff] [blame^] | 7 | struct fsys_entry { |
| 8 | char *name; |
| 9 | int (*mount_func) (void); |
| 10 | int (*read_func) (char *buf, int len); // read from open file |
| 11 | int (*dir_func) (char *dirname); // open file |
| 12 | int (*close_func) (void); |
| 13 | } fsys_table[] = { |
| 14 | { "dummy", NULL, NULL, NULL, NULL}, |
| 15 | }; |
| 16 | |
| 17 | static const size_t fsys_table_length = sizeof(fsys_table) / sizeof(struct fsys_entry); |
| 18 | |
| 19 | struct program_options { |
| 20 | char *devname; |
| 21 | }; |
| 22 | |
| 23 | static int get_options(int argc, char* argv[], struct program_options* opt); |
| 24 | |
Thomas Heijligen | d1e0457 | 2023-11-27 14:28:55 +0000 | [diff] [blame] | 25 | |
| 26 | int main(int argc, char* argv[]) |
| 27 | { |
Thomas Heijligen | b00b316 | 2023-11-29 10:02:31 +0000 | [diff] [blame^] | 28 | struct program_options opt; |
| 29 | |
| 30 | if (get_options(argc, argv, &opt)) { |
Thomas Heijligen | d1e0457 | 2023-11-27 14:28:55 +0000 | [diff] [blame] | 31 | return -1; |
| 32 | } |
| 33 | |
Thomas Heijligen | b00b316 | 2023-11-29 10:02:31 +0000 | [diff] [blame^] | 34 | |
| 35 | if (devopen(opt.devname, NULL) != 1) { |
Thomas Heijligen | d1e0457 | 2023-11-27 14:28:55 +0000 | [diff] [blame] | 36 | return -1; |
| 37 | } |
| 38 | |
| 39 | // TODO |
| 40 | |
Thomas Heijligen | d1e0457 | 2023-11-27 14:28:55 +0000 | [diff] [blame] | 41 | devclose(); |
| 42 | return 0; |
| 43 | } |
| 44 | |
Thomas Heijligen | b00b316 | 2023-11-29 10:02:31 +0000 | [diff] [blame^] | 45 | |
| 46 | |
| 47 | static void fprint_help(FILE* to, char * pname) |
| 48 | { |
| 49 | fprintf(to, "Usage: %s\n" |
| 50 | " -d | --dev <path> \t File to use as block device\n" |
| 51 | , pname); |
| 52 | } |
| 53 | |
| 54 | static int get_options(int argc, char* argv[], struct program_options *opt){ |
| 55 | const struct option long_options[] = { |
| 56 | {"dev", required_argument, NULL, 'd'}, |
| 57 | {NULL, 0, NULL, 0}, |
| 58 | }; |
| 59 | |
| 60 | int c, option_index = 0; |
| 61 | while ((c = getopt_long(argc, argv, "d:", long_options, &option_index)) != -1) { |
| 62 | switch (c) { |
| 63 | case 'd': |
| 64 | opt->devname = optarg; |
| 65 | break; |
| 66 | default: |
| 67 | fprint_help(stderr, argv[0]); |
| 68 | return -1; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | if (argc == 1) { |
| 73 | fprintf(stderr, "%s needs arguments.\n", argv[0]); |
| 74 | fprint_help(stderr, argv[0]); |
| 75 | return -1; |
| 76 | } |
| 77 | |
| 78 | if (opt->devname == NULL) { |
| 79 | fprintf(stderr, "Argument \"--dev/-d\" missing.\n"); |
| 80 | return -1; |
| 81 | } |
| 82 | return 0; |
| 83 | } |