blob: ee3095ca1186d0d9d30187179bbb8a5d4dfb1765 [file] [log] [blame]
Thomas Heijligend1e04572023-11-27 14:28:55 +00001#include <stdio.h>
Thomas Heijligenb00b3162023-11-29 10:02:31 +00002#include <stdbool.h>
3#include <getopt.h>
Thomas Heijligend1e04572023-11-27 14:28:55 +00004
Thomas Heijligen62268ee2023-11-27 15:10:41 +00005#include "blockdev.h"
Thomas Heijligen75d1ff32023-12-04 13:40:11 +00006#include "vfs.h"
Thomas Heijligenb00b3162023-11-29 10:02:31 +00007
8struct program_options {
9 char *devname;
10};
11
12static int get_options(int argc, char* argv[], struct program_options* opt);
13
Thomas Heijligend1e04572023-11-27 14:28:55 +000014
15int main(int argc, char* argv[])
16{
Thomas Heijligenb00b3162023-11-29 10:02:31 +000017 struct program_options opt;
18
19 if (get_options(argc, argv, &opt)) {
Thomas Heijligend1e04572023-11-27 14:28:55 +000020 return -1;
21 }
22
Thomas Heijligenb00b3162023-11-29 10:02:31 +000023
24 if (devopen(opt.devname, NULL) != 1) {
Thomas Heijligend1e04572023-11-27 14:28:55 +000025 return -1;
26 }
27
28 // TODO
29
Thomas Heijligend1e04572023-11-27 14:28:55 +000030 devclose();
31 return 0;
32}
33
Thomas Heijligenb00b3162023-11-29 10:02:31 +000034
35
36static void fprint_help(FILE* to, char * pname)
37{
38 fprintf(to, "Usage: %s\n"
39 " -d | --dev <path> \t File to use as block device\n"
40 , pname);
41}
42
43static int get_options(int argc, char* argv[], struct program_options *opt){
44 const struct option long_options[] = {
45 {"dev", required_argument, NULL, 'd'},
46 {NULL, 0, NULL, 0},
47 };
48
49 int c, option_index = 0;
50 while ((c = getopt_long(argc, argv, "d:", long_options, &option_index)) != -1) {
51 switch (c) {
52 case 'd':
53 opt->devname = optarg;
54 break;
55 default:
56 fprint_help(stderr, argv[0]);
57 return -1;
58 }
59 }
60
61 if (argc == 1) {
62 fprintf(stderr, "%s needs arguments.\n", argv[0]);
63 fprint_help(stderr, argv[0]);
64 return -1;
65 }
66
67 if (opt->devname == NULL) {
68 fprintf(stderr, "Argument \"--dev/-d\" missing.\n");
69 return -1;
70 }
71 return 0;
72}