-
Notifications
You must be signed in to change notification settings - Fork 4
/
parti.c
131 lines (104 loc) · 2.48 KB
/
parti.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <stdio.h>
#include <unistd.h>
#include <inttypes.h>
#include <getopt.h>
#include "util.h"
#include "json.h"
#include "disk.h"
#include "eltorito.h"
#include "filesystem.h"
#include "ptable_apple.h"
#include "ptable_gpt.h"
#include "ptable_mbr.h"
#include "zipl.h"
#ifndef VERSION
#define VERSION "0.0"
#endif
void help(void);
struct option options[] = {
{ "help", 0, NULL, 'h' },
{ "verbose", 0, NULL, 'v' },
{ "raw", 0, NULL, 1001 },
{ "version", 0, NULL, 1002 },
{ "export-disk", 1, NULL, 1003 },
{ "import-disk", 1, NULL, 1004 },
{ "json", 0, NULL, 1005 },
{ }
};
int main(int argc, char **argv)
{
int i;
extern int optind;
extern int opterr;
json_init();
opterr = 0;
while((i = getopt_long(argc, argv, "hv", options, NULL)) != -1) {
switch(i) {
case 'v':
opt.verbose++;
break;
case 1001:
opt.show.raw = 1;
break;
case 1002:
printf(VERSION "\n");
return 0;
break;
case 1003:
opt.export_file = optarg;
break;
case 1004:
disk_import(optarg);
break;
case 1005:
opt.json = 1;
break;
default:
help();
return i == 'h' ? 0 : 1;
}
}
argc -= optind;
argv += optind;
while(*argv) disk_init(*argv++);
if(!disk_list_size) {
help();
return 1;
}
for(unsigned u = 0; u < disk_list_size; u++) {
dump_fs(disk_list + u, 0, 0);
dump_mbr_ptable(disk_list + u);
dump_gpt_ptables(disk_list + u);
dump_apple_ptables(disk_list + u);
dump_eltorito(disk_list + u);
dump_zipl(disk_list + u);
}
if(opt.export_file) {
unlink(opt.export_file);
for(unsigned u = 0; u < disk_list_size; u++) {
disk_export(disk_list + u, opt.export_file);
}
}
json_print();
json_done();
return 0;
}
void help()
{
fprintf(stderr,
"Partition Info " VERSION "\n"
"Usage: parti [OPTIONS] DISK_DEVICES\n"
"\n"
"Print information about disk devices.\n"
"\n"
"Options:\n"
"\n"
" --json Use JSON format for output.\n"
" --export-disk FILE Export all relevant disk data to FILE. FILE can then be used\n"
" with --import-disk to reproduce the results.\n"
" --import-disk FILE Import relevant disk data from FILE.\n"
" --verbose Report more details.\n"
" --version Show version.\n"
" --help Print this help text.\n"
);
}