forked from raidzero/RZrecovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wipe_menu.c
211 lines (183 loc) · 4.64 KB
/
wipe_menu.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#include <stdlib.h>
#include <stdio.h>
#include "mtdutils/mtdutils.h"
#include "mmcutils/mmcutils.h"
#include "recovery.h"
#include "roots.h"
#include "recovery_ui.h"
int wipe_partition(char* partition, int autoaccept)
{
char wipe_header[255] = "";
char path_string[255] = "";
char operation[255] = "";
if (strcmp(partition,"battery statistics") != 0 && strcmp(partition,"dalvik-cache") !=0 &&
strcmp(partition,"android_secure") != 0)
{
sprintf(path_string,"/%s", partition);
}
else
{
sprintf(path_string,"%s", partition);
}
sprintf(wipe_header,"Wipe %s?", path_string);
sprintf(operation,"Yes - wipe %s", path_string);
if (strcmp (partition, "all") == 0)
{
if (confirm_selection("Wipe EVERYTHING?", "Yes - wipe the entire device", autoaccept)) {
ui_print("Preparing to wipe everything...\n");
ui_show_indeterminate_progress();
write_files();
ui_print ("\n-- Wiping system... ");
ensure_path_unmounted ("/system");
erase_volume ("/system");
if (volume_present("/datadata"))
{
ui_print("\n-- Wiping datadata");
ensure_path_unmounted("/datadata");
erase_volume("/datadata");
}
ui_print ("\n-- Wiping data... ");
ensure_path_unmounted ("/data");
erase_volume ("/data");
ui_print ("\n-- Wiping cache... ");
ensure_path_unmounted ("/cache");
erase_volume ("/cache");
ensure_path_mounted ("/cache");
ui_print ("\n-- Wiping .android_secure... ");
ensure_path_mounted ("/sdcard");
__system ("rm -rf /sdcard/.android_secure/*");
ui_print ("\n-- Wiping boot...");
erase_volume("/boot");
ui_print ("\nDone.\n");
ui_print ("Device completely wiped.\n\n");
ui_print ("All that remains is RZR.\n");
read_files ();
ui_reset_progress();
return 0;
} else {
return -1;
}
}
if (confirm_selection(wipe_header, operation, autoaccept))
{
ui_print("-- Wiping %s... ",partition);
ui_show_indeterminate_progress();
if (strcmp(path_string, "/cache") == 0) write_files();
if (strcmp (partition, "battery statistics") == 0)
{
ensure_path_mounted("/data");
__system ("rm /data/system/batterystats.bin");
ensure_path_unmounted("/data");
ui_print("Done.\n");
ui_reset_progress();
return 0;
}
if (strcmp (partition, "android_secure") == 0)
{
ensure_path_mounted ("/sdcard");
__system ("rm -rf /sdcard/.android_secure/*");
ui_print("Done.\n");
ui_reset_progress();
return 0;
}
if (strcmp (partition, "dalvik-cache") == 0)
{
ensure_path_mounted ("/data");
ensure_path_mounted("/cache");
__system ("rm -rf /cache/dalvik-cache/*");
__system ("rm -rf /data/dalvik-cache/*");
ui_print("Done.\n");
read_files();
ui_reset_progress();
return 0;
}
if (strcmp(path_string,"/data") == 0)
{
if (volume_present("/datadata"))
{
ui_print("\n-- Wiping datadata");
ensure_path_unmounted("/datadata");
erase_volume("/datadata");
ui_reset_progress();
}
}
ensure_path_unmounted (path_string);
if (erase_volume (path_string) == 0)
{
ui_print ("Done.\n", path_string);
read_files();
ui_reset_progress();
return 0;
} else {
ui_print("Failed.\n", path_string);
read_files();
ui_reset_progress();
return -1;
}
} else {
ui_reset_progress();
return -1;
}
}
void
show_wipe_menu ()
{
static char *headers[] = { "Choose a partition to wipe",
"USE CAUTION:",
"These operations *CANNOT BE UNDONE*",
"",
NULL
};
char *items[] = { "Wipe all",
"Wipe system",
"Wipe data",
"Wipe .android_secure",
"Wipe boot",
"Wipe cache",
"Wipe battery stats",
"Wipe dalvik-cache",
NULL
};
#define WIPE_ALL 0
#define WIPE_SYSTEM 1
#define WIPE_DATA 2
#define WIPE_AS 3
#define WIPE_BOOT 4
#define WIPE_CACHE 5
#define WIPE_BATT 6
#define WIPE_DK 7
int chosen_item = -1;
while (chosen_item != ITEM_BACK)
{
chosen_item =
get_menu_selection (headers, items, 0,
chosen_item < 0 ? 0 : chosen_item);
switch (chosen_item)
{
case WIPE_ALL:
wipe_partition("all", 0);
break;
case WIPE_SYSTEM:
wipe_partition("system", 0);
break;
case WIPE_DATA:
wipe_partition("data", 0);
break;
case WIPE_AS:
wipe_partition("android_secure", 0);
break;
case WIPE_BOOT:
wipe_partition("boot", 0);
break;
case WIPE_CACHE:
wipe_partition("cache", 0);
break;
case WIPE_BATT:
wipe_partition("battery statistics", 0);
break;
case WIPE_DK:
wipe_partition("dalvik-cache", 0);
break;
}
}
}