-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
66 lines (56 loc) · 1.73 KB
/
main.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
#include <stdio.h>
#include <string.h>
#include "mmc_write_prot.h"
static int usage(const char *prog) {
fprintf(stderr, "Usage:\n");
fprintf(stderr, "%s --dump\n", prog);
fprintf(stderr, "%s --unprotect-all\n", prog);
fprintf(stderr, "%s --unprotect <partition> ...\n", prog);
fprintf(stderr, "%s --protect <partition> ...\n", prog);
fprintf(stderr, "%s --protect-power-on <partition> ...\n", prog);
fprintf(stderr, "%s --protect-permanent <partition> ...\n", prog);
return 1;
}
int main(int argc, char *argv[]) {
int rc, i;
int on = 0;
mmc_write_prot_type on_type = invalid_wp;
if (argc < 2) {
return usage(argv[0]);
}
if (!strcmp(argv[1], "--dump")) {
if (argc != 2)
return usage(argv[0]);
rc = mmc_write_prot_dump();
return rc;
}
if (!strcmp(argv[1], "--unprotect-all")) {
if (argc != 2)
return usage(argv[0]);
rc = mmc_write_prot_off();
return rc;
}
if (!strcmp(argv[1], "--protect")) {
on = 1;
on_type = temp_wp;
} else if (!strcmp(argv[1], "--protect-power-on")) {
on = 1;
on_type = power_on_wp;
} else if (!strcmp(argv[1], "--protect-permanent")) {
on = 1;
on_type = perm_wp;
} else if (strcmp(argv[1], "--unprotect"))
return usage(argv[0]);
for (i = 2; i < argc; i++) {
fprintf(stdout, "WP%s: %s ... ", on ? "ON" : "OFF", argv[i]);
fflush(stdout);
if (on)
rc = mmc_write_prot_on_part(argv[i], on_type);
else
rc = mmc_write_prot_off_part(argv[i]);
fprintf(stdout, "%s", rc ? "NG" : "OK");
fprintf(stdout, "\n");
fflush(stdout);
}
return 0;
}