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