diff --git a/bmlutils/bmlutils.c b/bmlutils/bmlutils.c index a6b5415..a7b09b4 100644 --- a/bmlutils/bmlutils.c +++ b/bmlutils/bmlutils.c @@ -171,3 +171,35 @@ int cmd_bml_get_partition_device(const char *partition, char *device) { return -1; } + +int format_rfs_device (const char *device, const char *path) { + const char *fatsize = "32"; + const char *sectorsize = "1"; + + if (strcmp(path, "/datadata") == 0 || strcmp(path, "/cache") == 0) { + fatsize = "16"; + } + + // Just in case /data sector size needs to be altered + else if (strcmp(path, "/data") == 0 ) { + sectorsize = "1"; + } + + // dump 10KB of zeros to partition before format due to fat.format bug + char cmd[PATH_MAX]; + + sprintf(cmd, "/sbin/dd if=/dev/zero of=%s bs=4096 count=10", device); + if(__system(cmd)) { + printf("failure while zeroing rfs partition.\n"); + return -1; + } + + // Run fat.format + sprintf(cmd, "/sbin/fat.format -F %s -S 4096 -s %s %s", fatsize, sectorsize, device); + if(__system(cmd)) { + printf("failure while running fat.format\n"); + return -1; + } + + return 0; +} diff --git a/bmlutils/bmlutils.h b/bmlutils/bmlutils.h new file mode 100644 index 0000000..e6ffeee --- /dev/null +++ b/bmlutils/bmlutils.h @@ -0,0 +1,6 @@ +#ifndef BMLUTILS_H_ +#define BMLUTILS_H_ + +int format_rfs_device (const char *device, const char *path); + +#endif // BMLUTILS_H_ diff --git a/extendedcommands.c b/extendedcommands.c index ce9ef19..2e30cd7 100644 --- a/extendedcommands.c +++ b/extendedcommands.c @@ -41,6 +41,7 @@ #include "edify/expr.h" #include #include "mtdutils/mtdutils.h" +#include "bmlutils/bmlutils.h" int signature_check_enabled = 1; @@ -441,6 +442,18 @@ int format_device(const char *device, const char *path, const char *fs_type) { return -1; } + if (strcmp(fs_type, "rfs") == 0) { + if (ensure_path_unmounted(path) != 0) { + LOGE("format_volume failed to unmount \"%s\"\n", v->mount_point); + return -1; + } + if (0 != format_rfs_device(device, path)) { + LOGE("format_volume: format_rfs_device failed on %s\n", device); + return -1; + } + return 0; + } + if (strcmp(v->mount_point, path) != 0) { return format_unknown_device(v->device, path, NULL); } @@ -723,7 +736,7 @@ void show_nandroid_advanced_restore_menu(const char* path) }; char tmp[PATH_MAX]; - sprintf(tmp, "%s/clockworkmod/backup", path); + sprintf(tmp, "%s/clockworkmod/backup/", path); char* file = choose_file_menu(tmp, NULL, advancedheaders); if (file == NULL) return; diff --git a/utilities/Android.mk b/utilities/Android.mk index ffaf0e7..7d95449 100755 --- a/utilities/Android.mk +++ b/utilities/Android.mk @@ -58,6 +58,15 @@ else LOCAL_SRC_FILES := ../../../$(BOARD_MKE2FS) endif include $(BUILD_PREBUILT) - - endif + +BOARD_RECOVERY_RFS_CHECK := $(shell grep rfs $(TARGET_DEVICE_DIR)/recovery.fstab) +ifneq ($(BOARD_RECOVERY_RFS_CHECK),) +include $(CLEAR_VARS) +LOCAL_MODULE := fat.format +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 \ No newline at end of file diff --git a/utilities/fat.format b/utilities/fat.format new file mode 100755 index 0000000..6a743e7 Binary files /dev/null and b/utilities/fat.format differ