blob: d1939ee2a6e80c38465de7406a259beebd452106 [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"
6
Thomas Heijligenb00b3162023-11-29 10:02:31 +00007struct 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
17static const size_t fsys_table_length = sizeof(fsys_table) / sizeof(struct fsys_entry);
18
19struct program_options {
20 char *devname;
21};
22
23static int get_options(int argc, char* argv[], struct program_options* opt);
24
Thomas Heijligend1e04572023-11-27 14:28:55 +000025
26int main(int argc, char* argv[])
27{
Thomas Heijligenb00b3162023-11-29 10:02:31 +000028 struct program_options opt;
29
30 if (get_options(argc, argv, &opt)) {
Thomas Heijligend1e04572023-11-27 14:28:55 +000031 return -1;
32 }
33
Thomas Heijligenb00b3162023-11-29 10:02:31 +000034
35 if (devopen(opt.devname, NULL) != 1) {
Thomas Heijligend1e04572023-11-27 14:28:55 +000036 return -1;
37 }
38
39 // TODO
40
Thomas Heijligend1e04572023-11-27 14:28:55 +000041 devclose();
42 return 0;
43}
44
Thomas Heijligenb00b3162023-11-29 10:02:31 +000045
46
47static 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
54static 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}