| #include <stdio.h> |
| #include <stdbool.h> |
| #include <getopt.h> |
| |
| #include "blockdev.h" |
| #include "vfs.h" |
| |
| extern void adainit (void); |
| extern void adafinal (void); |
| |
| struct program_options { |
| char *devname; |
| }; |
| |
| static int get_options(int argc, char* argv[], struct program_options* opt); |
| |
| |
| int main(int argc, char* argv[]) |
| { |
| struct program_options opt; |
| int ret = -1; |
| |
| adainit(); |
| |
| if (get_options(argc, argv, &opt)) { |
| goto final; |
| } |
| |
| |
| if (devopen(opt.devname, NULL) != 1) { |
| goto final; |
| } |
| |
| fs_tests(); |
| |
| devclose(); |
| ret = 0; |
| |
| final: |
| adafinal(); |
| return ret; |
| } |
| |
| |
| |
| static void fprint_help(FILE* to, char * pname) |
| { |
| fprintf(to, "Usage: %s\n" |
| " -d | --dev <path> \t File to use as block device\n" |
| , pname); |
| } |
| |
| static int get_options(int argc, char* argv[], struct program_options *opt){ |
| const struct option long_options[] = { |
| {"dev", required_argument, NULL, 'd'}, |
| {NULL, 0, NULL, 0}, |
| }; |
| |
| int c, option_index = 0; |
| while ((c = getopt_long(argc, argv, "d:", long_options, &option_index)) != -1) { |
| switch (c) { |
| case 'd': |
| opt->devname = optarg; |
| break; |
| default: |
| fprint_help(stderr, argv[0]); |
| return -1; |
| } |
| } |
| |
| if (argc == 1) { |
| fprintf(stderr, "%s needs arguments.\n", argv[0]); |
| fprint_help(stderr, argv[0]); |
| return -1; |
| } |
| |
| if (opt->devname == NULL) { |
| fprintf(stderr, "Argument \"--dev/-d\" missing.\n"); |
| return -1; |
| } |
| return 0; |
| } |