Make the library when building dist and normal targets
[omfsprogs.git] / mkomfs.c
blob48ed80869249f45cf34ef407a22500793992090f
1 /* mkomfs.c - Create an OMFS filesystem
2 *
3 * GPL blah blah
4 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <unistd.h>
12 #include "config.h"
13 #include "disksize.h"
14 #include "create_fs.h"
16 #include <getopt.h>
18 int main(int argc, char *argv[])
20 FILE *fp;
21 char *dev;
22 u64 size;
24 fs_config_t config = {
25 .block_size = 8192,
26 .cluster_size = 8,
27 .clear_dev = 0
30 while (1)
32 int c;
34 c = getopt(argc, argv, "b:c:x");
35 if (c == -1)
36 break;
38 switch(c)
40 case 'b':
41 config.block_size = atoi(optarg);
42 break;
43 case 'c':
44 config.cluster_size = atoi(optarg);
45 break;
46 case 'x':
47 config.clear_dev = 1;
48 break;
52 if (argc - optind < 1)
54 fprintf(stderr, "Usage: %s [options] <device>\n", argv[0]);
55 exit(1);
58 dev = argv[optind];
60 if (!get_disk_size(dev, &size))
62 fprintf(stderr, "Could not get size of disk %s\n",
63 argv[optind]);
64 exit(1);
67 printf("Creating a new fs on dev %s (%lld blks)\n", dev, size/512);
69 printf("Warning: this could kill some important data; Are you sure? ");
70 char ch = getchar();
72 if (ch != 'y')
73 exit(0);
75 fp = fopen(dev, "r+");
76 if (!fp)
78 perror("mkomfs: ");
79 exit(2);
82 create_fs(fp, size/512, &config);
83 fclose(fp);
84 return 0;