2010-02-12 06:27:06 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2010-02-12 08:43:24 +00:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/limits.h>
|
|
|
|
#include <dirent.h>
|
2010-02-25 22:51:05 +00:00
|
|
|
#include <sys/stat.h>
|
2010-02-12 08:43:24 +00:00
|
|
|
|
2010-02-25 19:39:07 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
2010-02-12 06:27:06 +00:00
|
|
|
#include "bootloader.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "cutils/properties.h"
|
|
|
|
#include "firmware.h"
|
|
|
|
#include "install.h"
|
|
|
|
#include "minui/minui.h"
|
|
|
|
#include "minzip/DirUtil.h"
|
|
|
|
#include "roots.h"
|
|
|
|
#include "recovery_ui.h"
|
|
|
|
|
2010-03-13 01:00:58 +00:00
|
|
|
#include "../../external/yaffs2/yaffs2/utils/mkyaffs2image.h"
|
2010-03-13 01:43:26 +00:00
|
|
|
#include "../../external/yaffs2/yaffs2/utils/unyaffs.h"
|
2010-03-13 01:00:58 +00:00
|
|
|
|
2010-03-13 07:21:12 +00:00
|
|
|
#include "extendedcommands.h"
|
|
|
|
#include "nandroid.h"
|
2010-12-19 01:42:31 +00:00
|
|
|
#include "mounts.h"
|
2010-12-19 05:31:02 +00:00
|
|
|
#include "flashutils/flashutils.h"
|
2010-12-20 04:37:57 +00:00
|
|
|
#include "edify/expr.h"
|
2010-03-13 07:21:12 +00:00
|
|
|
|
2010-02-12 06:27:06 +00:00
|
|
|
int signature_check_enabled = 1;
|
|
|
|
int script_assert_enabled = 1;
|
2010-12-19 01:42:31 +00:00
|
|
|
static const char *SDCARD_UPDATE_FILE = "/sdcard/update.zip";
|
2010-02-12 06:27:06 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
toggle_signature_check()
|
|
|
|
{
|
|
|
|
signature_check_enabled = !signature_check_enabled;
|
|
|
|
ui_print("Signature Check: %s\n", signature_check_enabled ? "Enabled" : "Disabled");
|
|
|
|
}
|
|
|
|
|
|
|
|
void toggle_script_asserts()
|
|
|
|
{
|
|
|
|
script_assert_enabled = !script_assert_enabled;
|
2010-02-12 08:43:24 +00:00
|
|
|
ui_print("Script Asserts: %s\n", script_assert_enabled ? "Enabled" : "Disabled");
|
|
|
|
}
|
|
|
|
|
2010-03-08 10:58:04 +00:00
|
|
|
int install_zip(const char* packagefilepath)
|
2010-02-22 05:10:25 +00:00
|
|
|
{
|
|
|
|
ui_print("\n-- Installing: %s\n", packagefilepath);
|
2010-12-19 05:31:02 +00:00
|
|
|
if (device_flash_type() == MTD) {
|
|
|
|
set_sdcard_update_bootloader_message();
|
|
|
|
}
|
2010-02-22 05:10:25 +00:00
|
|
|
int status = install_package(packagefilepath);
|
2010-04-19 01:06:24 +00:00
|
|
|
ui_reset_progress();
|
2010-02-22 05:10:25 +00:00
|
|
|
if (status != INSTALL_SUCCESS) {
|
|
|
|
ui_set_background(BACKGROUND_ICON_ERROR);
|
|
|
|
ui_print("Installation aborted.\n");
|
2010-03-08 10:58:04 +00:00
|
|
|
return 1;
|
2010-11-14 08:18:40 +00:00
|
|
|
}
|
2010-02-25 22:53:57 +00:00
|
|
|
ui_set_background(BACKGROUND_ICON_NONE);
|
2010-03-03 08:42:58 +00:00
|
|
|
ui_print("\nInstall from sdcard complete.\n");
|
2010-03-08 10:58:04 +00:00
|
|
|
return 0;
|
2010-02-22 05:10:25 +00:00
|
|
|
}
|
|
|
|
|
2010-12-19 01:42:31 +00:00
|
|
|
char* INSTALL_MENU_ITEMS[] = { "apply /sdcard/update.zip",
|
2010-02-22 05:10:25 +00:00
|
|
|
"choose zip from sdcard",
|
|
|
|
"toggle signature verification",
|
|
|
|
"toggle script asserts",
|
|
|
|
NULL };
|
|
|
|
#define ITEM_APPLY_SDCARD 0
|
|
|
|
#define ITEM_CHOOSE_ZIP 1
|
|
|
|
#define ITEM_SIG_CHECK 2
|
|
|
|
#define ITEM_ASSERTS 3
|
|
|
|
|
|
|
|
void show_install_update_menu()
|
|
|
|
{
|
|
|
|
static char* headers[] = { "Apply update from .zip file on SD card",
|
|
|
|
"",
|
2010-11-14 08:18:40 +00:00
|
|
|
NULL
|
2010-02-22 05:10:25 +00:00
|
|
|
};
|
|
|
|
for (;;)
|
|
|
|
{
|
2010-12-19 01:42:31 +00:00
|
|
|
int chosen_item = get_menu_selection(headers, INSTALL_MENU_ITEMS, 0, 0);
|
2010-02-22 05:10:25 +00:00
|
|
|
switch (chosen_item)
|
|
|
|
{
|
|
|
|
case ITEM_ASSERTS:
|
|
|
|
toggle_script_asserts();
|
|
|
|
break;
|
|
|
|
case ITEM_SIG_CHECK:
|
|
|
|
toggle_signature_check();
|
|
|
|
break;
|
|
|
|
case ITEM_APPLY_SDCARD:
|
2010-07-15 04:01:21 +00:00
|
|
|
{
|
|
|
|
if (confirm_selection("Confirm install?", "Yes - Install /sdcard/update.zip"))
|
2010-12-19 01:42:31 +00:00
|
|
|
install_zip(SDCARD_UPDATE_FILE);
|
2010-02-22 05:10:25 +00:00
|
|
|
break;
|
2010-07-15 04:01:21 +00:00
|
|
|
}
|
2010-02-22 05:10:25 +00:00
|
|
|
case ITEM_CHOOSE_ZIP:
|
|
|
|
show_choose_zip_menu();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2010-02-22 05:10:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-02 23:46:21 +00:00
|
|
|
void free_string_array(char** array)
|
|
|
|
{
|
|
|
|
if (array == NULL)
|
|
|
|
return;
|
|
|
|
char* cursor = array[0];
|
|
|
|
int i = 0;
|
|
|
|
while (cursor != NULL)
|
|
|
|
{
|
|
|
|
free(cursor);
|
|
|
|
cursor = array[++i];
|
|
|
|
}
|
|
|
|
free(array);
|
|
|
|
}
|
|
|
|
|
2010-02-25 22:51:05 +00:00
|
|
|
char** gather_files(const char* directory, const char* fileExtensionOrDirectory, int* numFiles)
|
2010-02-12 08:43:24 +00:00
|
|
|
{
|
|
|
|
char path[PATH_MAX] = "";
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *de;
|
|
|
|
int total = 0;
|
|
|
|
int i;
|
2010-03-13 07:21:12 +00:00
|
|
|
char** files = NULL;
|
2010-02-25 22:53:57 +00:00
|
|
|
int pass;
|
|
|
|
*numFiles = 0;
|
|
|
|
int dirLen = strlen(directory);
|
2010-02-12 08:43:24 +00:00
|
|
|
|
2010-02-22 05:10:25 +00:00
|
|
|
dir = opendir(directory);
|
2010-02-12 08:43:24 +00:00
|
|
|
if (dir == NULL) {
|
2010-02-22 05:10:25 +00:00
|
|
|
ui_print("Couldn't open directory.\n");
|
|
|
|
return NULL;
|
2010-02-12 08:43:24 +00:00
|
|
|
}
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2010-03-13 07:21:12 +00:00
|
|
|
int extension_length = 0;
|
2010-02-25 22:53:57 +00:00
|
|
|
if (fileExtensionOrDirectory != NULL)
|
|
|
|
extension_length = strlen(fileExtensionOrDirectory);
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2010-02-25 22:53:57 +00:00
|
|
|
int isCounting = 1;
|
|
|
|
i = 0;
|
|
|
|
for (pass = 0; pass < 2; pass++) {
|
|
|
|
while ((de=readdir(dir)) != NULL) {
|
|
|
|
// skip hidden files
|
|
|
|
if (de->d_name[0] == '.')
|
|
|
|
continue;
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2010-02-25 22:53:57 +00:00
|
|
|
// NULL means that we are gathering directories, so skip this
|
|
|
|
if (fileExtensionOrDirectory != NULL)
|
|
|
|
{
|
|
|
|
// make sure that we can have the desired extension (prevent seg fault)
|
|
|
|
if (strlen(de->d_name) < extension_length)
|
|
|
|
continue;
|
|
|
|
// compare the extension
|
|
|
|
if (strcmp(de->d_name + strlen(de->d_name) - extension_length, fileExtensionOrDirectory) != 0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct stat info;
|
2010-04-02 23:46:21 +00:00
|
|
|
char fullFileName[PATH_MAX];
|
2010-02-25 22:53:57 +00:00
|
|
|
strcpy(fullFileName, directory);
|
|
|
|
strcat(fullFileName, de->d_name);
|
|
|
|
stat(fullFileName, &info);
|
|
|
|
// make sure it is a directory
|
|
|
|
if (!(S_ISDIR(info.st_mode)))
|
|
|
|
continue;
|
|
|
|
}
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2010-02-25 22:53:57 +00:00
|
|
|
if (pass == 0)
|
|
|
|
{
|
|
|
|
total++;
|
|
|
|
continue;
|
|
|
|
}
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2010-02-25 22:51:05 +00:00
|
|
|
files[i] = (char*) malloc(dirLen + strlen(de->d_name) + 2);
|
|
|
|
strcpy(files[i], directory);
|
|
|
|
strcat(files[i], de->d_name);
|
2010-02-25 22:53:57 +00:00
|
|
|
if (fileExtensionOrDirectory == NULL)
|
|
|
|
strcat(files[i], "/");
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (pass == 1)
|
|
|
|
break;
|
|
|
|
if (total == 0)
|
|
|
|
break;
|
|
|
|
rewinddir(dir);
|
|
|
|
*numFiles = total;
|
|
|
|
files = (char**) malloc((total+1)*sizeof(char*));
|
|
|
|
files[total]=NULL;
|
|
|
|
}
|
2010-02-25 22:51:05 +00:00
|
|
|
|
|
|
|
if(closedir(dir) < 0) {
|
|
|
|
LOGE("Failed to close directory.");
|
2010-02-12 08:43:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (total==0) {
|
2010-02-22 05:10:25 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-02-12 08:43:24 +00:00
|
|
|
|
2010-12-29 18:15:18 +00:00
|
|
|
// sort the result
|
|
|
|
if (files != NULL) {
|
|
|
|
for (i = 0; i < total; i++) {
|
|
|
|
int curMax = -1;
|
|
|
|
int j;
|
|
|
|
for (j = 0; j < total - i; j++) {
|
|
|
|
if (curMax == -1 || strcmp(files[curMax], files[j]) < 0)
|
|
|
|
curMax = j;
|
|
|
|
}
|
|
|
|
char* temp = files[curMax];
|
|
|
|
files[curMax] = files[total - i - 1];
|
|
|
|
files[total - i - 1] = temp;
|
|
|
|
}
|
|
|
|
}
|
2010-07-01 07:23:25 +00:00
|
|
|
|
2010-02-25 22:53:57 +00:00
|
|
|
return files;
|
2010-02-25 22:51:05 +00:00
|
|
|
}
|
2010-02-12 08:43:24 +00:00
|
|
|
|
2010-02-25 22:51:05 +00:00
|
|
|
// pass in NULL for fileExtensionOrDirectory and you will get a directory chooser
|
|
|
|
char* choose_file_menu(const char* directory, const char* fileExtensionOrDirectory, const char* headers[])
|
|
|
|
{
|
|
|
|
char path[PATH_MAX] = "";
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *de;
|
|
|
|
int numFiles = 0;
|
2010-02-25 22:53:57 +00:00
|
|
|
int numDirs = 0;
|
2010-02-25 22:51:05 +00:00
|
|
|
int i;
|
2010-04-02 23:46:21 +00:00
|
|
|
char* return_value = NULL;
|
2010-02-25 22:53:57 +00:00
|
|
|
int dir_len = strlen(directory);
|
|
|
|
|
|
|
|
char** files = gather_files(directory, fileExtensionOrDirectory, &numFiles);
|
2010-03-13 07:21:12 +00:00
|
|
|
char** dirs = NULL;
|
2010-02-25 22:53:57 +00:00
|
|
|
if (fileExtensionOrDirectory != NULL)
|
|
|
|
dirs = gather_files(directory, NULL, &numDirs);
|
|
|
|
int total = numDirs + numFiles;
|
|
|
|
if (total == 0)
|
|
|
|
{
|
|
|
|
ui_print("No files found.\n");
|
|
|
|
}
|
2010-04-02 23:46:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
char** list = (char**) malloc((total + 1) * sizeof(char*));
|
|
|
|
list[total] = NULL;
|
2010-02-25 22:53:57 +00:00
|
|
|
|
|
|
|
|
2010-04-02 23:46:21 +00:00
|
|
|
for (i = 0 ; i < numDirs; i++)
|
|
|
|
{
|
|
|
|
list[i] = strdup(dirs[i] + dir_len);
|
|
|
|
}
|
2010-02-22 05:10:25 +00:00
|
|
|
|
2010-04-02 23:46:21 +00:00
|
|
|
for (i = 0 ; i < numFiles; i++)
|
|
|
|
{
|
|
|
|
list[numDirs + i] = strdup(files[i] + dir_len);
|
|
|
|
}
|
2010-02-22 05:10:25 +00:00
|
|
|
|
2010-04-02 23:46:21 +00:00
|
|
|
for (;;)
|
2010-02-25 22:53:57 +00:00
|
|
|
{
|
2010-12-19 01:42:31 +00:00
|
|
|
int chosen_item = get_menu_selection(headers, list, 0, 0);
|
2010-04-02 23:46:21 +00:00
|
|
|
if (chosen_item == GO_BACK)
|
|
|
|
break;
|
|
|
|
static char ret[PATH_MAX];
|
|
|
|
if (chosen_item < numDirs)
|
|
|
|
{
|
|
|
|
char* subret = choose_file_menu(dirs[chosen_item], fileExtensionOrDirectory, headers);
|
|
|
|
if (subret != NULL)
|
|
|
|
{
|
|
|
|
strcpy(ret, subret);
|
|
|
|
return_value = ret;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
2010-11-14 08:18:40 +00:00
|
|
|
}
|
2010-04-02 23:46:21 +00:00
|
|
|
strcpy(ret, files[chosen_item - numDirs]);
|
|
|
|
return_value = ret;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free_string_array(list);
|
2010-02-22 16:53:34 +00:00
|
|
|
}
|
2010-04-02 23:46:21 +00:00
|
|
|
|
|
|
|
free_string_array(files);
|
|
|
|
free_string_array(dirs);
|
|
|
|
return return_value;
|
2010-02-22 05:10:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void show_choose_zip_menu()
|
|
|
|
{
|
2010-12-19 01:42:31 +00:00
|
|
|
if (ensure_path_mounted("/sdcard") != 0) {
|
2010-02-22 05:10:25 +00:00
|
|
|
LOGE ("Can't mount /sdcard\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char* headers[] = { "Choose a zip to apply",
|
|
|
|
"",
|
2010-11-14 08:18:40 +00:00
|
|
|
NULL
|
2010-02-22 05:10:25 +00:00
|
|
|
};
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2010-02-22 05:10:25 +00:00
|
|
|
char* file = choose_file_menu("/sdcard/", ".zip", headers);
|
|
|
|
if (file == NULL)
|
|
|
|
return;
|
2010-07-15 04:01:21 +00:00
|
|
|
static char* confirm_install = "Confirm install?";
|
|
|
|
static char confirm[PATH_MAX];
|
|
|
|
sprintf(confirm, "Yes - Install %s", basename(file));
|
|
|
|
if (confirm_selection(confirm_install, confirm))
|
2010-12-19 01:42:31 +00:00
|
|
|
install_zip(file);
|
2010-02-22 05:10:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void show_nandroid_restore_menu()
|
|
|
|
{
|
2010-12-19 01:42:31 +00:00
|
|
|
if (ensure_path_mounted("/sdcard") != 0) {
|
2010-03-13 01:43:26 +00:00
|
|
|
LOGE ("Can't mount /sdcard\n");
|
2010-03-13 07:21:12 +00:00
|
|
|
return;
|
2010-03-13 01:43:26 +00:00
|
|
|
}
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2010-02-22 05:10:25 +00:00
|
|
|
static char* headers[] = { "Choose an image to restore",
|
|
|
|
"",
|
2010-11-14 08:18:40 +00:00
|
|
|
NULL
|
2010-02-22 05:10:25 +00:00
|
|
|
};
|
|
|
|
|
2010-02-25 22:51:05 +00:00
|
|
|
char* file = choose_file_menu("/sdcard/clockworkmod/backup/", NULL, headers);
|
2010-02-22 05:10:25 +00:00
|
|
|
if (file == NULL)
|
|
|
|
return;
|
2010-07-15 04:01:21 +00:00
|
|
|
|
|
|
|
if (confirm_selection("Confirm restore?", "Yes - Restore"))
|
2010-12-30 07:36:03 +00:00
|
|
|
nandroid_restore(file, 1, 1, 1, 1, 1, 0);
|
2010-02-26 22:14:23 +00:00
|
|
|
}
|
|
|
|
|
2011-02-28 00:54:09 +00:00
|
|
|
#ifndef BOARD_UMS_LUNFILE
|
|
|
|
#define BOARD_UMS_LUNFILE "/sys/devices/platform/usb_mass_storage/lun0/file"
|
|
|
|
#endif
|
|
|
|
|
2010-03-15 05:42:30 +00:00
|
|
|
void show_mount_usb_storage_menu()
|
2010-02-26 22:14:23 +00:00
|
|
|
{
|
2011-01-02 04:03:30 +00:00
|
|
|
int fd;
|
2010-12-19 01:42:31 +00:00
|
|
|
Volume *vol = volume_for_path("/sdcard");
|
2011-02-28 00:54:09 +00:00
|
|
|
if ((fd = open(BOARD_UMS_LUNFILE, O_WRONLY)) < 0) {
|
2011-01-02 04:03:30 +00:00
|
|
|
LOGE("Unable to open ums lunfile (%s)", strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-04-26 16:15:22 +00:00
|
|
|
if ((write(fd, vol->device, strlen(vol->device)) < 0) &&
|
|
|
|
(!vol->device2 || (write(fd, vol->device, strlen(vol->device2)) < 0))) {
|
2011-01-02 04:03:30 +00:00
|
|
|
LOGE("Unable to write to ums lunfile (%s)", strerror(errno));
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
2010-02-26 22:14:23 +00:00
|
|
|
static char* headers[] = { "USB Mass Storage device",
|
|
|
|
"Leaving this menu unmount",
|
|
|
|
"your SD card from your PC.",
|
|
|
|
"",
|
2010-11-14 08:18:40 +00:00
|
|
|
NULL
|
2010-02-26 22:14:23 +00:00
|
|
|
};
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2010-02-26 22:14:23 +00:00
|
|
|
static char* list[] = { "Unmount", NULL };
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2010-02-26 22:14:23 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
2010-12-19 01:42:31 +00:00
|
|
|
int chosen_item = get_menu_selection(headers, list, 0, 0);
|
2010-02-26 22:14:23 +00:00
|
|
|
if (chosen_item == GO_BACK || chosen_item == 0)
|
|
|
|
break;
|
|
|
|
}
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2011-02-28 00:54:09 +00:00
|
|
|
if ((fd = open(BOARD_UMS_LUNFILE, O_WRONLY)) < 0) {
|
2011-01-02 04:03:30 +00:00
|
|
|
LOGE("Unable to open ums lunfile (%s)", strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
char ch = 0;
|
|
|
|
if (write(fd, &ch, 1) < 0) {
|
|
|
|
LOGE("Unable to write to ums lunfile (%s)", strerror(errno));
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
2010-02-27 01:44:33 +00:00
|
|
|
}
|
2010-03-07 21:39:21 +00:00
|
|
|
|
2010-07-15 04:01:21 +00:00
|
|
|
int confirm_selection(const char* title, const char* confirm)
|
2010-03-19 21:37:11 +00:00
|
|
|
{
|
2010-08-23 23:13:14 +00:00
|
|
|
struct stat info;
|
|
|
|
if (0 == stat("/sdcard/clockworkmod/.no_confirm", &info))
|
|
|
|
return 1;
|
|
|
|
|
2010-07-15 04:01:21 +00:00
|
|
|
char* confirm_headers[] = { title, " THIS CAN NOT BE UNDONE.", "", NULL };
|
|
|
|
char* items[] = { "No",
|
|
|
|
"No",
|
|
|
|
"No",
|
|
|
|
"No",
|
|
|
|
"No",
|
|
|
|
"No",
|
|
|
|
"No",
|
2010-07-15 01:38:02 +00:00
|
|
|
confirm, //" Yes -- wipe partition", // [7
|
2010-07-15 04:01:21 +00:00
|
|
|
"No",
|
|
|
|
"No",
|
|
|
|
"No",
|
2010-03-19 21:37:11 +00:00
|
|
|
NULL };
|
|
|
|
|
2010-12-19 01:42:31 +00:00
|
|
|
int chosen_item = get_menu_selection(confirm_headers, items, 0, 0);
|
2010-03-19 21:37:11 +00:00
|
|
|
return chosen_item == 7;
|
|
|
|
}
|
|
|
|
|
2011-01-02 01:55:22 +00:00
|
|
|
#define MKE2FS_BIN "/sbin/mke2fs"
|
|
|
|
#define TUNE2FS_BIN "/sbin/tune2fs"
|
|
|
|
#define E2FSCK_BIN "/sbin/e2fsck"
|
|
|
|
|
|
|
|
int format_unknown_device(const char *device, const char* path, const char *fs_type)
|
2010-03-31 06:29:43 +00:00
|
|
|
{
|
2011-01-02 02:06:17 +00:00
|
|
|
LOGI("Formatting unknown device.\n");
|
2011-01-02 02:00:27 +00:00
|
|
|
|
2011-01-02 01:55:22 +00:00
|
|
|
// device may simply be a name, like "system"
|
|
|
|
if (device[0] != '/')
|
2011-04-17 07:49:15 +00:00
|
|
|
return erase_raw_partition(device);
|
2011-01-02 01:55:22 +00:00
|
|
|
|
2011-01-02 22:11:24 +00:00
|
|
|
// if this is SDEXT:, don't worry about it if it does not exist.
|
2010-12-19 01:42:31 +00:00
|
|
|
if (0 == strcmp(path, "/sd-ext"))
|
2010-04-19 01:06:24 +00:00
|
|
|
{
|
|
|
|
struct stat st;
|
2010-12-19 01:42:31 +00:00
|
|
|
Volume *vol = volume_for_path("/sd-ext");
|
|
|
|
if (vol == NULL || 0 != stat(vol->device, &st))
|
2010-04-19 01:06:24 +00:00
|
|
|
{
|
|
|
|
ui_print("No app2sd partition found. Skipping format of /sd-ext.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2010-04-18 23:00:21 +00:00
|
|
|
|
2011-01-02 22:11:24 +00:00
|
|
|
if (NULL != fs_type) {
|
|
|
|
if (strcmp("ext3", fs_type) == 0) {
|
|
|
|
LOGI("Formatting ext3 device.\n");
|
|
|
|
if (0 != ensure_path_unmounted(path)) {
|
|
|
|
LOGE("Error while unmounting %s.\n", path);
|
|
|
|
return -12;
|
|
|
|
}
|
|
|
|
return format_ext3_device(device);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp("ext2", fs_type) == 0) {
|
|
|
|
LOGI("Formatting ext2 device.\n");
|
|
|
|
if (0 != ensure_path_unmounted(path)) {
|
|
|
|
LOGE("Error while unmounting %s.\n", path);
|
|
|
|
return -12;
|
|
|
|
}
|
|
|
|
return format_ext2_device(device);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-19 01:42:31 +00:00
|
|
|
if (0 != ensure_path_mounted(path))
|
2010-03-31 06:29:43 +00:00
|
|
|
{
|
|
|
|
ui_print("Error mounting %s!\n", path);
|
2010-06-23 07:02:14 +00:00
|
|
|
ui_print("Skipping format...\n");
|
|
|
|
return 0;
|
2010-03-31 06:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char tmp[PATH_MAX];
|
|
|
|
sprintf(tmp, "rm -rf %s/*", path);
|
|
|
|
__system(tmp);
|
|
|
|
sprintf(tmp, "rm -rf %s/.*", path);
|
|
|
|
__system(tmp);
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2010-12-19 01:42:31 +00:00
|
|
|
ensure_path_unmounted(path);
|
2010-03-31 06:29:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-19 01:42:31 +00:00
|
|
|
//#define MOUNTABLE_COUNT 5
|
|
|
|
//#define DEVICE_COUNT 4
|
|
|
|
//#define MMC_COUNT 2
|
2010-03-15 05:42:30 +00:00
|
|
|
|
2011-02-13 19:59:30 +00:00
|
|
|
typedef struct {
|
|
|
|
char mount[255];
|
|
|
|
char unmount[255];
|
|
|
|
Volume* v;
|
|
|
|
} MountMenuEntry;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char txt[255];
|
|
|
|
Volume* v;
|
|
|
|
} FormatMenuEntry;
|
|
|
|
|
2011-04-09 05:41:45 +00:00
|
|
|
int is_safe_to_format(char* name)
|
|
|
|
{
|
2011-05-08 05:42:58 +00:00
|
|
|
char str[255];
|
|
|
|
char* partition;
|
|
|
|
property_get("ro.recovery.format_ignore_partitions", str, "/misc,/radio,/bootloader,/recovery");
|
|
|
|
|
|
|
|
partition = strtok(str, ", ");
|
|
|
|
while (partition != NULL) {
|
|
|
|
if (strcmp(name, partition) == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
partition = strtok(NULL, ", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2011-04-09 05:41:45 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 20:34:36 +00:00
|
|
|
void show_partition_menu()
|
2010-03-15 05:42:30 +00:00
|
|
|
{
|
2010-08-23 23:13:14 +00:00
|
|
|
static char* headers[] = { "Mounts and Storage Menu",
|
2010-03-15 05:42:30 +00:00
|
|
|
"",
|
2010-11-14 08:18:40 +00:00
|
|
|
NULL
|
2010-03-15 05:42:30 +00:00
|
|
|
};
|
|
|
|
|
2011-02-13 19:59:30 +00:00
|
|
|
static MountMenuEntry* mount_menue = NULL;
|
|
|
|
static FormatMenuEntry* format_menue = NULL;
|
|
|
|
|
2010-03-15 05:42:30 +00:00
|
|
|
typedef char* string;
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2011-02-13 19:59:30 +00:00
|
|
|
int i, mountable_volumes, formatable_volumes;
|
|
|
|
int num_volumes;
|
|
|
|
Volume* device_volumes;
|
|
|
|
|
|
|
|
num_volumes = get_num_volumes();
|
|
|
|
device_volumes = get_device_volumes();
|
|
|
|
|
|
|
|
string options[255];
|
|
|
|
|
|
|
|
if(!device_volumes)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mountable_volumes = 0;
|
|
|
|
formatable_volumes = 0;
|
|
|
|
|
|
|
|
mount_menue = malloc(num_volumes * sizeof(MountMenuEntry));
|
|
|
|
format_menue = malloc(num_volumes * sizeof(FormatMenuEntry));
|
|
|
|
|
|
|
|
for (i = 0; i < num_volumes; ++i) {
|
|
|
|
Volume* v = &device_volumes[i];
|
2011-03-17 18:37:21 +00:00
|
|
|
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)
|
2011-02-13 19:59:30 +00:00
|
|
|
{
|
|
|
|
sprintf(&mount_menue[mountable_volumes].mount, "mount %s", v->mount_point);
|
|
|
|
sprintf(&mount_menue[mountable_volumes].unmount, "unmount %s", v->mount_point);
|
|
|
|
mount_menue[mountable_volumes].v = &device_volumes[i];
|
|
|
|
++mountable_volumes;
|
2011-04-09 05:41:45 +00:00
|
|
|
if (is_safe_to_format(v->mount_point)) {
|
|
|
|
sprintf(&format_menue[formatable_volumes].txt, "format %s", v->mount_point);
|
|
|
|
format_menue[formatable_volumes].v = &device_volumes[i];
|
|
|
|
++formatable_volumes;
|
|
|
|
}
|
2011-02-13 19:59:30 +00:00
|
|
|
}
|
2011-04-09 05:41:45 +00:00
|
|
|
else if (strcmp("ramdisk", v->fs_type) != 0 && strcmp("mtd", v->fs_type) == 0 && is_safe_to_format(v->mount_point))
|
2011-02-13 19:59:30 +00:00
|
|
|
{
|
|
|
|
sprintf(&format_menue[formatable_volumes].txt, "format %s", v->mount_point);
|
|
|
|
format_menue[formatable_volumes].v = &device_volumes[i];
|
|
|
|
++formatable_volumes;
|
|
|
|
}
|
|
|
|
}
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2010-12-19 01:42:31 +00:00
|
|
|
|
2010-07-15 04:01:21 +00:00
|
|
|
static char* confirm_format = "Confirm format?";
|
2010-07-15 01:38:02 +00:00
|
|
|
static char* confirm = "Yes - Format";
|
2011-05-01 01:04:04 +00:00
|
|
|
char confirm_string[255];
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2010-03-15 05:42:30 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2011-02-13 19:59:30 +00:00
|
|
|
for (i = 0; i < mountable_volumes; i++)
|
|
|
|
{
|
|
|
|
MountMenuEntry* e = &mount_menue[i];
|
|
|
|
Volume* v = e->v;
|
|
|
|
if(is_path_mounted(v->mount_point))
|
|
|
|
options[i] = e->unmount;
|
|
|
|
else
|
|
|
|
options[i] = e->mount;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < formatable_volumes; i++)
|
|
|
|
{
|
|
|
|
FormatMenuEntry* e = &format_menue[i];
|
|
|
|
|
|
|
|
options[mountable_volumes+i] = e->txt;
|
|
|
|
}
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2011-02-13 19:59:30 +00:00
|
|
|
options[mountable_volumes+formatable_volumes] = "mount USB storage";
|
|
|
|
options[mountable_volumes+formatable_volumes + 1] = NULL;
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2011-02-13 19:59:30 +00:00
|
|
|
int chosen_item = get_menu_selection(headers, &options, 0, 0);
|
2010-03-15 05:42:30 +00:00
|
|
|
if (chosen_item == GO_BACK)
|
|
|
|
break;
|
2011-02-13 19:59:30 +00:00
|
|
|
if (chosen_item == (mountable_volumes+formatable_volumes))
|
2010-03-15 05:42:30 +00:00
|
|
|
{
|
|
|
|
show_mount_usb_storage_menu();
|
|
|
|
}
|
2011-02-13 19:59:30 +00:00
|
|
|
else if (chosen_item < mountable_volumes)
|
2010-03-15 05:42:30 +00:00
|
|
|
{
|
2011-02-13 19:59:30 +00:00
|
|
|
MountMenuEntry* e = &mount_menue[chosen_item];
|
|
|
|
Volume* v = e->v;
|
|
|
|
|
|
|
|
if (is_path_mounted(v->mount_point))
|
2010-03-15 05:42:30 +00:00
|
|
|
{
|
2011-02-13 19:59:30 +00:00
|
|
|
if (0 != ensure_path_unmounted(v->mount_point))
|
|
|
|
ui_print("Error unmounting %s!\n", v->mount_point);
|
2010-03-15 05:42:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-13 19:59:30 +00:00
|
|
|
if (0 != ensure_path_mounted(v->mount_point))
|
|
|
|
ui_print("Error mounting %s!\n", v->mount_point);
|
2010-03-15 05:42:30 +00:00
|
|
|
}
|
|
|
|
}
|
2011-02-13 19:59:30 +00:00
|
|
|
else if (chosen_item < (mountable_volumes + formatable_volumes))
|
2010-03-19 20:34:36 +00:00
|
|
|
{
|
2011-02-13 19:59:30 +00:00
|
|
|
chosen_item = chosen_item - mountable_volumes;
|
|
|
|
FormatMenuEntry* e = &format_menue[chosen_item];
|
|
|
|
Volume* v = e->v;
|
|
|
|
|
2011-05-01 01:04:04 +00:00
|
|
|
sprintf(confirm_string, "%s - %s", v->mount_point, confirm_format);
|
|
|
|
|
|
|
|
if (!confirm_selection(confirm_string, confirm))
|
2010-03-19 21:37:11 +00:00
|
|
|
continue;
|
2011-02-13 19:59:30 +00:00
|
|
|
ui_print("Formatting %s...\n", v->mount_point);
|
|
|
|
if (0 != format_volume(v->mount_point))
|
|
|
|
ui_print("Error formatting %s!\n", v->mount_point);
|
2010-03-31 06:29:43 +00:00
|
|
|
else
|
|
|
|
ui_print("Done.\n");
|
2010-03-19 20:34:36 +00:00
|
|
|
}
|
2010-03-15 05:42:30 +00:00
|
|
|
}
|
2011-02-13 19:59:30 +00:00
|
|
|
|
|
|
|
free(mount_menue);
|
|
|
|
free(format_menue);
|
|
|
|
|
2010-03-15 05:42:30 +00:00
|
|
|
}
|
|
|
|
|
2010-03-07 22:10:26 +00:00
|
|
|
#define EXTENDEDCOMMAND_SCRIPT "/cache/recovery/extendedcommand"
|
2010-03-07 21:39:21 +00:00
|
|
|
|
2010-03-07 22:10:26 +00:00
|
|
|
int extendedcommand_file_exists()
|
|
|
|
{
|
|
|
|
struct stat file_info;
|
|
|
|
return 0 == stat(EXTENDEDCOMMAND_SCRIPT, &file_info);
|
|
|
|
}
|
2010-03-07 21:39:21 +00:00
|
|
|
|
2010-12-20 04:37:57 +00:00
|
|
|
int edify_main(int argc, char** argv) {
|
|
|
|
load_volume_table();
|
|
|
|
process_volumes();
|
|
|
|
RegisterBuiltins();
|
|
|
|
RegisterRecoveryHooks();
|
|
|
|
FinishRegistration();
|
2010-12-19 01:42:31 +00:00
|
|
|
|
2010-12-20 04:37:57 +00:00
|
|
|
if (argc != 2) {
|
|
|
|
printf("edify <filename>\n");
|
2010-03-07 21:39:21 +00:00
|
|
|
return 1;
|
2010-12-20 04:37:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FILE* f = fopen(argv[1], "r");
|
|
|
|
if (f == NULL) {
|
|
|
|
printf("%s: %s: No such file or directory\n", argv[0], argv[1]);
|
2010-03-07 21:39:21 +00:00
|
|
|
return 1;
|
2010-11-14 08:18:40 +00:00
|
|
|
}
|
2010-12-20 04:37:57 +00:00
|
|
|
char buffer[8192];
|
|
|
|
int size = fread(buffer, 1, 8191, f);
|
|
|
|
fclose(f);
|
|
|
|
buffer[size] = '\0';
|
|
|
|
|
|
|
|
Expr* root;
|
|
|
|
int error_count = 0;
|
|
|
|
yy_scan_bytes(buffer, size);
|
|
|
|
int error = yyparse(&root, &error_count);
|
|
|
|
printf("parse returned %d; %d errors encountered\n", error, error_count);
|
|
|
|
if (error == 0 || error_count > 0) {
|
|
|
|
|
|
|
|
//ExprDump(0, root, buffer);
|
|
|
|
|
|
|
|
State state;
|
|
|
|
state.cookie = NULL;
|
|
|
|
state.script = buffer;
|
|
|
|
state.errmsg = NULL;
|
|
|
|
|
|
|
|
char* result = Evaluate(&state, root);
|
|
|
|
if (result == NULL) {
|
|
|
|
printf("result was NULL, message is: %s\n",
|
|
|
|
(state.errmsg == NULL ? "(NULL)" : state.errmsg));
|
|
|
|
free(state.errmsg);
|
|
|
|
} else {
|
|
|
|
printf("result is [%s]\n", result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2010-03-07 21:39:21 +00:00
|
|
|
}
|
2010-03-07 22:10:26 +00:00
|
|
|
|
2010-04-04 06:28:39 +00:00
|
|
|
int run_script(char* filename)
|
2010-03-12 06:17:43 +00:00
|
|
|
{
|
|
|
|
struct stat file_info;
|
|
|
|
if (0 != stat(filename, &file_info)) {
|
|
|
|
printf("Error executing stat on file: %s\n", filename);
|
|
|
|
return 1;
|
|
|
|
}
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2010-03-12 06:17:43 +00:00
|
|
|
int script_len = file_info.st_size;
|
2010-03-23 18:44:33 +00:00
|
|
|
char* script_data = (char*)malloc(script_len + 1);
|
2010-03-12 06:17:43 +00:00
|
|
|
FILE *file = fopen(filename, "rb");
|
|
|
|
fread(script_data, script_len, 1, file);
|
2010-03-23 18:44:33 +00:00
|
|
|
// supposedly not necessary, but let's be safe.
|
|
|
|
script_data[script_len] = '\0';
|
2010-03-12 06:17:43 +00:00
|
|
|
fclose(file);
|
2010-06-21 15:16:19 +00:00
|
|
|
LOGI("Running script:\n");
|
|
|
|
LOGI("\n%s\n", script_data);
|
2010-03-12 06:17:43 +00:00
|
|
|
|
2010-04-19 01:06:24 +00:00
|
|
|
int ret = run_script_from_buffer(script_data, script_len, filename);
|
2010-04-02 23:46:21 +00:00
|
|
|
free(script_data);
|
|
|
|
return ret;
|
2010-03-12 06:17:43 +00:00
|
|
|
}
|
|
|
|
|
2010-03-07 22:10:26 +00:00
|
|
|
int run_and_remove_extendedcommand()
|
|
|
|
{
|
2010-04-04 06:28:39 +00:00
|
|
|
char tmp[PATH_MAX];
|
|
|
|
sprintf(tmp, "cp %s /tmp/%s", EXTENDEDCOMMAND_SCRIPT, basename(EXTENDEDCOMMAND_SCRIPT));
|
|
|
|
__system(tmp);
|
|
|
|
remove(EXTENDEDCOMMAND_SCRIPT);
|
2010-03-09 03:22:41 +00:00
|
|
|
int i = 0;
|
|
|
|
for (i = 20; i > 0; i--) {
|
|
|
|
ui_print("Waiting for SD Card to mount (%ds)\n", i);
|
2010-12-19 01:42:31 +00:00
|
|
|
if (ensure_path_mounted("/sdcard") == 0) {
|
2010-03-09 03:22:41 +00:00
|
|
|
ui_print("SD Card mounted...\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sleep(1);
|
|
|
|
}
|
2010-07-15 07:10:08 +00:00
|
|
|
remove("/sdcard/clockworkmod/.recoverycheckpoint");
|
2010-03-09 03:22:41 +00:00
|
|
|
if (i == 0) {
|
|
|
|
ui_print("Timed out waiting for SD card... continuing anyways.");
|
|
|
|
}
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2010-04-04 06:28:39 +00:00
|
|
|
sprintf(tmp, "/tmp/%s", basename(EXTENDEDCOMMAND_SCRIPT));
|
|
|
|
return run_script(tmp);
|
2010-03-07 22:10:26 +00:00
|
|
|
}
|
|
|
|
|
2010-03-26 01:19:23 +00:00
|
|
|
void show_nandroid_advanced_restore_menu()
|
|
|
|
{
|
2010-12-19 01:42:31 +00:00
|
|
|
if (ensure_path_mounted("/sdcard") != 0) {
|
2010-03-26 01:19:23 +00:00
|
|
|
LOGE ("Can't mount /sdcard\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char* advancedheaders[] = { "Choose an image to restore",
|
|
|
|
"",
|
|
|
|
"Choose an image to restore",
|
|
|
|
"first. The next menu will",
|
|
|
|
"you more options.",
|
|
|
|
"",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
char* file = choose_file_menu("/sdcard/clockworkmod/backup/", NULL, advancedheaders);
|
|
|
|
if (file == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
static char* headers[] = { "Nandroid Advanced Restore",
|
|
|
|
"",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static char* list[] = { "Restore boot",
|
|
|
|
"Restore system",
|
|
|
|
"Restore data",
|
|
|
|
"Restore cache",
|
2010-04-01 19:20:39 +00:00
|
|
|
"Restore sd-ext",
|
2010-12-29 18:15:18 +00:00
|
|
|
"Restore wimax",
|
2010-03-26 01:19:23 +00:00
|
|
|
NULL
|
|
|
|
};
|
2010-12-30 07:36:03 +00:00
|
|
|
|
|
|
|
char tmp[PATH_MAX];
|
|
|
|
if (0 != get_partition_device("wimax", tmp)) {
|
|
|
|
// disable wimax restore option
|
|
|
|
list[5] = NULL;
|
|
|
|
}
|
2010-07-15 04:01:21 +00:00
|
|
|
|
|
|
|
static char* confirm_restore = "Confirm restore?";
|
|
|
|
|
2010-12-19 01:42:31 +00:00
|
|
|
int chosen_item = get_menu_selection(headers, list, 0, 0);
|
2010-03-26 01:19:23 +00:00
|
|
|
switch (chosen_item)
|
|
|
|
{
|
|
|
|
case 0:
|
2010-07-15 04:01:21 +00:00
|
|
|
if (confirm_selection(confirm_restore, "Yes - Restore boot"))
|
2010-12-29 18:15:18 +00:00
|
|
|
nandroid_restore(file, 1, 0, 0, 0, 0, 0);
|
2010-03-26 01:19:23 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2010-07-15 04:01:21 +00:00
|
|
|
if (confirm_selection(confirm_restore, "Yes - Restore system"))
|
2010-12-29 18:15:18 +00:00
|
|
|
nandroid_restore(file, 0, 1, 0, 0, 0, 0);
|
2010-03-26 01:19:23 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2010-07-15 04:01:21 +00:00
|
|
|
if (confirm_selection(confirm_restore, "Yes - Restore data"))
|
2010-12-29 18:15:18 +00:00
|
|
|
nandroid_restore(file, 0, 0, 1, 0, 0, 0);
|
2010-03-26 01:19:23 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2010-07-15 04:01:21 +00:00
|
|
|
if (confirm_selection(confirm_restore, "Yes - Restore cache"))
|
2010-12-29 18:15:18 +00:00
|
|
|
nandroid_restore(file, 0, 0, 0, 1, 0, 0);
|
2010-03-26 01:19:23 +00:00
|
|
|
break;
|
2010-04-18 23:00:21 +00:00
|
|
|
case 4:
|
2010-07-15 04:01:21 +00:00
|
|
|
if (confirm_selection(confirm_restore, "Yes - Restore sd-ext"))
|
2010-12-29 18:15:18 +00:00
|
|
|
nandroid_restore(file, 0, 0, 0, 0, 1, 0);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
if (confirm_selection(confirm_restore, "Yes - Restore wimax"))
|
|
|
|
nandroid_restore(file, 0, 0, 0, 0, 0, 1);
|
2010-04-18 23:00:21 +00:00
|
|
|
break;
|
2010-03-26 01:19:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-19 20:34:36 +00:00
|
|
|
void show_nandroid_menu()
|
|
|
|
{
|
|
|
|
static char* headers[] = { "Nandroid",
|
|
|
|
"",
|
2010-11-14 08:18:40 +00:00
|
|
|
NULL
|
2010-03-19 20:34:36 +00:00
|
|
|
};
|
|
|
|
|
2010-11-14 08:18:40 +00:00
|
|
|
static char* list[] = { "Backup",
|
2010-03-19 20:34:36 +00:00
|
|
|
"Restore",
|
2010-03-26 01:19:23 +00:00
|
|
|
"Advanced Restore",
|
2010-03-19 20:34:36 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-12-19 01:42:31 +00:00
|
|
|
int chosen_item = get_menu_selection(headers, list, 0, 0);
|
2010-03-19 20:34:36 +00:00
|
|
|
switch (chosen_item)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
char backup_path[PATH_MAX];
|
2010-03-27 22:26:11 +00:00
|
|
|
time_t t = time(NULL);
|
|
|
|
struct tm *tmp = localtime(&t);
|
|
|
|
if (tmp == NULL)
|
|
|
|
{
|
|
|
|
struct timeval tp;
|
|
|
|
gettimeofday(&tp, NULL);
|
|
|
|
sprintf(backup_path, "/sdcard/clockworkmod/backup/%d", tp.tv_sec);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strftime(backup_path, sizeof(backup_path), "/sdcard/clockworkmod/backup/%F.%H.%M.%S", tmp);
|
|
|
|
}
|
2010-03-19 20:34:36 +00:00
|
|
|
nandroid_backup(backup_path);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
show_nandroid_restore_menu();
|
|
|
|
break;
|
2010-03-26 01:19:23 +00:00
|
|
|
case 2:
|
|
|
|
show_nandroid_advanced_restore_menu();
|
|
|
|
break;
|
2010-03-19 20:34:36 +00:00
|
|
|
}
|
2010-03-19 21:51:45 +00:00
|
|
|
}
|
|
|
|
|
2010-05-01 19:46:55 +00:00
|
|
|
void wipe_battery_stats()
|
|
|
|
{
|
2010-12-19 01:42:31 +00:00
|
|
|
ensure_path_mounted("/data");
|
2010-05-01 19:46:55 +00:00
|
|
|
remove("/data/system/batterystats.bin");
|
2010-12-19 01:42:31 +00:00
|
|
|
ensure_path_unmounted("/data");
|
2010-05-01 19:46:55 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 21:51:45 +00:00
|
|
|
void show_advanced_menu()
|
|
|
|
{
|
|
|
|
static char* headers[] = { "Advanced and Debugging Menu",
|
|
|
|
"",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-04-07 06:04:52 +00:00
|
|
|
static char* list[] = { "Reboot Recovery",
|
2010-06-21 20:45:51 +00:00
|
|
|
"Wipe Dalvik Cache",
|
2010-05-01 19:46:55 +00:00
|
|
|
"Wipe Battery Stats",
|
2010-06-20 16:42:47 +00:00
|
|
|
"Report Error",
|
2010-04-07 06:04:52 +00:00
|
|
|
"Key Test",
|
2010-08-29 19:35:10 +00:00
|
|
|
#ifndef BOARD_HAS_SMALL_RECOVERY
|
2010-08-23 23:13:14 +00:00
|
|
|
"Partition SD Card",
|
|
|
|
"Fix Permissions",
|
2010-12-12 03:52:06 +00:00
|
|
|
#ifdef BOARD_HAS_SDCARD_INTERNAL
|
|
|
|
"Partition Internal SD Card",
|
|
|
|
#endif
|
2010-08-29 19:35:10 +00:00
|
|
|
#endif
|
2010-03-19 21:51:45 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
2010-12-19 01:42:31 +00:00
|
|
|
int chosen_item = get_menu_selection(headers, list, 0, 0);
|
2010-03-19 21:51:45 +00:00
|
|
|
if (chosen_item == GO_BACK)
|
|
|
|
break;
|
|
|
|
switch (chosen_item)
|
|
|
|
{
|
|
|
|
case 0:
|
2011-05-03 04:25:01 +00:00
|
|
|
#ifdef TARGET_RECOVERY_PRE_COMMAND
|
|
|
|
__system( TARGET_RECOVERY_PRE_COMMAND );
|
|
|
|
#endif
|
2010-04-07 06:04:52 +00:00
|
|
|
__reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, "recovery");
|
|
|
|
break;
|
|
|
|
case 1:
|
2010-07-15 04:01:21 +00:00
|
|
|
{
|
2010-12-19 01:42:31 +00:00
|
|
|
if (0 != ensure_path_mounted("/data"))
|
2010-06-21 20:45:51 +00:00
|
|
|
break;
|
2010-12-19 01:42:31 +00:00
|
|
|
ensure_path_mounted("/sd-ext");
|
|
|
|
ensure_path_mounted("/cache");
|
2010-08-07 19:17:13 +00:00
|
|
|
if (confirm_selection( "Confirm wipe?", "Yes - Wipe Dalvik Cache")) {
|
2010-07-15 04:01:21 +00:00
|
|
|
__system("rm -r /data/dalvik-cache");
|
2010-08-07 19:17:13 +00:00
|
|
|
__system("rm -r /cache/dalvik-cache");
|
|
|
|
__system("rm -r /sd-ext/dalvik-cache");
|
|
|
|
}
|
2010-12-19 01:42:31 +00:00
|
|
|
ensure_path_unmounted("/data");
|
2010-08-07 19:17:13 +00:00
|
|
|
ui_print("Dalvik Cache wiped.\n");
|
2010-05-01 19:46:55 +00:00
|
|
|
break;
|
2010-07-15 04:01:21 +00:00
|
|
|
}
|
2010-05-01 19:46:55 +00:00
|
|
|
case 2:
|
2010-07-15 04:01:21 +00:00
|
|
|
{
|
|
|
|
if (confirm_selection( "Confirm wipe?", "Yes - Wipe Battery Stats"))
|
|
|
|
wipe_battery_stats();
|
2010-06-20 16:42:47 +00:00
|
|
|
break;
|
2010-07-15 04:01:21 +00:00
|
|
|
}
|
2010-06-20 16:42:47 +00:00
|
|
|
case 3:
|
2010-06-21 20:45:51 +00:00
|
|
|
handle_failure(1);
|
|
|
|
break;
|
|
|
|
case 4:
|
2010-03-19 21:51:45 +00:00
|
|
|
{
|
|
|
|
ui_print("Outputting key codes.\n");
|
|
|
|
ui_print("Go back to end debugging.\n");
|
|
|
|
int key;
|
|
|
|
int action;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
key = ui_wait_key();
|
|
|
|
action = device_handle_key(key, 1);
|
|
|
|
ui_print("Key: %d\n", key);
|
|
|
|
}
|
|
|
|
while (action != GO_BACK);
|
2010-08-23 23:15:33 +00:00
|
|
|
break;
|
2010-03-19 21:51:45 +00:00
|
|
|
}
|
2010-08-17 23:55:38 +00:00
|
|
|
case 5:
|
|
|
|
{
|
2010-08-23 23:13:14 +00:00
|
|
|
static char* ext_sizes[] = { "128M",
|
|
|
|
"256M",
|
|
|
|
"512M",
|
|
|
|
"1024M",
|
2010-11-14 22:31:17 +00:00
|
|
|
"2048M",
|
|
|
|
"4096M",
|
2010-08-23 23:13:14 +00:00
|
|
|
NULL };
|
|
|
|
|
|
|
|
static char* swap_sizes[] = { "0M",
|
|
|
|
"32M",
|
|
|
|
"64M",
|
|
|
|
"128M",
|
|
|
|
"256M",
|
|
|
|
NULL };
|
|
|
|
|
|
|
|
static char* ext_headers[] = { "Ext Size", "", NULL };
|
|
|
|
static char* swap_headers[] = { "Swap Size", "", NULL };
|
|
|
|
|
2010-12-19 01:42:31 +00:00
|
|
|
int ext_size = get_menu_selection(ext_headers, ext_sizes, 0, 0);
|
2010-08-23 23:13:14 +00:00
|
|
|
if (ext_size == GO_BACK)
|
|
|
|
continue;
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2010-12-19 01:42:31 +00:00
|
|
|
int swap_size = get_menu_selection(swap_headers, swap_sizes, 0, 0);
|
2010-08-23 23:13:14 +00:00
|
|
|
if (swap_size == GO_BACK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
char sddevice[256];
|
2010-12-19 01:42:31 +00:00
|
|
|
Volume *vol = volume_for_path("/sdcard");
|
|
|
|
strcpy(sddevice, vol->device);
|
2010-08-23 23:13:14 +00:00
|
|
|
// we only want the mmcblk, not the partition
|
|
|
|
sddevice[strlen("/dev/block/mmcblkX")] = NULL;
|
|
|
|
char cmd[PATH_MAX];
|
|
|
|
setenv("SDPATH", sddevice, 1);
|
|
|
|
sprintf(cmd, "sdparted -es %s -ss %s -efs ext3 -s", ext_sizes[ext_size], swap_sizes[swap_size]);
|
|
|
|
ui_print("Partitioning SD Card... please wait...\n");
|
|
|
|
if (0 == __system(cmd))
|
|
|
|
ui_print("Done!\n");
|
|
|
|
else
|
|
|
|
ui_print("An error occured while partitioning your SD Card. Please see /tmp/recovery.log for more details.\n");
|
2010-08-23 23:15:33 +00:00
|
|
|
break;
|
2010-08-17 23:55:38 +00:00
|
|
|
}
|
2010-08-18 05:21:53 +00:00
|
|
|
case 6:
|
|
|
|
{
|
2010-12-19 01:42:31 +00:00
|
|
|
ensure_path_mounted("/system");
|
|
|
|
ensure_path_mounted("/data");
|
2010-08-23 23:13:14 +00:00
|
|
|
ui_print("Fixing permissions...\n");
|
|
|
|
__system("fix_permissions");
|
|
|
|
ui_print("Done!\n");
|
2010-08-23 23:15:33 +00:00
|
|
|
break;
|
2010-08-18 05:21:53 +00:00
|
|
|
}
|
2010-12-12 03:52:06 +00:00
|
|
|
case 7:
|
|
|
|
{
|
|
|
|
static char* ext_sizes[] = { "128M",
|
|
|
|
"256M",
|
|
|
|
"512M",
|
|
|
|
"1024M",
|
|
|
|
"2048M",
|
|
|
|
"4096M",
|
|
|
|
NULL };
|
|
|
|
|
|
|
|
static char* swap_sizes[] = { "0M",
|
|
|
|
"32M",
|
|
|
|
"64M",
|
|
|
|
"128M",
|
|
|
|
"256M",
|
|
|
|
NULL };
|
|
|
|
|
|
|
|
static char* ext_headers[] = { "Data Size", "", NULL };
|
|
|
|
static char* swap_headers[] = { "Swap Size", "", NULL };
|
|
|
|
|
2010-12-19 01:42:31 +00:00
|
|
|
int ext_size = get_menu_selection(ext_headers, ext_sizes, 0, 0);
|
2010-12-12 03:52:06 +00:00
|
|
|
if (ext_size == GO_BACK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int swap_size = 0;
|
|
|
|
if (swap_size == GO_BACK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
char sddevice[256];
|
2010-12-19 01:42:31 +00:00
|
|
|
Volume *vol = volume_for_path("/emmc");
|
|
|
|
strcpy(sddevice, vol->device);
|
2010-12-12 03:52:06 +00:00
|
|
|
// we only want the mmcblk, not the partition
|
|
|
|
sddevice[strlen("/dev/block/mmcblkX")] = NULL;
|
|
|
|
char cmd[PATH_MAX];
|
|
|
|
setenv("SDPATH", sddevice, 1);
|
|
|
|
sprintf(cmd, "sdparted -es %s -ss %s -efs ext3 -s", ext_sizes[ext_size], swap_sizes[swap_size]);
|
|
|
|
ui_print("Partitioning Internal SD Card... please wait...\n");
|
|
|
|
if (0 == __system(cmd))
|
|
|
|
ui_print("Done!\n");
|
|
|
|
else
|
|
|
|
ui_print("An error occured while partitioning your Internal SD Card. Please see /tmp/recovery.log for more details.\n");
|
|
|
|
break;
|
|
|
|
}
|
2010-03-19 21:51:45 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-14 22:02:48 +00:00
|
|
|
}
|
|
|
|
|
2010-12-19 02:39:39 +00:00
|
|
|
void write_fstab_root(char *path, FILE *file)
|
2010-06-14 22:02:48 +00:00
|
|
|
{
|
2010-12-19 02:39:39 +00:00
|
|
|
Volume *vol = volume_for_path(path);
|
|
|
|
if (vol == NULL) {
|
2010-12-19 05:31:02 +00:00
|
|
|
LOGW("Unable to get recovery.fstab info for %s during fstab generation!\n", path);
|
2010-06-20 16:42:47 +00:00
|
|
|
return;
|
2010-06-20 20:16:06 +00:00
|
|
|
}
|
2010-11-14 08:18:40 +00:00
|
|
|
|
2010-12-20 16:49:20 +00:00
|
|
|
char device[200];
|
|
|
|
if (vol->device[0] != '/')
|
|
|
|
get_partition_device(vol->device, device);
|
|
|
|
else
|
|
|
|
strcpy(device, vol->device);
|
|
|
|
|
|
|
|
fprintf(file, "%s ", device);
|
2010-12-19 02:39:39 +00:00
|
|
|
fprintf(file, "%s ", path);
|
2011-02-28 01:28:30 +00:00
|
|
|
// special case rfs cause auto will mount it as vfat on samsung.
|
|
|
|
fprintf(file, "%s rw\n", vol->fs_type2 != NULL && strcmp(vol->fs_type, "rfs") != 0 ? "auto" : vol->fs_type);
|
2010-06-14 22:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void create_fstab()
|
|
|
|
{
|
2010-12-19 02:39:39 +00:00
|
|
|
struct stat info;
|
2010-06-23 07:02:14 +00:00
|
|
|
__system("touch /etc/mtab");
|
2010-06-14 22:02:48 +00:00
|
|
|
FILE *file = fopen("/etc/fstab", "w");
|
2010-06-20 20:16:06 +00:00
|
|
|
if (file == NULL) {
|
2010-12-19 02:39:39 +00:00
|
|
|
LOGW("Unable to create /etc/fstab!\n");
|
2010-06-20 16:42:47 +00:00
|
|
|
return;
|
2010-06-20 20:16:06 +00:00
|
|
|
}
|
2011-01-28 20:39:10 +00:00
|
|
|
Volume *vol = volume_for_path("/boot");
|
2011-02-12 18:21:11 +00:00
|
|
|
if (NULL != vol && strcmp(vol->fs_type, "mtd") != 0 && strcmp(vol->fs_type, "emmc") != 0 && strcmp(vol->fs_type, "bml") != 0)
|
2011-01-28 20:39:10 +00:00
|
|
|
write_fstab_root("/boot", file);
|
2010-12-19 02:39:39 +00:00
|
|
|
write_fstab_root("/cache", file);
|
|
|
|
write_fstab_root("/data", file);
|
2010-12-19 06:37:49 +00:00
|
|
|
if (has_datadata()) {
|
|
|
|
write_fstab_root("/datadata", file);
|
|
|
|
}
|
2010-12-19 02:39:39 +00:00
|
|
|
write_fstab_root("/system", file);
|
|
|
|
write_fstab_root("/sdcard", file);
|
|
|
|
write_fstab_root("/sd-ext", file);
|
2010-06-14 22:02:48 +00:00
|
|
|
fclose(file);
|
2010-12-19 05:31:02 +00:00
|
|
|
LOGI("Completed outputting fstab.\n");
|
2010-06-20 16:42:47 +00:00
|
|
|
}
|
|
|
|
|
2010-12-19 11:38:29 +00:00
|
|
|
int bml_check_volume(const char *path) {
|
|
|
|
ui_print("Checking %s...\n", path);
|
|
|
|
ensure_path_unmounted(path);
|
|
|
|
if (0 == ensure_path_mounted(path)) {
|
|
|
|
ensure_path_unmounted(path);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Volume *vol = volume_for_path(path);
|
|
|
|
if (vol == NULL) {
|
|
|
|
LOGE("Unable process volume! Skipping...\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-20 04:37:57 +00:00
|
|
|
ui_print("%s may be rfs. Checking...\n", path);
|
2010-12-19 11:38:29 +00:00
|
|
|
char tmp[PATH_MAX];
|
|
|
|
sprintf(tmp, "mount -t rfs %s %s", vol->device, path);
|
|
|
|
int ret = __system(tmp);
|
|
|
|
printf("%d\n", ret);
|
|
|
|
return ret == 0 ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void process_volumes() {
|
|
|
|
create_fstab();
|
|
|
|
|
2011-02-27 22:00:19 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// dead code.
|
2010-12-19 11:38:29 +00:00
|
|
|
if (device_flash_type() != BML)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ui_print("Checking for ext4 partitions...\n");
|
|
|
|
int ret = 0;
|
|
|
|
ret = bml_check_volume("/system");
|
|
|
|
ret |= bml_check_volume("/data");
|
|
|
|
if (has_datadata())
|
|
|
|
ret |= bml_check_volume("/datadata");
|
|
|
|
ret |= bml_check_volume("/cache");
|
|
|
|
|
|
|
|
if (ret == 0) {
|
|
|
|
ui_print("Done!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-21 08:58:43 +00:00
|
|
|
char backup_path[PATH_MAX];
|
|
|
|
time_t t = time(NULL);
|
|
|
|
char backup_name[PATH_MAX];
|
|
|
|
struct timeval tp;
|
|
|
|
gettimeofday(&tp, NULL);
|
|
|
|
sprintf(backup_name, "before-ext4-convert-%d", tp.tv_sec);
|
|
|
|
sprintf(backup_path, "/sdcard/clockworkmod/backup/%s", backup_name);
|
|
|
|
|
2010-12-19 11:38:29 +00:00
|
|
|
ui_set_show_text(1);
|
|
|
|
ui_print("Filesystems need to be converted to ext4.\n");
|
|
|
|
ui_print("A backup and restore will now take place.\n");
|
2010-12-20 04:37:57 +00:00
|
|
|
ui_print("If anything goes wrong, your backup will be\n");
|
2010-12-21 08:58:43 +00:00
|
|
|
ui_print("named %s. Try restoring it\n", backup_name);
|
2010-12-20 04:37:57 +00:00
|
|
|
ui_print("in case of error.\n");
|
2010-12-19 11:38:29 +00:00
|
|
|
|
2010-12-21 08:58:43 +00:00
|
|
|
nandroid_backup(backup_path);
|
2010-12-30 07:36:03 +00:00
|
|
|
nandroid_restore(backup_path, 1, 1, 1, 1, 1, 0);
|
2010-12-19 11:38:29 +00:00
|
|
|
ui_set_show_text(0);
|
|
|
|
}
|
|
|
|
|
2010-06-20 16:42:47 +00:00
|
|
|
void handle_failure(int ret)
|
|
|
|
{
|
|
|
|
if (ret == 0)
|
|
|
|
return;
|
2010-12-19 01:42:31 +00:00
|
|
|
if (0 != ensure_path_mounted("/sdcard"))
|
2010-06-20 16:42:47 +00:00
|
|
|
return;
|
2010-06-20 20:16:06 +00:00
|
|
|
mkdir("/sdcard/clockworkmod", S_IRWXU);
|
|
|
|
__system("cp /tmp/recovery.log /sdcard/clockworkmod/recovery.log");
|
2010-08-18 05:21:53 +00:00
|
|
|
ui_print("/tmp/recovery.log was copied to /sdcard/clockworkmod/recovery.log. Please open ROM Manager to report the issue.\n");
|
2010-11-14 08:18:40 +00:00
|
|
|
}
|
2010-12-19 01:42:31 +00:00
|
|
|
|
|
|
|
int is_path_mounted(const char* path) {
|
|
|
|
Volume* v = volume_for_path(path);
|
|
|
|
if (v == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (strcmp(v->fs_type, "ramdisk") == 0) {
|
|
|
|
// the ramdisk is always mounted.
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int result;
|
|
|
|
result = scan_mounted_volumes();
|
|
|
|
if (result < 0) {
|
|
|
|
LOGE("failed to scan mounted volumes\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MountedVolume* mv =
|
|
|
|
find_mounted_volume_by_mount_point(v->mount_point);
|
|
|
|
if (mv) {
|
|
|
|
// volume is already mounted
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2010-12-19 06:37:49 +00:00
|
|
|
|
|
|
|
int has_datadata() {
|
|
|
|
Volume *vol = volume_for_path("/datadata");
|
|
|
|
return vol != NULL;
|
2011-01-04 18:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int volume_main(int argc, char **argv) {
|
|
|
|
load_volume_table();
|
|
|
|
return 0;
|
|
|
|
}
|