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 K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 336 | void show_nandroid_restore_menu() |
| 337 | { |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 338 | if (ensure_path_mounted("/sdcard") != 0) { |
Koushik K. Dutta | 54305a8 | 2010-03-12 17:43:26 -0800 | [diff] [blame] | 339 | LOGE ("Can't mount /sdcard\n"); |
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 K. Dutta | 49f5689 | 2010-02-25 14:51:05 -0800 | [diff] [blame] | 348 | char* file = choose_file_menu("/sdcard/clockworkmod/backup/", NULL, headers); |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 349 | if (file == NULL) |
| 350 | return; |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 351 | |
| 352 | if (confirm_selection("Confirm restore?", "Yes - Restore")) |
Koushik Dutta | 5b7f34a | 2010-12-29 23:36:03 -0800 | [diff] [blame] | 353 | nandroid_restore(file, 1, 1, 1, 1, 1, 0); |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 354 | } |
| 355 | |
jt1134 | 47d86a3 | 2011-02-27 18:54:09 -0600 | [diff] [blame] | 356 | #ifndef BOARD_UMS_LUNFILE |
| 357 | #define BOARD_UMS_LUNFILE "/sys/devices/platform/usb_mass_storage/lun0/file" |
| 358 | #endif |
| 359 | |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 360 | void show_mount_usb_storage_menu() |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 361 | { |
Koushik Dutta | f1cb0d5 | 2011-01-01 20:03:30 -0800 | [diff] [blame] | 362 | int fd; |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 363 | Volume *vol = volume_for_path("/sdcard"); |
jt1134 | 47d86a3 | 2011-02-27 18:54:09 -0600 | [diff] [blame] | 364 | if ((fd = open(BOARD_UMS_LUNFILE, O_WRONLY)) < 0) { |
Koushik Dutta | f1cb0d5 | 2011-01-01 20:03:30 -0800 | [diff] [blame] | 365 | LOGE("Unable to open ums lunfile (%s)", strerror(errno)); |
| 366 | return -1; |
| 367 | } |
| 368 | |
mik_os | df3004b | 2011-04-26 19:15:22 +0300 | [diff] [blame] | 369 | if ((write(fd, vol->device, strlen(vol->device)) < 0) && |
| 370 | (!vol->device2 || (write(fd, vol->device, strlen(vol->device2)) < 0))) { |
Koushik Dutta | f1cb0d5 | 2011-01-01 20:03:30 -0800 | [diff] [blame] | 371 | LOGE("Unable to write to ums lunfile (%s)", strerror(errno)); |
| 372 | close(fd); |
| 373 | return -1; |
| 374 | } |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 375 | static char* headers[] = { "USB Mass Storage device", |
| 376 | "Leaving this menu unmount", |
| 377 | "your SD card from your PC.", |
| 378 | "", |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 379 | NULL |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 380 | }; |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 381 | |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 382 | static char* list[] = { "Unmount", NULL }; |
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 | for (;;) |
| 385 | { |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 386 | int chosen_item = get_menu_selection(headers, list, 0, 0); |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 387 | if (chosen_item == GO_BACK || chosen_item == 0) |
| 388 | break; |
| 389 | } |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 390 | |
jt1134 | 47d86a3 | 2011-02-27 18:54:09 -0600 | [diff] [blame] | 391 | if ((fd = open(BOARD_UMS_LUNFILE, O_WRONLY)) < 0) { |
Koushik Dutta | f1cb0d5 | 2011-01-01 20:03:30 -0800 | [diff] [blame] | 392 | LOGE("Unable to open ums lunfile (%s)", strerror(errno)); |
| 393 | return -1; |
| 394 | } |
| 395 | |
| 396 | char ch = 0; |
| 397 | if (write(fd, &ch, 1) < 0) { |
| 398 | LOGE("Unable to write to ums lunfile (%s)", strerror(errno)); |
| 399 | close(fd); |
| 400 | return -1; |
| 401 | } |
Koushik K. Dutta | e81cb75 | 2010-02-26 17:44:33 -0800 | [diff] [blame] | 402 | } |
Koushik K. Dutta | f68aaaf | 2010-03-07 13:39:21 -0800 | [diff] [blame] | 403 | |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 404 | int confirm_selection(const char* title, const char* confirm) |
Koushik K. Dutta | 16f0b49 | 2010-03-19 14:37:11 -0700 | [diff] [blame] | 405 | { |
Koushik Dutta | ceddcd5 | 2010-08-23 16:13:14 -0700 | [diff] [blame] | 406 | struct stat info; |
| 407 | if (0 == stat("/sdcard/clockworkmod/.no_confirm", &info)) |
| 408 | return 1; |
| 409 | |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 410 | char* confirm_headers[] = { title, " THIS CAN NOT BE UNDONE.", "", NULL }; |
| 411 | char* items[] = { "No", |
| 412 | "No", |
| 413 | "No", |
| 414 | "No", |
| 415 | "No", |
| 416 | "No", |
| 417 | "No", |
Koushik Dutta | ecd32fa | 2010-07-14 18:38:02 -0700 | [diff] [blame] | 418 | confirm, //" Yes -- wipe partition", // [7 |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 419 | "No", |
| 420 | "No", |
| 421 | "No", |
Koushik K. Dutta | 16f0b49 | 2010-03-19 14:37:11 -0700 | [diff] [blame] | 422 | NULL }; |
| 423 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 424 | int chosen_item = get_menu_selection(confirm_headers, items, 0, 0); |
Koushik K. Dutta | 16f0b49 | 2010-03-19 14:37:11 -0700 | [diff] [blame] | 425 | return chosen_item == 7; |
| 426 | } |
| 427 | |
Koushik Dutta | da32b54 | 2011-01-01 17:55:22 -0800 | [diff] [blame] | 428 | #define MKE2FS_BIN "/sbin/mke2fs" |
| 429 | #define TUNE2FS_BIN "/sbin/tune2fs" |
| 430 | #define E2FSCK_BIN "/sbin/e2fsck" |
| 431 | |
Koushik Dutta | 30a937a | 2011-09-05 21:14:06 -0700 | [diff] [blame] | 432 | int format_device(const char *device, const char *path, const char *fs_type) { |
| 433 | Volume* v = volume_for_path(path); |
| 434 | if (v == NULL) { |
| 435 | // no /sdcard? let's assume /data/media |
| 436 | if (strstr(path, "/sdcard") == path && is_data_media()) { |
| 437 | return format_unknown_device(NULL, path, NULL); |
| 438 | } |
| 439 | // silent failure for sd-ext |
| 440 | if (strcmp(path, "/sd-ext") == 0) |
| 441 | return -1; |
| 442 | LOGE("unknown volume \"%s\"\n", path); |
| 443 | return -1; |
| 444 | } |
| 445 | if (strcmp(fs_type, "ramdisk") == 0) { |
| 446 | // you can't format the ramdisk. |
| 447 | LOGE("can't format_volume \"%s\"", path); |
| 448 | return -1; |
| 449 | } |
| 450 | |
| 451 | if (strcmp(v->mount_point, path) != 0) { |
| 452 | return format_unknown_device(v->device, path, NULL); |
| 453 | } |
| 454 | |
| 455 | if (ensure_path_unmounted(path) != 0) { |
| 456 | LOGE("format_volume failed to unmount \"%s\"\n", v->mount_point); |
| 457 | return -1; |
| 458 | } |
| 459 | |
| 460 | if (strcmp(fs_type, "yaffs2") == 0 || strcmp(fs_type, "mtd") == 0) { |
| 461 | mtd_scan_partitions(); |
| 462 | const MtdPartition* partition = mtd_find_partition_by_name(device); |
| 463 | if (partition == NULL) { |
| 464 | LOGE("format_volume: no MTD partition \"%s\"\n", device); |
| 465 | return -1; |
| 466 | } |
| 467 | |
| 468 | MtdWriteContext *write = mtd_write_partition(partition); |
| 469 | if (write == NULL) { |
| 470 | LOGW("format_volume: can't open MTD \"%s\"\n", device); |
| 471 | return -1; |
| 472 | } else if (mtd_erase_blocks(write, -1) == (off_t) -1) { |
| 473 | LOGW("format_volume: can't erase MTD \"%s\"\n", device); |
| 474 | mtd_write_close(write); |
| 475 | return -1; |
| 476 | } else if (mtd_write_close(write)) { |
| 477 | LOGW("format_volume: can't close MTD \"%s\"\n",device); |
| 478 | return -1; |
| 479 | } |
| 480 | return 0; |
| 481 | } |
| 482 | |
| 483 | if (strcmp(fs_type, "ext4") == 0) { |
| 484 | reset_ext4fs_info(); |
| 485 | int result = make_ext4fs(device, NULL, NULL, 0, 0, 0); |
| 486 | if (result != 0) { |
| 487 | LOGE("format_volume: make_extf4fs failed on %s\n", device); |
| 488 | return -1; |
| 489 | } |
| 490 | return 0; |
| 491 | } |
| 492 | |
| 493 | return format_unknown_device(device, path, fs_type); |
| 494 | } |
| 495 | |
Koushik Dutta | da32b54 | 2011-01-01 17:55:22 -0800 | [diff] [blame] | 496 | 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] | 497 | { |
Koushik Dutta | 2e45449 | 2011-01-01 18:06:17 -0800 | [diff] [blame] | 498 | LOGI("Formatting unknown device.\n"); |
Koushik Dutta | a8708c6 | 2011-01-01 18:00:27 -0800 | [diff] [blame] | 499 | |
Koushik Dutta | fb3bd71 | 2011-06-16 14:13:02 -0700 | [diff] [blame] | 500 | if (fs_type != NULL && get_flash_type(fs_type) != UNSUPPORTED) |
Koushik Dutta | 8a6bc77 | 2011-05-26 11:14:15 -0700 | [diff] [blame] | 501 | return erase_raw_partition(fs_type, device); |
Koushik Dutta | da32b54 | 2011-01-01 17:55:22 -0800 | [diff] [blame] | 502 | |
Koushik Dutta | 9f52e5f | 2011-01-02 14:11:24 -0800 | [diff] [blame] | 503 | // 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] | 504 | if (0 == strcmp(path, "/sd-ext")) |
Koushik K. Dutta | f3534d0 | 2010-04-18 18:06:24 -0700 | [diff] [blame] | 505 | { |
| 506 | struct stat st; |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 507 | Volume *vol = volume_for_path("/sd-ext"); |
| 508 | if (vol == NULL || 0 != stat(vol->device, &st)) |
Koushik K. Dutta | f3534d0 | 2010-04-18 18:06:24 -0700 | [diff] [blame] | 509 | { |
| 510 | ui_print("No app2sd partition found. Skipping format of /sd-ext.\n"); |
| 511 | return 0; |
| 512 | } |
| 513 | } |
Koushik Dutta | 2f73e58 | 2010-04-18 16:00:21 -0700 | [diff] [blame] | 514 | |
Koushik Dutta | 9f52e5f | 2011-01-02 14:11:24 -0800 | [diff] [blame] | 515 | if (NULL != fs_type) { |
| 516 | if (strcmp("ext3", fs_type) == 0) { |
| 517 | LOGI("Formatting ext3 device.\n"); |
| 518 | if (0 != ensure_path_unmounted(path)) { |
| 519 | LOGE("Error while unmounting %s.\n", path); |
| 520 | return -12; |
| 521 | } |
| 522 | return format_ext3_device(device); |
| 523 | } |
| 524 | |
| 525 | if (strcmp("ext2", fs_type) == 0) { |
| 526 | LOGI("Formatting ext2 device.\n"); |
| 527 | if (0 != ensure_path_unmounted(path)) { |
| 528 | LOGE("Error while unmounting %s.\n", path); |
| 529 | return -12; |
| 530 | } |
| 531 | return format_ext2_device(device); |
| 532 | } |
| 533 | } |
| 534 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 535 | if (0 != ensure_path_mounted(path)) |
Koushik K. Dutta | 3f99539 | 2010-03-30 23:29:43 -0700 | [diff] [blame] | 536 | { |
| 537 | ui_print("Error mounting %s!\n", path); |
Koushik Dutta | cd44ab9 | 2010-06-23 00:02:14 -0700 | [diff] [blame] | 538 | ui_print("Skipping format...\n"); |
| 539 | return 0; |
Koushik K. Dutta | 3f99539 | 2010-03-30 23:29:43 -0700 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | static char tmp[PATH_MAX]; |
Koushik Dutta | 5082299 | 2011-06-08 19:03:27 -0700 | [diff] [blame] | 543 | if (strcmp(path, "/data") == 0) { |
| 544 | sprintf(tmp, "cd /data ; for f in $(ls -a | grep -v ^media$); do rm -rf $f; done"); |
| 545 | __system(tmp); |
| 546 | } |
| 547 | else { |
| 548 | sprintf(tmp, "rm -rf %s/*", path); |
| 549 | __system(tmp); |
| 550 | sprintf(tmp, "rm -rf %s/.*", path); |
| 551 | __system(tmp); |
| 552 | } |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 553 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 554 | ensure_path_unmounted(path); |
Koushik K. Dutta | 3f99539 | 2010-03-30 23:29:43 -0700 | [diff] [blame] | 555 | return 0; |
| 556 | } |
| 557 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 558 | //#define MOUNTABLE_COUNT 5 |
| 559 | //#define DEVICE_COUNT 4 |
| 560 | //#define MMC_COUNT 2 |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 561 | |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 562 | typedef struct { |
| 563 | char mount[255]; |
| 564 | char unmount[255]; |
| 565 | Volume* v; |
| 566 | } MountMenuEntry; |
| 567 | |
| 568 | typedef struct { |
| 569 | char txt[255]; |
| 570 | Volume* v; |
| 571 | } FormatMenuEntry; |
| 572 | |
Steve Kondik | 0d87851 | 2011-04-09 01:41:45 -0400 | [diff] [blame] | 573 | int is_safe_to_format(char* name) |
| 574 | { |
Brandon Bennett | 9ad8ba2 | 2011-05-07 23:42:58 -0600 | [diff] [blame] | 575 | char str[255]; |
| 576 | char* partition; |
j_r0dd | 14d9e75 | 2011-06-09 18:37:28 -0400 | [diff] [blame] | 577 | property_get("ro.cwm.forbid_format", str, "/misc,/radio,/bootloader,/recovery,/efs"); |
Brandon Bennett | 9ad8ba2 | 2011-05-07 23:42:58 -0600 | [diff] [blame] | 578 | |
| 579 | partition = strtok(str, ", "); |
| 580 | while (partition != NULL) { |
| 581 | if (strcmp(name, partition) == 0) { |
| 582 | return 0; |
| 583 | } |
| 584 | partition = strtok(NULL, ", "); |
| 585 | } |
| 586 | |
| 587 | return 1; |
Steve Kondik | 0d87851 | 2011-04-09 01:41:45 -0400 | [diff] [blame] | 588 | } |
| 589 | |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 590 | void show_partition_menu() |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 591 | { |
Koushik Dutta | ceddcd5 | 2010-08-23 16:13:14 -0700 | [diff] [blame] | 592 | static char* headers[] = { "Mounts and Storage Menu", |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 593 | "", |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 594 | NULL |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 595 | }; |
| 596 | |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 597 | static MountMenuEntry* mount_menue = NULL; |
| 598 | static FormatMenuEntry* format_menue = NULL; |
| 599 | |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 600 | typedef char* string; |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 601 | |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 602 | int i, mountable_volumes, formatable_volumes; |
| 603 | int num_volumes; |
| 604 | Volume* device_volumes; |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 605 | |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 606 | num_volumes = get_num_volumes(); |
| 607 | device_volumes = get_device_volumes(); |
| 608 | |
| 609 | string options[255]; |
| 610 | |
| 611 | if(!device_volumes) |
| 612 | return; |
| 613 | |
| 614 | mountable_volumes = 0; |
| 615 | formatable_volumes = 0; |
| 616 | |
| 617 | mount_menue = malloc(num_volumes * sizeof(MountMenuEntry)); |
| 618 | format_menue = malloc(num_volumes * sizeof(FormatMenuEntry)); |
| 619 | |
| 620 | for (i = 0; i < num_volumes; ++i) { |
| 621 | Volume* v = &device_volumes[i]; |
Koushik Dutta | 67fa0c3 | 2011-03-17 11:37:21 -0700 | [diff] [blame] | 622 | 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] | 623 | { |
| 624 | sprintf(&mount_menue[mountable_volumes].mount, "mount %s", v->mount_point); |
| 625 | sprintf(&mount_menue[mountable_volumes].unmount, "unmount %s", v->mount_point); |
| 626 | mount_menue[mountable_volumes].v = &device_volumes[i]; |
| 627 | ++mountable_volumes; |
Steve Kondik | 0d87851 | 2011-04-09 01:41:45 -0400 | [diff] [blame] | 628 | if (is_safe_to_format(v->mount_point)) { |
| 629 | sprintf(&format_menue[formatable_volumes].txt, "format %s", v->mount_point); |
| 630 | format_menue[formatable_volumes].v = &device_volumes[i]; |
| 631 | ++formatable_volumes; |
| 632 | } |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 633 | } |
Steve Kondik | 0d87851 | 2011-04-09 01:41:45 -0400 | [diff] [blame] | 634 | 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] | 635 | { |
| 636 | sprintf(&format_menue[formatable_volumes].txt, "format %s", v->mount_point); |
| 637 | format_menue[formatable_volumes].v = &device_volumes[i]; |
| 638 | ++formatable_volumes; |
| 639 | } |
| 640 | } |
| 641 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 642 | |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 643 | static char* confirm_format = "Confirm format?"; |
Koushik Dutta | ecd32fa | 2010-07-14 18:38:02 -0700 | [diff] [blame] | 644 | static char* confirm = "Yes - Format"; |
wjb | cea6eba | 2011-04-30 21:04:04 -0400 | [diff] [blame] | 645 | char confirm_string[255]; |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 646 | |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 647 | for (;;) |
| 648 | { |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 649 | |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 650 | for (i = 0; i < mountable_volumes; i++) |
| 651 | { |
| 652 | MountMenuEntry* e = &mount_menue[i]; |
| 653 | Volume* v = e->v; |
| 654 | if(is_path_mounted(v->mount_point)) |
| 655 | options[i] = e->unmount; |
| 656 | else |
| 657 | options[i] = e->mount; |
| 658 | } |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 659 | |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 660 | for (i = 0; i < formatable_volumes; i++) |
| 661 | { |
| 662 | FormatMenuEntry* e = &format_menue[i]; |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 663 | |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 664 | options[mountable_volumes+i] = e->txt; |
| 665 | } |
| 666 | |
| 667 | options[mountable_volumes+formatable_volumes] = "mount USB storage"; |
| 668 | options[mountable_volumes+formatable_volumes + 1] = NULL; |
| 669 | |
| 670 | int chosen_item = get_menu_selection(headers, &options, 0, 0); |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 671 | if (chosen_item == GO_BACK) |
| 672 | break; |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 673 | if (chosen_item == (mountable_volumes+formatable_volumes)) |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 674 | { |
| 675 | show_mount_usb_storage_menu(); |
| 676 | } |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 677 | else if (chosen_item < mountable_volumes) |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 678 | { |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 679 | MountMenuEntry* e = &mount_menue[chosen_item]; |
| 680 | Volume* v = e->v; |
| 681 | |
| 682 | if (is_path_mounted(v->mount_point)) |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 683 | { |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 684 | if (0 != ensure_path_unmounted(v->mount_point)) |
| 685 | ui_print("Error unmounting %s!\n", v->mount_point); |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 686 | } |
| 687 | else |
| 688 | { |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 689 | if (0 != ensure_path_mounted(v->mount_point)) |
| 690 | ui_print("Error mounting %s!\n", v->mount_point); |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 691 | } |
| 692 | } |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 693 | else if (chosen_item < (mountable_volumes + formatable_volumes)) |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 694 | { |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 695 | chosen_item = chosen_item - mountable_volumes; |
| 696 | FormatMenuEntry* e = &format_menue[chosen_item]; |
| 697 | Volume* v = e->v; |
| 698 | |
wjb | cea6eba | 2011-04-30 21:04:04 -0400 | [diff] [blame] | 699 | sprintf(confirm_string, "%s - %s", v->mount_point, confirm_format); |
| 700 | |
| 701 | if (!confirm_selection(confirm_string, confirm)) |
Koushik K. Dutta | 16f0b49 | 2010-03-19 14:37:11 -0700 | [diff] [blame] | 702 | continue; |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 703 | ui_print("Formatting %s...\n", v->mount_point); |
| 704 | if (0 != format_volume(v->mount_point)) |
| 705 | ui_print("Error formatting %s!\n", v->mount_point); |
Koushik K. Dutta | 3f99539 | 2010-03-30 23:29:43 -0700 | [diff] [blame] | 706 | else |
| 707 | ui_print("Done.\n"); |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 708 | } |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 709 | } |
Kolja Dummann | 92796ec | 2011-02-13 20:59:30 +0100 | [diff] [blame] | 710 | |
| 711 | free(mount_menue); |
| 712 | free(format_menue); |
| 713 | |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 714 | } |
| 715 | |
Koushik K. Dutta | 72a1db6 | 2010-03-07 14:10:26 -0800 | [diff] [blame] | 716 | #define EXTENDEDCOMMAND_SCRIPT "/cache/recovery/extendedcommand" |
| 717 | |
| 718 | int extendedcommand_file_exists() |
Koushik K. Dutta | f68aaaf | 2010-03-07 13:39:21 -0800 | [diff] [blame] | 719 | { |
Koushik K. Dutta | f68aaaf | 2010-03-07 13:39:21 -0800 | [diff] [blame] | 720 | struct stat file_info; |
Koushik K. Dutta | 72a1db6 | 2010-03-07 14:10:26 -0800 | [diff] [blame] | 721 | return 0 == stat(EXTENDEDCOMMAND_SCRIPT, &file_info); |
| 722 | } |
| 723 | |
Koushik Dutta | bec0995 | 2010-12-19 20:37:57 -0800 | [diff] [blame] | 724 | int edify_main(int argc, char** argv) { |
| 725 | load_volume_table(); |
| 726 | process_volumes(); |
| 727 | RegisterBuiltins(); |
| 728 | RegisterRecoveryHooks(); |
| 729 | FinishRegistration(); |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 730 | |
Koushik Dutta | bec0995 | 2010-12-19 20:37:57 -0800 | [diff] [blame] | 731 | if (argc != 2) { |
| 732 | printf("edify <filename>\n"); |
Koushik K. Dutta | f68aaaf | 2010-03-07 13:39:21 -0800 | [diff] [blame] | 733 | return 1; |
Koushik K. Dutta | f68aaaf | 2010-03-07 13:39:21 -0800 | [diff] [blame] | 734 | } |
| 735 | |
Koushik Dutta | bec0995 | 2010-12-19 20:37:57 -0800 | [diff] [blame] | 736 | FILE* f = fopen(argv[1], "r"); |
| 737 | if (f == NULL) { |
| 738 | printf("%s: %s: No such file or directory\n", argv[0], argv[1]); |
| 739 | return 1; |
| 740 | } |
| 741 | char buffer[8192]; |
| 742 | int size = fread(buffer, 1, 8191, f); |
| 743 | fclose(f); |
| 744 | buffer[size] = '\0'; |
| 745 | |
| 746 | Expr* root; |
| 747 | int error_count = 0; |
| 748 | yy_scan_bytes(buffer, size); |
| 749 | int error = yyparse(&root, &error_count); |
| 750 | printf("parse returned %d; %d errors encountered\n", error, error_count); |
| 751 | if (error == 0 || error_count > 0) { |
| 752 | |
| 753 | //ExprDump(0, root, buffer); |
| 754 | |
| 755 | State state; |
| 756 | state.cookie = NULL; |
| 757 | state.script = buffer; |
| 758 | state.errmsg = NULL; |
| 759 | |
| 760 | char* result = Evaluate(&state, root); |
| 761 | if (result == NULL) { |
| 762 | printf("result was NULL, message is: %s\n", |
| 763 | (state.errmsg == NULL ? "(NULL)" : state.errmsg)); |
| 764 | free(state.errmsg); |
| 765 | } else { |
| 766 | printf("result is [%s]\n", result); |
Koushik K. Dutta | f68aaaf | 2010-03-07 13:39:21 -0800 | [diff] [blame] | 767 | } |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 768 | } |
Koushik Dutta | bec0995 | 2010-12-19 20:37:57 -0800 | [diff] [blame] | 769 | return 0; |
Koushik K. Dutta | f68aaaf | 2010-03-07 13:39:21 -0800 | [diff] [blame] | 770 | } |
Koushik K. Dutta | 72a1db6 | 2010-03-07 14:10:26 -0800 | [diff] [blame] | 771 | |
Koushik K. Dutta | 6771aca | 2010-04-03 23:28:39 -0700 | [diff] [blame] | 772 | int run_script(char* filename) |
Koushik K. Dutta | 3836f72 | 2010-03-11 22:17:43 -0800 | [diff] [blame] | 773 | { |
| 774 | struct stat file_info; |
| 775 | if (0 != stat(filename, &file_info)) { |
| 776 | printf("Error executing stat on file: %s\n", filename); |
| 777 | return 1; |
| 778 | } |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 779 | |
Koushik K. Dutta | 3836f72 | 2010-03-11 22:17:43 -0800 | [diff] [blame] | 780 | int script_len = file_info.st_size; |
Koushik K. Dutta | 707fa6d | 2010-03-23 11:44:33 -0700 | [diff] [blame] | 781 | char* script_data = (char*)malloc(script_len + 1); |
Koushik K. Dutta | 3836f72 | 2010-03-11 22:17:43 -0800 | [diff] [blame] | 782 | FILE *file = fopen(filename, "rb"); |
| 783 | fread(script_data, script_len, 1, file); |
Koushik K. Dutta | 707fa6d | 2010-03-23 11:44:33 -0700 | [diff] [blame] | 784 | // supposedly not necessary, but let's be safe. |
| 785 | script_data[script_len] = '\0'; |
Koushik K. Dutta | 3836f72 | 2010-03-11 22:17:43 -0800 | [diff] [blame] | 786 | fclose(file); |
Koushik Dutta | e25908b | 2010-06-21 08:16:19 -0700 | [diff] [blame] | 787 | LOGI("Running script:\n"); |
| 788 | LOGI("\n%s\n", script_data); |
Koushik K. Dutta | 3836f72 | 2010-03-11 22:17:43 -0800 | [diff] [blame] | 789 | |
Koushik K. Dutta | f3534d0 | 2010-04-18 18:06:24 -0700 | [diff] [blame] | 790 | int ret = run_script_from_buffer(script_data, script_len, filename); |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 791 | free(script_data); |
| 792 | return ret; |
Koushik K. Dutta | 3836f72 | 2010-03-11 22:17:43 -0800 | [diff] [blame] | 793 | } |
| 794 | |
Koushik K. Dutta | 72a1db6 | 2010-03-07 14:10:26 -0800 | [diff] [blame] | 795 | int run_and_remove_extendedcommand() |
| 796 | { |
Koushik K. Dutta | 6771aca | 2010-04-03 23:28:39 -0700 | [diff] [blame] | 797 | char tmp[PATH_MAX]; |
| 798 | sprintf(tmp, "cp %s /tmp/%s", EXTENDEDCOMMAND_SCRIPT, basename(EXTENDEDCOMMAND_SCRIPT)); |
| 799 | __system(tmp); |
| 800 | remove(EXTENDEDCOMMAND_SCRIPT); |
Koushik K. Dutta | 3a25cf5 | 2010-03-08 19:22:41 -0800 | [diff] [blame] | 801 | int i = 0; |
| 802 | for (i = 20; i > 0; i--) { |
| 803 | ui_print("Waiting for SD Card to mount (%ds)\n", i); |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 804 | if (ensure_path_mounted("/sdcard") == 0) { |
Koushik K. Dutta | 3a25cf5 | 2010-03-08 19:22:41 -0800 | [diff] [blame] | 805 | ui_print("SD Card mounted...\n"); |
| 806 | break; |
| 807 | } |
| 808 | sleep(1); |
| 809 | } |
Koushik Dutta | 92077c1 | 2010-07-15 00:10:08 -0700 | [diff] [blame] | 810 | remove("/sdcard/clockworkmod/.recoverycheckpoint"); |
Koushik K. Dutta | 3a25cf5 | 2010-03-08 19:22:41 -0800 | [diff] [blame] | 811 | if (i == 0) { |
| 812 | ui_print("Timed out waiting for SD card... continuing anyways."); |
| 813 | } |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 814 | |
Koushik Dutta | 30a937a | 2011-09-05 21:14:06 -0700 | [diff] [blame] | 815 | ui_print("Verifying SD Card marker...\n"); |
| 816 | struct stat st; |
| 817 | if (stat("/sdcard/clockworkmod/.salted_hash", &st) != 0) { |
| 818 | ui_print("SD Card marker not found...\n"); |
| 819 | if (volume_for_path("/emmc") != NULL) { |
| 820 | ui_print("Checking Internal SD Card marker...\n"); |
| 821 | ensure_path_unmounted("/sdcard"); |
| 822 | if (ensure_path_mounted_at_mount_point("/emmc", "/sdcard") != 0) { |
| 823 | ui_print("Internal SD Card marker not found... continuing anyways.\n"); |
| 824 | // unmount everything, and remount as normal |
| 825 | ensure_path_unmounted("/emmc"); |
| 826 | ensure_path_unmounted("/sdcard"); |
| 827 | |
| 828 | ensure_path_mounted("/sdcard"); |
| 829 | } |
| 830 | } |
| 831 | } |
| 832 | |
Koushik K. Dutta | 6771aca | 2010-04-03 23:28:39 -0700 | [diff] [blame] | 833 | sprintf(tmp, "/tmp/%s", basename(EXTENDEDCOMMAND_SCRIPT)); |
Koushik Dutta | 30a937a | 2011-09-05 21:14:06 -0700 | [diff] [blame] | 834 | int ret; |
| 835 | #ifdef I_AM_KOUSH |
| 836 | if (0 != (ret = before_run_script(tmp))) { |
Koushik Dutta | 81a6151 | 2011-09-22 15:10:20 -0700 | [diff] [blame] | 837 | ui_print("Error processing ROM Manager script. Please verify that you are performing the backup, restore, or ROM installation from ROM Manager v4.4.0.0 or higher.\n"); |
Koushik Dutta | 30a937a | 2011-09-05 21:14:06 -0700 | [diff] [blame] | 838 | return ret; |
| 839 | } |
| 840 | #endif |
Koushik K. Dutta | 6771aca | 2010-04-03 23:28:39 -0700 | [diff] [blame] | 841 | return run_script(tmp); |
Koushik K. Dutta | 72a1db6 | 2010-03-07 14:10:26 -0800 | [diff] [blame] | 842 | } |
| 843 | |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 844 | void show_nandroid_advanced_restore_menu() |
| 845 | { |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 846 | if (ensure_path_mounted("/sdcard") != 0) { |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 847 | LOGE ("Can't mount /sdcard\n"); |
| 848 | return; |
| 849 | } |
| 850 | |
| 851 | static char* advancedheaders[] = { "Choose an image to restore", |
| 852 | "", |
| 853 | "Choose an image to restore", |
| 854 | "first. The next menu will", |
| 855 | "you more options.", |
| 856 | "", |
| 857 | NULL |
| 858 | }; |
| 859 | |
| 860 | char* file = choose_file_menu("/sdcard/clockworkmod/backup/", NULL, advancedheaders); |
| 861 | if (file == NULL) |
| 862 | return; |
| 863 | |
| 864 | static char* headers[] = { "Nandroid Advanced Restore", |
| 865 | "", |
| 866 | NULL |
| 867 | }; |
| 868 | |
| 869 | static char* list[] = { "Restore boot", |
| 870 | "Restore system", |
| 871 | "Restore data", |
| 872 | "Restore cache", |
Koushik K. Dutta | 68b0190 | 2010-04-01 12:20:39 -0700 | [diff] [blame] | 873 | "Restore sd-ext", |
agrabren | 1f76a5d | 2010-12-29 12:15:18 -0600 | [diff] [blame] | 874 | "Restore wimax", |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 875 | NULL |
| 876 | }; |
Koushik Dutta | 5b7f34a | 2010-12-29 23:36:03 -0800 | [diff] [blame] | 877 | |
| 878 | char tmp[PATH_MAX]; |
| 879 | if (0 != get_partition_device("wimax", tmp)) { |
| 880 | // disable wimax restore option |
| 881 | list[5] = NULL; |
| 882 | } |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 883 | |
| 884 | static char* confirm_restore = "Confirm restore?"; |
| 885 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 886 | int chosen_item = get_menu_selection(headers, list, 0, 0); |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 887 | switch (chosen_item) |
| 888 | { |
| 889 | case 0: |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 890 | if (confirm_selection(confirm_restore, "Yes - Restore boot")) |
agrabren | 1f76a5d | 2010-12-29 12:15:18 -0600 | [diff] [blame] | 891 | nandroid_restore(file, 1, 0, 0, 0, 0, 0); |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 892 | break; |
| 893 | case 1: |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 894 | if (confirm_selection(confirm_restore, "Yes - Restore system")) |
agrabren | 1f76a5d | 2010-12-29 12:15:18 -0600 | [diff] [blame] | 895 | nandroid_restore(file, 0, 1, 0, 0, 0, 0); |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 896 | break; |
| 897 | case 2: |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 898 | if (confirm_selection(confirm_restore, "Yes - Restore data")) |
agrabren | 1f76a5d | 2010-12-29 12:15:18 -0600 | [diff] [blame] | 899 | nandroid_restore(file, 0, 0, 1, 0, 0, 0); |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 900 | break; |
| 901 | case 3: |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 902 | if (confirm_selection(confirm_restore, "Yes - Restore cache")) |
agrabren | 1f76a5d | 2010-12-29 12:15:18 -0600 | [diff] [blame] | 903 | nandroid_restore(file, 0, 0, 0, 1, 0, 0); |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 904 | break; |
Koushik Dutta | 2f73e58 | 2010-04-18 16:00:21 -0700 | [diff] [blame] | 905 | case 4: |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 906 | if (confirm_selection(confirm_restore, "Yes - Restore sd-ext")) |
agrabren | 1f76a5d | 2010-12-29 12:15:18 -0600 | [diff] [blame] | 907 | nandroid_restore(file, 0, 0, 0, 0, 1, 0); |
| 908 | break; |
| 909 | case 5: |
| 910 | if (confirm_selection(confirm_restore, "Yes - Restore wimax")) |
| 911 | nandroid_restore(file, 0, 0, 0, 0, 0, 1); |
Koushik Dutta | 2f73e58 | 2010-04-18 16:00:21 -0700 | [diff] [blame] | 912 | break; |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 913 | } |
| 914 | } |
| 915 | |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 916 | void show_nandroid_menu() |
| 917 | { |
| 918 | static char* headers[] = { "Nandroid", |
| 919 | "", |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 920 | NULL |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 921 | }; |
| 922 | |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 923 | static char* list[] = { "Backup", |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 924 | "Restore", |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 925 | "Advanced Restore", |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 926 | NULL |
| 927 | }; |
| 928 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 929 | int chosen_item = get_menu_selection(headers, list, 0, 0); |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 930 | switch (chosen_item) |
| 931 | { |
| 932 | case 0: |
| 933 | { |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 934 | char backup_path[PATH_MAX]; |
Koushik K. Dutta | 6a26e7c | 2010-03-27 15:26:11 -0700 | [diff] [blame] | 935 | time_t t = time(NULL); |
| 936 | struct tm *tmp = localtime(&t); |
| 937 | if (tmp == NULL) |
| 938 | { |
| 939 | struct timeval tp; |
| 940 | gettimeofday(&tp, NULL); |
| 941 | sprintf(backup_path, "/sdcard/clockworkmod/backup/%d", tp.tv_sec); |
| 942 | } |
| 943 | else |
| 944 | { |
| 945 | strftime(backup_path, sizeof(backup_path), "/sdcard/clockworkmod/backup/%F.%H.%M.%S", tmp); |
| 946 | } |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 947 | nandroid_backup(backup_path); |
| 948 | } |
| 949 | break; |
| 950 | case 1: |
| 951 | show_nandroid_restore_menu(); |
| 952 | break; |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 953 | case 2: |
| 954 | show_nandroid_advanced_restore_menu(); |
| 955 | break; |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 956 | } |
Koushik K. Dutta | a496b51 | 2010-03-19 14:51:45 -0700 | [diff] [blame] | 957 | } |
| 958 | |
Koushik Dutta | fd1579b | 2010-05-01 12:46:55 -0700 | [diff] [blame] | 959 | void wipe_battery_stats() |
| 960 | { |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 961 | ensure_path_mounted("/data"); |
Koushik Dutta | fd1579b | 2010-05-01 12:46:55 -0700 | [diff] [blame] | 962 | remove("/data/system/batterystats.bin"); |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 963 | ensure_path_unmounted("/data"); |
j_r0dd | 3f2e286 | 2011-07-10 22:48:39 -0400 | [diff] [blame] | 964 | ui_print("Battery Stats wiped.\n"); |
Koushik Dutta | fd1579b | 2010-05-01 12:46:55 -0700 | [diff] [blame] | 965 | } |
| 966 | |
Koushik K. Dutta | a496b51 | 2010-03-19 14:51:45 -0700 | [diff] [blame] | 967 | void show_advanced_menu() |
| 968 | { |
| 969 | static char* headers[] = { "Advanced and Debugging Menu", |
| 970 | "", |
| 971 | NULL |
| 972 | }; |
| 973 | |
Koushik K. Dutta | 7fe4d7b | 2010-04-06 23:04:52 -0700 | [diff] [blame] | 974 | static char* list[] = { "Reboot Recovery", |
Koushik Dutta | 49af23c | 2010-06-21 13:45:51 -0700 | [diff] [blame] | 975 | "Wipe Dalvik Cache", |
Koushik Dutta | fd1579b | 2010-05-01 12:46:55 -0700 | [diff] [blame] | 976 | "Wipe Battery Stats", |
Koushik Dutta | 598cfc7 | 2010-06-20 09:42:47 -0700 | [diff] [blame] | 977 | "Report Error", |
Koushik K. Dutta | 7fe4d7b | 2010-04-06 23:04:52 -0700 | [diff] [blame] | 978 | "Key Test", |
Tanguy Pruvot | 67d358c | 2011-06-10 20:26:44 +0200 | [diff] [blame] | 979 | "Show log", |
Koushik Dutta | e17a78d | 2010-08-29 12:35:10 -0700 | [diff] [blame] | 980 | #ifndef BOARD_HAS_SMALL_RECOVERY |
Koushik Dutta | ceddcd5 | 2010-08-23 16:13:14 -0700 | [diff] [blame] | 981 | "Partition SD Card", |
| 982 | "Fix Permissions", |
Brint E. Kriebel | d352233 | 2010-12-11 20:52:06 -0700 | [diff] [blame] | 983 | #ifdef BOARD_HAS_SDCARD_INTERNAL |
| 984 | "Partition Internal SD Card", |
| 985 | #endif |
Koushik Dutta | e17a78d | 2010-08-29 12:35:10 -0700 | [diff] [blame] | 986 | #endif |
Koushik K. Dutta | a496b51 | 2010-03-19 14:51:45 -0700 | [diff] [blame] | 987 | NULL |
| 988 | }; |
| 989 | |
| 990 | for (;;) |
| 991 | { |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 992 | int chosen_item = get_menu_selection(headers, list, 0, 0); |
Koushik K. Dutta | a496b51 | 2010-03-19 14:51:45 -0700 | [diff] [blame] | 993 | if (chosen_item == GO_BACK) |
| 994 | break; |
| 995 | switch (chosen_item) |
| 996 | { |
| 997 | case 0: |
Tanguy Pruvot | 67d358c | 2011-06-10 20:26:44 +0200 | [diff] [blame] | 998 | { |
Austen Dicken | 7126ef4 | 2011-06-14 15:47:40 -0500 | [diff] [blame] | 999 | reboot_wrapper("recovery"); |
Koushik K. Dutta | 7fe4d7b | 2010-04-06 23:04:52 -0700 | [diff] [blame] | 1000 | break; |
Tanguy Pruvot | 67d358c | 2011-06-10 20:26:44 +0200 | [diff] [blame] | 1001 | } |
Koushik K. Dutta | 7fe4d7b | 2010-04-06 23:04:52 -0700 | [diff] [blame] | 1002 | case 1: |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 1003 | { |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 1004 | if (0 != ensure_path_mounted("/data")) |
Koushik Dutta | 49af23c | 2010-06-21 13:45:51 -0700 | [diff] [blame] | 1005 | break; |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 1006 | ensure_path_mounted("/sd-ext"); |
| 1007 | ensure_path_mounted("/cache"); |
Koushik Dutta | 6c7745d | 2010-08-07 12:17:13 -0700 | [diff] [blame] | 1008 | if (confirm_selection( "Confirm wipe?", "Yes - Wipe Dalvik Cache")) { |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 1009 | __system("rm -r /data/dalvik-cache"); |
Koushik Dutta | 6c7745d | 2010-08-07 12:17:13 -0700 | [diff] [blame] | 1010 | __system("rm -r /cache/dalvik-cache"); |
| 1011 | __system("rm -r /sd-ext/dalvik-cache"); |
Koushik Dutta | 30a937a | 2011-09-05 21:14:06 -0700 | [diff] [blame] | 1012 | ui_print("Dalvik Cache wiped.\n"); |
Koushik Dutta | 6c7745d | 2010-08-07 12:17:13 -0700 | [diff] [blame] | 1013 | } |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 1014 | ensure_path_unmounted("/data"); |
Koushik Dutta | fd1579b | 2010-05-01 12:46:55 -0700 | [diff] [blame] | 1015 | break; |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 1016 | } |
Koushik Dutta | fd1579b | 2010-05-01 12:46:55 -0700 | [diff] [blame] | 1017 | case 2: |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 1018 | { |
| 1019 | if (confirm_selection( "Confirm wipe?", "Yes - Wipe Battery Stats")) |
| 1020 | wipe_battery_stats(); |
Koushik Dutta | 598cfc7 | 2010-06-20 09:42:47 -0700 | [diff] [blame] | 1021 | break; |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 1022 | } |
Koushik Dutta | 598cfc7 | 2010-06-20 09:42:47 -0700 | [diff] [blame] | 1023 | case 3: |
Koushik Dutta | 49af23c | 2010-06-21 13:45:51 -0700 | [diff] [blame] | 1024 | handle_failure(1); |
| 1025 | break; |
| 1026 | case 4: |
Koushik K. Dutta | a496b51 | 2010-03-19 14:51:45 -0700 | [diff] [blame] | 1027 | { |
| 1028 | ui_print("Outputting key codes.\n"); |
| 1029 | ui_print("Go back to end debugging.\n"); |
| 1030 | int key; |
| 1031 | int action; |
| 1032 | do |
| 1033 | { |
| 1034 | key = ui_wait_key(); |
| 1035 | action = device_handle_key(key, 1); |
| 1036 | ui_print("Key: %d\n", key); |
| 1037 | } |
| 1038 | while (action != GO_BACK); |
Koushik Dutta | 56606a2 | 2010-08-23 16:15:33 -0700 | [diff] [blame] | 1039 | break; |
Koushik K. Dutta | a496b51 | 2010-03-19 14:51:45 -0700 | [diff] [blame] | 1040 | } |
Koushik Dutta | f0e31b8 | 2010-08-17 16:55:38 -0700 | [diff] [blame] | 1041 | case 5: |
| 1042 | { |
Tanguy Pruvot | 67d358c | 2011-06-10 20:26:44 +0200 | [diff] [blame] | 1043 | ui_printlogtail(12); |
| 1044 | break; |
| 1045 | } |
| 1046 | case 6: |
| 1047 | { |
Koushik Dutta | ceddcd5 | 2010-08-23 16:13:14 -0700 | [diff] [blame] | 1048 | static char* ext_sizes[] = { "128M", |
| 1049 | "256M", |
| 1050 | "512M", |
| 1051 | "1024M", |
Brint E. Kriebel | 0b23331 | 2010-11-14 15:31:17 -0700 | [diff] [blame] | 1052 | "2048M", |
| 1053 | "4096M", |
Koushik Dutta | ceddcd5 | 2010-08-23 16:13:14 -0700 | [diff] [blame] | 1054 | NULL }; |
| 1055 | |
| 1056 | static char* swap_sizes[] = { "0M", |
| 1057 | "32M", |
| 1058 | "64M", |
| 1059 | "128M", |
| 1060 | "256M", |
| 1061 | NULL }; |
| 1062 | |
| 1063 | static char* ext_headers[] = { "Ext Size", "", NULL }; |
| 1064 | static char* swap_headers[] = { "Swap Size", "", NULL }; |
| 1065 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 1066 | int ext_size = get_menu_selection(ext_headers, ext_sizes, 0, 0); |
Koushik Dutta | ceddcd5 | 2010-08-23 16:13:14 -0700 | [diff] [blame] | 1067 | if (ext_size == GO_BACK) |
| 1068 | continue; |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 1069 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 1070 | int swap_size = get_menu_selection(swap_headers, swap_sizes, 0, 0); |
Koushik Dutta | ceddcd5 | 2010-08-23 16:13:14 -0700 | [diff] [blame] | 1071 | if (swap_size == GO_BACK) |
| 1072 | continue; |
| 1073 | |
| 1074 | char sddevice[256]; |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 1075 | Volume *vol = volume_for_path("/sdcard"); |
| 1076 | strcpy(sddevice, vol->device); |
Koushik Dutta | ceddcd5 | 2010-08-23 16:13:14 -0700 | [diff] [blame] | 1077 | // we only want the mmcblk, not the partition |
| 1078 | sddevice[strlen("/dev/block/mmcblkX")] = NULL; |
| 1079 | char cmd[PATH_MAX]; |
| 1080 | setenv("SDPATH", sddevice, 1); |
| 1081 | sprintf(cmd, "sdparted -es %s -ss %s -efs ext3 -s", ext_sizes[ext_size], swap_sizes[swap_size]); |
| 1082 | ui_print("Partitioning SD Card... please wait...\n"); |
| 1083 | if (0 == __system(cmd)) |
| 1084 | ui_print("Done!\n"); |
| 1085 | else |
| 1086 | 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] | 1087 | break; |
Koushik Dutta | f0e31b8 | 2010-08-17 16:55:38 -0700 | [diff] [blame] | 1088 | } |
Tanguy Pruvot | 67d358c | 2011-06-10 20:26:44 +0200 | [diff] [blame] | 1089 | case 7: |
Koushik Dutta | 38e8b2b | 2010-08-17 22:21:53 -0700 | [diff] [blame] | 1090 | { |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 1091 | ensure_path_mounted("/system"); |
| 1092 | ensure_path_mounted("/data"); |
Koushik Dutta | ceddcd5 | 2010-08-23 16:13:14 -0700 | [diff] [blame] | 1093 | ui_print("Fixing permissions...\n"); |
| 1094 | __system("fix_permissions"); |
| 1095 | ui_print("Done!\n"); |
Koushik Dutta | 56606a2 | 2010-08-23 16:15:33 -0700 | [diff] [blame] | 1096 | break; |
Koushik Dutta | 38e8b2b | 2010-08-17 22:21:53 -0700 | [diff] [blame] | 1097 | } |
Tanguy Pruvot | 67d358c | 2011-06-10 20:26:44 +0200 | [diff] [blame] | 1098 | case 8: |
Brint E. Kriebel | d352233 | 2010-12-11 20:52:06 -0700 | [diff] [blame] | 1099 | { |
| 1100 | static char* ext_sizes[] = { "128M", |
| 1101 | "256M", |
| 1102 | "512M", |
| 1103 | "1024M", |
| 1104 | "2048M", |
| 1105 | "4096M", |
| 1106 | NULL }; |
| 1107 | |
| 1108 | static char* swap_sizes[] = { "0M", |
| 1109 | "32M", |
| 1110 | "64M", |
| 1111 | "128M", |
| 1112 | "256M", |
| 1113 | NULL }; |
| 1114 | |
| 1115 | static char* ext_headers[] = { "Data Size", "", NULL }; |
| 1116 | static char* swap_headers[] = { "Swap Size", "", NULL }; |
| 1117 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 1118 | 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] | 1119 | if (ext_size == GO_BACK) |
| 1120 | continue; |
| 1121 | |
| 1122 | int swap_size = 0; |
| 1123 | if (swap_size == GO_BACK) |
| 1124 | continue; |
| 1125 | |
| 1126 | char sddevice[256]; |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 1127 | Volume *vol = volume_for_path("/emmc"); |
| 1128 | strcpy(sddevice, vol->device); |
Brint E. Kriebel | d352233 | 2010-12-11 20:52:06 -0700 | [diff] [blame] | 1129 | // we only want the mmcblk, not the partition |
| 1130 | sddevice[strlen("/dev/block/mmcblkX")] = NULL; |
| 1131 | char cmd[PATH_MAX]; |
| 1132 | setenv("SDPATH", sddevice, 1); |
| 1133 | sprintf(cmd, "sdparted -es %s -ss %s -efs ext3 -s", ext_sizes[ext_size], swap_sizes[swap_size]); |
| 1134 | ui_print("Partitioning Internal SD Card... please wait...\n"); |
| 1135 | if (0 == __system(cmd)) |
| 1136 | ui_print("Done!\n"); |
| 1137 | else |
| 1138 | ui_print("An error occured while partitioning your Internal SD Card. Please see /tmp/recovery.log for more details.\n"); |
| 1139 | break; |
| 1140 | } |
Koushik K. Dutta | a496b51 | 2010-03-19 14:51:45 -0700 | [diff] [blame] | 1141 | } |
| 1142 | } |
Koushik Dutta | 14239d2 | 2010-06-14 15:02:48 -0700 | [diff] [blame] | 1143 | } |
| 1144 | |
Koushik Dutta | b643e4f | 2010-12-18 18:39:39 -0800 | [diff] [blame] | 1145 | void write_fstab_root(char *path, FILE *file) |
Koushik Dutta | 14239d2 | 2010-06-14 15:02:48 -0700 | [diff] [blame] | 1146 | { |
Koushik Dutta | b643e4f | 2010-12-18 18:39:39 -0800 | [diff] [blame] | 1147 | Volume *vol = volume_for_path(path); |
| 1148 | if (vol == NULL) { |
Koushik Dutta | 9765a03 | 2010-12-18 21:31:02 -0800 | [diff] [blame] | 1149 | 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] | 1150 | return; |
Koushik Dutta | a6522b3 | 2010-06-20 13:16:06 -0700 | [diff] [blame] | 1151 | } |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 1152 | |
Koushik Dutta | 31b7411 | 2010-12-20 08:49:20 -0800 | [diff] [blame] | 1153 | char device[200]; |
| 1154 | if (vol->device[0] != '/') |
| 1155 | get_partition_device(vol->device, device); |
| 1156 | else |
| 1157 | strcpy(device, vol->device); |
| 1158 | |
| 1159 | fprintf(file, "%s ", device); |
Koushik Dutta | b643e4f | 2010-12-18 18:39:39 -0800 | [diff] [blame] | 1160 | fprintf(file, "%s ", path); |
Koushik Dutta | ab1f8b8 | 2011-02-27 17:28:30 -0800 | [diff] [blame] | 1161 | // special case rfs cause auto will mount it as vfat on samsung. |
| 1162 | 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] | 1163 | } |
| 1164 | |
| 1165 | void create_fstab() |
| 1166 | { |
Koushik Dutta | b643e4f | 2010-12-18 18:39:39 -0800 | [diff] [blame] | 1167 | struct stat info; |
Koushik Dutta | cd44ab9 | 2010-06-23 00:02:14 -0700 | [diff] [blame] | 1168 | __system("touch /etc/mtab"); |
Koushik Dutta | 14239d2 | 2010-06-14 15:02:48 -0700 | [diff] [blame] | 1169 | FILE *file = fopen("/etc/fstab", "w"); |
Koushik Dutta | a6522b3 | 2010-06-20 13:16:06 -0700 | [diff] [blame] | 1170 | if (file == NULL) { |
Koushik Dutta | b643e4f | 2010-12-18 18:39:39 -0800 | [diff] [blame] | 1171 | LOGW("Unable to create /etc/fstab!\n"); |
Koushik Dutta | 598cfc7 | 2010-06-20 09:42:47 -0700 | [diff] [blame] | 1172 | return; |
Koushik Dutta | a6522b3 | 2010-06-20 13:16:06 -0700 | [diff] [blame] | 1173 | } |
Brandon Bennett | 6d0604b | 2011-01-28 13:39:10 -0700 | [diff] [blame] | 1174 | Volume *vol = volume_for_path("/boot"); |
Koushik Dutta | a9f0e7f | 2011-02-12 10:21:11 -0800 | [diff] [blame] | 1175 | 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] | 1176 | write_fstab_root("/boot", file); |
Koushik Dutta | b643e4f | 2010-12-18 18:39:39 -0800 | [diff] [blame] | 1177 | write_fstab_root("/cache", file); |
| 1178 | write_fstab_root("/data", file); |
Koushik Dutta | 5460f0c | 2010-12-18 22:37:49 -0800 | [diff] [blame] | 1179 | if (has_datadata()) { |
| 1180 | write_fstab_root("/datadata", file); |
| 1181 | } |
Koushik Dutta | b643e4f | 2010-12-18 18:39:39 -0800 | [diff] [blame] | 1182 | write_fstab_root("/system", file); |
| 1183 | write_fstab_root("/sdcard", file); |
| 1184 | write_fstab_root("/sd-ext", file); |
Koushik Dutta | 14239d2 | 2010-06-14 15:02:48 -0700 | [diff] [blame] | 1185 | fclose(file); |
Koushik Dutta | 9765a03 | 2010-12-18 21:31:02 -0800 | [diff] [blame] | 1186 | LOGI("Completed outputting fstab.\n"); |
Koushik Dutta | 598cfc7 | 2010-06-20 09:42:47 -0700 | [diff] [blame] | 1187 | } |
| 1188 | |
Koushik Dutta | 4196e0f | 2010-12-19 03:38:29 -0800 | [diff] [blame] | 1189 | int bml_check_volume(const char *path) { |
| 1190 | ui_print("Checking %s...\n", path); |
| 1191 | ensure_path_unmounted(path); |
| 1192 | if (0 == ensure_path_mounted(path)) { |
| 1193 | ensure_path_unmounted(path); |
| 1194 | return 0; |
| 1195 | } |
| 1196 | |
| 1197 | Volume *vol = volume_for_path(path); |
| 1198 | if (vol == NULL) { |
| 1199 | LOGE("Unable process volume! Skipping...\n"); |
| 1200 | return 0; |
| 1201 | } |
| 1202 | |
Koushik Dutta | bec0995 | 2010-12-19 20:37:57 -0800 | [diff] [blame] | 1203 | ui_print("%s may be rfs. Checking...\n", path); |
Koushik Dutta | 4196e0f | 2010-12-19 03:38:29 -0800 | [diff] [blame] | 1204 | char tmp[PATH_MAX]; |
| 1205 | sprintf(tmp, "mount -t rfs %s %s", vol->device, path); |
| 1206 | int ret = __system(tmp); |
| 1207 | printf("%d\n", ret); |
| 1208 | return ret == 0 ? 1 : 0; |
| 1209 | } |
| 1210 | |
| 1211 | void process_volumes() { |
| 1212 | create_fstab(); |
Koushik Dutta | 38a9214 | 2011-06-10 09:45:52 -0700 | [diff] [blame] | 1213 | |
| 1214 | if (is_data_media()) { |
| 1215 | setup_data_media(); |
Koushik Dutta | 94caefe | 2011-06-10 09:17:30 -0700 | [diff] [blame] | 1216 | } |
| 1217 | |
Koushik Dutta | e8bc2c8 | 2011-02-27 14:00:19 -0800 | [diff] [blame] | 1218 | return; |
| 1219 | |
| 1220 | // dead code. |
Koushik Dutta | 4196e0f | 2010-12-19 03:38:29 -0800 | [diff] [blame] | 1221 | if (device_flash_type() != BML) |
| 1222 | return; |
| 1223 | |
| 1224 | ui_print("Checking for ext4 partitions...\n"); |
| 1225 | int ret = 0; |
| 1226 | ret = bml_check_volume("/system"); |
| 1227 | ret |= bml_check_volume("/data"); |
| 1228 | if (has_datadata()) |
| 1229 | ret |= bml_check_volume("/datadata"); |
| 1230 | ret |= bml_check_volume("/cache"); |
| 1231 | |
| 1232 | if (ret == 0) { |
| 1233 | ui_print("Done!\n"); |
| 1234 | return; |
| 1235 | } |
| 1236 | |
Koushik Dutta | 745b5ff | 2010-12-21 00:58:43 -0800 | [diff] [blame] | 1237 | char backup_path[PATH_MAX]; |
| 1238 | time_t t = time(NULL); |
| 1239 | char backup_name[PATH_MAX]; |
| 1240 | struct timeval tp; |
| 1241 | gettimeofday(&tp, NULL); |
| 1242 | sprintf(backup_name, "before-ext4-convert-%d", tp.tv_sec); |
| 1243 | sprintf(backup_path, "/sdcard/clockworkmod/backup/%s", backup_name); |
| 1244 | |
Koushik Dutta | 4196e0f | 2010-12-19 03:38:29 -0800 | [diff] [blame] | 1245 | ui_set_show_text(1); |
| 1246 | ui_print("Filesystems need to be converted to ext4.\n"); |
| 1247 | ui_print("A backup and restore will now take place.\n"); |
Koushik Dutta | bec0995 | 2010-12-19 20:37:57 -0800 | [diff] [blame] | 1248 | ui_print("If anything goes wrong, your backup will be\n"); |
Koushik Dutta | 745b5ff | 2010-12-21 00:58:43 -0800 | [diff] [blame] | 1249 | ui_print("named %s. Try restoring it\n", backup_name); |
Koushik Dutta | bec0995 | 2010-12-19 20:37:57 -0800 | [diff] [blame] | 1250 | ui_print("in case of error.\n"); |
Koushik Dutta | 4196e0f | 2010-12-19 03:38:29 -0800 | [diff] [blame] | 1251 | |
Koushik Dutta | 745b5ff | 2010-12-21 00:58:43 -0800 | [diff] [blame] | 1252 | nandroid_backup(backup_path); |
Koushik Dutta | 5b7f34a | 2010-12-29 23:36:03 -0800 | [diff] [blame] | 1253 | nandroid_restore(backup_path, 1, 1, 1, 1, 1, 0); |
Koushik Dutta | 4196e0f | 2010-12-19 03:38:29 -0800 | [diff] [blame] | 1254 | ui_set_show_text(0); |
| 1255 | } |
| 1256 | |
Koushik Dutta | 598cfc7 | 2010-06-20 09:42:47 -0700 | [diff] [blame] | 1257 | void handle_failure(int ret) |
| 1258 | { |
| 1259 | if (ret == 0) |
| 1260 | return; |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 1261 | if (0 != ensure_path_mounted("/sdcard")) |
Koushik Dutta | 598cfc7 | 2010-06-20 09:42:47 -0700 | [diff] [blame] | 1262 | return; |
Koushik Dutta | a6522b3 | 2010-06-20 13:16:06 -0700 | [diff] [blame] | 1263 | mkdir("/sdcard/clockworkmod", S_IRWXU); |
| 1264 | __system("cp /tmp/recovery.log /sdcard/clockworkmod/recovery.log"); |
Koushik Dutta | 38e8b2b | 2010-08-17 22:21:53 -0700 | [diff] [blame] | 1265 | 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] | 1266 | } |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 1267 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 1268 | int is_path_mounted(const char* path) { |
| 1269 | Volume* v = volume_for_path(path); |
| 1270 | if (v == NULL) { |
| 1271 | return 0; |
| 1272 | } |
| 1273 | if (strcmp(v->fs_type, "ramdisk") == 0) { |
| 1274 | // the ramdisk is always mounted. |
| 1275 | return 1; |
| 1276 | } |
| 1277 | |
| 1278 | int result; |
| 1279 | result = scan_mounted_volumes(); |
| 1280 | if (result < 0) { |
| 1281 | LOGE("failed to scan mounted volumes\n"); |
| 1282 | return 0; |
| 1283 | } |
| 1284 | |
| 1285 | const MountedVolume* mv = |
| 1286 | find_mounted_volume_by_mount_point(v->mount_point); |
| 1287 | if (mv) { |
| 1288 | // volume is already mounted |
| 1289 | return 1; |
| 1290 | } |
| 1291 | return 0; |
| 1292 | } |
Koushik Dutta | 5460f0c | 2010-12-18 22:37:49 -0800 | [diff] [blame] | 1293 | |
| 1294 | int has_datadata() { |
| 1295 | Volume *vol = volume_for_path("/datadata"); |
| 1296 | return vol != NULL; |
Koushik Dutta | d8e21c3 | 2011-01-04 10:46:23 -0800 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | int volume_main(int argc, char **argv) { |
| 1300 | load_volume_table(); |
| 1301 | return 0; |
| 1302 | } |