Skip to content

Commit

Permalink
Fix roots.c to use fs_mgr
Browse files Browse the repository at this point in the history
Change-Id: Ie68daba5e014dff0c4998da85576f35abe8ad270
  • Loading branch information
koush committed Aug 1, 2013
1 parent 00857c9 commit 8b26c06
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 238 deletions.
10 changes: 5 additions & 5 deletions Android.mk
Expand Up @@ -63,7 +63,7 @@ BOARD_RECOVERY_CHAR_HEIGHT := $(shell echo $(BOARD_USE_CUSTOM_RECOVERY_FONT) | c

LOCAL_CFLAGS += -DBOARD_RECOVERY_CHAR_WIDTH=$(BOARD_RECOVERY_CHAR_WIDTH) -DBOARD_RECOVERY_CHAR_HEIGHT=$(BOARD_RECOVERY_CHAR_HEIGHT)

BOARD_RECOVERY_DEFINES := BOARD_HAS_NO_SELECT_BUTTON BOARD_UMS_LUNFILE BOARD_RECOVERY_ALWAYS_WIPES BOARD_RECOVERY_HANDLES_MOUNT BOARD_TOUCH_RECOVERY RECOVERY_EXTEND_NANDROID_MENU TARGET_USE_CUSTOM_LUN_FILE_PATH TARGET_DEVICE
BOARD_RECOVERY_DEFINES := BOARD_HAS_NO_SELECT_BUTTON BOARD_UMS_LUNFILE BOARD_RECOVERY_ALWAYS_WIPES BOARD_RECOVERY_HANDLES_MOUNT BOARD_TOUCH_RECOVERY RECOVERY_EXTEND_NANDROID_MENU TARGET_USE_CUSTOM_LUN_FILE_PATH TARGET_DEVICE TARGET_RECOVERY_FSTAB

$(foreach board_define,$(BOARD_RECOVERY_DEFINES), \
$(if $($(board_define)), \
Expand All @@ -74,7 +74,7 @@ $(foreach board_define,$(BOARD_RECOVERY_DEFINES), \
LOCAL_STATIC_LIBRARIES :=

LOCAL_CFLAGS += -DUSE_EXT4
LOCAL_C_INCLUDES += system/extras/ext4_utils
LOCAL_C_INCLUDES += system/extras/ext4_utils system/core/fs_mgr/include
LOCAL_STATIC_LIBRARIES += libext4_utils_static libz libsparse_static

# This binary is in the recovery ramdisk, which is otherwise a copy of root.
Expand All @@ -96,7 +96,7 @@ LOCAL_STATIC_LIBRARIES += libminzip libunz libmincrypt
LOCAL_STATIC_LIBRARIES += libminizip libminadbd libedify libbusybox libmkyaffs2image libunyaffs liberase_image libdump_image libflash_image
LOCAL_LDFLAGS += -Wl,--no-fatal-warnings

LOCAL_STATIC_LIBRARIES += libdedupe libcrypto_static libcrecovery libflashutils libmtdutils libmmcutils libbmlutils
LOCAL_STATIC_LIBRARIES += libfs_mgr libdedupe libcrypto_static libcrecovery libflashutils libmtdutils libmmcutils libbmlutils

ifeq ($(BOARD_USES_BML_OVER_MTD),true)
LOCAL_STATIC_LIBRARIES += libbml_over_mtd
Expand All @@ -107,8 +107,6 @@ LOCAL_STATIC_LIBRARIES += libstdc++ libc

LOCAL_STATIC_LIBRARIES += libselinux

LOCAL_C_INCLUDES += system/extras/ext4_utils

include $(BUILD_EXECUTABLE)

RECOVERY_LINKS := bu make_ext4fs edify busybox flash_image dump_image mkyaffs2image unyaffs erase_image nandroid reboot volume setprop getprop dedupe minizip
Expand Down Expand Up @@ -157,6 +155,8 @@ include $(CLEAR_VARS)

LOCAL_SRC_FILES := verifier_test.c verifier.c

LOCAL_C_INCLUDES += system/extras/ext4_utils system/core/fs_mgr/include

LOCAL_MODULE := verifier_test

LOCAL_FORCE_STATIC_EXECUTABLE := true
Expand Down
42 changes: 21 additions & 21 deletions bootloader.c
Expand Up @@ -71,22 +71,22 @@ static int get_bootloader_message_mtd(struct bootloader_message *out,
const Volume* v) {
size_t write_size;
mtd_scan_partitions();
const MtdPartition *part = mtd_find_partition_by_name(v->device);
const MtdPartition *part = mtd_find_partition_by_name(v->blk_device);
if (part == NULL || mtd_partition_info(part, NULL, NULL, &write_size)) {
LOGE("Can't find %s\n", v->device);
LOGE("Can't find %s\n", v->blk_device);
return -1;
}

MtdReadContext *read = mtd_read_partition(part);
if (read == NULL) {
LOGE("Can't open %s\n(%s)\n", v->device, strerror(errno));
LOGE("Can't open %s\n(%s)\n", v->blk_device, strerror(errno));
return -1;
}

const ssize_t size = write_size * MISC_PAGES;
char data[size];
ssize_t r = mtd_read_data(read, data, size);
if (r != size) LOGE("Can't read %s\n(%s)\n", v->device, strerror(errno));
if (r != size) LOGE("Can't read %s\n(%s)\n", v->blk_device, strerror(errno));
mtd_read_close(read);
if (r != size) return -1;

Expand All @@ -97,39 +97,39 @@ static int set_bootloader_message_mtd(const struct bootloader_message *in,
const Volume* v) {
size_t write_size;
mtd_scan_partitions();
const MtdPartition *part = mtd_find_partition_by_name(v->device);
const MtdPartition *part = mtd_find_partition_by_name(v->blk_device);
if (part == NULL || mtd_partition_info(part, NULL, NULL, &write_size)) {
LOGE("Can't find %s\n", v->device);
LOGE("Can't find %s\n", v->blk_device);
return -1;
}

MtdReadContext *read = mtd_read_partition(part);
if (read == NULL) {
LOGE("Can't open %s\n(%s)\n", v->device, strerror(errno));
LOGE("Can't open %s\n(%s)\n", v->blk_device, strerror(errno));
return -1;
}

ssize_t size = write_size * MISC_PAGES;
char data[size];
ssize_t r = mtd_read_data(read, data, size);
if (r != size) LOGE("Can't read %s\n(%s)\n", v->device, strerror(errno));
if (r != size) LOGE("Can't read %s\n(%s)\n", v->blk_device, strerror(errno));
mtd_read_close(read);
if (r != size) return -1;

memcpy(&data[write_size * MISC_COMMAND_PAGE], in, sizeof(*in));

MtdWriteContext *write = mtd_write_partition(part);
if (write == NULL) {
LOGE("Can't open %s\n(%s)\n", v->device, strerror(errno));
LOGE("Can't open %s\n(%s)\n", v->blk_device, strerror(errno));
return -1;
}
if (mtd_write_data(write, data, size) != size) {
LOGE("Can't write %s\n(%s)\n", v->device, strerror(errno));
LOGE("Can't write %s\n(%s)\n", v->blk_device, strerror(errno));
mtd_write_close(write);
return -1;
}
if (mtd_write_close(write)) {
LOGE("Can't finish %s\n(%s)\n", v->device, strerror(errno));
LOGE("Can't finish %s\n(%s)\n", v->blk_device, strerror(errno));
return -1;
}

Expand Down Expand Up @@ -161,20 +161,20 @@ static void wait_for_device(const char* fn) {

static int get_bootloader_message_block(struct bootloader_message *out,
const Volume* v) {
wait_for_device(v->device);
FILE* f = fopen(v->device, "rb");
wait_for_device(v->blk_device);
FILE* f = fopen(v->blk_device, "rb");
if (f == NULL) {
LOGE("Can't open %s\n(%s)\n", v->device, strerror(errno));
LOGE("Can't open %s\n(%s)\n", v->blk_device, strerror(errno));
return -1;
}
struct bootloader_message temp;
int count = fread(&temp, sizeof(temp), 1, f);
if (count != 1) {
LOGE("Failed reading %s\n(%s)\n", v->device, strerror(errno));
LOGE("Failed reading %s\n(%s)\n", v->blk_device, strerror(errno));
return -1;
}
if (fclose(f) != 0) {
LOGE("Failed closing %s\n(%s)\n", v->device, strerror(errno));
LOGE("Failed closing %s\n(%s)\n", v->blk_device, strerror(errno));
return -1;
}
memcpy(out, &temp, sizeof(temp));
Expand All @@ -183,19 +183,19 @@ static int get_bootloader_message_block(struct bootloader_message *out,

static int set_bootloader_message_block(const struct bootloader_message *in,
const Volume* v) {
wait_for_device(v->device);
FILE* f = fopen(v->device, "wb");
wait_for_device(v->blk_device);
FILE* f = fopen(v->blk_device, "wb");
if (f == NULL) {
LOGE("Can't open %s\n(%s)\n", v->device, strerror(errno));
LOGE("Can't open %s\n(%s)\n", v->blk_device, strerror(errno));
return -1;
}
int count = fwrite(in, sizeof(*in), 1, f);
if (count != 1) {
LOGE("Failed writing %s\n(%s)\n", v->device, strerror(errno));
LOGE("Failed writing %s\n(%s)\n", v->blk_device, strerror(errno));
return -1;
}
if (fclose(f) != 0) {
LOGE("Failed closing %s\n(%s)\n", v->device, strerror(errno));
LOGE("Failed closing %s\n(%s)\n", v->blk_device, strerror(errno));
return -1;
}
return 0;
Expand Down
29 changes: 2 additions & 27 deletions common.h
Expand Up @@ -18,6 +18,7 @@
#define RECOVERY_COMMON_H

#include <stdio.h>
#include <fs_mgr.h>

// Initialize the graphics system.
void ui_init();
Expand Down Expand Up @@ -110,33 +111,7 @@ void ui_reset_progress();
#define STRINGIFY(x) #x
#define EXPAND(x) STRINGIFY(x)

typedef struct {
const char* mount_point; // eg. "/cache". must live in the root directory.

const char* fs_type; // "yaffs2" or "ext4" or "vfat"

const char* device; // MTD partition name if fs_type == "yaffs"
// block device if fs_type == "ext4" or "vfat"

const char* device2; // alternative device to try if fs_type
// == "ext4" or "vfat" and mounting
// 'device' fails

long long length; // (ext4 partition only) when
// formatting, size to use for the
// partition. 0 or negative number
// means to format all but the last
// (that much).

const char* fs_type2;

const char* fs_options;

const char* fs_options2;

const char* lun; // (/sdcard, /emmc, /external_sd only) LUN file to
// use when mounting via USB mass storage
} Volume;
typedef struct fstab_rec Volume;

typedef struct {
// number of frames in indeterminate progress bar animation
Expand Down
30 changes: 15 additions & 15 deletions extendedcommands.c
Expand Up @@ -458,7 +458,7 @@ static struct lun_node *lun_head = NULL;
static struct lun_node *lun_tail = NULL;

int control_usb_storage_set_lun(Volume* vol, bool enable, const char *lun_file) {
const char *vol_device = enable ? vol->device : "";
const char *vol_device = enable ? vol->blk_device : "";
int fd;
struct lun_node *node;

Expand All @@ -471,15 +471,15 @@ int control_usb_storage_set_lun(Volume* vol, bool enable, const char *lun_file)
}

// Open a handle to the LUN file
LOGI("Trying %s on LUN file %s\n", vol->device, lun_file);
LOGI("Trying %s on LUN file %s\n", vol->blk_device, lun_file);
if ((fd = open(lun_file, O_WRONLY)) < 0) {
LOGW("Unable to open ums lunfile %s (%s)\n", lun_file, strerror(errno));
return -1;
}

// Write the volume path to the LUN file
if ((write(fd, vol_device, strlen(vol_device) + 1) < 0) &&
(!enable || !vol->device2 || (write(fd, vol->device2, strlen(vol->device2)) < 0))) {
(!enable || !vol->blk_device2 || (write(fd, vol->blk_device2, strlen(vol->blk_device2)) < 0))) {
LOGW("Unable to write to ums lunfile %s (%s)\n", lun_file, strerror(errno));
close(fd);
return -1;
Expand All @@ -498,7 +498,7 @@ int control_usb_storage_set_lun(Volume* vol, bool enable, const char *lun_file)
lun_tail = node;
}

LOGI("Successfully %sshared %s on LUN file %s\n", enable ? "" : "un", vol->device, lun_file);
LOGI("Successfully %sshared %s on LUN file %s\n", enable ? "" : "un", vol->blk_device, lun_file);
return 0;
}
}
Expand Down Expand Up @@ -544,7 +544,7 @@ int control_usb_storage_for_lun(Volume* vol, bool enable) {
}

// All LUNs were exhausted and none worked
LOGW("Could not %sable %s on LUN %d\n", enable ? "en" : "dis", vol->device, lun_num);
LOGW("Could not %sable %s on LUN %d\n", enable ? "en" : "dis", vol->blk_device, lun_num);

return -1; // -1 failure, 0 success
}
Expand Down Expand Up @@ -681,7 +681,7 @@ int format_device(const char *device, const char *path, const char *fs_type) {
}

if (strcmp(v->mount_point, path) != 0) {
return format_unknown_device(v->device, path, NULL);
return format_unknown_device(v->blk_device, path, NULL);
}

if (ensure_path_unmounted(path) != 0) {
Expand Down Expand Up @@ -742,7 +742,7 @@ int format_unknown_device(const char *device, const char* path, const char *fs_t
{
struct stat st;
Volume *vol = volume_for_path("/sd-ext");
if (vol == NULL || 0 != stat(vol->device, &st))
if (vol == NULL || 0 != stat(vol->blk_device, &st))
{
ui_print("No app2sd partition found. Skipping format of /sd-ext.\n");
return 0;
Expand Down Expand Up @@ -1275,7 +1275,7 @@ static void partition_sdcard(const char* volume) {

char sddevice[256];
Volume *vol = volume_for_path(volume);
strcpy(sddevice, vol->device);
strcpy(sddevice, vol->blk_device);
// we only want the mmcblk, not the partition
sddevice[strlen("/dev/block/mmcblkX")] = NULL;
char cmd[PATH_MAX];
Expand All @@ -1295,10 +1295,10 @@ int can_partition(const char* volume) {
return 0;
}

int vol_len = strlen(vol->device);
int vol_len = strlen(vol->blk_device);
// do not allow partitioning of a device that isn't mmcblkX or mmcblkXp1
if (vol->device[vol_len - 2] == 'p' && vol->device[vol_len - 1] != '1') {
LOGI("Can't partition unsafe device: %s\n", vol->device);
if (vol->blk_device[vol_len - 2] == 'p' && vol->blk_device[vol_len - 1] != '1') {
LOGI("Can't partition unsafe device: %s\n", vol->blk_device);
return 0;
}

Expand Down Expand Up @@ -1432,10 +1432,10 @@ void write_fstab_root(char *path, FILE *file)
}

char device[200];
if (vol->device[0] != '/')
get_partition_device(vol->device, device);
if (vol->blk_device[0] != '/')
get_partition_device(vol->blk_device, device);
else
strcpy(device, vol->device);
strcpy(device, vol->blk_device);

fprintf(file, "%s ", device);
fprintf(file, "%s ", path);
Expand Down Expand Up @@ -1483,7 +1483,7 @@ int bml_check_volume(const char *path) {

ui_print("%s may be rfs. Checking...\n", path);
char tmp[PATH_MAX];
sprintf(tmp, "mount -t rfs %s %s", vol->device, path);
sprintf(tmp, "mount -t rfs %s %s", vol->blk_device, path);
int ret = __system(tmp);
printf("%d\n", ret);
return ret == 0 ? 1 : 0;
Expand Down
2 changes: 2 additions & 0 deletions minadbd/Android.mk
Expand Up @@ -25,6 +25,8 @@ LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE

LOCAL_MODULE := libminadbd

LOCAL_C_INCLUDES += system/extras/ext4_utils system/core/fs_mgr/include

LOCAL_STATIC_LIBRARIES := libcutils libc
include $(BUILD_STATIC_LIBRARY)

Expand Down

0 comments on commit 8b26c06

Please sign in to comment.