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