45 Commits

Author SHA1 Message Date
adf906d034 custom keymapping support 2010-09-26 15:58:35 -07:00
7f4ff5cd3a favor primary device always for fstab 2010-09-20 19:21:52 -07:00
23ce6b14ae allow the parted and fix permissions tools to be optional 2010-08-29 12:35:10 -07:00
56606a2da3 fix missing break statements in switch... 2010-08-23 16:15:33 -07:00
ceddcd59ac add fix permissions and partition sd card to the recovery. TODO: Restrict to devicess that support large recovery images. 2010-08-23 16:13:14 -07:00
54a284568b 2507 2010-08-20 11:35:15 -07:00
3b4135826d remove hijac 2010-08-20 09:56:15 -07:00
38e8b2b6a9 cleanups 2010-08-17 22:21:53 -07:00
f0e31b89b9 fixes and stuff for droid x 2010-08-17 16:55:38 -07:00
d632c0def4 hijack executable 2010-08-16 18:05:55 -07:00
2098707b02 droid x test crap 2010-08-16 01:21:10 -07:00
6c7745d928 rename some menus. wipe more locations for dalvik cache. 2010-08-07 12:17:13 -07:00
4e625e8cd2 missing files 2010-07-24 11:21:12 -07:00
852bb420e7 Do not unmount on wipe unless needed. Add reboot binary. Restart recovery process for Galaxy S. 2010-07-24 11:18:00 -07:00
d4060c3eb6 Galaxy S initial support. Fix firmware flash on inc. May need to fix other phones. 2010-07-22 20:14:44 -07:00
e074d8d543 need to remove that line about the recovery process start.... this will break other phones. or check the process list. 2010-07-20 16:39:23 -07:00
5aaa8238f7 galaxys 2010-07-20 16:23:18 -07:00
92077c15d6 removal of the recovery checkpoint needs to happen AFTER sdcard is mounted. 2010-07-15 00:10:08 -07:00
fae335e159 version 2.5.0.0 2010-07-14 21:01:44 -07:00
d63eaef179 add confirmations to anything that would change the system. 2010-07-14 21:01:21 -07:00
ecd32fa2e8 Make generic confirmation function. 2010-07-14 18:38:08 -07:00
1bf4f695d4 allow toggling of software back menu item. add recovery checkpoint file. mount auto now uses busybox mount. 2010-07-14 18:37:33 -07:00
37186b19bc up the version 2010-07-07 19:10:09 -07:00
d8038e15f8 2.0.2.0 2010-07-03 16:38:34 -07:00
062d6b0bb3 Backup of Froyo apps on external storage. 2010-07-03 13:54:32 -07:00
6440ed585f fail 2010-07-01 12:52:34 -07:00
b9c595c654 change where the recovery version is spit 2010-07-01 12:39:15 -07:00
1e8aabad34 alphabetical sort
Change-Id: I4b1bb6787a5cbe1e99e3d8b0cc5bf37d7167398d
2010-07-01 00:23:45 -07:00
0837091e8d command line nandroid 2010-06-26 12:25:02 -07:00
d634bb2d2b 2.0.1.4 2010-06-25 12:23:35 -07:00
cd44ab973e dont fail if nonmtd format fails... create mtab 2010-06-23 00:02:14 -07:00
49af23cbce dalvik cache wip support 2010-06-21 13:45:51 -07:00
8ec9418782 fix fstab for /sdcard 2010-06-21 12:27:43 -07:00
52d3f205b5 fix sdext backup bug 2010-06-21 12:11:13 -07:00
5cd94a9a73 2.0.0.8 2010-06-21 08:53:41 -07:00
e25908bd87 logging 2010-06-21 08:16:19 -07:00
a6522b3584 add recovery.log reporting 2010-06-20 13:16:06 -07:00
598cfc7e9d Remove any references to mmcblk0. Add recovery.log failure hook into ROM Manager. 2010-06-20 09:42:47 -07:00
c290861d4b fix copy and paste typo that was messing up sd-ext backup 2010-06-19 08:42:59 -07:00
e51e47d814 fix up the default SDCARD devices 2010-06-18 15:57:18 -07:00
63e0476b6e Wipe DATADATA as well when doing factory resets or wiping DATA. 2010-06-15 12:56:17 -07:00
8b5e1856b3 support DATADATA 2010-06-14 22:04:22 -07:00
14239d291a begin to abstract out the file system and mount information. known issue: create_fstab causes segfault on incredible. and thus subsequent crash loop of recovery. 2010-06-14 15:02:48 -07:00
f8b21c2b4d hacking away 2010-06-14 12:49:47 -07:00
59bcc7eb3f support ext3 and ext4 partitions 2010-06-11 15:48:49 -07:00
25 changed files with 1952 additions and 192 deletions

View File

@ -13,21 +13,39 @@ LOCAL_SRC_FILES := \
legacy.c \
commands.c \
recovery.c \
bootloader.c \
firmware.c \
install.c \
roots.c \
ui.c \
verifier.c
LOCAL_SRC_FILES += \
reboot.c \
setprop.c
ifndef BOARD_HAS_NO_MISC_PARTITION
LOCAL_SRC_FILES += \
firmware.c \
bootloader.c
else
LOCAL_CFLAGS += -DBOARD_HAS_NO_MISC_PARTITION
endif
ifdef BOARD_RECOVERY_IGNORE_BOOTABLES
LOCAL_CFLAGS += -DBOARD_RECOVERY_IGNORE_BOOTABLES
endif
ifdef BOARD_HIJACK_RECOVERY_PATH
LOCAL_CFLAGS += -DBOARD_HIJACK_RECOVERY_PATH=\"$(BOARD_HIJACK_RECOVERY_PATH)\"
endif
LOCAL_SRC_FILES += test_roots.c
LOCAL_MODULE := recovery
LOCAL_FORCE_STATIC_EXECUTABLE := true
RECOVERY_VERSION := ClockworkMod Recovery v1.8.1.8
LOCAL_CFLAGS := -DRECOVERY_VERSION="$(RECOVERY_VERSION)"
RECOVERY_VERSION := ClockworkMod Recovery v2.5.1.0
LOCAL_CFLAGS += -DRECOVERY_VERSION="$(RECOVERY_VERSION)"
RECOVERY_API_VERSION := 2
LOCAL_CFLAGS += -DRECOVERY_API_VERSION=$(RECOVERY_API_VERSION)
@ -35,6 +53,82 @@ ifeq ($(BOARD_HAS_NO_SELECT_BUTTON),true)
LOCAL_CFLAGS += -DKEY_POWER_IS_SELECT_ITEM
endif
ifdef BOARD_SDCARD_DEVICE_PRIMARY
LOCAL_CFLAGS += -DSDCARD_DEVICE_PRIMARY=\"$(BOARD_SDCARD_DEVICE_PRIMARY)\"
endif
ifdef BOARD_SDCARD_DEVICE_SECONDARY
LOCAL_CFLAGS += -DSDCARD_DEVICE_SECONDARY=\"$(BOARD_SDCARD_DEVICE_SECONDARY)\"
endif
ifdef BOARD_SDEXT_DEVICE
LOCAL_CFLAGS += -DSDEXT_DEVICE=\"$(BOARD_SDEXT_DEVICE)\"
endif
ifdef BOARD_SDEXT_FILESYSTEM
LOCAL_CFLAGS += -DSDEXT_FILESYSTEM=\"$(BOARD_SDEXT_FILESYSTEM)\"
endif
ifdef BOARD_DATA_DEVICE
LOCAL_CFLAGS += -DDATA_DEVICE=\"$(BOARD_DATA_DEVICE)\"
endif
ifdef BOARD_DATA_FILESYSTEM
LOCAL_CFLAGS += -DDATA_FILESYSTEM=\"$(BOARD_DATA_FILESYSTEM)\"
endif
ifdef BOARD_DATADATA_DEVICE
LOCAL_CFLAGS += -DDATADATA_DEVICE=\"$(BOARD_DATADATA_DEVICE)\"
endif
ifdef BOARD_DATADATA_FILESYSTEM
LOCAL_CFLAGS += -DDATADATA_FILESYSTEM=\"$(BOARD_DATADATA_FILESYSTEM)\"
endif
ifdef BOARD_CACHE_DEVICE
LOCAL_CFLAGS += -DCACHE_DEVICE=\"$(BOARD_CACHE_DEVICE)\"
endif
ifdef BOARD_CACHE_FILESYSTEM
LOCAL_CFLAGS += -DCACHE_FILESYSTEM=\"$(BOARD_CACHE_FILESYSTEM)\"
endif
ifdef BOARD_SYSTEM_DEVICE
LOCAL_CFLAGS += -DSYSTEM_DEVICE=\"$(BOARD_SYSTEM_DEVICE)\"
endif
ifdef BOARD_SYSTEM_FILESYSTEM
LOCAL_CFLAGS += -DSYSTEM_FILESYSTEM=\"$(BOARD_SYSTEM_FILESYSTEM)\"
endif
ifdef BOARD_HAS_DATADATA
LOCAL_CFLAGS += -DHAS_DATADATA
endif
ifdef BOARD_DATA_FILESYSTEM_OPTIONS
LOCAL_CFLAGS += -DDATA_FILESYSTEM_OPTIONS=\"$(BOARD_DATA_FILESYSTEM_OPTIONS)\"
endif
ifdef BOARD_DATADATA_FILESYSTEM_OPTIONS
LOCAL_CFLAGS += -DDATADATA_FILESYSTEM_OPTIONS=\"$(BOARD_DATADATA_FILESYSTEM_OPTIONS)\"
endif
ifdef BOARD_CACHE_FILESYSTEM_OPTIONS
LOCAL_CFLAGS += -DCACHE_FILESYSTEM_OPTIONS=\"$(BOARD_CACHE_FILESYSTEM_OPTIONS)\"
endif
ifdef BOARD_SYSTEM_FILESYSTEM_OPTIONS
LOCAL_CFLAGS += -DSYSTEM_FILESYSTEM_OPTIONS=\"$(BOARD_SYSTEM_FILESYSTEM_OPTIONS)\"
endif
ifdef BOARD_HAS_MTD_CACHE
LOCAL_CFLAGS += -DBOARD_HAS_MTD_CACHE
endif
ifdef BOARD_HAS_SMALL_RECOVERY
LOCAL_CFLAGS += -DBOARD_HAS_SMALL_RECOVERY
endif
# This binary is in the recovery ramdisk, which is otherwise a copy of root.
# It gets copied there in config/Makefile. LOCAL_MODULE_TAGS suppresses
# a (redundant) copy of the binary in /system/bin for user builds.
@ -43,10 +137,10 @@ endif
LOCAL_MODULE_TAGS := eng
LOCAL_STATIC_LIBRARIES :=
ifeq ($(TARGET_RECOVERY_UI_LIB),)
ifeq ($(BOARD_CUSTOM_RECOVERY_KEYMAPPING),)
LOCAL_SRC_FILES += default_recovery_ui.c
else
LOCAL_STATIC_LIBRARIES += $(TARGET_RECOVERY_UI_LIB)
LOCAL_SRC_FILES += $(BOARD_CUSTOM_RECOVERY_KEYMAPPING)
endif
LOCAL_STATIC_LIBRARIES += libbusybox libclearsilverregex libmkyaffs2image libunyaffs liberase_image libdump_image libflash_image libmtdutils
LOCAL_STATIC_LIBRARIES += libamend
@ -56,7 +150,8 @@ LOCAL_STATIC_LIBRARIES += libstdc++ libc
include $(BUILD_EXECUTABLE)
RECOVERY_LINKS := amend busybox flash_image dump_image mkyaffs2image unyaffs erase_image
RECOVERY_LINKS := amend busybox flash_image dump_image mkyaffs2image unyaffs erase_image nandroid reboot
# nc is provided by external/netcat
SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(RECOVERY_LINKS))
$(SYMLINKS): RECOVERY_BINARY := $(LOCAL_MODULE)
@ -88,14 +183,6 @@ LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_SRC_FILES := nandroid-md5.sh
include $(BUILD_PREBUILT)
include $(CLEAR_VARS)
LOCAL_MODULE := mkfstab.sh
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_SRC_FILES := mkfstab.sh
include $(BUILD_PREBUILT)
include $(CLEAR_VARS)
LOCAL_MODULE := killrecovery.sh
LOCAL_MODULE_TAGS := eng
@ -111,6 +198,7 @@ include $(commands_recovery_local_path)/mtdutils/Android.mk
include $(commands_recovery_local_path)/tools/Android.mk
include $(commands_recovery_local_path)/edify/Android.mk
include $(commands_recovery_local_path)/updater/Android.mk
include $(commands_recovery_local_path)/utilities/Android.mk
commands_recovery_local_path :=
endif # TARGET_ARCH == arm

View File

@ -145,7 +145,15 @@ cmd_format(const char *name, void *cookie, int argc, const char *argv[],
LOGE("Can't format %s\n", root);
return 1;
}
#ifdef HAS_DATADATA
if (0 == strcmp(root, "DATA:")) {
ret = format_root_device("DATADATA:");
if (ret != 0) {
LOGE("Can't format %s\n", root);
return 1;
}
}
#endif
return 0;
}
@ -618,11 +626,13 @@ cmd_write_firmware_image(const char *name, void *cookie,
return 1;
}
#ifndef BOARD_HAS_NO_MISC_PARTITION
if (remember_firmware_update(type, context.data, context.total_bytes)) {
LOGE("Can't store %s image\n", type);
free(context.data);
return 1;
}
#endif
return 0;
}
@ -774,18 +784,7 @@ cmd_backup_rom(const char *name, void *cookie, int argc, const char *argv[],
case 0:
{
char backup_path[PATH_MAX];
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);
}
nandroid_generate_timestamp_path(backup_path);
backup_name = backup_path;
}
break;

View File

@ -47,6 +47,9 @@ int ui_menu_select(int sel);
// statements will be displayed.
void ui_end_menu();
int ui_get_showing_back_button();
void ui_set_showing_back_button(int showBackButton);
// Set the icon (normally the only thing visible besides the progress bar).
enum {
BACKGROUND_ICON_NONE,

View File

@ -27,8 +27,8 @@ char* MENU_ITEMS[] = { "reboot system now",
"wipe data/factory reset",
"wipe cache partition",
"install zip from sdcard",
"nandroid",
"partitions menu",
"backup and restore",
"mounts and storage",
"advanced",
NULL };
@ -37,11 +37,10 @@ int device_toggle_display(volatile char* key_pressed, int key_code) {
if (alt && key_code == KEY_L)
return 1;
// allow toggling of the display if the correct key is pressed, and the display toggle is allowed or the display is currently off
#ifdef KEY_POWER_IS_SELECT_ITEM
return get_allow_toggle_display() && (key_code == KEY_HOME || key_code == KEY_MENU || key_code == KEY_END);
#else
if (ui_get_showing_back_button()) {
return get_allow_toggle_display() && (key_code == KEY_HOME || key_code == KEY_MENU || key_code == KEY_END);
}
return get_allow_toggle_display() && (key_code == KEY_HOME || key_code == KEY_MENU || key_code == KEY_POWER || key_code == KEY_END);
#endif
}
int device_reboot_now(volatile char* key_pressed, int key_code) {
@ -51,17 +50,24 @@ int device_reboot_now(volatile char* key_pressed, int key_code) {
int device_handle_key(int key_code, int visible) {
if (visible) {
switch (key_code) {
case KEY_CAPSLOCK:
case KEY_DOWN:
case KEY_VOLUMEDOWN:
return HIGHLIGHT_DOWN;
case KEY_LEFTSHIFT:
case KEY_UP:
case KEY_VOLUMEUP:
return HIGHLIGHT_UP;
#ifdef KEY_POWER_IS_SELECT_ITEM
case KEY_POWER:
#endif
if (ui_get_showing_back_button()) {
return SELECT_ITEM;
}
if (!get_allow_toggle_display())
return GO_BACK;
break;
case KEY_LEFTBRACE:
case KEY_ENTER:
case BTN_MOUSE:
case KEY_CENTER:
@ -70,9 +76,6 @@ int device_handle_key(int key_code, int visible) {
case KEY_SEND:
return SELECT_ITEM;
#ifndef KEY_POWER_IS_SELECT_ITEM
case KEY_POWER:
#endif
case KEY_END:
case KEY_BACKSPACE:
case KEY_BACK:

View File

@ -33,6 +33,7 @@
#include "commands.h"
#include "amend/amend.h"
#include "mtdutils/mtdutils.h"
#include "mtdutils/dump_image.h"
#include "../../external/yaffs2/yaffs2/utils/mkyaffs2image.h"
#include "../../external/yaffs2/yaffs2/utils/unyaffs.h"
@ -60,7 +61,9 @@ void toggle_script_asserts()
int install_zip(const char* packagefilepath)
{
ui_print("\n-- Installing: %s\n", packagefilepath);
#ifndef BOARD_HAS_NO_MISC_PARTITION
set_sdcard_update_bootloader_message();
#endif
int status = install_package(packagefilepath);
ui_reset_progress();
if (status != INSTALL_SUCCESS) {
@ -68,9 +71,11 @@ int install_zip(const char* packagefilepath)
ui_print("Installation aborted.\n");
return 1;
}
#ifndef BOARD_HAS_NO_MISC_PARTITION
if (firmware_update_pending()) {
ui_print("\nReboot via menu to complete\ninstallation.\n");
}
#endif
ui_set_background(BACKGROUND_ICON_NONE);
ui_print("\nInstall from sdcard complete.\n");
return 0;
@ -104,8 +109,11 @@ void show_install_update_menu()
toggle_signature_check();
break;
case ITEM_APPLY_SDCARD:
install_zip(SDCARD_PACKAGE_FILE);
{
if (confirm_selection("Confirm install?", "Yes - Install /sdcard/update.zip"))
install_zip(SDCARD_PACKAGE_FILE);
break;
}
case ITEM_CHOOSE_ZIP:
show_choose_zip_menu();
break;
@ -213,6 +221,21 @@ char** gather_files(const char* directory, const char* fileExtensionOrDirectory,
return NULL;
}
// 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;
}
}
return files;
}
@ -300,7 +323,11 @@ void show_choose_zip_menu()
char sdcard_package_file[1024];
strcpy(sdcard_package_file, "SDCARD:");
strcat(sdcard_package_file, file + strlen("/sdcard/"));
install_zip(sdcard_package_file);
static char* confirm_install = "Confirm install?";
static char confirm[PATH_MAX];
sprintf(confirm, "Yes - Install %s", basename(file));
if (confirm_selection(confirm_install, confirm))
install_zip(sdcard_package_file);
}
// This was pulled from bionic: The default system command always looks
@ -359,12 +386,16 @@ void show_nandroid_restore_menu()
char* file = choose_file_menu("/sdcard/clockworkmod/backup/", NULL, headers);
if (file == NULL)
return;
nandroid_restore(file, 1, 1, 1, 1, 1);
if (confirm_selection("Confirm restore?", "Yes - Restore"))
nandroid_restore(file, 1, 1, 1, 1, 1);
}
void show_mount_usb_storage_menu()
{
__system("echo /dev/block/mmcblk0 > /sys/devices/platform/usb_mass_storage/lun0/file");
char command[PATH_MAX];
sprintf(command, "echo %s > /sys/devices/platform/usb_mass_storage/lun0/file", SDCARD_DEVICE_PRIMARY);
__system(command);
static char* headers[] = { "USB Mass Storage device",
"Leaving this menu unmount",
"your SD card from your PC.",
@ -385,28 +416,27 @@ void show_mount_usb_storage_menu()
__system("echo 0 > /sys/devices/platform/usb_mass_storage/lun0/enable");
}
int confirm_format()
int confirm_selection(const char* title, const char* confirm)
{
static char* title_headers[] = { "Confirm format?",
" THIS CAN NOT BE UNDONE.",
"",
NULL,
};
struct stat info;
if (0 == stat("/sdcard/clockworkmod/.no_confirm", &info))
return 1;
char* items[] = { " No",
" No",
" No",
" No",
" No",
" No",
" No",
" Yes -- wipe partition", // [7]
" No",
" No",
" No",
char* confirm_headers[] = { title, " THIS CAN NOT BE UNDONE.", "", NULL };
char* items[] = { "No",
"No",
"No",
"No",
"No",
"No",
"No",
confirm, //" Yes -- wipe partition", // [7
"No",
"No",
"No",
NULL };
int chosen_item = get_menu_selection(title_headers, items, 0);
int chosen_item = get_menu_selection(confirm_headers, items, 0);
return chosen_item == 7;
}
@ -416,7 +446,7 @@ int format_non_mtd_device(const char* root)
if (0 == strcmp(root, "SDEXT:"))
{
struct stat st;
if (0 != stat("/dev/block/mmcblk0p2", &st))
if (0 != stat(SDEXT_DEVICE, &st))
{
ui_print("No app2sd partition found. Skipping format of /sd-ext.\n");
return 0;
@ -428,7 +458,8 @@ int format_non_mtd_device(const char* root)
if (0 != ensure_root_path_mounted(root))
{
ui_print("Error mounting %s!\n", path);
return 1;
ui_print("Skipping format...\n");
return 0;
}
static char tmp[PATH_MAX];
@ -447,7 +478,7 @@ int format_non_mtd_device(const char* root)
void show_partition_menu()
{
static char* headers[] = { "Mount and unmount partitions",
static char* headers[] = { "Mounts and Storage Menu",
"",
NULL
};
@ -472,6 +503,9 @@ void show_partition_menu()
{ "format sdcard", "SDCARD:" },
{ "format sd-ext", "SDEXT:" }
};
static char* confirm_format = "Confirm format?";
static char* confirm = "Yes - Format";
for (;;)
{
@ -520,7 +554,7 @@ void show_partition_menu()
else if (chosen_item < MOUNTABLE_COUNT + MTD_COUNT)
{
chosen_item = chosen_item - MOUNTABLE_COUNT;
if (!confirm_format())
if (!confirm_selection(confirm_format, confirm))
continue;
ui_print("Formatting %s...\n", mtds[chosen_item][1]);
if (0 != format_root_device(mtds[chosen_item][1]))
@ -531,7 +565,7 @@ void show_partition_menu()
else if (chosen_item < MOUNTABLE_COUNT + MTD_COUNT + MMC_COUNT)
{
chosen_item = chosen_item - MOUNTABLE_COUNT - MTD_COUNT;
if (!confirm_format())
if (!confirm_selection(confirm_format, confirm))
continue;
ui_print("Formatting %s...\n", mmcs[chosen_item][1]);
if (0 != format_non_mtd_device(mmcs[chosen_item][1]))
@ -595,6 +629,8 @@ int run_script(char* filename)
// supposedly not necessary, but let's be safe.
script_data[script_len] = '\0';
fclose(file);
LOGI("Running script:\n");
LOGI("\n%s\n", script_data);
int ret = run_script_from_buffer(script_data, script_len, filename);
free(script_data);
@ -616,6 +652,7 @@ int run_and_remove_extendedcommand()
}
sleep(1);
}
remove("/sdcard/clockworkmod/.recoverycheckpoint");
if (i == 0) {
ui_print("Timed out waiting for SD card... continuing anyways.");
}
@ -672,23 +709,31 @@ void show_nandroid_advanced_restore_menu()
NULL
};
static char* confirm_restore = "Confirm restore?";
int chosen_item = get_menu_selection(headers, list, 0);
switch (chosen_item)
{
case 0:
nandroid_restore(file, 1, 0, 0, 0, 0);
if (confirm_selection(confirm_restore, "Yes - Restore boot"))
nandroid_restore(file, 1, 0, 0, 0, 0);
break;
case 1:
nandroid_restore(file, 0, 1, 0, 0, 0);
if (confirm_selection(confirm_restore, "Yes - Restore system"))
nandroid_restore(file, 0, 1, 0, 0, 0);
break;
case 2:
nandroid_restore(file, 0, 0, 1, 0, 0);
if (confirm_selection(confirm_restore, "Yes - Restore data"))
nandroid_restore(file, 0, 0, 1, 0, 0);
break;
case 3:
nandroid_restore(file, 0, 0, 0, 1, 0);
if (confirm_selection(confirm_restore, "Yes - Restore cache"))
nandroid_restore(file, 0, 0, 0, 1, 0);
break;
case 4:
nandroid_restore(file, 0, 0, 0, 0, 1);
if (confirm_selection(confirm_restore, "Yes - Restore sd-ext"))
nandroid_restore(file, 0, 0, 0, 0, 1);
break;
}
}
@ -751,8 +796,14 @@ void show_advanced_menu()
};
static char* list[] = { "Reboot Recovery",
"Wipe Dalvik Cache",
"Wipe Battery Stats",
"Report Error",
"Key Test",
#ifndef BOARD_HAS_SMALL_RECOVERY
"Partition SD Card",
"Fix Permissions",
#endif
NULL
};
@ -767,9 +818,30 @@ void show_advanced_menu()
__reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, "recovery");
break;
case 1:
wipe_battery_stats();
{
if (0 != ensure_root_path_mounted("DATA:"))
break;
ensure_root_path_mounted("SDEXT:");
ensure_root_path_mounted("CACHE:");
if (confirm_selection( "Confirm wipe?", "Yes - Wipe Dalvik Cache")) {
__system("rm -r /data/dalvik-cache");
__system("rm -r /cache/dalvik-cache");
__system("rm -r /sd-ext/dalvik-cache");
}
ensure_root_path_unmounted("DATA:");
ui_print("Dalvik Cache wiped.\n");
break;
}
case 2:
{
if (confirm_selection( "Confirm wipe?", "Yes - Wipe Battery Stats"))
wipe_battery_stats();
break;
}
case 3:
handle_failure(1);
break;
case 4:
{
ui_print("Outputting key codes.\n");
ui_print("Go back to end debugging.\n");
@ -782,7 +854,109 @@ void show_advanced_menu()
ui_print("Key: %d\n", key);
}
while (action != GO_BACK);
break;
}
case 5:
{
static char* ext_sizes[] = { "128M",
"256M",
"512M",
"1024M",
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 };
int ext_size = get_menu_selection(ext_headers, ext_sizes, 0);
if (ext_size == GO_BACK)
continue;
int swap_size = get_menu_selection(swap_headers, swap_sizes, 0);
if (swap_size == GO_BACK)
continue;
char sddevice[256];
const RootInfo *ri = get_root_info_for_path("SDCARD:");
strcpy(sddevice, ri->device);
// 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");
break;
}
case 6:
{
ensure_root_path_mounted("SYSTEM:");
ensure_root_path_mounted("DATA:");
ui_print("Fixing permissions...\n");
__system("fix_permissions");
ui_print("Done!\n");
break;
}
}
}
}
void write_fstab_root(char *root_path, FILE *file)
{
RootInfo *info = get_root_info_for_path(root_path);
if (info == NULL) {
LOGW("Unable to get root info for %s during fstab generation!", root_path);
return;
}
MtdPartition *mtd = get_root_mtd_partition(root_path);
if (mtd != NULL)
{
fprintf(file, "/dev/block/mtdblock%d ", mtd->device_index);
}
else
{
fprintf(file, "%s ", info->device);
}
fprintf(file, "%s ", info->mount_point);
fprintf(file, "%s %s\n", info->filesystem, info->filesystem_options == NULL ? "rw" : info->filesystem_options);
}
void create_fstab()
{
__system("touch /etc/mtab");
FILE *file = fopen("/etc/fstab", "w");
if (file == NULL) {
LOGW("Unable to create /etc/fstab!");
return;
}
write_fstab_root("CACHE:", file);
write_fstab_root("DATA:", file);
#ifdef HAS_DATADATA
write_fstab_root("DATADATA:", file);
#endif
write_fstab_root("SYSTEM:", file);
write_fstab_root("SDCARD:", file);
write_fstab_root("SDEXT:", file);
fclose(file);
}
void handle_failure(int ret)
{
if (ret == 0)
return;
if (0 != ensure_root_path_mounted("SDCARD:"))
return;
mkdir("/sdcard/clockworkmod", S_IRWXU);
__system("cp /tmp/recovery.log /sdcard/clockworkmod/recovery.log");
ui_print("/tmp/recovery.log was copied to /sdcard/clockworkmod/recovery.log. Please open ROM Manager to report the issue.\n");
}

View File

@ -43,3 +43,4 @@ format_non_mtd_device(const char* root);
void
wipe_battery_stats();
void create_fstab();

View File

@ -90,11 +90,13 @@ handle_firmware_update(char* type, char* filename, ZipArchive* zip) {
fclose(f);
}
#ifndef BOARD_HAS_NO_MISC_PARTITION
if (remember_firmware_update(type, data, data_size)) {
LOGE("Can't store %s image\n", type);
free(data);
return INSTALL_ERROR;
}
#endif
free(filename);
return INSTALL_SUCCESS;

View File

@ -5,4 +5,18 @@ rm /cache/update.zip
touch /tmp/.ignorebootmessage
kill $(ps | grep /sbin/adbd)
kill $(ps | grep /sbin/recovery)
exit 1
# On the Galaxy S, the recovery comes test signed, but the
# recovery is not automatically restarted.
if [ -f /init.smdkc110.rc ]
then
/sbin/recovery &
fi
# Droid X
if [ -f /init.mapphone_cdma.rc ]
then
/sbin/recovery &
fi
exit 1

View File

@ -1,35 +0,0 @@
#!/sbin/sh
rm -f /etc/fstab
cat /proc/mtd | while read mtdentry
do
mtd=$(echo $mtdentry | awk '{print $1}')
mtd=$(echo $mtd | sed s/mtd//)
mtd=$(echo $mtd | sed s/://)
exist=$(ls -l /dev/block/mtdblock$mtd) 2> /dev/null
if [ -z "$exist" ]
then
continue
fi
partition=$(echo $mtdentry | awk '{print $4}')
partition=$(echo $partition | sed s/\"//g)
mount=$partition
type=
if [ "$partition" = "system" ]
then
type=yaffs2
elif [ "$partition" = "userdata" ]
then
type=yaffs2
mount=data
elif [ "$partition" == "cache" ]
then
type=yaffs2
else
continue
fi
echo "/dev/block/mtdblock$mtd /$mount $type rw" >> /etc/fstab
done
echo "/dev/block/mmcblk0p1" /sdcard vfat rw >> /etc/fstab
echo "/dev/block/mmcblk0p2" /sd-ext ext4 rw >> /etc/fstab

View File

@ -28,13 +28,6 @@
#include "mtdutils.h"
struct MtdPartition {
int device_index;
unsigned int size;
unsigned int erase_size;
char *name;
};
struct MtdReadContext {
const MtdPartition *partition;
char *buffer;

View File

@ -52,4 +52,11 @@ off_t mtd_erase_blocks(MtdWriteContext *, int blocks); /* 0 ok, -1 for all */
off_t mtd_find_write_start(MtdWriteContext *ctx, off_t pos);
int mtd_write_close(MtdWriteContext *);
struct MtdPartition {
int device_index;
unsigned int size;
unsigned int erase_size;
char *name;
};
#endif // MTDUTILS_H_

View File

@ -75,7 +75,7 @@ void compute_directory_stats(char* directory)
ui_show_progress(1, 0);
}
int nandroid_backup_partition(const char* backup_path, char* root) {
int nandroid_backup_partition_extended(const char* backup_path, char* root, int umount_when_finished) {
int ret = 0;
char mount_point[PATH_MAX];
translate_root_path(root, mount_point, PATH_MAX);
@ -96,7 +96,9 @@ int nandroid_backup_partition(const char* backup_path, char* root) {
char tmp[PATH_MAX];
sprintf(tmp, "%s/%s.img", backup_path, name);
ret = mkyaffs2image(mount_point, tmp, 0, callback);
ensure_root_path_unmounted(root);
if (umount_when_finished) {
ensure_root_path_unmounted(root);
}
if (0 != ret) {
ui_print("Error while making a yaffs2 image of %s!\n", mount_point);
return ret;
@ -104,6 +106,10 @@ int nandroid_backup_partition(const char* backup_path, char* root) {
return 0;
}
int nandroid_backup_partition(const char* backup_path, char* root) {
return nandroid_backup_partition_extended(backup_path, root, 1);
}
int nandroid_backup(const char* backup_path)
{
ui_set_background(BACKGROUND_ICON_INSTALLING);
@ -127,6 +133,7 @@ int nandroid_backup(const char* backup_path)
sprintf(tmp, "mkdir -p %s", backup_path);
__system(tmp);
#ifndef BOARD_RECOVERY_IGNORE_BOOTABLES
ui_print("Backing up boot...\n");
sprintf(tmp, "%s/%s", backup_path, "boot.img");
ret = dump_image("boot", tmp, NULL);
@ -137,7 +144,8 @@ int nandroid_backup(const char* backup_path)
sprintf(tmp, "%s/%s", backup_path, "recovery.img");
ret = dump_image("recovery", tmp, NULL);
if (0 != ret)
return print_and_error("Error while dumping boot image!\n");
return print_and_error("Error while dumping recovery image!\n");
#endif
if (0 != (ret = nandroid_backup_partition(backup_path, "SYSTEM:")))
return ret;
@ -145,22 +153,37 @@ int nandroid_backup(const char* backup_path)
if (0 != (ret = nandroid_backup_partition(backup_path, "DATA:")))
return ret;
if (0 != (ret = nandroid_backup_partition(backup_path, "CACHE:")))
#ifdef HAS_DATADATA
if (0 != (ret = nandroid_backup_partition(backup_path, "DATADATA:")))
return ret;
#endif
struct stat st;
if (0 != stat("/dev/block/mmcblk0p2", &st))
if (0 != stat("/sdcard/.android_secure", &st))
{
ui_print("No /sdcard/.android_secure found. Skipping backup of applications on external storage.\n");
}
else
{
if (0 != (ret = nandroid_backup_partition_extended(backup_path, "SDCARD:/.android_secure", 0)))
return ret;
}
if (0 != (ret = nandroid_backup_partition_extended(backup_path, "CACHE:", 0)))
return ret;
if (0 != stat(SDEXT_DEVICE, &st))
{
ui_print("No sd-ext found. Skipping backup of sd-ext.\n");
}
else
{
if (0 != ensure_root_path_mounted("SDEXT:"))
ui_print("Could not mount sd-ext. sd-ext backup may not be supported on this device. Skipping backup of sd-ext.");
ui_print("Could not mount sd-ext. sd-ext backup may not be supported on this device. Skipping backup of sd-ext.\n");
else if (0 != (ret = nandroid_backup_partition(backup_path, "SDEXT:")))
return ret;
}
ui_print("Generating md5 sum...\n");
sprintf(tmp, "nandroid-md5.sh %s", backup_path);
if (0 != (ret = __system(tmp))) {
@ -177,23 +200,40 @@ int nandroid_backup(const char* backup_path)
typedef int (*format_function)(char* root);
int nandroid_restore_partition(const char* backup_path, const char* root) {
static void ensure_directory(const char* dir) {
char tmp[PATH_MAX];
sprintf(tmp, "mkdir -p %s", dir);
__system(tmp);
}
int nandroid_restore_partition_extended(const char* backup_path, const char* root, int umount_when_finished) {
int ret = 0;
char mount_point[PATH_MAX];
translate_root_path(root, mount_point, PATH_MAX);
char* name = basename(mount_point);
char tmp[PATH_MAX];
sprintf(tmp, "%s/%s.img", backup_path, name);
struct stat file_info;
if (0 != (ret = statfs(tmp, &file_info))) {
ui_print("%s.img not found. Skipping restore of %s.\n", name, mount_point);
return 0;
}
ensure_directory(mount_point);
unyaffs_callback callback = NULL;
if (0 != stat("/sdcard/clockworkmod/.hidenandroidprogress", &file_info)) {
callback = yaffs_callback;
}
ui_print("Restoring %s...\n", name);
/*
if (0 != (ret = ensure_root_path_unmounted(root))) {
ui_print("Can't unmount %s!\n", mount_point);
return ret;
}
*/
if (0 != (ret = format_root_device(root))) {
ui_print("Error while formatting %s!\n", root);
return ret;
@ -204,19 +244,22 @@ int nandroid_restore_partition(const char* backup_path, const char* root) {
return ret;
}
char tmp[PATH_MAX];
sprintf(tmp, "%s/%s.img", backup_path, name);
if (0 != (ret = unyaffs(tmp, mount_point, callback))) {
ui_print("Error while restoring %s!\n", mount_point);
return ret;
}
if (0 != strcmp(root, "CACHE")) {
if (umount_when_finished) {
ensure_root_path_unmounted(root);
}
return 0;
}
int nandroid_restore_partition(const char* backup_path, const char* root) {
return nandroid_restore_partition_extended(backup_path, root, 1);
}
int nandroid_restore(const char* backup_path, int restore_boot, int restore_system, int restore_data, int restore_cache, int restore_sdext)
{
ui_set_background(BACKGROUND_ICON_INSTALLING);
@ -234,6 +277,7 @@ int nandroid_restore(const char* backup_path, int restore_boot, int restore_syst
return print_and_error("MD5 mismatch!\n");
int ret;
#ifndef BOARD_RECOVERY_IGNORE_BOOTABLES
if (restore_boot)
{
ui_print("Erasing boot before restore...\n");
@ -246,25 +290,27 @@ int nandroid_restore(const char* backup_path, int restore_boot, int restore_syst
return ret;
}
}
#endif
if (restore_system && 0 != (ret = nandroid_restore_partition(backup_path, "SYSTEM:")))
return ret;
if (restore_data && 0 != (ret = nandroid_restore_partition(backup_path, "DATA:")))
return ret;
#ifdef HAS_DATADATA
if (restore_data && 0 != (ret = nandroid_restore_partition(backup_path, "DATADATA:")))
return ret;
#endif
if (restore_cache && 0 != (ret = nandroid_restore_partition(backup_path, "CACHE:")))
if (restore_data && 0 != (ret = nandroid_restore_partition_extended(backup_path, "SDCARD:/.android_secure", 0)))
return ret;
if (restore_sdext)
{
struct statfs s;
sprintf(tmp, "%s/sd-ext.img", backup_path);
if (0 != (ret = statfs(tmp, &s)))
ui_print("sd-ext.img not found. Skipping restore of /sd-ext.");
else if (0 != (ret = nandroid_restore_partition(backup_path, "SDEXT:")))
return ret;
}
if (restore_cache && 0 != (ret = nandroid_restore_partition_extended(backup_path, "CACHE:", 0)))
return ret;
if (restore_sdext && 0 != (ret = nandroid_restore_partition(backup_path, "SDEXT:")))
return ret;
sync();
ui_set_background(BACKGROUND_ICON_NONE);
@ -272,3 +318,51 @@ int nandroid_restore(const char* backup_path, int restore_boot, int restore_syst
ui_print("\nRestore complete!\n");
return 0;
}
void nandroid_generate_timestamp_path(char* backup_path)
{
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, PATH_MAX, "/sdcard/clockworkmod/backup/%F.%H.%M.%S", tmp);
}
}
int nandroid_usage()
{
printf("Usage: nandroid backup\n");
printf("Usage: nandroid restore <directory>\n");
return 1;
}
int nandroid_main(int argc, char** argv)
{
if (argc > 3 || argc < 2)
return nandroid_usage();
if (strcmp("backup", argv[1]) == 0)
{
if (argc != 2)
return nandroid_usage();
char backup_path[PATH_MAX];
nandroid_generate_timestamp_path(backup_path);
return nandroid_backup(backup_path);
}
if (strcmp("restore", argv[1]) == 0)
{
if (argc != 3)
return nandroid_usage();
return nandroid_restore(argv[2], 1, 1, 1, 1, 1);
}
return nandroid_usage();
}

View File

@ -4,5 +4,6 @@
int nandroid_main(int argc, char** argv);
int nandroid_backup(const char* backup_path);
int nandroid_restore(const char* backup_path, int restore_boot, int restore_system, int restore_data, int restore_cache, int restore_sdext);
void nandroid_generate_timestamp_path(char* backup_path);
#endif

72
reboot.c Normal file
View File

@ -0,0 +1,72 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/reboot.h>
#include <unistd.h>
#include <cutils/properties.h>
int reboot_main(int argc, char *argv[])
{
int ret;
int nosync = 0;
int poweroff = 0;
int force = 0;
opterr = 0;
do {
int c;
c = getopt(argc, argv, "npf");
if (c == EOF) {
break;
}
switch (c) {
case 'n':
nosync = 1;
break;
case 'p':
poweroff = 1;
break;
case 'f':
force = 1;
break;
case '?':
fprintf(stderr, "usage: %s [-n] [-p] [rebootcommand]\n", argv[0]);
exit(EXIT_FAILURE);
}
} while (1);
if(argc > optind + 1) {
fprintf(stderr, "%s: too many arguments\n", argv[0]);
exit(EXIT_FAILURE);
}
if(!nosync)
sync();
if(force || argc > optind) {
if(poweroff)
ret = __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_POWER_OFF, NULL);
else if(argc > optind)
ret = __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, argv[optind]);
else
ret = reboot(RB_AUTOBOOT);
} else {
if(poweroff) {
property_set("ctl.start", "poweroff");
ret = 0;
} else {
property_set("ctl.start", "reboot");
ret = 0;
}
}
if(ret < 0) {
perror("reboot");
exit(EXIT_FAILURE);
}
fprintf(stderr, "reboot returned\n");
return 0;
}

View File

@ -157,7 +157,9 @@ static void
get_args(int *argc, char ***argv) {
struct bootloader_message boot;
memset(&boot, 0, sizeof(boot));
#ifndef BOARD_HAS_NO_MISC_PARTITION
get_bootloader_message(&boot); // this may fail, leaving a zeroed structure
#endif
if (boot.command[0] != 0 && boot.command[0] != 255) {
LOGI("Boot command: %.*s\n", sizeof(boot.command), boot.command);
@ -214,9 +216,12 @@ get_args(int *argc, char ***argv) {
strlcat(boot.recovery, (*argv)[i], sizeof(boot.recovery));
strlcat(boot.recovery, "\n", sizeof(boot.recovery));
}
#ifndef BOARD_HAS_NO_MISC_PARTITION
set_bootloader_message(&boot);
#endif
}
#ifndef BOARD_HAS_NO_MISC_PARTITION
void
set_sdcard_update_bootloader_message()
{
@ -226,6 +231,7 @@ set_sdcard_update_bootloader_message()
strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery));
set_bootloader_message(&boot);
}
#endif
// clear the recovery command and prepare to boot a (hopefully working) system,
// copy our log file to cache as well (for the system to read), and
@ -260,10 +266,12 @@ finish_recovery(const char *send_intent)
check_and_fclose(log, LOG_FILE);
}
#ifndef BOARD_HAS_NO_MISC_PARTITION
// Reset the bootloader message to revert to a normal main system boot.
struct bootloader_message boot;
memset(&boot, 0, sizeof(boot));
set_bootloader_message(&boot);
#endif
// Remove the command file, so recovery won't repeat indefinitely.
char path[PATH_MAX] = "";
@ -317,12 +325,19 @@ get_menu_selection(char** headers, char** items, int menu_only) {
int selected = 0;
int chosen_item = -1;
// Some users with dead enter keys need a way to turn on power to select.
// Jiggering across the wrapping menu is one "secret" way to enable it.
// We can't rely on /cache or /sdcard since they may not be available.
int wrap_count = 0;
while (chosen_item < 0 && chosen_item != GO_BACK) {
int key = ui_wait_key();
int visible = ui_text_visible();
int action = device_handle_key(key, visible);
int old_selected = selected;
if (action < 0) {
switch (action) {
case HIGHLIGHT_UP:
@ -335,11 +350,11 @@ get_menu_selection(char** headers, char** items, int menu_only) {
break;
case SELECT_ITEM:
chosen_item = selected;
#ifdef KEY_POWER_IS_SELECT_ITEM
if (chosen_item == item_count) {
chosen_item = GO_BACK;
if (ui_get_showing_back_button()) {
if (chosen_item == item_count) {
chosen_item = GO_BACK;
}
}
#endif
break;
case NO_ACTION:
break;
@ -350,6 +365,21 @@ get_menu_selection(char** headers, char** items, int menu_only) {
} else if (!menu_only) {
chosen_item = action;
}
if (abs(selected - old_selected) > 1) {
wrap_count++;
if (wrap_count == 3) {
wrap_count = 0;
if (ui_get_showing_back_button()) {
ui_print("Back menu button disabled.\n");
ui_set_showing_back_button(0);
}
else {
ui_print("Back menu button enabled.\n");
ui_set_showing_back_button(1);
}
}
}
}
ui_end_menu();
@ -392,8 +422,12 @@ wipe_data(int confirm) {
ui_print("\n-- Wiping data...\n");
device_wipe_data();
erase_root("DATA:");
#ifdef HAS_DATADATA
erase_root("DATADATA:");
#endif
erase_root("CACHE:");
erase_root("SDEXT:");
erase_root("SDCARD:/.android_secure");
ui_print("Data wipe complete.\n");
}
@ -401,7 +435,6 @@ static void
prompt_and_wait()
{
char** headers = prepend_title(MENU_HEADERS);
ui_print(EXPAND(RECOVERY_VERSION)"\n");
for (;;) {
finish_recovery(NULL);
@ -426,27 +459,39 @@ prompt_and_wait()
break;
case ITEM_WIPE_CACHE:
ui_print("\n-- Wiping cache...\n");
erase_root("CACHE:");
ui_print("Cache wipe complete.\n");
if (!ui_text_visible()) return;
if (confirm_selection("Confirm wipe?", "Yes - Wipe Cache"))
{
ui_print("\n-- Wiping cache...\n");
erase_root("CACHE:");
ui_print("Cache wipe complete.\n");
if (!ui_text_visible()) return;
}
break;
case ITEM_APPLY_SDCARD:
ui_print("\n-- Install from sdcard...\n");
set_sdcard_update_bootloader_message();
int status = install_package(SDCARD_PACKAGE_FILE);
if (status != INSTALL_SUCCESS) {
ui_set_background(BACKGROUND_ICON_ERROR);
ui_print("Installation aborted.\n");
} else if (!ui_text_visible()) {
return; // reboot if logs aren't visible
} else {
if (firmware_update_pending()) {
ui_print("\nReboot via menu to complete\n"
"installation.\n");
if (confirm_selection("Confirm install?", "Yes - Install /sdcard/update.zip"))
{
ui_print("\n-- Install from sdcard...\n");
#ifndef BOARD_HAS_NO_MISC_PARTITION
set_sdcard_update_bootloader_message();
#endif
int status = install_package(SDCARD_PACKAGE_FILE);
if (status != INSTALL_SUCCESS) {
ui_set_background(BACKGROUND_ICON_ERROR);
ui_print("Installation aborted.\n");
} else if (!ui_text_visible()) {
return; // reboot if logs aren't visible
} else {
#ifndef BOARD_HAS_NO_MISC_PARTITION
if (firmware_update_pending()) {
ui_print("\nReboot via menu to complete\n"
"installation.\n");
} else {
ui_print("\nInstall from sdcard complete.\n");
}
#else
ui_print("\nInstall from sdcard complete.\n");
#endif
}
}
break;
@ -489,9 +534,16 @@ main(int argc, char **argv)
return unyaffs_main(argc, argv);
if (strstr(argv[0], "amend"))
return amend_main(argc, argv);
if (strstr(argv[0], "nandroid"))
return nandroid_main(argc, argv);
if (strstr(argv[0], "reboot"))
return reboot_main(argc, argv);
if (strstr(argv[0], "setprop"))
return setprop_main(argc, argv);
return busybox_driver(argc, argv);
}
__system("/sbin/mkfstab.sh");
__system("/sbin/postrecoveryboot.sh");
create_fstab();
int is_user_initiated_recovery = 0;
time_t start = time(NULL);
@ -502,6 +554,7 @@ main(int argc, char **argv)
fprintf(stderr, "Starting recovery on %s", ctime(&start));
ui_init();
ui_print(EXPAND(RECOVERY_VERSION)"\n");
get_args(&argc, &argv);
int previous_runs = 0;
@ -563,10 +616,14 @@ main(int argc, char **argv)
if (extendedcommand_file_exists()) {
LOGI("Running extendedcommand...\n");
if (0 == run_and_remove_extendedcommand()) {
int ret;
if (0 == (ret = run_and_remove_extendedcommand())) {
status = INSTALL_SUCCESS;
ui_set_show_text(0);
}
else {
handle_failure(ret);
}
} else {
LOGI("Skipping execution of extendedcommand, file not found...\n");
}
@ -575,8 +632,10 @@ main(int argc, char **argv)
if (status != INSTALL_SUCCESS && !is_user_initiated_recovery) ui_set_background(BACKGROUND_ICON_ERROR);
if (status != INSTALL_SUCCESS || ui_text_visible()) prompt_and_wait();
#ifndef BOARD_HAS_NO_MISC_PARTITION
// If there is a radio image pending, reboot now to install it.
maybe_install_firmware_update(send_intent);
#endif
// Otherwise, get ready to boot the main system...
finish_recovery(send_intent);

65
roots.c
View File

@ -21,6 +21,8 @@
#include <sys/types.h>
#include <unistd.h>
#include <limits.h>
#include "mtdutils/mtdutils.h"
#include "mtdutils/mounts.h"
#include "minzip/Zip.h"
@ -29,15 +31,6 @@
#include "extendedcommands.h"
typedef struct {
const char *name;
const char *device;
const char *device2; // If the first one doesn't work (may be NULL)
const char *partition_name;
const char *mount_point;
const char *filesystem;
} RootInfo;
/* Canonical pointers.
xxx may just want to use enums
*/
@ -46,23 +39,26 @@ static const char g_raw[] = "@\0g_raw";
static const char g_package_file[] = "@\0g_package_file";
static RootInfo g_roots[] = {
{ "BOOT:", g_mtd_device, NULL, "boot", NULL, g_raw },
{ "CACHE:", g_mtd_device, NULL, "cache", "/cache", "yaffs2" },
{ "DATA:", g_mtd_device, NULL, "userdata", "/data", "yaffs2" },
{ "MISC:", g_mtd_device, NULL, "misc", NULL, g_raw },
{ "PACKAGE:", NULL, NULL, NULL, NULL, g_package_file },
{ "RECOVERY:", g_mtd_device, NULL, "recovery", "/", g_raw },
{ "SDCARD:", "/dev/block/mmcblk0p1", "/dev/block/mmcblk0", NULL, "/sdcard", "vfat" },
{ "SDEXT:", "/dev/block/mmcblk0p2", NULL, NULL, "/sd-ext", "ext4" },
{ "SYSTEM:", g_mtd_device, NULL, "system", "/system", "yaffs2" },
{ "MBM:", g_mtd_device, NULL, "mbm", NULL, g_raw },
{ "TMP:", NULL, NULL, NULL, "/tmp", NULL },
{ "BOOT:", g_mtd_device, NULL, "boot", NULL, g_raw, NULL },
{ "CACHE:", CACHE_DEVICE, NULL, "cache", "/cache", CACHE_FILESYSTEM, CACHE_FILESYSTEM_OPTIONS },
{ "DATA:", DATA_DEVICE, NULL, "userdata", "/data", DATA_FILESYSTEM, DATA_FILESYSTEM_OPTIONS },
#ifdef HAS_DATADATA
{ "DATADATA:", DATADATA_DEVICE, NULL, "datadata", "/datadata", DATADATA_FILESYSTEM, DATADATA_FILESYSTEM_OPTIONS },
#endif
{ "MISC:", g_mtd_device, NULL, "misc", NULL, g_raw, NULL },
{ "PACKAGE:", NULL, NULL, NULL, NULL, g_package_file, NULL },
{ "RECOVERY:", g_mtd_device, NULL, "recovery", "/", g_raw, NULL },
{ "SDCARD:", SDCARD_DEVICE_PRIMARY, SDCARD_DEVICE_SECONDARY, NULL, "/sdcard", "vfat", NULL },
{ "SDEXT:", SDEXT_DEVICE, NULL, NULL, "/sd-ext", SDEXT_FILESYSTEM, NULL },
{ "SYSTEM:", SYSTEM_DEVICE, NULL, "system", "/system", SYSTEM_FILESYSTEM, SYSTEM_FILESYSTEM_OPTIONS },
{ "MBM:", g_mtd_device, NULL, "mbm", NULL, g_raw, NULL },
{ "TMP:", NULL, NULL, NULL, "/tmp", NULL, NULL },
};
#define NUM_ROOTS (sizeof(g_roots) / sizeof(g_roots[0]))
// TODO: for SDCARD:, try /dev/block/mmcblk0 if mmcblk0p1 fails
static const RootInfo *
const RootInfo *
get_root_info_for_path(const char *root_path)
{
const char *c;
@ -211,6 +207,19 @@ is_root_path_mounted(const char *root_path)
return internal_root_mounted(info) >= 0;
}
static int mount_internal(const char* device, const char* mount_point, const char* filesystem, const char* filesystem_options)
{
if (strcmp(filesystem, "auto") != 0 && filesystem_options == NULL) {
return mount(device, mount_point, filesystem, MS_NOATIME | MS_NODEV | MS_NODIRATIME, "");
}
else {
char mount_cmd[PATH_MAX];
const char* options = filesystem_options == NULL ? "noatime,nodiratime,nodev" : filesystem_options;
sprintf(mount_cmd, "mount -t %s -o%s %s %s", filesystem, options, device, mount_point);
return __system(mount_cmd);
}
}
int
ensure_root_path_mounted(const char *root_path)
{
@ -251,8 +260,7 @@ ensure_root_path_mounted(const char *root_path)
}
mkdir(info->mount_point, 0755); // in case it doesn't already exist
if (mount(info->device, info->mount_point, info->filesystem,
MS_NOATIME | MS_NODEV | MS_NODIRATIME, "")) {
if (mount_internal(info->device, info->mount_point, info->filesystem, info->filesystem_options)) {
if (info->device2 == NULL) {
LOGE("Can't mount %s\n(%s)\n", info->device, strerror(errno));
return -1;
@ -304,7 +312,12 @@ get_root_mtd_partition(const char *root_path)
if (info == NULL || info->device != g_mtd_device ||
info->partition_name == NULL)
{
#ifdef BOARD_HAS_MTD_CACHE
if (strcmp(root_path, "CACHE:") != 0)
return NULL;
#else
return NULL;
#endif
}
mtd_scan_partitions();
return mtd_find_partition_by_name(info->partition_name);
@ -320,17 +333,19 @@ format_root_device(const char *root)
while (*c != '\0' && *c != ':') {
c++;
}
/*
if (c[0] != ':' || c[1] != '\0') {
LOGW("format_root_device: bad root name \"%s\"\n", root);
return -1;
}
*/
const RootInfo *info = get_root_info_for_path(root);
if (info == NULL || info->device == NULL) {
LOGW("format_root_device: can't resolve \"%s\"\n", root);
return -1;
}
if (info->mount_point != NULL) {
if (info->mount_point != NULL && info->device == g_mtd_device) {
/* Don't try to format a mounted device.
*/
int ret = ensure_root_path_unmounted(root);
@ -368,6 +383,6 @@ format_root_device(const char *root)
}
}
}
return format_non_mtd_device(root);
}

75
roots.h
View File

@ -20,6 +20,71 @@
#include "minzip/Zip.h"
#include "mtdutils/mtdutils.h"
#ifndef SDCARD_DEVICE_PRIMARY
#define SDCARD_DEVICE_PRIMARY "/dev/block/mmcblk0p1"
#endif
#ifndef SDCARD_DEVICE_SECONDARY
#define SDCARD_DEVICE_SECONDARY "/dev/block/mmcblk0"
#endif
#ifndef SDEXT_DEVICE
#define SDEXT_DEVICE "/dev/block/mmcblk0p2"
#endif
#ifndef SDEXT_FILESYSTEM
#define SDEXT_FILESYSTEM "auto"
#endif
#ifndef DATA_DEVICE
#define DATA_DEVICE g_mtd_device
#endif
#ifndef DATA_FILESYSTEM
#define DATA_FILESYSTEM "yaffs2"
#endif
#ifndef DATADATA_DEVICE
#define DATADATA_DEVICE g_mtd_device
#endif
#ifndef DATADATA_FILESYSTEM
#define DATADATA_FILESYSTEM "yaffs2"
#endif
#ifndef CACHE_DEVICE
#define CACHE_DEVICE g_mtd_device
#endif
#ifndef CACHE_FILESYSTEM
#define CACHE_FILESYSTEM "yaffs2"
#endif
#ifndef SYSTEM_DEVICE
#define SYSTEM_DEVICE g_mtd_device
#endif
#ifndef SYSTEM_FILESYSTEM
#define SYSTEM_FILESYSTEM "yaffs2"
#endif
#ifndef DATA_FILESYSTEM_OPTIONS
#define DATA_FILESYSTEM_OPTIONS NULL
#endif
#ifndef CACHE_FILESYSTEM_OPTIONS
#define CACHE_FILESYSTEM_OPTIONS NULL
#endif
#ifndef DATADATA_FILESYSTEM_OPTIONS
#define DATADATA_FILESYSTEM_OPTIONS NULL
#endif
#ifndef SYSTEM_FILESYSTEM_OPTIONS
#define SYSTEM_FILESYSTEM_OPTIONS NULL
#endif
/* Any of the "root_path" arguments can be paths with relative
* components, like "SYSTEM:a/b/c".
*/
@ -60,4 +125,14 @@ const MtdPartition *get_root_mtd_partition(const char *root_path);
*/
int format_root_device(const char *root);
typedef struct {
const char *name;
const char *device;
const char *device2; // If the first one doesn't work (may be NULL)
const char *partition_name;
const char *mount_point;
const char *filesystem;
const char *filesystem_options;
} RootInfo;
#endif // RECOVERY_ROOTS_H_

18
setprop.c Normal file
View File

@ -0,0 +1,18 @@
#include <stdio.h>
#include <cutils/properties.h>
int setprop_main(int argc, char *argv[])
{
if(argc != 3) {
fprintf(stderr,"usage: setprop <key> <value>\n");
return 1;
}
if(property_set(argv[1], argv[2])){
fprintf(stderr,"could not set property\n");
return 1;
}
return 0;
}

35
ui.c
View File

@ -29,6 +29,12 @@
#include "minui/minui.h"
#include "recovery_ui.h"
#ifdef KEY_POWER_IS_SELECT_ITEM
static int gShowBackButton = 1;
#else
static int gShowBackButton = 0;
#endif
#define MAX_COLS 64
#define MAX_ROWS 32
@ -48,6 +54,7 @@ static gr_surface gBackgroundIcon[NUM_BACKGROUND_ICONS];
static gr_surface gProgressBarIndeterminate[PROGRESSBAR_INDETERMINATE_STATES];
static gr_surface gProgressBarEmpty[NUM_SIDES];
static gr_surface gProgressBarFill[NUM_SIDES];
static int ui_has_initialized = 0;
static const struct { gr_surface* surface; const char *name; } BITMAPS[] = {
{ &gBackgroundIcon[BACKGROUND_ICON_INSTALLING], "icon_installing" },
@ -176,6 +183,7 @@ static void draw_text_line(int row, const char* t) {
// Should only be called with gUpdateMutex locked.
static void draw_screen_locked(void)
{
if (!ui_has_initialized) return;
draw_background_locked(gCurrentIcon);
draw_progress_locked();
@ -229,6 +237,7 @@ static void draw_screen_locked(void)
// Should only be called with gUpdateMutex locked.
static void update_screen_locked(void)
{
if (!ui_has_initialized) return;
draw_screen_locked();
gr_flip();
}
@ -237,6 +246,7 @@ static void update_screen_locked(void)
// Should only be called with gUpdateMutex locked.
static void update_progress_locked(void)
{
if (!ui_has_initialized) return;
if (show_text || !gPagesIdentical) {
draw_screen_locked(); // Must redraw the whole screen
gPagesIdentical = 1;
@ -346,6 +356,7 @@ static void *input_thread(void *cookie)
void ui_init(void)
{
ui_has_initialized = 1;
gr_init();
ev_init();
@ -506,10 +517,11 @@ int ui_start_menu(char** headers, char** items) {
strncpy(menu[i] + MENU_ITEM_HEADER_LENGTH, items[i-menu_top], text_cols-1 - MENU_ITEM_HEADER_LENGTH);
menu[i][text_cols-1] = '\0';
}
#ifdef KEY_POWER_IS_SELECT_ITEM
strcpy(menu[i], " - +++++Go Back+++++");
++i;
#endif
if (gShowBackButton) {
strcpy(menu[i], " - +++++Go Back+++++");
++i;
}
menu_items = i - menu_top;
show_menu = 1;
@ -517,11 +529,10 @@ int ui_start_menu(char** headers, char** items) {
update_screen_locked();
}
pthread_mutex_unlock(&gUpdateMutex);
#ifdef KEY_POWER_IS_SELECT_ITEM
return menu_items - 1;
#else
if (gShowBackButton) {
return menu_items - 1;
}
return menu_items;
#endif
}
int ui_menu_select(int sel) {
@ -597,3 +608,11 @@ void ui_clear_key_queue() {
void ui_set_show_text(int value) {
show_text = value;
}
void ui_set_showing_back_button(int showBackButton) {
gShowBackButton = showBackButton;
}
int ui_get_showing_back_button() {
return gShowBackButton;
}

45
utilities/Android.mk Normal file
View File

@ -0,0 +1,45 @@
LOCAL_PATH := $(call my-dir)
ifndef BOARD_HAS_SMALL_RECOVERY
include $(CLEAR_VARS)
LOCAL_MODULE := e2fsck
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)
include $(CLEAR_VARS)
LOCAL_MODULE := fix_permissions
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)
include $(CLEAR_VARS)
LOCAL_MODULE := parted
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)
include $(CLEAR_VARS)
LOCAL_MODULE := sdparted
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)
include $(CLEAR_VARS)
LOCAL_MODULE := tune2fs
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)
endif

BIN
utilities/e2fsck Normal file

Binary file not shown.

476
utilities/fix_permissions Normal file
View File

@ -0,0 +1,476 @@
#! /system/bin/sh
#
# Warning: if you want to run this script in cm-recovery change the above to #!/sbin/sh
#
# fix_permissions - fixes permissions on Android data directories after upgrade
# shade@chemlab.org
#
# original concept: http://blog.elsdoerfer.name/2009/05/25/android-fix-package-uid-mismatches/
# implementation by: Cyanogen
# improved by: ankn, smeat, thenefield, farmatito, rikupw, Kastro
#
# v1.1-v1.31r3 - many improvements and concepts from XDA developers.
# v1.34 through v2.00 - A lot of frustration [by Kastro]
# v2.01 - Completely rewrote the script for SPEED, thanks for the input farmatito
# /data/data depth recursion is tweaked;
# fixed single mode;
# functions created for modularity;
# logging can be disabled via CLI for more speed;
# runtime computation added to end (Runtime: mins secs);
# progress (current # of total) added to screen;
# fixed CLI argument parsing, now you can have more than one option!;
# debug cli option;
# verbosity can be disabled via CLI option for less noise;;
# [by Kastro, (XDA: k4str0), twitter;mattcarver]
# v2.02 - ignore com.htc.resources.apk if it exists and minor code cleanups,
# fix help text, implement simulated run (-s) [farmatito]
# v2.03 - fixed chown group ownership output [Kastro]
VERSION="2.03"
# Defaults
DEBUG=0 # Debug off by default
LOGGING=1 # Logging on by default
VERBOSE=1 # Verbose on by default
# Messages
UID_MSG="Changing user ownership for:"
GID_MSG="Changing group ownership for:"
PERM_MSG="Changing permissions for:"
# Programs needed
ECHO="busybox echo"
GREP="busybox grep"
EGREP="busybox egrep"
CAT="busybox cat"
CHOWN="busybox chown"
CHMOD="busybox chmod"
MOUNT="busybox mount"
UMOUNT="busybox umount"
CUT="busybox cut"
FIND="busybox find"
LS="busybox ls"
TR="busybox tr"
TEE="busybox tee"
TEST="busybox test"
SED="busybox sed"
RM="busybox rm"
WC="busybox wc"
EXPR="busybox expr"
DATE="busybox date"
# Initialise vars
CODEPATH=""
UID=""
GID=""
PACKAGE=""
REMOVE=0
NOSYSTEM=0
ONLY_ONE=""
SIMULATE=0
SYSREMOUNT=0
SYSMOUNT=0
DATAMOUNT=0
SYSSDMOUNT=0
FP_STARTTIME=$( $DATE +"%m-%d-%Y %H:%M:%S" )
FP_STARTEPOCH=$( $DATE +%s )
fp_usage()
{
$ECHO "Usage $0 [OPTIONS] [APK_PATH]"
$ECHO " -d turn on debug"
$ECHO " -f fix only package APK_PATH"
$ECHO " -l disable logging for this run (faster)"
$ECHO " -r remove stale data directories"
$ECHO " of uninstalled packages while fixing permissions"
$ECHO " -s simulate only"
$ECHO " -u check only non-system directories"
$ECHO " -v disable verbosity for this run (less output)"
$ECHO " -V print version"
$ECHO " -h this help"
}
fp_parseargs()
{
# Parse options
while $TEST $# -ne 0; do
case "$1" in
-d)
DEBUG=1
;;
-f)
if $TEST $# -lt 2; then
$ECHO "$0: missing argument for option $1"
exit 1
else
if $TEST $( $ECHO $2 | $CUT -c1 ) != "-"; then
ONLY_ONE=$2
shift;
else
$ECHO "$0: missing argument for option $1"
exit 1
fi
fi
;;
-r)
REMOVE=1
;;
-s)
SIMULATE=1
;;
-l)
if $TEST $LOGGING -eq 0; then
LOGGING=1
else
LOGGING=0
fi
;;
-v)
if $TEST $VERBOSE -eq 0; then
VERBOSE=1
else
VERBOSE=0
fi
;;
-u)
NOSYSTEM=1
;;
-V)
$ECHO "$0 $VERSION"
exit 0
;;
-h)
fp_usage
exit 0
;;
-*)
$ECHO "$0: unknown option $1"
$ECHO
fp_usage
exit 1
;;
esac
shift;
done
}
fp_print()
{
MSG=$@
if $TEST $LOGGING -eq 1; then
$ECHO $MSG | $TEE -a $LOG_FILE
else
$ECHO $MSG
fi
}
fp_start()
{
if $TEST $SIMULATE -eq 0 ; then
if $TEST $( $GREP -c " /system " "/proc/mounts" ) -ne 0; then
DEVICE=$( $GREP " /system " "/proc/mounts" | $CUT -d ' ' -f1 )
if $TEST $DEBUG -eq 1; then
fp_print "/system mounted on $DEVICE"
fi
if $TEST $( $GREP " /system " "/proc/mounts" | $GREP -c " ro " ) -ne 0; then
$MOUNT -o remount,rw $DEVICE /system
SYSREMOUNT=1
fi
else
$MOUNT /system > /dev/null 2>&1
SYSMOUNT=1
fi
if $TEST $( $GREP -c " /data " "/proc/mounts" ) -eq 0; then
$MOUNT /data > /dev/null 2>&1
DATAMOUNT=1
fi
if $TEST -e /dev/block/mmcblk0p2 && $TEST $( $GREP -c " /system/sd " "/proc/mounts" ) -eq 0; then
$MOUNT /system/sd > /dev/null 2>&1
SYSSDMOUNT=1
fi
fi
if $TEST $( $MOUNT | $GREP -c /sdcard ) -eq 0; then
LOG_FILE="/data/fix_permissions.log"
else
LOG_FILE="/sdcard/fix_permissions.log"
fi
if $TEST ! -e "$LOG_FILE"; then
> $LOG_FILE
fi
fp_print "$0 $VERSION started at $FP_STARTTIME"
}
fp_chown_uid()
{
FP_OLDUID=$1
FP_UID=$2
FP_FILE=$3
#if user ownership doesn't equal then change them
if $TEST "$FP_OLDUID" != "$FP_UID"; then
if $TEST $VERBOSE -ne 0; then
fp_print "$UID_MSG $FP_FILE from '$FP_OLDUID' to '$FP_UID'"
fi
if $TEST $SIMULATE -eq 0; then
$CHOWN $FP_UID "$FP_FILE"
fi
fi
}
fp_chown_gid()
{
FP_OLDGID=$1
FP_GID=$2
FP_FILE=$3
#if group ownership doesn't equal then change them
if $TEST "$FP_OLDGID" != "$FP_GID"; then
if $TEST $VERBOSE -ne 0; then
fp_print "$GID_MSG $FP_FILE from '$FP_OLDGID' to '$FP_GID'"
fi
if $TEST $SIMULATE -eq 0; then
$CHOWN :$FP_GID "$FP_FILE"
fi
fi
}
fp_chmod()
{
FP_OLDPER=$1
FP_OLDPER=$( $ECHO $FP_OLDPER | cut -c2-10 )
FP_PERSTR=$2
FP_PERNUM=$3
FP_FILE=$4
#if the permissions are not equal
if $TEST "$FP_OLDPER" != "$FP_PERSTR"; then
if $TEST $VERBOSE -ne 0; then
fp_print "$PERM_MSG $FP_FILE from '$FP_OLDPER' to '$FP_PERSTR' ($FP_PERNUM)"
fi
#change the permissions
if $TEST $SIMULATE -eq 0; then
$CHMOD $FP_PERNUM "$FP_FILE"
fi
fi
}
fp_all()
{
FP_NUMS=$( $CAT /data/system/packages.xml | $EGREP "^<package.*serId" | $GREP -v framework-res.apk | $GREP -v com.htc.resources.apk | $WC -l )
I=0
$CAT /data/system/packages.xml | $EGREP "^<package.*serId" | $GREP -v framework-res.apk | $GREP -v com.htc.resources.apk | while read all_line; do
I=$( $EXPR $I + 1 )
fp_package "$all_line" $I $FP_NUMS
done
}
fp_single()
{
FP_SFOUND=$( $CAT /data/system/packages.xml | $EGREP "^<package.*serId" | $GREP -v framework-res.apk | $GREP -v com.htc.resources.apk | $GREP -i $ONLY_ONE | wc -l )
if $TEST $FP_SFOUND -gt 1; then
fp_print "Cannot perform single operation on $FP_SFOUND matched package(s)."
elif $TEST $FP_SFOUND = "" -o $FP_SFOUND -eq 0; then
fp_print "Could not find the package you specified in the packages.xml file."
else
FP_SPKG=$( $CAT /data/system/packages.xml | $EGREP "^<package.*serId" | $GREP -v framework-res.apk | $GREP -v com.htc.resources.apk | $GREP -i $ONLY_ONE )
fp_package "${FP_SPKG}" 1 1
fi
}
fp_package()
{
pkgline=$1
curnum=$2
endnum=$3
CODEPATH=$( $ECHO $pkgline | $SED 's%.* codePath="\(.*\)".*%\1%' | $CUT -d '"' -f1 )
PACKAGE=$( $ECHO $pkgline | $SED 's%.* name="\(.*\)".*%\1%' | $CUT -d '"' -f1 )
UID=$( $ECHO $pkgline | $SED 's%.*serId="\(.*\)".*%\1%' | $CUT -d '"' -f1 )
GID=$UID
APPDIR=$( $ECHO $CODEPATH | $SED 's%^\(.*\)/.*%\1%' )
APK=$( $ECHO $CODEPATH | $SED 's%^.*/\(.*\..*\)$%\1%' )
#debug
if $TEST $DEBUG -eq 1; then
fp_print "CODEPATH: $CODEPATH APPDIR: $APPDIR APK:$APK UID/GID:$UID:$GID"
fi
#check for existence of apk
if $TEST -e $CODEPATH; then
fp_print "Processing ($curnum of $endnum): $PACKAGE..."
#lets get existing permissions of CODEPATH
OLD_UGD=$( $LS -ln "$CODEPATH" )
OLD_PER=$( $ECHO $OLD_UGD | $CUT -d ' ' -f1 )
OLD_UID=$( $ECHO $OLD_UGD | $CUT -d ' ' -f3 )
OLD_GID=$( $ECHO $OLD_UGD | $CUT -d ' ' -f4 )
#apk source dirs
if $TEST "$APPDIR" = "/system/app"; then
#skip system apps if set
if $TEST "$NOSYSTEM" = "1"; then
fp_print "***SKIPPING SYSTEM APP ($PACKAGE)!"
return
fi
fp_chown_uid $OLD_UID 0 "$CODEPATH"
fp_chown_gid $OLD_GID 0 "$CODEPATH"
fp_chmod $OLD_PER "rw-r--r--" 644 "$CODEPATH"
elif $TEST "$APPDIR" = "/data/app" || $TEST "$APPDIR" = "/sd-ext/app"; then
fp_chown_uid $OLD_UID 1000 "$CODEPATH"
fp_chown_gid $OLD_GID 1000 "$CODEPATH"
fp_chmod $OLD_PER "rw-r--r--" 644 "$CODEPATH"
elif $TEST "$APPDIR" = "/data/app-private" || $TEST "$APPDIR" = "/sd-ext/app-private"; then
fp_chown_uid $OLD_UID 1000 "$CODEPATH"
fp_chown_gid $OLD_GID $GID "$CODEPATH"
fp_chmod $OLD_PER "rw-r-----" 640 "$CODEPATH"
fi
else
fp_print "$CODEPATH does not exist ($curnum of $endnum). Reinstall..."
if $TEST $REMOVE -eq 1; then
if $TEST -d /data/data/$PACKAGE ; then
fp_print "Removing stale dir /data/data/$PACKAGE"
if $TEST $SIMULATE -eq 0 ; then
$RM -R /data/data/$PACKAGE
fi
fi
fi
fi
#the data/data for the package
if $TEST -d "/data/data/$PACKAGE"; then
#find all directories in /data/data/$PACKAGE
$FIND /data/data/$PACKAGE -type d -exec $LS -ldn {} \; | while read dataline; do
#get existing permissions of that directory
OLD_PER=$( $ECHO $dataline | $CUT -d ' ' -f1 )
OLD_UID=$( $ECHO $dataline | $CUT -d ' ' -f3 )
OLD_GID=$( $ECHO $dataline | $CUT -d ' ' -f4 )
FILEDIR=$( $ECHO $dataline | $CUT -d ' ' -f9 )
FOURDIR=$( $ECHO $FILEDIR | $CUT -d '/' -f5 )
#set defaults for iteration
ISLIB=0
REVPERM=755
REVPSTR="rwxr-xr-x"
REVUID=$UID
REVGID=$GID
if $TEST "$FOURDIR" = ""; then
#package directory, perms:755 owner:$UID:$GID
fp_chmod $OLD_PER "rwxr-xr-x" 755 "$FILEDIR"
elif $TEST "$FOURDIR" = "lib"; then
#lib directory, perms:755 owner:1000:1000
#lib files, perms:755 owner:1000:1000
ISLIB=1
REVPERM=755
REVPSTR="rwxr-xr-x"
REVUID=1000
REVGID=1000
fp_chmod $OLD_PER "rwxr-xr-x" 755 "$FILEDIR"
elif $TEST "$FOURDIR" = "shared_prefs"; then
#shared_prefs directories, perms:771 owner:$UID:$GID
#shared_prefs files, perms:660 owner:$UID:$GID
REVPERM=660
REVPSTR="rw-rw----"
fp_chmod $OLD_PER "rwxrwx--x" 771 "$FILEDIR"
elif $TEST "$FOURDIR" = "databases"; then
#databases directories, perms:771 owner:$UID:$GID
#databases files, perms:660 owner:$UID:$GID
REVPERM=660
REVPSTR="rw-rw----"
fp_chmod $OLD_PER "rwxrwx--x" 771 "$FILEDIR"
elif $TEST "$FOURDIR" = "cache"; then
#cache directories, perms:771 owner:$UID:$GID
#cache files, perms:600 owner:$UID:GID
REVPERM=600
REVPSTR="rw-------"
fp_chmod $OLD_PER "rwxrwx--x" 771 "$FILEDIR"
else
#other directories, perms:771 owner:$UID:$GID
REVPERM=771
REVPSTR="rwxrwx--x"
fp_chmod $OLD_PER "rwxrwx--x" 771 "$FILEDIR"
fi
#change ownership of directories matched
if $TEST "$ISLIB" = "1"; then
fp_chown_uid $OLD_UID 1000 "$FILEDIR"
fp_chown_gid $OLD_GID 1000 "$FILEDIR"
else
fp_chown_uid $OLD_UID $UID "$FILEDIR"
fp_chown_gid $OLD_GID $GID "$FILEDIR"
fi
#if any files exist in directory with improper permissions reset them
$FIND $FILEDIR -type f -maxdepth 1 ! -perm $REVPERM -exec $LS -ln {} \; | while read subline; do
OLD_PER=$( $ECHO $subline | $CUT -d ' ' -f1 )
SUBFILE=$( $ECHO $subline | $CUT -d ' ' -f9 )
fp_chmod $OLD_PER $REVPSTR $REVPERM "$SUBFILE"
done
#if any files exist in directory with improper user reset them
$FIND $FILEDIR -type f -maxdepth 1 ! -user $REVUID -exec $LS -ln {} \; | while read subline; do
OLD_UID=$( $ECHO $subline | $CUT -d ' ' -f3 )
SUBFILE=$( $ECHO $subline | $CUT -d ' ' -f9 )
fp_chown_uid $OLD_UID $REVUID "$SUBFILE"
done
#if any files exist in directory with improper group reset them
$FIND $FILEDIR -type f -maxdepth 1 ! -group $REVGID -exec $LS -ln {} \; | while read subline; do
OLD_GID=$( $ECHO $subline | $CUT -d ' ' -f4 )
SUBFILE=$( $ECHO $subline | $CUT -d ' ' -f9 )
fp_chown_gid $OLD_GID $REVGID "$SUBFILE"
done
done
fi
}
date_diff()
{
if $TEST $# -ne 2; then
FP_DDM="E"
FP_DDS="E"
return
fi
FP_DDD=$( $EXPR $2 - $1 )
FP_DDM=$( $EXPR $FP_DDD / 60 )
FP_DDS=$( $EXPR $FP_DDD % 60 )
}
fp_end()
{
if $TEST $SYSREMOUNT -eq 1; then
$MOUNT -o remount,ro $DEVICE /system > /dev/null 2>&1
fi
if $TEST $SYSSDMOUNT -eq 1; then
$UMOUNT /system/sd > /dev/null 2>&1
fi
if $TEST $SYSMOUNT -eq 1; then
$UMOUNT /system > /dev/null 2>&1
fi
if $TEST $DATAMOUNT -eq 1; then
$UMOUNT /data > /dev/null 2>&1
fi
FP_ENDTIME=$( $DATE +"%m-%d-%Y %H:%M:%S" )
FP_ENDEPOCH=$( $DATE +%s )
date_diff $FP_STARTEPOCH $FP_ENDEPOCH
fp_print "$0 $VERSION ended at $FP_ENDTIME (Runtime:${FP_DDM}m${FP_DDS}s)"
}
#MAIN SCRIPT
fp_parseargs $@
fp_start
if $TEST "$ONLY_ONE" != "" -a "$ONLY_ONE" != "0" ; then
fp_single "$ONLY_ONE"
else
fp_all
fi
fp_end

BIN
utilities/parted Normal file

Binary file not shown.

637
utilities/sdparted Normal file
View File

@ -0,0 +1,637 @@
#!/sbin/sh
# do logging, if not excluded with -x
LOGFILE="/data/sdparted.log"
[ "$1" != "-x" ] && echo "$0" "$@" >> "$LOGFILE" && "$0" -x "$@" 2>&1 | tee -a "$LOGFILE" && exit
shift
ShowError() { echo ; echo " err: $1" ; echo ; exit 1 ; }
ShowMessage() { echo ; echo " msg: $1" ; }
ShowHelp() {
cat <<DONEHELP
$SCRIPTNAME v$SCRIPTREV created by $MYNAME
if you use this script in your work, please give some credit. thanks.
requirements: cm-recovery-v1.4
usage: $SCRIPTNAME [options]
options:
--fatsize|-fs SIZE[MG] set the size of the fat32 partition to <SIZE>.
default=total sdcard size - (ext + swap)
--extsize|-es SIZE[MG] set the size of the ext partition to <SIZE>.
default=$EXTSIZE
--swapsize|-ss SIZE[MG] set the size of the swap partition to <SIZE>.
if set to 0, no swap partition will be created.
default=$SWAPSIZE
--extfs|-efs TYPE set the filesystem of ext partition to <TYPE>.
valid types=ext2, ext3, ext4
default=$EXTFS
--upgradefs|-ufs TYPE upgrades existing ext partition to <TYPE>.
this operation will NOT wipe your sdcard and
cannot be used with any partition creation options.
valid types=ext3, ext4
--downgradefs|-dfs TYPE downgrades existing ext partition to <TYPE>.
this operation will NOT wipe your sdcard and
cannot be used with any partition creation options.
valid types=ext2
--interactive|-i interactive mode
--help|-h display this help
--printonly|-po display sdcard information
--silent|-s do not prompt user, not even initial warning.
examples:
$SCRIPTNAME creates swap=$SWAPSIZE ext2=$EXTSIZE fat32=remaining free space
$SCRIPTNAME -efs ext4 creates swap=$SWAPSIZE ext4=$EXTSIZE fat32=remaining free space
$SCRIPTNAME -fs 1.5G -efs ext3 creates swap=$SWAPSIZE ext3=$EXTSIZE fat32=1536
$SCRIPTNAME -es 256M -ss 0 creates no swap ext2=256 fat32=remaining free space
$SCRIPTNAME -ufs ext4 upgrades ext partition to ext4
DONEHELP
}
UserAbort() {
WHILEEXIT=
while [ -z "$WHILEEXIT" ]
do
echo -n "do you want to continue? (Y/n) "
read response
echo
[ "$response" = "Y" ] || [ "$response" = "n" ] || [ "$response" = "N" ] && WHILEEXIT="$response"
done
echo "$response" > /dev/null 2>&1 >>"$LOGFILE"
[ "$response" != "Y" ]
}
UnmountAll () {
# unmount all partitions so we can work with $SDPATH
# i'm assuming no more than 3 partitions
# maybe make a little more elegant later
echo -n "unmounting all partitions..."
umount "$FATPATH" > /dev/null 2>&1 >>"$LOGFILE"
umount "$EXTPATH" > /dev/null 2>&1 >>"$LOGFILE"
umount "$SWAPPATH" > /dev/null 2>&1 >>"$LOGFILE"
echo "done"
echo
}
CheckReqs() {
echo -n "checking script requirements..."
# check for valid sdcard
[ -e $SDPATH ] || ShowError "$SDPATH does not exist!"
# look for necessary programs
[ -e $CMPARTED ] || ShowError "$CMPARTED does not exist!"
[ -e $CMTUNE2FS ] || ShowError "$CMTUNE2FS does not exist!"
[ -e $CME2FSCK ] || ShowError "$CME2FSCK does not exist!"
# verify cm-v1.4
PARTEDREV=`"$CMPARTED" "$SDPATH" version | grep Parted | cut -d" " -f3`
[ "$PARTEDREV" == "1.8.8.1.179-aef3" ] || ShowError "you are not using parted v1.8.8.1.179-aef3!"
echo "done"
echo
}
CheckTableType() {
TABLETYPE=`"$CMPARTED" "$SDPATH" print | grep Table: | cut -d" " -f3`
[ "$TABLETYPE" == "loop" -o "$TABLETYPE" == "msdos" ] && TTISOK=1 || TTISOK=0
[ "$TABLETYPE" == "loop" ] && TTISLOOP=1 || TTISLOOP=0
[ "$TABLETYPE" == "msdos" ] && TTISMSDOS=1 || TTISMOSDOS=0
}
ValidateExtArg() {
FUNC_RET="nonzero"
# validating argument
[ "$1" != "ext2" ] && [ "$1" != "ext3" ] && [ "$1" != "ext4" ] && FUNC_RET=
[ -z "$FUNC_RET" ] && [ -z "$IMODE" ] && ShowError "$1 is not a valid filesystem."
[ -z "$FUNC_RET" ] && [ -n "$IMODE" ] && ShowMessage "$1 is not a valid filesystem."
# return valid argument
[ -n "$FUNC_RET" ] && FUNC_RET="$1"
}
ValidateSizeArg() {
# check for zero-length arg to protect expr length
[ -z "$1" ] && ShowError "zero-length argument passed to size-validator"
SIZEMB=
ARGLEN=`expr length $1`
SIZELEN=$(($ARGLEN-1))
SIZEARG=`expr substr $1 1 $SIZELEN`
SIZEUNIT=`expr substr $1 $ARGLEN 1`
# check if SIZEARG is an integer
if [ $SIZEARG -eq $SIZEARG 2> /dev/null ] ; then
# look for G
[ "$SIZEUNIT" == "G" ] && SIZEMB=$(($SIZEARG * 1024))
# look for M
[ "$SIZEUNIT" == "M" ] && SIZEMB=$SIZEARG
# no units on arg AND prevents using bogus size units
[ -z "$SIZEMB" ] && [ $SIZEUNIT -eq $SIZEUNIT 2> /dev/null ] && SIZEMB=$1
# check if SIZEARG is a floating point number, GB only
elif [ `expr index "$SIZEARG" .` != 0 ] && [ "$SIZEUNIT" == "G" ] ; then
INT=`echo "$SIZEARG" | cut -d"." -f1`
FRAC=`echo "$SIZEARG" | cut -d"." -f2`
SIGDIGITS=`expr length $FRAC`
[ -z "$INT" ] && INT=0
INTMB=$(($INT * 1024))
FRACMB=$((($FRAC * 1024) / (10**$SIGDIGITS)))
SIZEMB=$(($INTMB + $FRACMB))
# it's not a valid size
else
[ -z "$IMODE" ] && ShowError "$1 is not a valid size"
fi
[ -z "$SIZEMB" ] && [ -n "$IMODE" ] && ShowMessage "$1 is not a valid size"
# return valid argument in MB
FUNC_RET=$SIZEMB
}
CalculatePartitions() {
# get size of sdcard in MB & do some math
SDSIZEMB=`"$CMPARTED" "$SDPATH" unit MB print | grep $SDPATH | cut -d" " -f3`
SDSIZE=${SDSIZEMB%MB}
[ -n "$FATSIZE" ] || FATSIZE=$(($SDSIZE - $EXTSIZE - $SWAPSIZE))
EXTEND=$(($FATSIZE + $EXTSIZE))
SWAPEND=$(($EXTEND + $SWAPSIZE))
# check for fatsize of 0
[ $FATSIZE -le 0 ] && ShowError "must have a fat32 partition greater than 0MB"
# check for zero-length sdsize...
# indicative of parted not reporting length
# correctly b/c of error on sdcard
[ -z "$SDSIZE" ] && ShowError "zero-length argument passed to partition-calculator"
# make sure we're not being asked to do the impossible
[ $(($FATSIZE + $EXTSIZE + $SWAPSIZE)) -gt $SDSIZE ] && [ -z "$IMODE" ] && ShowError "sum of requested partitions is greater than sdcard size"
}
UpgradeDowngradeOnly() {
if [ -n "$UEXTFSONLY" ] ; then
echo
[ -n "$CREATEPART" ] && ShowError "cannot use upgrade option when creating partitions, use -efs instead"
[ -n "$DEXTFSONLY" ] && ShowError "cannot upgrade AND downgrade, it just doesn't make sense"
echo "you have chosen to upgrade $EXTPATH to $UEXTFSONLY."
echo "this action will NOT delete any data from sdcard."
echo
[ -z "$SILENTRUN" ] && UserAbort && ShowError "script canceled by user"
echo
UpgradeExt "$UEXTFSONLY"
ShowCardInfo
elif [ -n "$DEXTFSONLY" ] ; then
echo
[ -n "$CREATEPART" ] && ShowError "cannot use downgrade option when creating partitions."
[ -n "$UEXTFSONLY" ] && ShowError "cannot downgrade AND upgrade, it just doesn't make sense."
echo "you have chosen to downgrade $EXTPATH to $DEXTFSONLY."
echo "this action will NOT delete any data from sdcard."
echo
[ -z "$SILENTRUN" ] && UserAbort && ShowError "script canceled by user"
echo
DowngradeExt "$DEXTFSONLY"
ShowCardInfo
fi
}
PrepareSdCard() {
echo
if [ $TTISOK -eq 0 ] ; then
echo "partition 1 may not be aligned to cylinder boundaries."
echo "to continue, this must be corrected."
elif [ $TTISLOOP -gt 0 ] ; then
echo "your sdcard's partition table type is $TABLETYPE."
echo "to continue, partition table must be set to 'msdos'."
elif [ $TTISMSDOS -gt 0 ] ; then
# just a reminder..in a later version,
# i may implement resizing of partitions,
# so this will be unnecessary. but until then...
echo "to continue, all existing partitions must be removed."
else
# this is not good, and should never happen
# if it does, there is a serious problem
ShowError "sdcard failed table type check."
fi
echo
echo "this action will remove all data from your sdcard."
echo
[ -z "$SILENTRUN" ] && UserAbort && ShowError "script canceled by user"
[ $TTISOK -eq 0 ] && echo -n "correcting cylinder boundaries..."
[ $TTISLOOP -gt 0 ] && echo -n "setting partition table to msdos..."
[ $TTISMSDOS -gt 0 ] && echo -n "removing all partitions..."
"$CMPARTED" -s "$SDPATH" mklabel msdos 2>&1 >>"$LOGFILE"
echo "done"
echo
}
ShowActions() {
echo
echo "total size of sdcard=$SDSIZEMB"
echo
echo "the following actions will be performed:"
echo " -create $FATSIZE""MB fat32 partition"
[ $EXTSIZE -gt 0 ] && echo " -create $EXTSIZE""MB ext2 partition"
[ $SWAPSIZE -gt 0 ] && echo " -create $SWAPSIZE""MB swap partition"
[ "$EXTFS" != "ext2" ] && echo " -ext2 partition will be upgraded to $EXTFS"
echo
[ -z "$SILENTRUN" ] && UserAbort && ShowError "script canceled by user"
echo
}
ShowCardInfo() {
CheckTableType
echo
echo "retrieving current sdcard information..."
if [ $TTISOK -gt 0 ] ; then
echo
parted "$SDPATH" print
echo
echo "script log is located @ /data/sdparted.log"
exit 0
else
echo
echo "partition 1 may not be aligned to cylinder boundaries."
ShowError "cannot complete print operation."
fi
echo
}
PartitionSdCard() {
echo "performing selected actions..."
echo
if [ $FATSIZE -gt 0 ] ; then
echo -n "creating fat32 partition..."
"$CMPARTED" -s "$SDPATH" mkpartfs primary fat32 0 "$FATSIZE"MB 2>&1 >>"$LOGFILE"
echo "done"
fi
if [ $EXTSIZE -gt 0 ] ; then
echo -n "creating ext2 partition..."
"$CMPARTED" -s "$SDPATH" mkpartfs primary ext2 "$FATSIZE"MB "$EXTEND"MB 2>&1 >>"$LOGFILE"
echo "done"
fi
if [ $SWAPSIZE -gt 0 ] ; then
echo -n "creating swap partition..."
"$CMPARTED" -s "$SDPATH" mkpartfs primary linux-swap "$EXTEND"MB "$SWAPEND"MB 2>&1 >>"$LOGFILE"
echo "done"
fi
echo
}
UpgradeExt() {
# check for no upgrade
[ "$1" == "ext2" ] && return
# check for ext partition
[ ! -e "$EXTPATH" ] && ShowError "$EXTPATH does not exist"
# have to use -m switch for this check b/c parted incorrectly
# reports all ext partitions as ext2 when running print <number>
CHECKEXTFS=`"$CMPARTED" -m "$SDPATH" print | grep ext | cut -d":" -f5`
[ "$CHECKEXTFS" == "$1" ] && ShowError "$EXTPATH is already $1"
# grabbed the code bits for ext3 from upgrade_fs(credit:cyanogen)
# check for ext2...must upgrade to ext3 first b4 ext4
if [ "$1" == "ext3" -o "$1" == "ext4" ] ; then
echo -n "adding journaling to $EXTPATH..."
umount /system/sd > /dev/null 2>&1 >>"$LOGFILE"
"$CME2FSCK" -p "$EXTPATH" 2>&1 >>"$LOGFILE"
"$CMTUNE2FS" -c0 -i0 -j "$EXTPATH" 2>&1 >>"$LOGFILE"
echo "done"
fi
# and got convert to ext4 from xda-forum(credit:Denkai)
if [ "$1" == "ext4" ] ; then
echo -n "converting $EXTPATH to ext4 filesystem..."
umount /system/sd > /dev/null 2>&1 >>"$LOGFILE"
"$CMTUNE2FS" -O extents,uninit_bg,dir_index "$EXTPATH" 2>&1 >>"$LOGFILE"
"$CME2FSCK" -fpDC0 "$EXTPATH" 2>&1 >>"$LOGFILE"
echo "done"
fi
echo
}
DowngradeExt() {
# check for ext partition
[ ! -e "$EXTPATH" ] && ShowError "$EXTPATH does not exist"
# have to use print for this check b/c parted incorrectly
# reports all ext partitions as ext2 when running print <number>
CHECKEXTFS=`"$CMPARTED" -m "$SDPATH" print | grep ext | cut -d":" -f5`
[ "$CHECKEXTFS" == "$1" ] && ShowError "$EXTPATH is already $1"
if [ "$CHECKEXTFS" == "ext4" -o "$1" == "ext3" ] ; then
# interweb says downgrading from ext4 is not possible
# without a backup/restore procedure.
# if i figure it out, i'll implement it.
ShowError "downgrading from ext4 is not currently supported"
fi
if [ "$1" == "ext2" ] ; then
echo -n "removing journaling from $EXTPATH..."
umount /system/sd > /dev/null 2>&1 >>"$LOGFILE"
"$CMTUNE2FS" -O ^has_journal "$EXTPATH" 2>&1 >>"$LOGFILE"
"$CME2FSCK" -fp "$EXTPATH" 2>&1 >>"$LOGFILE"
echo "done"
fi
echo
}
Interactive() {
cat <<DONEINSTRUCT
sdparted interactive mode
rules:
1. no answer means you accept default value
2. enter '0' for no partition
DONEINSTRUCT
UserAbort && ShowError "script canceled by user"
CalculatePartitions
GetSwapSize
FATSIZE=
CalculatePartitions
GetExtSize
GetExtType
FATSIZE=
CalculatePartitions
GetFatSize
}
GetSwapSize() {
SWAPTEST=
while [ -z "$SWAPTEST" ]
do
echo
echo -n "swap partition size [default=$SWAPSIZE]: "
read SWAPRESP
[ -z "$SWAPRESP" ] && SWAPRESP="$SWAPSIZE"
echo "$SWAPRESP" > /dev/null 2>&1 >>"$LOGFILE"
ValidateSizeArg "$SWAPRESP"
SWAPTEST="$FUNC_RET"
[ -n "$SWAPTEST" ] && [ $SWAPTEST -gt $SDSIZE ] && ShowMessage "$SWAPRESP > available space($(($SDSIZE))M)." && SWAPTEST=
done
SWAPSIZE=$SWAPTEST
}
GetExtSize() {
EXTTEST=
while [ -z "$EXTTEST" ]
do
echo
echo -n "ext partition size [default=$EXTSIZE]: "
read EXTRESP
[ -z "$EXTRESP" ] && EXTRESP="$EXTSIZE"
echo "$EXTRESP" > /dev/null 2>&1 >>"$LOGFILE"
ValidateSizeArg "$EXTRESP"
EXTTEST="$FUNC_RET"
[ -n "$EXTTEST" ] && [ $EXTTEST -gt $(($SDSIZE - $SWAPSIZE)) ] && ShowMessage "$EXTRESP > available space($(($SDSIZE - $SWAPSIZE))M)." && EXTTEST=
done
EXTSIZE=$EXTTEST
}
GetExtType() {
FSTEST=
while [ -z "$FSTEST" ]
do
echo
echo -n "ext partition type [default=$EXTFS]: "
read FSRESP
[ -z "$FSRESP" ] && FSRESP="$EXTFS"
echo "$FSRESP" > /dev/null 2>&1 >>"$LOGFILE"
ValidateExtArg "$FSRESP"
FSTEST="$FUNC_RET"
done
EXTFS="$FSTEST"
}
GetFatSize() {
FATTEST=
while [ -z "$FATTEST" ]
do
echo
echo -n "fat partition size [default=$FATSIZE]: "
read FATRESP
[ -z "$FATRESP" ] && FATRESP="$FATSIZE"
echo "$FATRESP" > /dev/null 2>&1 >>"$LOGFILE"
ValidateSizeArg "$FATRESP"
FATTEST="$FUNC_RET"
[ -n "$FATTEST" ] && [ $FATTEST -gt $FATSIZE ] && ShowMessage "$FATRESP > available space($(($SDSIZE - $SWAPSIZE - $EXTSIZE))M)." && FATTEST=
[ -n "$FATTEST" ] && [ $FATTEST -le 0 ] && ShowMessage "must have a fat32 partition greater than 0MB" && FATTEST=
done
FATSIZE=$FATTEST
}
SCRIPTNAME="sdparted"
SCRIPTREV="0.6"
MYNAME="51dusty"
IMODE=
SILENTRUN=
CREATEPART=
FUNC_RET=
UEXTFSONLY=
DEXTFSONLY=
TTISOK=
TTISLOOP=
TTISMSDOS=
SDSIZE=
SDSIZEMB=
if [ -z "$SDPATH" ]
then
SDPATH="/dev/block/mmcblk0"
else
echo Found SDPATH=$SDPATH
fi
FATSIZE=
FATTYPE="fat32"
FATPATH=$SDPATH"p1"
EXTSIZE=512
EXTFS="ext2"
EXTPATH=$SDPATH"p2"
EXTEND=
SWAPSIZE=32
SWAPTYPE="linux-swap"
SWAPPATH=$SDPATH"p3"
SWAPEND=
CMPARTED="/sbin/parted"
CMTUNE2FS="/sbin/tune2fs"
CME2FSCK="/sbin/e2fsck"
# give the output some breathing room
echo "$SCRIPTREV" >> "$LOGFILE"
echo
# check for arguments
while [ $# -gt 0 ] ; do
case "$1" in
-h|--help) ShowHelp ; exit 0 ;;
-fs|--fatsize) shift ; ValidateSizeArg "$1" ; FATSIZE="$FUNC_RET" ; CREATEPART="$1" ;;
-es|--extsize) shift ; ValidateSizeArg "$1" ; EXTSIZE="$FUNC_RET" ; CREATEPART="$1" ;;
-ss|--swapsize) shift ; ValidateSizeArg "$1" ; SWAPSIZE="$FUNC_RET" ; CREATEPART="$1" ;;
-efs|--extfs) shift ; ValidateExtArg "$1" ; EXTFS="$FUNC_RET" ; CREATEPART="$1" ;;
-ufs|--upgradefs) shift ; ValidateExtArg "$1" ; UEXTFSONLY="$FUNC_RET" ;;
-dfs|--downgradefs) shift ; ValidateExtArg "$1" ; DEXTFSONLY="$FUNC_RET" ;;
-i|--interactive) IMODE="$1" ;;
-s|--silent) SILENTRUN="$1" ;;
-po|--printonly) ShowCardInfo ;;
*) ShowHelp ; ShowError "unknown argument '$1'" ;;
esac
shift
done
# can't do silent when in interactive mode
[ -n "$IMODE" ] && SILENTRUN=
# make sure sdcard exists and all needed files are here
CheckReqs
# unmount all
UnmountAll
# upgrade only? downgrade only?
UpgradeDowngradeOnly
# check table
CheckTableType
# prep card
PrepareSdCard
# check for interactive mode
[ -n "$IMODE" ] && Interactive
# do some math
CalculatePartitions
# last chance to cancel
ShowActions
# partition card
PartitionSdCard
# upgrade fs if necessary
UpgradeExt "$EXTFS"
# say goodbye and show print output
ShowCardInfo

BIN
utilities/tune2fs Executable file

Binary file not shown.