Koushik K. Dutta | 6060e5c | 2010-02-11 22:27:06 -0800 | [diff] [blame] | 1 | #include <ctype.h> |
| 2 | #include <errno.h> |
| 3 | #include <fcntl.h> |
| 4 | #include <getopt.h> |
| 5 | #include <limits.h> |
| 6 | #include <linux/input.h> |
| 7 | #include <stdio.h> |
| 8 | #include <stdlib.h> |
| 9 | #include <string.h> |
| 10 | #include <sys/reboot.h> |
Austen Dicken | 7126ef4 | 2011-06-14 15:47:40 -0500 | [diff] [blame] | 11 | #include <reboot/reboot.h> |
Koushik K. Dutta | 6060e5c | 2010-02-11 22:27:06 -0800 | [diff] [blame] | 12 | #include <sys/types.h> |
| 13 | #include <time.h> |
| 14 | #include <unistd.h> |
| 15 | |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 16 | #include <sys/wait.h> |
| 17 | #include <sys/limits.h> |
| 18 | #include <dirent.h> |
Koushik K. Dutta | 49f5689 | 2010-02-25 14:51:05 -0800 | [diff] [blame] | 19 | #include <sys/stat.h> |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 20 | |
Koushik K. Dutta | 33370db | 2010-02-25 11:39:07 -0800 | [diff] [blame] | 21 | #include <signal.h> |
| 22 | #include <sys/wait.h> |
| 23 | |
Koushik K. Dutta | 6060e5c | 2010-02-11 22:27:06 -0800 | [diff] [blame] | 24 | #include "bootloader.h" |
| 25 | #include "common.h" |
| 26 | #include "cutils/properties.h" |
| 27 | #include "firmware.h" |
| 28 | #include "install.h" |
| 29 | #include "minui/minui.h" |
| 30 | #include "minzip/DirUtil.h" |
| 31 | #include "roots.h" |
| 32 | #include "recovery_ui.h" |
| 33 | |
Koushik K. Dutta | a85d7cc | 2010-03-12 17:00:58 -0800 | [diff] [blame] | 34 | #include "../../external/yaffs2/yaffs2/utils/mkyaffs2image.h" |
Koushik K. Dutta | 54305a8 | 2010-03-12 17:43:26 -0800 | [diff] [blame] | 35 | #include "../../external/yaffs2/yaffs2/utils/unyaffs.h" |
Koushik K. Dutta | a85d7cc | 2010-03-12 17:00:58 -0800 | [diff] [blame] | 36 | |
Koushik K. Dutta | ee57bbc | 2010-03-12 23:21:12 -0800 | [diff] [blame] | 37 | #include "extendedcommands.h" |
| 38 | #include "nandroid.h" |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 39 | #include "mounts.h" |
Koushik Dutta | 9765a03 | 2010-12-18 21:31:02 -0800 | [diff] [blame] | 40 | #include "flashutils/flashutils.h" |
Koushik Dutta | bec0995 | 2010-12-19 20:37:57 -0800 | [diff] [blame] | 41 | #include "edify/expr.h" |
Koushik Dutta | 7adeadc | 2011-05-26 11:47:56 -0700 | [diff] [blame] | 42 | #include <libgen.h> |
Koushik Dutta | 30a937a | 2011-09-05 21:14:06 -0700 | [diff] [blame] | 43 | #include "mtdutils/mtdutils.h" |
Koushik Dutta | 7adeadc | 2011-05-26 11:47:56 -0700 | [diff] [blame] | 44 | |
Koushik K. Dutta | ee57bbc | 2010-03-12 23:21:12 -0800 | [diff] [blame] | 45 | |
Koushik K. Dutta | 6060e5c | 2010-02-11 22:27:06 -0800 | [diff] [blame] | 46 | int signature_check_enabled = 1; |
| 47 | int script_assert_enabled = 1; |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 48 | static const char *SDCARD_UPDATE_FILE = "/sdcard/update.zip"; |
Koushik K. Dutta | 6060e5c | 2010-02-11 22:27:06 -0800 | [diff] [blame] | 49 | |
| 50 | void |
| 51 | toggle_signature_check() |
| 52 | { |
| 53 | signature_check_enabled = !signature_check_enabled; |
| 54 | ui_print("Signature Check: %s\n", signature_check_enabled ? "Enabled" : "Disabled"); |
| 55 | } |
| 56 | |
| 57 | void toggle_script_asserts() |
| 58 | { |
| 59 | script_assert_enabled = !script_assert_enabled; |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 60 | ui_print("Script Asserts: %s\n", script_assert_enabled ? "Enabled" : "Disabled"); |
| 61 | } |
| 62 | |
Koushik K. Dutta | ea46fe2 | 2010-03-08 02:58:04 -0800 | [diff] [blame] | 63 | int install_zip(const char* packagefilepath) |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 64 | { |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 65 | ui_print("\n-- Installing: %s\n", packagefilepath); |
Koushik Dutta | 9765a03 | 2010-12-18 21:31:02 -0800 | [diff] [blame] | 66 | if (device_flash_type() == MTD) { |
| 67 | set_sdcard_update_bootloader_message(); |
| 68 | } |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 69 | int status = install_package(packagefilepath); |
Koushik K. Dutta | f3534d0 | 2010-04-18 18:06:24 -0700 | [diff] [blame] | 70 | ui_reset_progress(); |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 71 | if (status != INSTALL_SUCCESS) { |
| 72 | ui_set_background(BACKGROUND_ICON_ERROR); |
| 73 | ui_print("Installation aborted.\n"); |
Koushik K. Dutta | ea46fe2 | 2010-03-08 02:58:04 -0800 | [diff] [blame] | 74 | return 1; |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 75 | } |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 76 | ui_set_background(BACKGROUND_ICON_NONE); |
Koushik K. Dutta | 99fb6fe | 2010-03-03 00:42:58 -0800 | [diff] [blame] | 77 | ui_print("\nInstall from sdcard complete.\n"); |
Koushik K. Dutta | ea46fe2 | 2010-03-08 02:58:04 -0800 | [diff] [blame] | 78 | return 0; |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Tanguy Pruvot | aaad77f | 2011-06-18 10:26:32 +0200 | [diff] [blame] | 81 | char* INSTALL_MENU_ITEMS[] = { "choose zip from sdcard", |
| 82 | "apply /sdcard/update.zip", |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 83 | "toggle signature verification", |
| 84 | "toggle script asserts", |
Koushik Dutta | 30a937a | 2011-09-05 21:14:06 -0700 | [diff] [blame] | 85 | "choose zip from internal sdcard", |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 86 | NULL }; |
Tanguy Pruvot | aaad77f | 2011-06-18 10:26:32 +0200 | [diff] [blame] | 87 | #define ITEM_CHOOSE_ZIP 0 |
| 88 | #define ITEM_APPLY_SDCARD 1 |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 89 | #define ITEM_SIG_CHECK 2 |
| 90 | #define ITEM_ASSERTS 3 |
Koushik Dutta | 30a937a | 2011-09-05 21:14:06 -0700 | [diff] [blame] | 91 | #define ITEM_CHOOSE_ZIP_INT 4 |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 92 | |
| 93 | void show_install_update_menu() |
| 94 | { |
| 95 | static char* headers[] = { "Apply update from .zip file on SD card", |
| 96 | "", |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 97 | NULL |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 98 | }; |
Koushik Dutta | 30a937a | 2011-09-05 21:14:06 -0700 | [diff] [blame] | 99 | |
| 100 | if (volume_for_path("/emmc") == NULL) |
| 101 | INSTALL_MENU_ITEMS[ITEM_CHOOSE_ZIP_INT] = NULL; |
| 102 | |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 103 | for (;;) |
| 104 | { |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 105 | int chosen_item = get_menu_selection(headers, INSTALL_MENU_ITEMS, 0, 0); |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 106 | switch (chosen_item) |
| 107 | { |
| 108 | case ITEM_ASSERTS: |
| 109 | toggle_script_asserts(); |
| 110 | break; |
| 111 | case ITEM_SIG_CHECK: |
| 112 | toggle_signature_check(); |
| 113 | break; |
| 114 | case ITEM_APPLY_SDCARD: |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 115 | { |
| 116 | if (confirm_selection("Confirm install?", "Yes - Install /sdcard/update.zip")) |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 117 | install_zip(SDCARD_UPDATE_FILE); |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 118 | break; |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 119 | } |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 120 | case ITEM_CHOOSE_ZIP: |
Koushik Dutta | 30a937a | 2011-09-05 21:14:06 -0700 | [diff] [blame] | 121 | show_choose_zip_menu("/sdcard/"); |
| 122 | break; |
| 123 | case ITEM_CHOOSE_ZIP_INT: |
| 124 | show_choose_zip_menu("/emmc/"); |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 125 | break; |
| 126 | default: |
| 127 | return; |
| 128 | } |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 129 | |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 133 | void free_string_array(char** array) |
| 134 | { |
| 135 | if (array == NULL) |
| 136 | return; |
| 137 | char* cursor = array[0]; |
| 138 | int i = 0; |
| 139 | while (cursor != NULL) |
| 140 | { |
| 141 | free(cursor); |
| 142 | cursor = array[++i]; |
| 143 | } |
| 144 | free(array); |
| 145 | } |
| 146 | |
Koushik K. Dutta | 49f5689 | 2010-02-25 14:51:05 -0800 | [diff] [blame] | 147 | char** gather_files(const char* directory, const char* fileExtensionOrDirectory, int* numFiles) |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 148 | { |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 149 | char path[PATH_MAX] = ""; |
| 150 | DIR *dir; |
| 151 | struct dirent *de; |
| 152 | int total = 0; |
| 153 | int i; |
Koushik K. Dutta | ee57bbc | 2010-03-12 23:21:12 -0800 | [diff] [blame] | 154 | char** files = NULL; |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 155 | int pass; |
| 156 | *numFiles = 0; |
| 157 | int dirLen = strlen(directory); |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 158 | |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 159 | dir = opendir(directory); |
| 160 | if (dir == NULL) { |
| 161 | ui_print("Couldn't open directory.\n"); |
| 162 | return NULL; |
| 163 | } |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 164 | |
Koushik K. Dutta | ee57bbc | 2010-03-12 23:21:12 -0800 | [diff] [blame] | 165 | int extension_length = 0; |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 166 | if (fileExtensionOrDirectory != NULL) |
| 167 | extension_length = strlen(fileExtensionOrDirectory); |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 168 | |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 169 | int isCounting = 1; |
| 170 | i = 0; |
| 171 | for (pass = 0; pass < 2; pass++) { |
| 172 | while ((de=readdir(dir)) != NULL) { |
| 173 | // skip hidden files |
| 174 | if (de->d_name[0] == '.') |
| 175 | continue; |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 176 | |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 177 | // NULL means that we are gathering directories, so skip this |
| 178 | if (fileExtensionOrDirectory != NULL) |
| 179 | { |
| 180 | // make sure that we can have the desired extension (prevent seg fault) |
| 181 | if (strlen(de->d_name) < extension_length) |
| 182 | continue; |
| 183 | // compare the extension |
| 184 | if (strcmp(de->d_name + strlen(de->d_name) - extension_length, fileExtensionOrDirectory) != 0) |
| 185 | continue; |
| 186 | } |
| 187 | else |
| 188 | { |
| 189 | struct stat info; |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 190 | char fullFileName[PATH_MAX]; |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 191 | strcpy(fullFileName, directory); |
| 192 | strcat(fullFileName, de->d_name); |
| 193 | stat(fullFileName, &info); |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 194 | // make sure it is a directory |
| 195 | if (!(S_ISDIR(info.st_mode))) |
| 196 | continue; |
| 197 | } |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 198 | |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 199 | if (pass == 0) |
| 200 | { |
| 201 | total++; |
| 202 | continue; |
| 203 | } |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 204 | |
Koushik K. Dutta | 49f5689 | 2010-02-25 14:51:05 -0800 | [diff] [blame] | 205 | files[i] = (char*) malloc(dirLen + strlen(de->d_name) + 2); |
| 206 | strcpy(files[i], directory); |
| 207 | strcat(files[i], de->d_name); |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 208 | if (fileExtensionOrDirectory == NULL) |
| 209 | strcat(files[i], "/"); |
| 210 | i++; |
| 211 | } |
| 212 | if (pass == 1) |
| 213 | break; |
| 214 | if (total == 0) |
| 215 | break; |
| 216 | rewinddir(dir); |
| 217 | *numFiles = total; |
| 218 | files = (char**) malloc((total+1)*sizeof(char*)); |
| 219 | files[total]=NULL; |
| 220 | } |
Koushik K. Dutta | 49f5689 | 2010-02-25 14:51:05 -0800 | [diff] [blame] | 221 | |
| 222 | if(closedir(dir) < 0) { |
| 223 | LOGE("Failed to close directory."); |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | if (total==0) { |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 227 | return NULL; |
| 228 | } |
| 229 | |
agrabren | 1f76a5d | 2010-12-29 12:15:18 -0600 | [diff] [blame] | 230 | // sort the result |
| 231 | if (files != NULL) { |
| 232 | for (i = 0; i < total; i++) { |
| 233 | int curMax = -1; |
| 234 | int j; |
| 235 | for (j = 0; j < total - i; j++) { |
| 236 | if (curMax == -1 || strcmp(files[curMax], files[j]) < 0) |
| 237 | curMax = j; |
| 238 | } |
| 239 | char* temp = files[curMax]; |
| 240 | files[curMax] = files[total - i - 1]; |
| 241 | files[total - i - 1] = temp; |
| 242 | } |
| 243 | } |
Koushik Dutta | 1e8aaba | 2010-07-01 00:23:25 -0700 | [diff] [blame] | 244 | |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 245 | return files; |
Koushik K. Dutta | 49f5689 | 2010-02-25 14:51:05 -0800 | [diff] [blame] | 246 | } |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 247 | |
Koushik K. Dutta | 49f5689 | 2010-02-25 14:51:05 -0800 | [diff] [blame] | 248 | // pass in NULL for fileExtensionOrDirectory and you will get a directory chooser |
| 249 | char* choose_file_menu(const char* directory, const char* fileExtensionOrDirectory, const char* headers[]) |
| 250 | { |
| 251 | char path[PATH_MAX] = ""; |
| 252 | DIR *dir; |
| 253 | struct dirent *de; |
| 254 | int numFiles = 0; |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 255 | int numDirs = 0; |
Koushik K. Dutta | 49f5689 | 2010-02-25 14:51:05 -0800 | [diff] [blame] | 256 | int i; |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 257 | char* return_value = NULL; |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 258 | int dir_len = strlen(directory); |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 259 | |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 260 | char** files = gather_files(directory, fileExtensionOrDirectory, &numFiles); |
Koushik K. Dutta | ee57bbc | 2010-03-12 23:21:12 -0800 | [diff] [blame] | 261 | char** dirs = NULL; |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 262 | if (fileExtensionOrDirectory != NULL) |
| 263 | dirs = gather_files(directory, NULL, &numDirs); |
| 264 | int total = numDirs + numFiles; |
| 265 | if (total == 0) |
| 266 | { |
| 267 | ui_print("No files found.\n"); |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 268 | } |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 269 | else |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 270 | { |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 271 | char** list = (char**) malloc((total + 1) * sizeof(char*)); |
| 272 | list[total] = NULL; |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 273 | |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 274 | |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 275 | for (i = 0 ; i < numDirs; i++) |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 276 | { |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 277 | list[i] = strdup(dirs[i] + dir_len); |
| 278 | } |
| 279 | |
| 280 | for (i = 0 ; i < numFiles; i++) |
| 281 | { |
| 282 | list[numDirs + i] = strdup(files[i] + dir_len); |
| 283 | } |
| 284 | |
| 285 | for (;;) |
| 286 | { |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 287 | int chosen_item = get_menu_selection(headers, list, 0, 0); |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 288 | if (chosen_item == GO_BACK) |
| 289 | break; |
| 290 | static char ret[PATH_MAX]; |
| 291 | if (chosen_item < numDirs) |
| 292 | { |
| 293 | char* subret = choose_file_menu(dirs[chosen_item], fileExtensionOrDirectory, headers); |
| 294 | if (subret != NULL) |
| 295 | { |
| 296 | strcpy(ret, subret); |
| 297 | return_value = ret; |
| 298 | break; |
| 299 | } |
| 300 | continue; |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 301 | } |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 302 | strcpy(ret, files[chosen_item - numDirs]); |
| 303 | return_value = ret; |
| 304 | break; |
| 305 | } |
| 306 | free_string_array(list); |
Koushik K. Dutta | 981b0cd | 2010-02-22 08:53:34 -0800 | [diff] [blame] | 307 | } |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 308 | |
| 309 | free_string_array(files); |
| 310 | free_string_array(dirs); |
| 311 | return return_value; |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 312 | } |
| 313 | |
Koushik Dutta | 30a937a | 2011-09-05 21:14:06 -0700 | [diff] [blame] | 314 | void show_choose_zip_menu(const char *mount_point) |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 315 | { |
Koushik Dutta | 30a937a | 2011-09-05 21:14:06 -0700 | [diff] [blame] | 316 | if (ensure_path_mounted(mount_point) != 0) { |
| 317 | LOGE ("Can't mount %s\n", mount_point); |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 318 | return; |
| 319 | } |
| 320 | |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 321 | static char* headers[] = { "Choose a zip to apply", |
| 322 | "", |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 323 | NULL |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 324 | }; |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 325 | |
Koushik Dutta | 30a937a | 2011-09-05 21:14:06 -0700 | [diff] [blame] | 326 | char* file = choose_file_menu(mount_point, ".zip", headers); |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 327 | if (file == NULL) |
| 328 | return; |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 329 | static char* confirm_install = "Confirm install?"; |
| 330 | static char confirm[PATH_MAX]; |
| 331 | sprintf(confirm, "Yes - Install %s", basename(file)); |
| 332 | if (confirm_selection(confirm_install, confirm)) |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 333 | install_zip(file); |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 334 | } |
| 335 | |
Koushik Dutta | 89ed0b7 | 2011-10-26 21:25:34 -0700 | [diff] [blame^] | 336 | void show_nandroid_restore_menu(const char* path) |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 337 | { |
Koushik Dutta | 89ed0b7 | 2011-10-26 21:25:34 -0700 | [diff] [blame^] | 338 | if (ensure_path_mounted(path) != 0) { |
| 339 | LOGE("Can't mount %s\n", path); |
Koushik K. Dutta | ee57bbc | 2010-03-12 23:21:12 -0800 | [diff] [blame] | 340 | return; |
Koushik K. Dutta | 54305a8 | 2010-03-12 17:43:26 -0800 | [diff] [blame] | 341 | } |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 342 | |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 343 | static char* headers[] = { "Choose an image to restore", |
| 344 | "", |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 345 | NULL |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 346 | }; |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 347 | |
Koushik Dutta | 89ed0b7 | 2011-10-26 21:25:34 -0700 | [diff] [blame^] | 348 | char tmp[PATH_MAX]; |
| 349 | sprintf(tmp, "%s/clockworkmod/backup/", path); |
| 350 | char* file = choose_file_menu(tmp, NULL, headers); |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 351 | if (file == NULL) |
| 352 | return; |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 353 | |
| 354 | if (confirm_selection("Confirm restore?", "Yes - Restore")) |
Koushik Dutta | 5b7f34a | 2010-12-29 23:36:03 -0800 | [diff] [blame] | 355 | nandroid_restore(file, 1, 1, 1, 1, 1, 0); |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 356 | } |
| 357 | |
jt1134 | 47d86a3 | 2011-02-27 18:54:09 -0600 | [diff] [blame] | 358 | #ifndef BOARD_UMS_LUNFILE |
| 359 | #define BOARD_UMS_LUNFILE "/sys/devices/platform/usb_mass_storage/lun0/file" |
| 360 | #endif |
| 361 | |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 362 | void show_mount_usb_storage_menu() |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 363 | { |
Koushik Dutta | f1cb0d5 | 2011-01-01 20:03:30 -0800 | [diff] [blame] | 364 | int fd; |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 365 | Volume *vol = volume_for_path("/sdcard"); |
jt1134 | 47d86a3 | 2011-02-27 18:54:09 -0600 | [diff] [blame] | 366 | if ((fd = open(BOARD_UMS_LUNFILE, O_WRONLY)) < 0) { |
Koushik Dutta | f1cb0d5 | 2011-01-01 20:03:30 -0800 | [diff] [blame] | 367 | LOGE("Unable to open ums lunfile (%s)", strerror(errno)); |
| 368 | return -1; |
| 369 | } |
| 370 | |
mik_os | df3004b | 2011-04-26 19:15:22 +0300 | [diff] [blame] | 371 | if ((write(fd, vol->device, strlen(vol->device)) < 0) && |
| 372 | (!vol->device2 || (write(fd, vol->device, strlen(vol->device2)) < 0))) { |
Koushik Dutta | f1cb0d5 | 2011-01-01 20:03:30 -0800 | [diff] [blame] | 373 | LOGE("Unable to write to ums lunfile (%s)", strerror(errno)); |
| 374 | close(fd); |
| 375 | return -1; |
| 376 | } |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 377 | static char* headers[] = { "USB Mass Storage device", |
| 378 | "Leaving this menu unmount", |
| 379 | "your SD card from your PC.", |
| 380 | "", |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 381 | NULL |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 382 | }; |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 383 | |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 384 | static char* list[] = { "Unmount", NULL }; |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 385 | |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 386 | for (;;) |
| 387 | { |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 388 | int chosen_item = get_menu_selection(headers, list, 0, 0); |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 389 | if (chosen_item == GO_BACK || chosen_item == 0) |
| 390 | break; |
| 391 | } |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 392 | |
jt1134 | 47d86a3 | 2011-02-27 18:54:09 -0600 | [diff] [blame] | 393 | if ((fd = open(BOARD_UMS_LUNFILE, O_WRONLY)) < 0) { |
Koushik Dutta | f1cb0d5 | 2011-01-01 20:03:30 -0800 | [diff] [blame] | 394 | LOGE("Unable to open ums lunfile (%s)", strerror(errno)); |
| 395 | return -1; |
| 396 | } |
| 397 | |
| 398 | char ch = 0; |
| 399 | if (write(fd, &ch, 1) < 0) { |
| 400 | LOGE("Unable to write to ums lunfile (%s)", strerror(errno)); |
| 401 | close(fd); |
| 402 | return -1; |
| 403 | } |
Koushik K. Dutta | e81cb75 | 2010-02-26 17:44:33 -0800 | [diff] [blame] | 404 | } |
Koushik K. Dutta | f68aaaf | 2010-03-07 13:39:21 -0800 | [diff] [blame] | 405 | |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 406 | int confirm_selection(const char* title, const char* confirm) |
Koushik K. Dutta | 16f0b49 | 2010-03-19 14:37:11 -0700 | [diff] [blame] | 407 | { |
Koushik Dutta | ceddcd5 | 2010-08-23 16:13:14 -0700 | [diff] [blame] | 408 | struct stat info; |
| 409 | if (0 == stat("/sdcard/clockworkmod/.no_confirm", &info)) |
| 410 | return 1; |
| 411 | |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 412 | char* confirm_headers[] = { title, " THIS CAN NOT BE UNDONE.", "", NULL }; |
| 413 | char* items[] = { "No", |
| 414 | "No", |
| 415 | "No", |
| 416 | "No", |
| 417 | "No", |
| 418 | "No", |
| 419 | "No", |
Koushik Dutta | ecd32fa | 2010-07-14 18:38:02 -0700 | [diff] [blame] | 420 | confirm, //" Yes -- wipe partition", // [7 |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 421 | "No", |
| 422 | "No", |
| 423 | "No", |
Koushik K. Dutta | 16f0b49 | 2010-03-19 14:37:11 -0700 | [diff] [blame] | 424 | NULL }; |
| 425 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 426 | int chosen_item = get_menu_selection(confirm_headers, items, 0, 0); |
Koushik K. Dutta | 16f0b49 | 2010-03-19 14:37:11 -0700 | [diff] [blame] | 427 | return chosen_item == 7; |
| 428 | } |
| 429 | |
Koushik Dutta | da32b54 | 2011-01-01 17:55:22 -0800 | [diff] [blame] | 430 | #define MKE2FS_BIN "/sbin/mke2fs" |
| 431 | #define TUNE2FS_BIN "/sbin/tune2fs" |
| 432 | #define E2FSCK_BIN "/sbin/e2fsck" |
| 433 | |
Koushik Dutta | 30a937a | 2011-09-05 21:14:06 -0700 | [diff] [blame] | 434 | int format_device(const char *device, const char *path, const char *fs_type) { |
| 435 | Volume* v = volume_for_path(path); |
| 436 | if (v == NULL) { |
| 437 | // no /sdcard? let's assume /data/media |
| 438 | if (strstr(path, "/sdcard") == path && is_data_media()) { |
| 439 | return format_unknown_device(NULL, path, NULL); |
| 440 | } |
| 441 | // silent failure for sd-ext |
| 442 | if (strcmp(path, "/sd-ext") == 0) |
| 443 | return -1; |
| 444 | LOGE("unknown volume \"%s\"\n", path); |
| 445 | return -1; |
| 446 | } |
| 447 | if (strcmp(fs_type, "ramdisk") == 0) { |
| 448 | // you can't format the ramdisk. |
| 449 | LOGE("can't format_volume \"%s\"", path); |
| 450 | return -1; |
| 451 | } |
| 452 | |
| 453 | if (strcmp(v->mount_point, path) != 0) { |
| 454 | return format_unknown_device(v->device, path, NULL); |
| 455 | } |
| 456 | |
| 457 | if (ensure_path_unmounted(path) != 0) { |
| 458 | LOGE("format_volume failed to unmount \"%s\"\n", v->mount_point); |
| 459 | return -1; |
| 460 | } |
| 461 | |
| 462 | if (strcmp(fs_type, "yaffs2") == 0 || strcmp(fs_type, "mtd") == 0) { |
| 463 | mtd_scan_partitions(); |
| 464 | const MtdPartition* partition = mtd_find_partition_by_name(device); |
| 465 | if (partition == NULL) { |
| 466 | LOGE("format_volume: no MTD partition \"%s\"\n", device); |
| 467 | return -1; |
| 468 | } |
| 469 | |
| 470 | MtdWriteContext *write = mtd_write_partition(partition); |
| 471 | if (write == NULL) { |
| 472 | LOGW("format_volume: can't open MTD \"%s\"\n", device); |
| 473 | return -1; |
| 474 | } else if (mtd_erase_blocks(write, -1) == (off_t) -1) { |
| 475 | LOGW("format_volume: can't erase MTD \"%s\"\n", device); |
| 476 | mtd_write_close(write); |
| 477 | return -1; |
| 478 | } else if (mtd_write_close(write)) { |
| 479 | LOGW("format_volume: can't close MTD \"%s\"\n",device); |
| 480 | return -1; |
| 481 | } |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | if (strcmp(fs_type, "ext4") == 0) { |
| 486 | reset_ext4fs_info(); |
| 487 | int result = make_ext4fs(device, NULL, NULL, 0, 0, 0); |
| 488 | if (result != 0) { |
| 489 | LOGE("format_volume: make_extf4fs failed on %s\n", device); |
| 490 | return -1; |
| 491 | } |
| 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | return format_unknown_device(device, path, fs_type); |
| 496 | } |
| 497 | |
Koushik Dutta | da32b54 | 2011-01-01 17:55:22 -0800 | [diff] [blame] | 498 | int format_unknown_device(const char *device, const char* path, const char *fs_type) |
Koushik K. Dutta | 3f99539 | 2010-03-30 23:29:43 -0700 | [diff] [blame] | 499 | { |
Koushik Dutta | 2e45449 | 2011-01-01 18:06:17 -0800 | [diff] [blame] | 500 | LOGI("Formatting unknown device.\n"); |
Koushik Dutta | a8708c6 | 2011-01-01 18:00:27 -0800 | [diff] [blame] | 501 | |
Koushik Dutta | fb3bd71 | 2011-06-16 14:13:02 -0700 | [diff] [blame] | 502 | if (fs_type != NULL && get_flash_type(fs_type) != UNSUPPORTED) |
Koushik Dutta | 8a6bc77 | 2011-05-26 11:14:15 -0700 | [diff] [blame] | 503 | return erase_raw_partition(fs_type, device); |
Koushik Dutta | da32b54 | 2011-01-01 17:55:22 -0800 | [diff] [blame] | 504 | |
Koushik Dutta | 9f52e5f | 2011-01-02 14:11:24 -0800 | [diff] [blame] | 505 | // if this is SDEXT:, don't worry about it if it does not exist. |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 506 | if (0 == strcmp(path, "/sd-ext")) |
Koushik K. Dutta | f3534d0 | 2010-04-18 18:06:24 -0700 | [diff] [blame] | 507 | { |
| 508 | struct stat st; |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 509 | Volume *vol = volume_for_path("/sd-ext"); |
| 510 | if (vol == NULL || 0 != stat(vol->device, &st)) |
Koushik K. Dutta | f3534d0 | 2010-04-18 18:06:24 -0700 | [diff] [blame] | 511 | { |
| 512 | ui_print("No app2sd partition found. Skipping format of /sd-ext.\n"); |
| 513 | return 0; |
| 514 | } |
| 515 | } |
Koushik Dutta | 2f73e58 | 2010-04-18 16:00:21 -0700 | [diff] [blame] | 516 | |
Koushik Dutta | 9f52e5f | 2011-01-02 14:11:24 -0800 | [diff] [blame] | 517 | if (NULL != fs_type) { |
| 518 | if (strcmp("ext3", fs_type) == 0) { |
| 519 | LOGI("Formatting ext3 device.\n"); |
| 520 | if (0 != ensure_path_unmounted(path)) { |
| 521 | LOGE("Error while unmounting %s.\n", path); |
| 522 | return -12; |
| 523 | } |
| 524 | return format_ext3_device(device); |
| 525 | } |
| 526 | |
| 527 | if (strcmp("ext2", fs_type) == 0) { |
| 528 | LOGI("Formatting ext2 device.\n"); |
| 529 | if (0 != ensure_path_unmounted(path)) { |
| 530 | LOGE("Error while unmounting %s.\n", path); |
| 531 | return -12; |
| 532 | } |
| 533 | return format_ext2_device(device); |
| 534 | } |
| 535 | } |
| 536 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 537 | if (0 != ensure_path_mounted(path)) |
Koushik K. Dutta | 3f99539 | 2010-03-30 23:29:43 -0700 | [diff] [blame] | 538 | { |
| 539 | ui_print("Error mounting %s!\n", path); |
Koushik Dutta | cd44ab9 | 2010-06-23 00:02:14 -0700 | [diff] [blame] | 540 | ui_print("Skipping format...\n"); |
| 541 | return 0; |
Koushik K. Dutta | 3f99539 | 2010-03-30 23:29:43 -0700 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | static char tmp[PATH_MAX]; |
Koushik Dutta | 5082299 | 2011-06-08 19:03:27 -0700 | [diff] [blame] | 545 | if (strcmp(path, "/data") == 0) { |
| 546 | sprintf(tmp, "cd /data ; for f in $(ls -a | grep -v ^media$); do rm -rf $f; done"); |
| 547 | __system(tmp); |
| 548 | } |
| 549 | else { |
| 550 | sprintf(tmp, "rm -rf %s/*", path); |
| 551 | __system(tmp); |
| 552 | sprintf(tmp, "rm -rf %s/.*", path); |
| 553 | __system(tmp); |
| 554 | } |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 555 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 556 | ensure_path_unmounted(path); |
Koushik K. Dutta | 3f99539 | 2010-03-30 23:29:43 -0700 | [diff] [blame] | 557 | return 0; |
| 558 | } |
| 559 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 560 | //#define MOUNTABLE_COUNT 5 |
| 561 | //#define DEVICE_COUNT 4 |
| 562 | //#define MMC_COUNT 2 |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 563 | |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 564 | typedef struct { |
| 565 | char mount[255]; |
| 566 | char unmount[255]; |
| 567 | Volume* v; |
| 568 | } MountMenuEntry; |
| 569 | |
| 570 | typedef struct { |
| 571 | char txt[255]; |
| 572 | Volume* v; |
| 573 | } FormatMenuEntry; |
| 574 | |
Steve Kondik | 0d87851 | 2011-04-09 01:41:45 -0400 | [diff] [blame] | 575 | int is_safe_to_format(char* name) |
| 576 | { |
Brandon Bennett | 9ad8ba2 | 2011-05-07 23:42:58 -0600 | [diff] [blame] | 577 | char str[255]; |
| 578 | char* partition; |
j_r0dd | 14d9e75 | 2011-06-09 18:37:28 -0400 | [diff] [blame] | 579 | property_get("ro.cwm.forbid_format", str, "/misc,/radio,/bootloader,/recovery,/efs"); |
Brandon Bennett | 9ad8ba2 | 2011-05-07 23:42:58 -0600 | [diff] [blame] | 580 | |
| 581 | partition = strtok(str, ", "); |
| 582 | while (partition != NULL) { |
| 583 | if (strcmp(name, partition) == 0) { |
| 584 | return 0; |
| 585 | } |
| 586 | partition = strtok(NULL, ", "); |
| 587 | } |
| 588 | |
| 589 | return 1; |
Steve Kondik | 0d87851 | 2011-04-09 01:41:45 -0400 | [diff] [blame] | 590 | } |
| 591 | |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 592 | void show_partition_menu() |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 593 | { |
Koushik Dutta | ceddcd5 | 2010-08-23 16:13:14 -0700 | [diff] [blame] | 594 | static char* headers[] = { "Mounts and Storage Menu", |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 595 | "", |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 596 | NULL |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 597 | }; |
| 598 | |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 599 | static MountMenuEntry* mount_menue = NULL; |
| 600 | static FormatMenuEntry* format_menue = NULL; |
| 601 | |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 602 | typedef char* string; |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 603 | |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 604 | int i, mountable_volumes, formatable_volumes; |
| 605 | int num_volumes; |
| 606 | Volume* device_volumes; |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 607 | |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 608 | num_volumes = get_num_volumes(); |
| 609 | device_volumes = get_device_volumes(); |
| 610 | |
| 611 | string options[255]; |
| 612 | |
| 613 | if(!device_volumes) |
| 614 | return; |
| 615 | |
| 616 | mountable_volumes = 0; |
| 617 | formatable_volumes = 0; |
| 618 | |
| 619 | mount_menue = malloc(num_volumes * sizeof(MountMenuEntry)); |
| 620 | format_menue = malloc(num_volumes * sizeof(FormatMenuEntry)); |
| 621 | |
| 622 | for (i = 0; i < num_volumes; ++i) { |
| 623 | Volume* v = &device_volumes[i]; |
Koushik Dutta | 67fa0c3 | 2011-03-17 11:37:21 -0700 | [diff] [blame] | 624 | if(strcmp("ramdisk", v->fs_type) != 0 && strcmp("mtd", v->fs_type) != 0 && strcmp("emmc", v->fs_type) != 0 && strcmp("bml", v->fs_type) != 0) |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 625 | { |
| 626 | sprintf(&mount_menue[mountable_volumes].mount, "mount %s", v->mount_point); |
| 627 | sprintf(&mount_menue[mountable_volumes].unmount, "unmount %s", v->mount_point); |
| 628 | mount_menue[mountable_volumes].v = &device_volumes[i]; |
| 629 | ++mountable_volumes; |
Steve Kondik | 0d87851 | 2011-04-09 01:41:45 -0400 | [diff] [blame] | 630 | if (is_safe_to_format(v->mount_point)) { |
| 631 | sprintf(&format_menue[formatable_volumes].txt, "format %s", v->mount_point); |
| 632 | format_menue[formatable_volumes].v = &device_volumes[i]; |
| 633 | ++formatable_volumes; |
| 634 | } |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 635 | } |
Steve Kondik | 0d87851 | 2011-04-09 01:41:45 -0400 | [diff] [blame] | 636 | else if (strcmp("ramdisk", v->fs_type) != 0 && strcmp("mtd", v->fs_type) == 0 && is_safe_to_format(v->mount_point)) |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 637 | { |
| 638 | sprintf(&format_menue[formatable_volumes].txt, "format %s", v->mount_point); |
| 639 | format_menue[formatable_volumes].v = &device_volumes[i]; |
| 640 | ++formatable_volumes; |
| 641 | } |
| 642 | } |
| 643 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 644 | |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 645 | static char* confirm_format = "Confirm format?"; |
Koushik Dutta | ecd32fa | 2010-07-14 18:38:02 -0700 | [diff] [blame] | 646 | static char* confirm = "Yes - Format"; |
wjb | cea6eba | 2011-04-30 21:04:04 -0400 | [diff] [blame] | 647 | char confirm_string[255]; |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 648 | |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 649 | for (;;) |
| 650 | { |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 651 | |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 652 | for (i = 0; i < mountable_volumes; i++) |
| 653 | { |
| 654 | MountMenuEntry* e = &mount_menue[i]; |
| 655 | Volume* v = e->v; |
| 656 | if(is_path_mounted(v->mount_point)) |
| 657 | options[i] = e->unmount; |
| 658 | else |
| 659 | options[i] = e->mount; |
| 660 | } |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 661 | |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 662 | for (i = 0; i < formatable_volumes; i++) |
| 663 | { |
| 664 | FormatMenuEntry* e = &format_menue[i]; |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 665 | |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 666 | options[mountable_volumes+i] = e->txt; |
| 667 | } |
| 668 | |
| 669 | options[mountable_volumes+formatable_volumes] = "mount USB storage"; |
| 670 | options[mountable_volumes+formatable_volumes + 1] = NULL; |
| 671 | |
| 672 | int chosen_item = get_menu_selection(headers, &options, 0, 0); |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 673 | if (chosen_item == GO_BACK) |
| 674 | break; |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 675 | if (chosen_item == (mountable_volumes+formatable_volumes)) |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 676 | { |
| 677 | show_mount_usb_storage_menu(); |
| 678 | } |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 679 | else if (chosen_item < mountable_volumes) |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 680 | { |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 681 | MountMenuEntry* e = &mount_menue[chosen_item]; |
| 682 | Volume* v = e->v; |
| 683 | |
| 684 | if (is_path_mounted(v->mount_point)) |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 685 | { |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 686 | if (0 != ensure_path_unmounted(v->mount_point)) |
| 687 | ui_print("Error unmounting %s!\n", v->mount_point); |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 688 | } |
| 689 | else |
| 690 | { |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 691 | if (0 != ensure_path_mounted(v->mount_point)) |
| 692 | ui_print("Error mounting %s!\n", v->mount_point); |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 693 | } |
| 694 | } |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 695 | else if (chosen_item < (mountable_volumes + formatable_volumes)) |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 696 | { |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 697 | chosen_item = chosen_item - mountable_volumes; |
| 698 | FormatMenuEntry* e = &format_menue[chosen_item]; |
| 699 | Volume* v = e->v; |
| 700 | |
wjb | cea6eba | 2011-04-30 21:04:04 -0400 | [diff] [blame] | 701 | sprintf(confirm_string, "%s - %s", v->mount_point, confirm_format); |
| 702 | |
| 703 | if (!confirm_selection(confirm_string, confirm)) |
Koushik K. Dutta | 16f0b49 | 2010-03-19 14:37:11 -0700 | [diff] [blame] | 704 | continue; |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 705 | ui_print("Formatting %s...\n", v->mount_point); |
| 706 | if (0 != format_volume(v->mount_point)) |
| 707 | ui_print("Error formatting %s!\n", v->mount_point); |
Koushik K. Dutta | 3f99539 | 2010-03-30 23:29:43 -0700 | [diff] [blame] | 708 | else |
| 709 | ui_print("Done.\n"); |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 710 | } |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 711 | } |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 712 | |
| 713 | free(mount_menue); |
| 714 | free(format_menue); |
| 715 | |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 716 | } |
| 717 | |
Koushik Dutta | 89ed0b7 | 2011-10-26 21:25:34 -0700 | [diff] [blame^] | 718 | void show_nandroid_advanced_restore_menu(const char* path) |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 719 | { |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 720 | if (ensure_path_mounted("/sdcard") != 0) { |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 721 | LOGE ("Can't mount /sdcard\n"); |
| 722 | return; |
| 723 | } |
| 724 | |
| 725 | static char* advancedheaders[] = { "Choose an image to restore", |
| 726 | "", |
| 727 | "Choose an image to restore", |
| 728 | "first. The next menu will", |
| 729 | "you more options.", |
| 730 | "", |
| 731 | NULL |
| 732 | }; |
| 733 | |
| 734 | char* file = choose_file_menu("/sdcard/clockworkmod/backup/", NULL, advancedheaders); |
| 735 | if (file == NULL) |
| 736 | return; |
| 737 | |
| 738 | static char* headers[] = { "Nandroid Advanced Restore", |
| 739 | "", |
| 740 | NULL |
| 741 | }; |
| 742 | |
| 743 | static char* list[] = { "Restore boot", |
| 744 | "Restore system", |
| 745 | "Restore data", |
| 746 | "Restore cache", |
Koushik K. Dutta | 68b0190 | 2010-04-01 12:20:39 -0700 | [diff] [blame] | 747 | "Restore sd-ext", |
agrabren | 1f76a5d | 2010-12-29 12:15:18 -0600 | [diff] [blame] | 748 | "Restore wimax", |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 749 | NULL |
| 750 | }; |
Koushik Dutta | 5b7f34a | 2010-12-29 23:36:03 -0800 | [diff] [blame] | 751 | |
| 752 | char tmp[PATH_MAX]; |
| 753 | if (0 != get_partition_device("wimax", tmp)) { |
| 754 | // disable wimax restore option |
| 755 | list[5] = NULL; |
| 756 | } |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 757 | |
| 758 | static char* confirm_restore = "Confirm restore?"; |
| 759 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 760 | int chosen_item = get_menu_selection(headers, list, 0, 0); |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 761 | switch (chosen_item) |
| 762 | { |
| 763 | case 0: |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 764 | if (confirm_selection(confirm_restore, "Yes - Restore boot")) |
agrabren | 1f76a5d | 2010-12-29 12:15:18 -0600 | [diff] [blame] | 765 | nandroid_restore(file, 1, 0, 0, 0, 0, 0); |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 766 | break; |
| 767 | case 1: |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 768 | if (confirm_selection(confirm_restore, "Yes - Restore system")) |
agrabren | 1f76a5d | 2010-12-29 12:15:18 -0600 | [diff] [blame] | 769 | nandroid_restore(file, 0, 1, 0, 0, 0, 0); |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 770 | break; |
| 771 | case 2: |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 772 | if (confirm_selection(confirm_restore, "Yes - Restore data")) |
agrabren | 1f76a5d | 2010-12-29 12:15:18 -0600 | [diff] [blame] | 773 | nandroid_restore(file, 0, 0, 1, 0, 0, 0); |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 774 | break; |
| 775 | case 3: |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 776 | if (confirm_selection(confirm_restore, "Yes - Restore cache")) |
agrabren | 1f76a5d | 2010-12-29 12:15:18 -0600 | [diff] [blame] | 777 | nandroid_restore(file, 0, 0, 0, 1, 0, 0); |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 778 | break; |
Koushik Dutta | 2f73e58 | 2010-04-18 16:00:21 -0700 | [diff] [blame] | 779 | case 4: |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 780 | if (confirm_selection(confirm_restore, "Yes - Restore sd-ext")) |
agrabren | 1f76a5d | 2010-12-29 12:15:18 -0600 | [diff] [blame] | 781 | nandroid_restore(file, 0, 0, 0, 0, 1, 0); |
| 782 | break; |
| 783 | case 5: |
| 784 | if (confirm_selection(confirm_restore, "Yes - Restore wimax")) |
| 785 | nandroid_restore(file, 0, 0, 0, 0, 0, 1); |
Koushik Dutta | 2f73e58 | 2010-04-18 16:00:21 -0700 | [diff] [blame] | 786 | break; |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 787 | } |
| 788 | } |
| 789 | |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 790 | void show_nandroid_menu() |
| 791 | { |
| 792 | static char* headers[] = { "Nandroid", |
| 793 | "", |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 794 | NULL |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 795 | }; |
| 796 | |
Koushik Dutta | 89ed0b7 | 2011-10-26 21:25:34 -0700 | [diff] [blame^] | 797 | static char* list[] = { "backup", |
| 798 | "restore", |
| 799 | "advanced restore", |
| 800 | "backup to internal sdcard", |
| 801 | "restore from internal sdcard", |
| 802 | "advanced restore from internal sdcard", |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 803 | NULL |
| 804 | }; |
| 805 | |
Koushik Dutta | 89ed0b7 | 2011-10-26 21:25:34 -0700 | [diff] [blame^] | 806 | if (volume_for_path("/emmc") == NULL) |
| 807 | INSTALL_MENU_ITEMS[3] = NULL; |
| 808 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 809 | int chosen_item = get_menu_selection(headers, list, 0, 0); |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 810 | switch (chosen_item) |
| 811 | { |
| 812 | case 0: |
| 813 | { |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 814 | char backup_path[PATH_MAX]; |
Koushik K. Dutta | 6a26e7c | 2010-03-27 15:26:11 -0700 | [diff] [blame] | 815 | time_t t = time(NULL); |
| 816 | struct tm *tmp = localtime(&t); |
| 817 | if (tmp == NULL) |
| 818 | { |
| 819 | struct timeval tp; |
| 820 | gettimeofday(&tp, NULL); |
| 821 | sprintf(backup_path, "/sdcard/clockworkmod/backup/%d", tp.tv_sec); |
| 822 | } |
| 823 | else |
| 824 | { |
| 825 | strftime(backup_path, sizeof(backup_path), "/sdcard/clockworkmod/backup/%F.%H.%M.%S", tmp); |
| 826 | } |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 827 | nandroid_backup(backup_path); |
| 828 | } |
| 829 | break; |
| 830 | case 1: |
Koushik Dutta | 89ed0b7 | 2011-10-26 21:25:34 -0700 | [diff] [blame^] | 831 | show_nandroid_restore_menu("/sdcard"); |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 832 | break; |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 833 | case 2: |
Koushik Dutta | 89ed0b7 | 2011-10-26 21:25:34 -0700 | [diff] [blame^] | 834 | show_nandroid_advanced_restore_menu("/sdcard"); |
| 835 | break; |
| 836 | case 3: |
| 837 | { |
| 838 | char backup_path[PATH_MAX]; |
| 839 | time_t t = time(NULL); |
| 840 | struct tm *tmp = localtime(&t); |
| 841 | if (tmp == NULL) |
| 842 | { |
| 843 | struct timeval tp; |
| 844 | gettimeofday(&tp, NULL); |
| 845 | sprintf(backup_path, "/emmc/clockworkmod/backup/%d", tp.tv_sec); |
| 846 | } |
| 847 | else |
| 848 | { |
| 849 | strftime(backup_path, sizeof(backup_path), "/emmc/clockworkmod/backup/%F.%H.%M.%S", tmp); |
| 850 | } |
| 851 | nandroid_backup(backup_path); |
| 852 | } |
| 853 | break; |
| 854 | case 4: |
| 855 | show_nandroid_restore_menu("/emmc"); |
| 856 | break; |
| 857 | case 5: |
| 858 | show_nandroid_advanced_restore_menu("/emmc"); |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 859 | break; |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 860 | } |
Koushik K. Dutta | a496b51 | 2010-03-19 14:51:45 -0700 | [diff] [blame] | 861 | } |
| 862 | |
Koushik Dutta | fd1579b | 2010-05-01 12:46:55 -0700 | [diff] [blame] | 863 | void wipe_battery_stats() |
| 864 | { |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 865 | ensure_path_mounted("/data"); |
Koushik Dutta | fd1579b | 2010-05-01 12:46:55 -0700 | [diff] [blame] | 866 | remove("/data/system/batterystats.bin"); |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 867 | ensure_path_unmounted("/data"); |
j_r0dd | 3f2e286 | 2011-07-10 22:48:39 -0400 | [diff] [blame] | 868 | ui_print("Battery Stats wiped.\n"); |
Koushik Dutta | fd1579b | 2010-05-01 12:46:55 -0700 | [diff] [blame] | 869 | } |
| 870 | |
Koushik K. Dutta | a496b51 | 2010-03-19 14:51:45 -0700 | [diff] [blame] | 871 | void show_advanced_menu() |
| 872 | { |
| 873 | static char* headers[] = { "Advanced and Debugging Menu", |
| 874 | "", |
| 875 | NULL |
| 876 | }; |
| 877 | |
Koushik K. Dutta | 7fe4d7b | 2010-04-06 23:04:52 -0700 | [diff] [blame] | 878 | static char* list[] = { "Reboot Recovery", |
Koushik Dutta | 49af23c | 2010-06-21 13:45:51 -0700 | [diff] [blame] | 879 | "Wipe Dalvik Cache", |
Koushik Dutta | fd1579b | 2010-05-01 12:46:55 -0700 | [diff] [blame] | 880 | "Wipe Battery Stats", |
Koushik Dutta | 598cfc7 | 2010-06-20 09:42:47 -0700 | [diff] [blame] | 881 | "Report Error", |
Koushik K. Dutta | 7fe4d7b | 2010-04-06 23:04:52 -0700 | [diff] [blame] | 882 | "Key Test", |
Tanguy Pruvot | 67d358c | 2011-06-10 20:26:44 +0200 | [diff] [blame] | 883 | "Show log", |
Koushik Dutta | e17a78d | 2010-08-29 12:35:10 -0700 | [diff] [blame] | 884 | #ifndef BOARD_HAS_SMALL_RECOVERY |
Koushik Dutta | ceddcd5 | 2010-08-23 16:13:14 -0700 | [diff] [blame] | 885 | "Partition SD Card", |
| 886 | "Fix Permissions", |
Brint E. Kriebel | d352233 | 2010-12-11 20:52:06 -0700 | [diff] [blame] | 887 | #ifdef BOARD_HAS_SDCARD_INTERNAL |
| 888 | "Partition Internal SD Card", |
| 889 | #endif |
Koushik Dutta | e17a78d | 2010-08-29 12:35:10 -0700 | [diff] [blame] | 890 | #endif |
Koushik K. Dutta | a496b51 | 2010-03-19 14:51:45 -0700 | [diff] [blame] | 891 | NULL |
| 892 | }; |
| 893 | |
| 894 | for (;;) |
| 895 | { |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 896 | int chosen_item = get_menu_selection(headers, list, 0, 0); |
Koushik K. Dutta | a496b51 | 2010-03-19 14:51:45 -0700 | [diff] [blame] | 897 | if (chosen_item == GO_BACK) |
| 898 | break; |
| 899 | switch (chosen_item) |
| 900 | { |
| 901 | case 0: |
Tanguy Pruvot | 67d358c | 2011-06-10 20:26:44 +0200 | [diff] [blame] | 902 | { |
Austen Dicken | 7126ef4 | 2011-06-14 15:47:40 -0500 | [diff] [blame] | 903 | reboot_wrapper("recovery"); |
Koushik K. Dutta | 7fe4d7b | 2010-04-06 23:04:52 -0700 | [diff] [blame] | 904 | break; |
Tanguy Pruvot | 67d358c | 2011-06-10 20:26:44 +0200 | [diff] [blame] | 905 | } |
Koushik K. Dutta | 7fe4d7b | 2010-04-06 23:04:52 -0700 | [diff] [blame] | 906 | case 1: |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 907 | { |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 908 | if (0 != ensure_path_mounted("/data")) |
Koushik Dutta | 49af23c | 2010-06-21 13:45:51 -0700 | [diff] [blame] | 909 | break; |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 910 | ensure_path_mounted("/sd-ext"); |
| 911 | ensure_path_mounted("/cache"); |
Koushik Dutta | 6c7745d | 2010-08-07 12:17:13 -0700 | [diff] [blame] | 912 | if (confirm_selection( "Confirm wipe?", "Yes - Wipe Dalvik Cache")) { |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 913 | __system("rm -r /data/dalvik-cache"); |
Koushik Dutta | 6c7745d | 2010-08-07 12:17:13 -0700 | [diff] [blame] | 914 | __system("rm -r /cache/dalvik-cache"); |
| 915 | __system("rm -r /sd-ext/dalvik-cache"); |
Koushik Dutta | 30a937a | 2011-09-05 21:14:06 -0700 | [diff] [blame] | 916 | ui_print("Dalvik Cache wiped.\n"); |
Koushik Dutta | 6c7745d | 2010-08-07 12:17:13 -0700 | [diff] [blame] | 917 | } |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 918 | ensure_path_unmounted("/data"); |
Koushik Dutta | fd1579b | 2010-05-01 12:46:55 -0700 | [diff] [blame] | 919 | break; |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 920 | } |
Koushik Dutta | fd1579b | 2010-05-01 12:46:55 -0700 | [diff] [blame] | 921 | case 2: |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 922 | { |
| 923 | if (confirm_selection( "Confirm wipe?", "Yes - Wipe Battery Stats")) |
| 924 | wipe_battery_stats(); |
Koushik Dutta | 598cfc7 | 2010-06-20 09:42:47 -0700 | [diff] [blame] | 925 | break; |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 926 | } |
Koushik Dutta | 598cfc7 | 2010-06-20 09:42:47 -0700 | [diff] [blame] | 927 | case 3: |
Koushik Dutta | 49af23c | 2010-06-21 13:45:51 -0700 | [diff] [blame] | 928 | handle_failure(1); |
| 929 | break; |
| 930 | case 4: |
Koushik K. Dutta | a496b51 | 2010-03-19 14:51:45 -0700 | [diff] [blame] | 931 | { |
| 932 | ui_print("Outputting key codes.\n"); |
| 933 | ui_print("Go back to end debugging.\n"); |
| 934 | int key; |
| 935 | int action; |
| 936 | do |
| 937 | { |
| 938 | key = ui_wait_key(); |
| 939 | action = device_handle_key(key, 1); |
| 940 | ui_print("Key: %d\n", key); |
| 941 | } |
| 942 | while (action != GO_BACK); |
Koushik Dutta | 56606a2 | 2010-08-23 16:15:33 -0700 | [diff] [blame] | 943 | break; |
Koushik K. Dutta | a496b51 | 2010-03-19 14:51:45 -0700 | [diff] [blame] | 944 | } |
Koushik Dutta | f0e31b8 | 2010-08-17 16:55:38 -0700 | [diff] [blame] | 945 | case 5: |
| 946 | { |
Tanguy Pruvot | 67d358c | 2011-06-10 20:26:44 +0200 | [diff] [blame] | 947 | ui_printlogtail(12); |
| 948 | break; |
| 949 | } |
| 950 | case 6: |
| 951 | { |
Koushik Dutta | ceddcd5 | 2010-08-23 16:13:14 -0700 | [diff] [blame] | 952 | static char* ext_sizes[] = { "128M", |
| 953 | "256M", |
| 954 | "512M", |
| 955 | "1024M", |
Brint E. Kriebel | 0b23331 | 2010-11-14 15:31:17 -0700 | [diff] [blame] | 956 | "2048M", |
| 957 | "4096M", |
Koushik Dutta | ceddcd5 | 2010-08-23 16:13:14 -0700 | [diff] [blame] | 958 | NULL }; |
| 959 | |
| 960 | static char* swap_sizes[] = { "0M", |
| 961 | "32M", |
| 962 | "64M", |
| 963 | "128M", |
| 964 | "256M", |
| 965 | NULL }; |
| 966 | |
| 967 | static char* ext_headers[] = { "Ext Size", "", NULL }; |
| 968 | static char* swap_headers[] = { "Swap Size", "", NULL }; |
| 969 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 970 | int ext_size = get_menu_selection(ext_headers, ext_sizes, 0, 0); |
Koushik Dutta | ceddcd5 | 2010-08-23 16:13:14 -0700 | [diff] [blame] | 971 | if (ext_size == GO_BACK) |
| 972 | continue; |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 973 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 974 | int swap_size = get_menu_selection(swap_headers, swap_sizes, 0, 0); |
Koushik Dutta | ceddcd5 | 2010-08-23 16:13:14 -0700 | [diff] [blame] | 975 | if (swap_size == GO_BACK) |
| 976 | continue; |
| 977 | |
| 978 | char sddevice[256]; |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 979 | Volume *vol = volume_for_path("/sdcard"); |
| 980 | strcpy(sddevice, vol->device); |
Koushik Dutta | ceddcd5 | 2010-08-23 16:13:14 -0700 | [diff] [blame] | 981 | // we only want the mmcblk, not the partition |
| 982 | sddevice[strlen("/dev/block/mmcblkX")] = NULL; |
| 983 | char cmd[PATH_MAX]; |
| 984 | setenv("SDPATH", sddevice, 1); |
| 985 | sprintf(cmd, "sdparted -es %s -ss %s -efs ext3 -s", ext_sizes[ext_size], swap_sizes[swap_size]); |
| 986 | ui_print("Partitioning SD Card... please wait...\n"); |
| 987 | if (0 == __system(cmd)) |
| 988 | ui_print("Done!\n"); |
| 989 | else |
| 990 | ui_print("An error occured while partitioning your SD Card. Please see /tmp/recovery.log for more details.\n"); |
Koushik Dutta | 56606a2 | 2010-08-23 16:15:33 -0700 | [diff] [blame] | 991 | break; |
Koushik Dutta | f0e31b8 | 2010-08-17 16:55:38 -0700 | [diff] [blame] | 992 | } |
Tanguy Pruvot | 67d358c | 2011-06-10 20:26:44 +0200 | [diff] [blame] | 993 | case 7: |
Koushik Dutta | 38e8b2b | 2010-08-17 22:21:53 -0700 | [diff] [blame] | 994 | { |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 995 | ensure_path_mounted("/system"); |
| 996 | ensure_path_mounted("/data"); |
Koushik Dutta | ceddcd5 | 2010-08-23 16:13:14 -0700 | [diff] [blame] | 997 | ui_print("Fixing permissions...\n"); |
| 998 | __system("fix_permissions"); |
| 999 | ui_print("Done!\n"); |
Koushik Dutta | 56606a2 | 2010-08-23 16:15:33 -0700 | [diff] [blame] | 1000 | break; |
Koushik Dutta | 38e8b2b | 2010-08-17 22:21:53 -0700 | [diff] [blame] | 1001 | } |
Tanguy Pruvot | 67d358c | 2011-06-10 20:26:44 +0200 | [diff] [blame] | 1002 | case 8: |
Brint E. Kriebel | d352233 | 2010-12-11 20:52:06 -0700 | [diff] [blame] | 1003 | { |
| 1004 | static char* ext_sizes[] = { "128M", |
| 1005 | "256M", |
| 1006 | "512M", |
| 1007 | "1024M", |
| 1008 | "2048M", |
| 1009 | "4096M", |
| 1010 | NULL }; |
| 1011 | |
| 1012 | static char* swap_sizes[] = { "0M", |
| 1013 | "32M", |
| 1014 | "64M", |
| 1015 | "128M", |
| 1016 | "256M", |
| 1017 | NULL }; |
| 1018 | |
| 1019 | static char* ext_headers[] = { "Data Size", "", NULL }; |
| 1020 | static char* swap_headers[] = { "Swap Size", "", NULL }; |
| 1021 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 1022 | int ext_size = get_menu_selection(ext_headers, ext_sizes, 0, 0); |
Brint E. Kriebel | d352233 | 2010-12-11 20:52:06 -0700 | [diff] [blame] | 1023 | if (ext_size == GO_BACK) |
| 1024 | continue; |
| 1025 | |
| 1026 | int swap_size = 0; |
| 1027 | if (swap_size == GO_BACK) |
| 1028 | continue; |
| 1029 | |
| 1030 | char sddevice[256]; |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 1031 | Volume *vol = volume_for_path("/emmc"); |
| 1032 | strcpy(sddevice, vol->device); |
Brint E. Kriebel | d352233 | 2010-12-11 20:52:06 -0700 | [diff] [blame] | 1033 | // we only want the mmcblk, not the partition |
| 1034 | sddevice[strlen("/dev/block/mmcblkX")] = NULL; |
| 1035 | char cmd[PATH_MAX]; |
| 1036 | setenv("SDPATH", sddevice, 1); |
| 1037 | sprintf(cmd, "sdparted -es %s -ss %s -efs ext3 -s", ext_sizes[ext_size], swap_sizes[swap_size]); |
| 1038 | ui_print("Partitioning Internal SD Card... please wait...\n"); |
| 1039 | if (0 == __system(cmd)) |
| 1040 | ui_print("Done!\n"); |
| 1041 | else |
| 1042 | ui_print("An error occured while partitioning your Internal SD Card. Please see /tmp/recovery.log for more details.\n"); |
| 1043 | break; |
| 1044 | } |
Koushik K. Dutta | a496b51 | 2010-03-19 14:51:45 -0700 | [diff] [blame] | 1045 | } |
| 1046 | } |
Koushik Dutta | 14239d2 | 2010-06-14 15:02:48 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
Koushik Dutta | b643e4f | 2010-12-18 18:39:39 -0800 | [diff] [blame] | 1049 | void write_fstab_root(char *path, FILE *file) |
Koushik Dutta | 14239d2 | 2010-06-14 15:02:48 -0700 | [diff] [blame] | 1050 | { |
Koushik Dutta | b643e4f | 2010-12-18 18:39:39 -0800 | [diff] [blame] | 1051 | Volume *vol = volume_for_path(path); |
| 1052 | if (vol == NULL) { |
Koushik Dutta | 9765a03 | 2010-12-18 21:31:02 -0800 | [diff] [blame] | 1053 | LOGW("Unable to get recovery.fstab info for %s during fstab generation!\n", path); |
Koushik Dutta | 598cfc7 | 2010-06-20 09:42:47 -0700 | [diff] [blame] | 1054 | return; |
Koushik Dutta | a6522b3 | 2010-06-20 13:16:06 -0700 | [diff] [blame] | 1055 | } |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 1056 | |
Koushik Dutta | 31b7411 | 2010-12-20 08:49:20 -0800 | [diff] [blame] | 1057 | char device[200]; |
| 1058 | if (vol->device[0] != '/') |
| 1059 | get_partition_device(vol->device, device); |
| 1060 | else |
| 1061 | strcpy(device, vol->device); |
| 1062 | |
| 1063 | fprintf(file, "%s ", device); |
Koushik Dutta | b643e4f | 2010-12-18 18:39:39 -0800 | [diff] [blame] | 1064 | fprintf(file, "%s ", path); |
Koushik Dutta | ab1f8b8 | 2011-02-27 17:28:30 -0800 | [diff] [blame] | 1065 | // special case rfs cause auto will mount it as vfat on samsung. |
| 1066 | fprintf(file, "%s rw\n", vol->fs_type2 != NULL && strcmp(vol->fs_type, "rfs") != 0 ? "auto" : vol->fs_type); |
Koushik Dutta | 14239d2 | 2010-06-14 15:02:48 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | void create_fstab() |
| 1070 | { |
Koushik Dutta | b643e4f | 2010-12-18 18:39:39 -0800 | [diff] [blame] | 1071 | struct stat info; |
Koushik Dutta | cd44ab9 | 2010-06-23 00:02:14 -0700 | [diff] [blame] | 1072 | __system("touch /etc/mtab"); |
Koushik Dutta | 14239d2 | 2010-06-14 15:02:48 -0700 | [diff] [blame] | 1073 | FILE *file = fopen("/etc/fstab", "w"); |
Koushik Dutta | a6522b3 | 2010-06-20 13:16:06 -0700 | [diff] [blame] | 1074 | if (file == NULL) { |
Koushik Dutta | b643e4f | 2010-12-18 18:39:39 -0800 | [diff] [blame] | 1075 | LOGW("Unable to create /etc/fstab!\n"); |
Koushik Dutta | 598cfc7 | 2010-06-20 09:42:47 -0700 | [diff] [blame] | 1076 | return; |
Koushik Dutta | a6522b3 | 2010-06-20 13:16:06 -0700 | [diff] [blame] | 1077 | } |
Brandon Bennett | 6d0604b | 2011-01-28 13:39:10 -0700 | [diff] [blame] | 1078 | Volume *vol = volume_for_path("/boot"); |
Koushik Dutta | a9f0e7f | 2011-02-12 10:21:11 -0800 | [diff] [blame] | 1079 | if (NULL != vol && strcmp(vol->fs_type, "mtd") != 0 && strcmp(vol->fs_type, "emmc") != 0 && strcmp(vol->fs_type, "bml") != 0) |
Brandon Bennett | 6d0604b | 2011-01-28 13:39:10 -0700 | [diff] [blame] | 1080 | write_fstab_root("/boot", file); |
Koushik Dutta | b643e4f | 2010-12-18 18:39:39 -0800 | [diff] [blame] | 1081 | write_fstab_root("/cache", file); |
| 1082 | write_fstab_root("/data", file); |
Koushik Dutta | 89ed0b7 | 2011-10-26 21:25:34 -0700 | [diff] [blame^] | 1083 | write_fstab_root("/datadata", file); |
| 1084 | write_fstab_root("/emmc", file); |
Koushik Dutta | b643e4f | 2010-12-18 18:39:39 -0800 | [diff] [blame] | 1085 | write_fstab_root("/system", file); |
| 1086 | write_fstab_root("/sdcard", file); |
| 1087 | write_fstab_root("/sd-ext", file); |
Koushik Dutta | 14239d2 | 2010-06-14 15:02:48 -0700 | [diff] [blame] | 1088 | fclose(file); |
Koushik Dutta | 9765a03 | 2010-12-18 21:31:02 -0800 | [diff] [blame] | 1089 | LOGI("Completed outputting fstab.\n"); |
Koushik Dutta | 598cfc7 | 2010-06-20 09:42:47 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
Koushik Dutta | 4196e0f | 2010-12-19 03:38:29 -0800 | [diff] [blame] | 1092 | int bml_check_volume(const char *path) { |
| 1093 | ui_print("Checking %s...\n", path); |
| 1094 | ensure_path_unmounted(path); |
| 1095 | if (0 == ensure_path_mounted(path)) { |
| 1096 | ensure_path_unmounted(path); |
| 1097 | return 0; |
| 1098 | } |
| 1099 | |
| 1100 | Volume *vol = volume_for_path(path); |
| 1101 | if (vol == NULL) { |
| 1102 | LOGE("Unable process volume! Skipping...\n"); |
| 1103 | return 0; |
| 1104 | } |
| 1105 | |
Koushik Dutta | bec0995 | 2010-12-19 20:37:57 -0800 | [diff] [blame] | 1106 | ui_print("%s may be rfs. Checking...\n", path); |
Koushik Dutta | 4196e0f | 2010-12-19 03:38:29 -0800 | [diff] [blame] | 1107 | char tmp[PATH_MAX]; |
| 1108 | sprintf(tmp, "mount -t rfs %s %s", vol->device, path); |
| 1109 | int ret = __system(tmp); |
| 1110 | printf("%d\n", ret); |
| 1111 | return ret == 0 ? 1 : 0; |
| 1112 | } |
| 1113 | |
| 1114 | void process_volumes() { |
| 1115 | create_fstab(); |
Koushik Dutta | 38a9214 | 2011-06-10 09:45:52 -0700 | [diff] [blame] | 1116 | |
| 1117 | if (is_data_media()) { |
| 1118 | setup_data_media(); |
Koushik Dutta | 94caefe | 2011-06-10 09:17:30 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
Koushik Dutta | e8bc2c8 | 2011-02-27 14:00:19 -0800 | [diff] [blame] | 1121 | return; |
| 1122 | |
| 1123 | // dead code. |
Koushik Dutta | 4196e0f | 2010-12-19 03:38:29 -0800 | [diff] [blame] | 1124 | if (device_flash_type() != BML) |
| 1125 | return; |
| 1126 | |
| 1127 | ui_print("Checking for ext4 partitions...\n"); |
| 1128 | int ret = 0; |
| 1129 | ret = bml_check_volume("/system"); |
| 1130 | ret |= bml_check_volume("/data"); |
| 1131 | if (has_datadata()) |
| 1132 | ret |= bml_check_volume("/datadata"); |
| 1133 | ret |= bml_check_volume("/cache"); |
| 1134 | |
| 1135 | if (ret == 0) { |
| 1136 | ui_print("Done!\n"); |
| 1137 | return; |
| 1138 | } |
| 1139 | |
Koushik Dutta | 745b5ff | 2010-12-21 00:58:43 -0800 | [diff] [blame] | 1140 | char backup_path[PATH_MAX]; |
| 1141 | time_t t = time(NULL); |
| 1142 | char backup_name[PATH_MAX]; |
| 1143 | struct timeval tp; |
| 1144 | gettimeofday(&tp, NULL); |
| 1145 | sprintf(backup_name, "before-ext4-convert-%d", tp.tv_sec); |
| 1146 | sprintf(backup_path, "/sdcard/clockworkmod/backup/%s", backup_name); |
| 1147 | |
Koushik Dutta | 4196e0f | 2010-12-19 03:38:29 -0800 | [diff] [blame] | 1148 | ui_set_show_text(1); |
| 1149 | ui_print("Filesystems need to be converted to ext4.\n"); |
| 1150 | ui_print("A backup and restore will now take place.\n"); |
Koushik Dutta | bec0995 | 2010-12-19 20:37:57 -0800 | [diff] [blame] | 1151 | ui_print("If anything goes wrong, your backup will be\n"); |
Koushik Dutta | 745b5ff | 2010-12-21 00:58:43 -0800 | [diff] [blame] | 1152 | ui_print("named %s. Try restoring it\n", backup_name); |
Koushik Dutta | bec0995 | 2010-12-19 20:37:57 -0800 | [diff] [blame] | 1153 | ui_print("in case of error.\n"); |
Koushik Dutta | 4196e0f | 2010-12-19 03:38:29 -0800 | [diff] [blame] | 1154 | |
Koushik Dutta | 745b5ff | 2010-12-21 00:58:43 -0800 | [diff] [blame] | 1155 | nandroid_backup(backup_path); |
Koushik Dutta | 5b7f34a | 2010-12-29 23:36:03 -0800 | [diff] [blame] | 1156 | nandroid_restore(backup_path, 1, 1, 1, 1, 1, 0); |
Koushik Dutta | 4196e0f | 2010-12-19 03:38:29 -0800 | [diff] [blame] | 1157 | ui_set_show_text(0); |
| 1158 | } |
| 1159 | |
Koushik Dutta | 598cfc7 | 2010-06-20 09:42:47 -0700 | [diff] [blame] | 1160 | void handle_failure(int ret) |
| 1161 | { |
| 1162 | if (ret == 0) |
| 1163 | return; |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 1164 | if (0 != ensure_path_mounted("/sdcard")) |
Koushik Dutta | 598cfc7 | 2010-06-20 09:42:47 -0700 | [diff] [blame] | 1165 | return; |
Koushik Dutta | a6522b3 | 2010-06-20 13:16:06 -0700 | [diff] [blame] | 1166 | mkdir("/sdcard/clockworkmod", S_IRWXU); |
| 1167 | __system("cp /tmp/recovery.log /sdcard/clockworkmod/recovery.log"); |
Koushik Dutta | 38e8b2b | 2010-08-17 22:21:53 -0700 | [diff] [blame] | 1168 | ui_print("/tmp/recovery.log was copied to /sdcard/clockworkmod/recovery.log. Please open ROM Manager to report the issue.\n"); |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 1169 | } |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 1170 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 1171 | int is_path_mounted(const char* path) { |
| 1172 | Volume* v = volume_for_path(path); |
| 1173 | if (v == NULL) { |
| 1174 | return 0; |
| 1175 | } |
| 1176 | if (strcmp(v->fs_type, "ramdisk") == 0) { |
| 1177 | // the ramdisk is always mounted. |
| 1178 | return 1; |
| 1179 | } |
| 1180 | |
| 1181 | int result; |
| 1182 | result = scan_mounted_volumes(); |
| 1183 | if (result < 0) { |
| 1184 | LOGE("failed to scan mounted volumes\n"); |
| 1185 | return 0; |
| 1186 | } |
| 1187 | |
| 1188 | const MountedVolume* mv = |
| 1189 | find_mounted_volume_by_mount_point(v->mount_point); |
| 1190 | if (mv) { |
| 1191 | // volume is already mounted |
| 1192 | return 1; |
| 1193 | } |
| 1194 | return 0; |
| 1195 | } |
Koushik Dutta | 5460f0c | 2010-12-18 22:37:49 -0800 | [diff] [blame] | 1196 | |
| 1197 | int has_datadata() { |
| 1198 | Volume *vol = volume_for_path("/datadata"); |
| 1199 | return vol != NULL; |
Koushik Dutta | d8e21c3 | 2011-01-04 10:46:23 -0800 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | int volume_main(int argc, char **argv) { |
| 1203 | load_volume_table(); |
| 1204 | return 0; |
| 1205 | } |