int is_path_mounted(const char* path) { Volume* v = volume_for_path(path); if (v == NULL) { return 0; } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted. return 1; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return 0; } const MountedVolume* mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv) { // volume is already mounted return 1; } return 0; }
static nandroid_backup_handler get_backup_handler(const char *backup_path) { Volume *v = volume_for_path(backup_path); if (v == NULL) { ui_print("Unable to find volume.\n"); return NULL; } MountedVolume *mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv == NULL) { ui_print("Unable to find mounted volume: %s\n", v->mount_point); return NULL; } if (strcmp(backup_path, "/data") == 0 && is_data_media()) { return default_backup_handler; } if (strlen(forced_backup_format) > 0) return default_backup_handler; // cwr5, we prefer dedupe for everything except yaffs2 if (strcmp("yaffs2", mv->filesystem) == 0) { return mkyaffs2image_wrapper; } return default_backup_handler; }
int ensure_path_unmounted(const char* path) { Volume* v = volume_for_path(path); if (v == NULL) { LOGE("unknown volume for path [%s]\n", path); return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted; you can't unmount it. return -1; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } const MountedVolume* mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv == NULL) { // volume is already unmounted return 0; } return unmount_mounted_volume(mv); }
int ensure_path_unmounted(const char* path) { // if we are using /data/media, do not ever unmount volumes /data or /sdcard if (strstr(path, "/data") == path && is_data_media()) { return 0; } Volume* v = volume_for_path(path); if (v == NULL) { LOGE("unknown volume for path [%s]\n", path); return -1; } if (is_data_media_volume_path(path)) { return ensure_path_unmounted("/data"); } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted; you can't unmount it. return -1; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } const MountedVolume* mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv == NULL) { // volume is already unmounted return 0; } return unmount_mounted_volume(mv); }
int ensure_root_path_unmounted(const char *root_path) { const RootInfo *info = get_root_info_for_path(root_path); if (info == NULL) { return -1; } if (info->mount_point == NULL) { /* This root can't be mounted, so by definition it isn't. */ return 0; } //xxx if TMP: (or similar) just return error /* See if this root is already mounted. */ int ret = scan_mounted_volumes(); if (ret < 0) { return ret; } const MountedVolume *volume; volume = find_mounted_volume_by_mount_point(info->mount_point); if (volume == NULL) { /* It's not mounted. */ return 0; } return unmount_mounted_volume(volume); }
static int internal_root_mounted(const RootInfo *info) { if (info->mount_point == NULL) { return -1; } if(info->device == NULL) return 0; //xxx if TMP: (or similar) just say "yes" /* See if this root is already mounted. */ int ret = scan_mounted_volumes(); if (ret < 0) { return ret; } const MountedVolume *volume; volume = find_mounted_volume_by_mount_point(info->mount_point); if (volume != NULL) { /* It's already mounted. */ return 0; } return -1; }
Value* UnmountFn(const char* name, State* state, int argc, Expr* argv[]) { char* result = NULL; if (argc != 1) { return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc); } char* mount_point; if (ReadArgs(state, argv, 1, &mount_point) < 0) { return NULL; } if (strlen(mount_point) == 0) { ErrorAbort(state, "mount_point argument to unmount() can't be empty"); goto done; } scan_mounted_volumes(); const MountedVolume* vol = find_mounted_volume_by_mount_point(mount_point); if (vol == NULL) { fprintf(stderr, "unmount of %s failed; no such volume\n", mount_point); result = strdup(""); } else { unmount_mounted_volume(vol); result = mount_point; } done: if (result != mount_point) free(mount_point); return StringValue(result); }
static nandroid_backup_handler get_backup_handler(const char *backup_path) { Volume *v = volume_for_path(backup_path); if (v == NULL) { ui_print("Unable to find volume.\n"); return NULL; } MountedVolume *mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv == NULL) { ui_print("Unable to find mounted volume: %s\n", v->mount_point); return NULL; } if (strcmp(backup_path, "/data") == 0 && is_data_media()) { return tar_compress_wrapper; } // cwr5, we prefer tar for everything except yaffs2 if (strcmp("yaffs2", mv->filesystem) == 0) { return mkyaffs2image_wrapper; } char str[255]; char* partition; property_get("ro.cwm.prefer_tar", str, "true"); if (strcmp("true", str) != 0) { return mkyaffs2image_wrapper; } return tar_compress_wrapper; }
int ensure_path_mounted(const char* path) { Volume* v = volume_for_path(path); if (v == NULL) { LOGE("unknown volume for path [%s]\n", path); return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted. return 0; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } const MountedVolume* mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv) { // volume is already mounted return 0; } mkdir("/mnt", 0755); // in case it doesn't already exist mkdir(v->mount_point, 0755); // in case it doesn't already exist if (strcmp(v->fs_type, "yaffs2") == 0) { // mount an MTD partition as a YAFFS2 filesystem. mtd_scan_partitions(); const MtdPartition* partition; partition = mtd_find_partition_by_name(v->device); if (partition == NULL) { LOGE("failed to find \"%s\" partition to mount at \"%s\"\n", v->device, v->mount_point); return -1; } return mtd_mount_partition(partition, v->mount_point, v->fs_type, 0); } else if (strcmp(v->fs_type, "ext4") == 0 || strcmp(v->fs_type, "vfat") == 0) { result = mount(v->device, v->mount_point, v->fs_type, MS_NOATIME | MS_NODEV | MS_NODIRATIME, ""); if (result == 0) return 0; if (v->device2) { LOGW("failed to mount %s (%s); trying %s\n", v->device, strerror(errno), v->device2); result = mount(v->device2, v->mount_point, v->fs_type, MS_NOATIME | MS_NODEV | MS_NODIRATIME, ""); if (result == 0) return 0; } LOGE("failed to mount %s (%s)\n", v->mount_point, strerror(errno)); return -1; } LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, v->mount_point); return -1; }
static nandroid_restore_handler get_restore_handler(const char *backup_path) { Volume *v = volume_for_path(backup_path); if (v == NULL) { ui_print("Unable to find volume.\n"); return NULL; } scan_mounted_volumes(); const MountedVolume *mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv == NULL) { ui_print("Unable to find mounted volume: %s\n", v->mount_point); return NULL; } if (strcmp(backup_path, "/data") == 0 && is_data_media()) { return tar_extract_wrapper; } // Disable tar backups of yaffs2 by default char prefer_tar[PROPERTY_VALUE_MAX]; property_get("ro.cwm.prefer_tar", prefer_tar, "false"); if (strcmp("yaffs2", mv->filesystem) == 0 && strcmp("false", prefer_tar) == 0) { return unyaffs_wrapper; } return tar_extract_wrapper; }
static nandroid_restore_handler get_restore_handler(const char *backup_path) { Volume *v = volume_for_path(backup_path); if (v == NULL) { ui_print("Unable to find volume.\n"); return NULL; } scan_mounted_volumes(); MountedVolume *mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv == NULL) { ui_print("Unable to find mounted volume: %s\n", v->mount_point); return NULL; } if (strcmp(backup_path, "/data") == 0 && is_data_media()) { return tar_extract_wrapper; } // cwr 5, we prefer tar for everything unless it is yaffs2 char str[255]; char* partition; property_get("ro.cwm.prefer_tar", str, "false"); if (strcmp("true", str) != 0) { return unyaffs_wrapper; } if (strcmp("yaffs2", mv->filesystem) == 0) { return unyaffs_wrapper; } return tar_extract_wrapper; }
int ensure_volume_mounted(fstab_rec* v) { if (v == NULL) { LOGE("cannot mount unknown volume\n"); return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted. return 0; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } if (!fs_mgr_is_voldmanaged(v)) { const MountedVolume* mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv) { // volume is already mounted return 0; } } mkdir_p(v->mount_point, 0755); // in case it doesn't already exist if (fs_mgr_is_voldmanaged(v)) { if (!strcmp(v->mount_point, "auto")) { return vold_mount_auto_volume(v->label, 1); } return vold_mount_volume(v->mount_point, 1); } else if (strcmp(v->fs_type, "yaffs2") == 0) { // mount an MTD partition as a YAFFS2 filesystem. mtd_scan_partitions(); const MtdPartition* partition; partition = mtd_find_partition_by_name(v->blk_device); if (partition == NULL) { LOGE("failed to find \"%s\" partition to mount at \"%s\"\n", v->blk_device, v->mount_point); return -1; } return mtd_mount_partition(partition, v->mount_point, v->fs_type, 0); } else if (strcmp(v->fs_type, "ext4") == 0 || strcmp(v->fs_type, "f2fs") == 0 || strcmp(v->fs_type, "vfat") == 0) { result = mount(v->blk_device, v->mount_point, v->fs_type, MS_NOATIME | MS_NODEV | MS_NODIRATIME, ""); if (result == 0) return 0; LOGE("failed to mount %s (%s)\n", v->mount_point, strerror(errno)); return -1; } LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, v->mount_point); return -1; }
// Mount the volume specified by path at the given mount_point. int ensure_path_mounted_at(const char* path, const char* mount_point) { Volume* v = volume_for_path(path); if (v == NULL) { LOGE("unknown volume for path [%s]\n", path); return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted. return 0; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } if (!mount_point) { mount_point = v->mount_point; } const MountedVolume* mv = find_mounted_volume_by_mount_point(mount_point); if (mv) { // volume is already mounted return 0; } mkdir(mount_point, 0755); // in case it doesn't already exist if (strcmp(v->fs_type, "yaffs2") == 0) { // mount an MTD partition as a YAFFS2 filesystem. mtd_scan_partitions(); const MtdPartition* partition; partition = mtd_find_partition_by_name(v->blk_device); if (partition == NULL) { LOGE("failed to find \"%s\" partition to mount at \"%s\"\n", v->blk_device, mount_point); return -1; } return mtd_mount_partition(partition, mount_point, v->fs_type, 0); } else if (strcmp(v->fs_type, "ext4") == 0 || strcmp(v->fs_type, "squashfs") == 0 || strcmp(v->fs_type, "vfat") == 0) { result = mount(v->blk_device, mount_point, v->fs_type, v->flags, v->fs_options); if (result == 0) return 0; LOGE("failed to mount %s (%s)\n", mount_point, strerror(errno)); return -1; } LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, mount_point); return -1; }
int device_truedualboot_mount(const char* path, const char* mount_point) { if(strcmp(path, "/data") != 0) return 1; else if(mount_point!=NULL && strcmp(mount_point, MOUNTPOINT_DATAROOT)==0) return 1; if(!dualboot_is_tdb_enabled()) return 1; ensure_path_mounted_at_mount_point("/data", MOUNTPOINT_DATAROOT); Volume* v = volume_for_path(path); if (v == NULL) { LOGE("unknown volume for path [%s]\n", path); return -1; } int result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } if (NULL == mount_point) mount_point = v->mount_point; const MountedVolume* mv = find_mounted_volume_by_mount_point(mount_point); if (mv) { // volume is already mounted return 0; } char* bind_path; if(get_selected_system()==SYSTEM1) bind_path = MOUNTPOINT_DATAROOT "/system0"; else if(get_selected_system()==SYSTEM2) bind_path = MOUNTPOINT_DATAROOT "/system1"; else return -1; mkdir(mount_point, 0755); // in case it doesn't already exist mkdir(bind_path, 0755); char mount_cmd[PATH_MAX]; sprintf(mount_cmd, "mount -o bind %s %s", bind_path, mount_point); int ret = __system(mount_cmd); if(ret!=0) return ret>0?-ret:ret; return 0; }
int nandroid_backup_partition_extended(const char* backup_path, const char* mount_point, int umount_when_finished) { int ret = 0; char name[PATH_MAX]; char tmp[PATH_MAX]; strcpy(name, basename(mount_point)); struct stat file_info; build_configuration_path(tmp, NANDROID_HIDE_PROGRESS_FILE); ensure_path_mounted(tmp); int callback = stat(tmp, &file_info) != 0; ui_print("Backing up %s...\n", name); if (0 != (ret = ensure_path_mounted(mount_point) != 0)) { ui_print("Can't mount %s!\n", mount_point); return ret; } compute_directory_stats(mount_point); scan_mounted_volumes(); Volume *v = volume_for_path(mount_point); const MountedVolume *mv = NULL; if (v != NULL) mv = find_mounted_volume_by_mount_point(v->mount_point); if (strcmp(backup_path, "-") == 0) sprintf(tmp, "/proc/self/fd/1"); else if (mv == NULL || mv->filesystem == NULL) sprintf(tmp, "%s/%s.auto", backup_path, name); else sprintf(tmp, "%s/%s.%s", backup_path, name, mv->filesystem); nandroid_backup_handler backup_handler = get_backup_handler(mount_point); if (backup_handler == NULL) { ui_print("Error finding an appropriate backup handler.\n"); return -2; } ret = backup_handler(mount_point, tmp, callback); if (umount_when_finished) { ensure_path_unmounted(mount_point); } if (0 != ret) { ui_print("Error while making a backup image of %s!\n", mount_point); return ret; } ui_print("Backup of %s completed.\n", name); return 0; }
int nandroid_backup_partition_extended(const char* backup_path, const char* mount_point, int umount_when_finished) { int ret = 0; char name[PATH_MAX]; strcpy(name, basename(mount_point)); struct stat file_info; int callback = stat("/sdcard/clockworkmod/.hidenandroidprogress", &file_info) != 0; ui_print("备份中 %s...\n", name); if (0 != (ret = ensure_path_mounted(mount_point) != 0)) { ui_print("无法挂载 %s!\n", mount_point); return ret; } compute_directory_stats(mount_point); char tmp[PATH_MAX]; scan_mounted_volumes(); Volume *v = volume_for_path(mount_point); MountedVolume *mv = NULL; if (v != NULL) mv = find_mounted_volume_by_mount_point(v->mount_point); if (strcmp(backup_path, "-") == 0) sprintf(tmp, "/proc/self/fd/1"); else if (mv == NULL || mv->filesystem == NULL) sprintf(tmp, "%s/%s.auto", backup_path, name); else sprintf(tmp, "%s/%s.%s", backup_path, name, mv->filesystem); nandroid_backup_handler backup_handler = get_backup_handler(mount_point); if (backup_handler == NULL) { ui_print("找不到合适的备份方案.\n"); return -2; } ret = backup_handler(mount_point, tmp, callback); if (umount_when_finished) { ensure_path_unmounted(mount_point); } if (0 != ret) { ui_print("生成下列镜像文件时失败: %s!\n", mount_point); return ret; } ui_print("备份 %s 完成.\n", name); return 0; }
int nandroid_backup_partition_extended(const char* backup_path, const char* mount_point, int umount_when_finished) { int ret = 0; char name[PATH_MAX]; strcpy(name, basename(mount_point)); ensure_path_mounted("/sdcard"); struct stat file_info; int callback = stat("/sdcard/clockworkmod/.hidenandroidprogress", &file_info) != 0; ui_print("Backing up %s...\n", name); if (0 != (ret = ensure_path_mounted(mount_point) != 0)) { ui_print("Can't mount %s!\n", mount_point); return ret; } compute_directory_stats(mount_point); char tmp[PATH_MAX]; scan_mounted_volumes(); Volume *v = volume_for_path(mount_point); MountedVolume *mv = NULL; if (v != NULL) mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv == NULL || mv->filesystem == NULL) sprintf(tmp, "%s/%s.auto", backup_path, name); else sprintf(tmp, "%s/%s.%s", backup_path, name, mv->filesystem); nandroid_backup_handler backup_handler = get_backup_handler(mount_point); if (backup_handler == NULL) { ui_print("Error finding an appropriate backup handler.\n"); return -2; } ret = backup_handler(mount_point, tmp, callback); if (umount_when_finished) { ensure_path_unmounted(mount_point); } if (0 != ret) { ui_print("Error while making a backup image of %s!\n", mount_point); return ret; } ui_print("Backup of %s completed.\n", name); return 0; }
int ensure_volume_unmounted(fstab_rec* v, bool detach) { if (v == NULL) { LOGE("cannot unmount unknown volume\n"); return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted; you can't unmount it. return -1; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } if (fs_mgr_is_voldmanaged(v)) { if (!strcmp(v->mount_point, "auto")) { return vold_unmount_auto_volume(v->label, 0, 1, detach); } return vold_unmount_volume(v->mount_point, 0, 1, detach); } const MountedVolume* mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv == NULL) { // volume is already unmounted return 0; } if (detach) { result = unmount_mounted_volume_detach(mv); } else { result = unmount_mounted_volume(mv); } return result; }
int ensure_root_path_unmounted(const char *root_path) { /* See if this root is already mounted. */ int ret = scan_mounted_volumes(); if (ret < 0) { return ret; } const MountedVolume *volume; volume = find_mounted_volume_by_mount_point(root_path); if (volume == NULL) { /* It's not mounted. */ LOGD(TAG "The path %s is unmounted\n", root_path); return 0; } return unmount_mounted_volume(volume); }
int ensure_path_unmounted(const char* path) { // This is an old, common method for ensuring a flush sync(); sync(); if (DataManager_GetIntValue(TW_DONT_UNMOUNT_SYSTEM) == 1 && strncmp(path, "/system", 7) == 0) return 0; if ((DataManager_GetIntValue(TW_HAS_DATA_MEDIA) == 1 || DataManager_GetIntValue(TW_HAS_DUAL_STORAGE) == 1) && strncmp(path, "/sdcard", 7) == 0) { LOGI("Unmounting /sdcard (dual storage path code)\n"); return system("umount /sdcard");; } Volume* v = volume_for_path(path); if (v == NULL) { LOGE("unknown volume for path [%s]\n", path); return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted; you can't unmount it. return -1; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } const MountedVolume* mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv == NULL) { // volume is already unmounted return 0; } return unmount_mounted_volume(mv); }
static nandroid_backup_handler get_backup_handler(const char *backup_path) { Volume *v = volume_for_path(backup_path); if (v == NULL) { #ifndef USE_CHINESE_FONT ui_print("Unable to find volume.\n"); #else ui_print("无法找到卷。\n"); #endif return NULL; } const MountedVolume *mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv == NULL) { #ifndef USE_CHINESE_FONT ui_print("Unable to find mounted volume: %s\n", v->mount_point); #else ui_print("无法挂载卷: %s\n", v->mount_point); #endif return NULL; } if (strcmp(backup_path, "/data") == 0 && is_data_media()) { return default_backup_handler; } if (strlen(forced_backup_format) > 0) return default_backup_handler; // Disable tar backups of yaffs2 by default char prefer_tar[PROPERTY_VALUE_MAX]; property_get("ro.cwm.prefer_tar", prefer_tar, "false"); if (strcmp("yaffs2", mv->filesystem) == 0 && strcmp("false", prefer_tar) == 0) { return mkyaffs2image_wrapper; } return default_backup_handler; }
Value* UpdateFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc != 7) { return ErrorAbort(state, "%s() expects 7 args, got %d", name, argc); } char* type = strrchr(name, '_'); if (type == NULL || *(type+1) == '\0') { return ErrorAbort(state, "%s() couldn't get type from function name", name); } ++type; Value* image; Value* width_string; Value* height_string; Value* bpp_string; Value* busy; Value* fail; Value* expected_sha1_string; if (ReadValueArgs(state, argv, 7, &image, &width_string, &height_string, &bpp_string, &busy, &fail, &expected_sha1_string) < 0) { return NULL; } // close the package ZipArchive* za = ((UpdaterInfo*)(state->cookie))->package_zip; mzCloseZipArchive(za); ((UpdaterInfo*)(state->cookie))->package_zip = NULL; // Try to unmount /cache. If we fail (because we're running in an // older recovery that still has the package file open), try to // remount it read-only. If that fails, abort. sync(); scan_mounted_volumes(); MountedVolume* vol = find_mounted_volume_by_mount_point("/cache"); int result = unmount_mounted_volume(vol); if (result != 0) { printf("%s(): failed to unmount cache (%d: %s)\n", name, result, strerror(errno)); result = remount_read_only(vol); if (result != 0) { printf("%s(): failed to remount cache (%d: %s)\n", name, result, strerror(errno)); return StringValue(strdup("")); } else { printf("%s(): remounted cache\n", name); } sync(); } else { printf("%s(): unmounted cache\n", name); } int width = 0, height = 0, bpp = 0; if (width_string->type != VAL_STRING || (width = strtol(width_string->data, NULL, 10)) == 0) { printf("%s(): bad width argument", name); } if (height_string->type != VAL_STRING || (height = strtol(height_string->data, NULL, 10)) == 0) { printf("%s(): bad height argument", name); } if (bpp_string->type != VAL_STRING || (bpp = strtol(bpp_string->data, NULL, 10)) == 0) { printf("%s(): bad bpp argument", name); } if (image->type != VAL_BLOB) { printf("image argument is not blob (is type %d)\n", image->type); goto done; } uint8_t expected_sha1[SHA_DIGEST_SIZE]; char* data = expected_sha1_string->data; if (expected_sha1_string->type != VAL_STRING || strlen(data) != SHA_DIGEST_SIZE*2) { printf("%s(): bad expected_sha1 argument", name); goto done; } printf("expected sha1 is: "); int i; for (i = 0; i < SHA_DIGEST_SIZE; ++i) { char temp = data[i*2+2]; data[i*2+2] = '\0'; expected_sha1[i] = strtol(data+i*2, NULL, 16); data[i*2+2] = temp; printf("%02x", expected_sha1[i]); } printf("\n"); install_firmware_update( type, image->data, image->size, width, height, bpp, busy->size > 0 ? busy->data : NULL, fail->size > 0 ? fail->data : NULL, "/tmp/recovery.log", expected_sha1); printf("%s: install_firmware_update returned!\n", name); done: FreeValue(image); FreeValue(width_string); FreeValue(height_string); FreeValue(bpp_string); FreeValue(busy); FreeValue(fail); // install_firmware_update should reboot. If it returns, it failed. return StringValue(strdup("")); }
int format_root_device(const char *root) { /* See if this root is already mounted. */ const MountedVolume *volume; char *filesystem; char *device; int ret = scan_mounted_volumes(); if (ret < 0) { LOGD(TAG "format_root_device: load mount info fail\n", root); return false; } volume = find_mounted_volume_by_mount_point(root); if (volume == NULL) { LOGD(TAG "The path %s is unmounted\n", root); return 0; } filesystem = strdup(volume->filesystem); device = strdup(volume->device); ret = unmount_mounted_volume(volume); if (ret < 0) { LOGD(TAG "format_root_device: can't unmount \"%s\"\n", root); return false; } LOGD(TAG "format_root_device : unmount %s scucess, type is %s\n", root, filesystem); if (!strcmp(filesystem, "yaffs2")) { LOGD(TAG "format yaffs2 partitions\n", root); /* Format the device. */ mtd_scan_partitions(); const MtdPartition *partition = NULL; if(!strcmp(root, DATA_PARTITION)) { LOGD(TAG "find the partition name is %s", root); partition = mtd_find_partition_by_name("userdata"); } if (partition == NULL) { LOGD(TAG "format_root_device: can't find mtd partition \"%s\"\n", root); return false; } MtdWriteContext *write = mtd_write_partition(partition); if (write == NULL) { LOGD(TAG "format_root_device: can't open \"%s\"\n", root); return false; } else if (mtd_erase_blocks(write, -1) == (off_t) - 1) { LOGD(TAG "format_root_device: can't erase \"%s\"\n", root); mtd_write_close(write); return false; } else if (mtd_write_close(write)) { LOGD(TAG "format_root_device: can't close \"%s\"\n", root); return false; } else { ret= true; } } else { if (!strcmp(filesystem, "ubifs")) { int ubi_num = -1, ubi_dev; int mtd_num = -1; char path[128]; char mtd_dev_name[128]; const char *binary_path = "/system/bin/ubiformat"; sscanf(device, "/dev/ubi%d_0", &ubi_num); if (ubi_num >= 0 && ubi_num <= 32) { LOGD(TAG "format_root_device: detach ubi device /dev/ubi%d_0\n", ubi_num); } else { LOGD(TAG "Can not find parse ubi num :%s\n", device); return false; } sprintf(path, "/sys/class/ubi/ubi%d/mtd_num", ubi_num); ubi_dev = open(path, O_RDONLY); if (ubi_dev != -1) { ret = read(ubi_dev, path, sizeof(path)); close(ubi_dev); if (ret > 0) { mtd_num = atoi(path); LOGD(TAG " %s mtd_num is %d \n", device, mtd_num); sprintf(mtd_dev_name, "/dev/mtd/mtd%d", mtd_num); } else { LOGD(TAG " read %s fail! \n", path); return false; } } else { LOGD(TAG " open %s fail! \n", path); return false; } ret = ubi_detach_dev(ubi_num); if (ret != 0) { LOGD(TAG "format_root_device: detach ubi device /dev/ubi%d_0 fail!ret=%d\n", ubi_num, ret); return false; } //int check; //check = chmod(binary_path, 0777); //printf("chmod = %d\n", check); const char **args = (const char **)malloc(sizeof(char *) * 3); args[0] = binary_path; args[1] = mtd_dev_name; args[2] = NULL; pid_t pid = fork(); if (pid == 0) { execv(binary_path, (char *const *)args); fprintf(stdout, "E:Can't run %s (%s)\n", binary_path, strerror(errno)); _exit(-1); } int status; waitpid(pid, &status, 0); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { LOGE("Error in ubiformat\n(Status %d)\n", WEXITSTATUS(status)); return false; } ret=true; } else { LOGD(TAG "format_root_device : unsupport filesystem %s\n", filesystem); return false; } } free(filesystem); free(device); return ret; }
int ensure_path_mounted(const char* path) { Volume* v = volume_for_path(path); if (v == NULL) { LOGE("unknown volume for path [%s]\n", path); return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted. return 0; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } const MountedVolume* mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv) { // volume is already mounted return 0; } mkdir(v->mount_point, 0755); // in case it doesn't already exist #if 1 if ((strcmp(v->mount_point, "/mnt/sdcard") == 0)||(strcmp(v->mount_point, "/mnt/usb") == 0)) { int wait_count = 0; FILE * fp; char read_buf[1024]; char s_dev_name[128]; char s_dev_fullpath[128]; int mount_ok = -1; int hasmounted = 0; while (wait_count < 30) { memset(s_dev_name, 0, 128); memset(s_dev_fullpath, 0, 128); fp = fopen("/proc/diskstats", "r"); if (fp == NULL) { return -1; } while(!feof(fp)) { if(!fgets(read_buf, 1023 , fp)) { break; } sscanf(read_buf, "%*d %*d %32s %*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*u", s_dev_name); hasmounted = 0; //mount_ok = -1; printf("[Root] From /proc/diskstats %s %s\n", s_dev_name, v->mount_point); /*Just look for sdX*/ if(strncmp("sd", s_dev_name, 2) == 0 && strcmp(v->mount_point, "/mnt/usb") == 0) { sprintf(s_dev_fullpath, "/dev/block/%s", s_dev_name); mount_ok = mount(s_dev_fullpath, v->mount_point, v->fs_type, MS_NOATIME | MS_NODEV | MS_NODIRATIME, ""); if (mount_ok == 0) { //break; printf("mount ok\n"); hasmounted = 1; } else { mount_ok = mount(s_dev_fullpath, v->mount_point, "ntfs", MS_NOATIME | MS_NODEV | MS_NODIRATIME, ""); printf("mount ok: %d\n", mount_ok); if (mount_ok == 0) { // break; hasmounted = 1; } } } else if (strncmp("mmcblk", s_dev_name, 6) == 0 && strcmp(v->mount_point, "/mnt/sdcard") == 0) { sprintf(s_dev_fullpath, "/dev/block/%s", s_dev_name); mount_ok = mount(s_dev_fullpath, v->mount_point, v->fs_type, MS_NOATIME | MS_NODEV | MS_NODIRATIME, ""); if (mount_ok == 0) { //break; hasmounted = 1; } else { mount_ok = mount(s_dev_fullpath, v->mount_point, "ntfs", MS_NOATIME | MS_NODEV | MS_NODIRATIME, ""); if (mount_ok == 0) { // break; hasmounted = 1; } } } if (hasmounted == 1) { if (access(path, R_OK) == 0) { printf("access error\n"); break; }else{ umount2(v->mount_point, MNT_FORCE); printf("umount2 here\n"); } } } fclose(fp); if (mount_ok == 0) { return 0; } usleep(800000); wait_count ++; } return -1; } #endif else if ( (strcmp(v->fs_type, "yaffs2") == 0) || (strcmp(v->fs_type, "ubifs") == 0)) { // mount an MTD partition as a YAFFS2 filesystem. mtd_scan_partitions(); const MtdPartition* partition; partition = mtd_find_partition_by_name(&v->mount_point[1]); if (partition == NULL) { LOGE("failed to find \"%s\" partition to mount at \"%s\"\n", v->device, v->mount_point); return -1; } return mtd_mount_partition(partition, v->mount_point, v->fs_type, 0); } else if (strcmp(v->fs_type, "ext4") == 0 || strcmp(v->fs_type, "vfat") == 0) { result = mount(v->device, v->mount_point, v->fs_type, MS_NOATIME | MS_NODEV | MS_NODIRATIME, ""); if (result == 0) return 0; if (v->device2) { LOGW("failed to mount %s (%s); trying %s\n", v->device, strerror(errno), v->device2); result = mount(v->device2, v->mount_point, v->fs_type, MS_NOATIME | MS_NODEV | MS_NODIRATIME, ""); if (result == 0) return 0; } LOGE("failed to mount %s (%s)\n", v->mount_point, strerror(errno)); return -1; } LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, v->mount_point); return -1; }
int ensure_path_mounted(const char* path) { Volume* v = volume_for_path(path); if (v == NULL) { // no /sdcard? let's assume /data/media if (strstr(path, "/sdcard") == path && is_data_media()) { LOGW("using /data/media, no /sdcard found.\n"); int ret; if (0 != (ret = ensure_path_mounted("/data"))) return ret; setup_data_media(); return 0; } LOGE("unknown volume for path [%s]\n", path); return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted. return 0; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } const MountedVolume* mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv) { // volume is already mounted return 0; } mkdir(v->mount_point, 0755); // in case it doesn't already exist if (strcmp(v->fs_type, "yaffs2") == 0) { // mount an MTD partition as a YAFFS2 filesystem. mtd_scan_partitions(); const MtdPartition* partition; partition = mtd_find_partition_by_name(v->device); if (partition == NULL) { LOGE("failed to find \"%s\" partition to mount at \"%s\"\n", v->device, v->mount_point); return -1; } return mtd_mount_partition(partition, v->mount_point, v->fs_type, 0); } else if (strcmp(v->fs_type, "ext4") == 0 || strcmp(v->fs_type, "ext3") == 0 || strcmp(v->fs_type, "rfs") == 0 || strcmp(v->fs_type, "vfat") == 0) { if ((result = try_mount(v->device, v->mount_point, v->fs_type, v->fs_options)) == 0) return 0; if ((result = try_mount(v->device2, v->mount_point, v->fs_type, v->fs_options)) == 0) return 0; if ((result = try_mount(v->device, v->mount_point, v->fs_type2, v->fs_options2)) == 0) return 0; if ((result = try_mount(v->device2, v->mount_point, v->fs_type2, v->fs_options2)) == 0) return 0; return result; } else { // let's try mounting with the mount binary and hope for the best. char mount_cmd[PATH_MAX]; sprintf(mount_cmd, "mount %s", path); return __system(mount_cmd); } LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, v->mount_point); return -1; }
int ensure_path_mounted(const char* path) { #ifdef RECOVERY_SDCARD_ON_DATA //if (strcmp(path, "/sdcard") == 0) return 0; #endif if (strncmp(path, "/sdcard", 7) == 0) { if (DataManager_GetIntValue(TW_HAS_DUAL_STORAGE) == 1) { char mount_command[255], mount_point[255]; memset(mount_command, 0, sizeof(mount_command)); memset(mount_point, 0, sizeof(mount_point)); strcpy(mount_point, DataManager_GetCurrentStoragePath()); sprintf(mount_command, "mount %s /sdcard", mount_point); LOGI("Mounting '%s'\n", mount_point); if (ensure_path_mounted(mount_point) != 0) { LOGI("Unable to mount '%s'\n", mount_point); return -1; } LOGI("Mounting /sdcard using: '%s'\n", mount_command); __system(mount_command); return 0; } else if (DataManager_GetIntValue(TW_HAS_DATA_MEDIA) == 1) { if (ensure_path_mounted("/data")) { LOGI("Unable to mount /data\n"); return -1; } LOGI("Mounting /sdcard using: 'mount /data/media /sdcard'\n"); __system("mount /data/media /sdcard"); return 0; } } Volume* v = volume_for_path(path); if (v == NULL) { LOGE("unknown volume for path [%s]\n", path); return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted. return 0; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } const MountedVolume* mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv) { // volume is already mounted return 0; } mkdir(v->mount_point, 0755); // in case it doesn't already exist if (strcmp(v->fs_type, "yaffs2") == 0) { // mount an MTD partition as a YAFFS2 filesystem. mtd_scan_partitions(); const MtdPartition* partition; partition = mtd_find_partition_by_name(v->device); if (partition == NULL) { LOGE("failed to find \"%s\" partition to mount at \"%s\"\n", v->device, v->mount_point); return -1; } return mtd_mount_partition(partition, v->mount_point, v->fs_type, 0); } else if (strcmp(v->fs_type, "ext4") == 0 || strcmp(v->fs_type, "ext3") == 0 || strcmp(v->fs_type, "ext2") == 0 || strcmp(v->fs_type, "vfat") == 0) { result = mount(v->device, v->mount_point, v->fs_type, MS_NOATIME | MS_NODEV | MS_NODIRATIME, ""); if (result == 0) return 0; if (v->device2) { LOGW("failed to mount %s (%s); trying %s\n", v->device, strerror(errno), v->device2); result = mount(v->device2, v->mount_point, v->fs_type, MS_NOATIME | MS_NODEV | MS_NODIRATIME, ""); if (result == 0) return 0; } LOGE("failed to mount %s (%s)\n", v->mount_point, strerror(errno)); return -1; } LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, v->mount_point); return -1; }
int ensure_path_mounted_at_mount_point(const char* path, const char* mount_point) { Volume* v = volume_for_path(path); if (v == NULL) { LOGE("unknown volume for path [%s]\n", path); return -1; } if (is_data_media_volume_path(path)) { LOGI("using /data/media for %s.\n", path); int ret; if (0 != (ret = ensure_path_mounted("/data"))) return ret; setup_data_media(); return 0; } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted. return 0; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } if (NULL == mount_point) mount_point = v->mount_point; const MountedVolume* mv = find_mounted_volume_by_mount_point(mount_point); if (mv) { // volume is already mounted return 0; } mkdir(mount_point, 0755); // in case it doesn't already exist if (strcmp(v->fs_type, "yaffs2") == 0) { // mount an MTD partition as a YAFFS2 filesystem. mtd_scan_partitions(); const MtdPartition* partition; partition = mtd_find_partition_by_name(v->device); if (partition == NULL) { LOGE("failed to find \"%s\" partition to mount at \"%s\"\n", v->device, mount_point); return -1; } return mtd_mount_partition(partition, mount_point, v->fs_type, 0); } else if (strcmp(v->fs_type, "ext4") == 0 || strcmp(v->fs_type, "ext3") == 0 || strcmp(v->fs_type, "rfs") == 0 || strcmp(v->fs_type, "vfat") == 0) { if ((result = try_mount(v->device, mount_point, v->fs_type, v->fs_options)) == 0) return 0; if ((result = try_mount(v->device2, mount_point, v->fs_type, v->fs_options)) == 0) return 0; if ((result = try_mount(v->device, mount_point, v->fs_type2, v->fs_options2)) == 0) return 0; if ((result = try_mount(v->device2, mount_point, v->fs_type2, v->fs_options2)) == 0) return 0; #ifdef KYLE_TOUCH_RECOVERY #include "/home/klaplante/recoverystuff/exfat2.c" #endif return result; } else { // let's try mounting with the mount binary and hope for the best. char mount_cmd[PATH_MAX]; sprintf(mount_cmd, "mount %s", path); return __system(mount_cmd); } LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, mount_point); return -1; }
int ensure_path_mounted(const char* path) { Volume* v = volume_for_path(path); if (v == NULL) { LOGE("unknown volume for path [%s]\n", path); return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted. return 0; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } const MountedVolume* mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv) { // volume is already mounted return 0; } mkdir(v->mount_point, 0755); // in case it doesn't already exist if (strcmp(v->fs_type, "yaffs2") == 0) { // mount an MTD partition as a YAFFS2 filesystem. mtd_scan_partitions(); const MtdPartition* partition; partition = mtd_find_partition_by_name(v->device); if (partition == NULL) { LOGE("failed to find \"%s\" partition to mount at \"%s\"\n", v->device, v->mount_point); return -1; } #if 0 return mtd_mount_partition(partition, v->mount_point, v->fs_type, 0); #else return mtd_mount_partition(partition, v->mount_point, v->fs_type, v->options); #endif } else if (strcmp(v->fs_type, "ext4") == 0 || strcmp(v->fs_type, "vfat") == 0) { /***************************************************************************/ //add support for some sdcard can not get ready immediately #define SLEEP_SDCARD 3 #define TRY_MOUNT_TIMES 8 int tryCount = 0; char *dev_buf; int path_length = 0; struct stat s; int i = 0; dev_buf = strdup(v->device); for(i = 1;i<6;){ sleep(SLEEP_SDCARD); if(stat(dev_buf, &s)==0) break; else { i++; path_length = strlen(dev_buf); sprintf(dev_buf + path_length -1, "%d\0", i); } } if(i==6){ path_length = strlen(dev_buf); dev_buf[path_length -2] = '\0'; } #if 0 while(tryCount++ < TRY_MOUNT_TIMES){ if( mount(v->device, v->mount_point, v->fs_type, MS_NOATIME | MS_NODEV | MS_NODIRATIME, "") && (v->device2 ? mount(v->device2, v->mount_point, v->fs_type, MS_NOATIME | MS_NODEV | MS_NODIRATIME, "") : 1)) sleep(SLEEP_SDCARD); else return 0; } #else while(tryCount++ < TRY_MOUNT_TIMES){ if(mount(dev_buf, v->mount_point, v->fs_type, MS_NOATIME | MS_NODEV | MS_NODIRATIME, v->options)) sleep(SLEEP_SDCARD); else return 0; } #endif #undef SLEEP_SDCARD #undef TRY_MOUNT_TIMES /***************************************************************************/ #if 0 result = mount(v->device, v->mount_point, v->fs_type, MS_NOATIME | MS_NODEV | MS_NODIRATIME, ""); #else result = mount(v->device, v->mount_point, v->fs_type, MS_NOATIME | MS_NODEV | MS_NODIRATIME, v->options); #endif if (result == 0) return 0; #if 0 if (v->device2) { LOGW("failed to mount %s (%s); trying %s\n", v->device, strerror(errno), v->device2); result = mount(v->device2, v->mount_point, v->fs_type, MS_NOATIME | MS_NODEV | MS_NODIRATIME, ""); if (result == 0) return 0; } #endif LOGE("failed to mount %s (%s)\n", v->mount_point, strerror(errno)); return -1; } LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, v->mount_point); return -1; }
int ensure_path_mounted(const char* path) { Volume* v = volume_for_path(path); if (v == NULL) { LOGE("unknown volume for path [%s]\n", path); return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted. return 0; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } const MountedVolume* mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv) { #if defined(CACHE_MERGE_SUPPORT) if (strncmp(path, "/cache", 6) == 0) { if (symlink(DATA_CACHE_ROOT, "/cache")) { if (errno != EEXIST) { LOGE("create symlink from %s to %s failed(%s)\n", DATA_CACHE_ROOT, "/cache", strerror(errno)); return -1; } } } #endif // volume is already mounted return 0; } mkdir(v->mount_point, 0755); // in case it doesn't already exist #if defined (UBIFS_SUPPORT) if (strcmp(v->fs_type, "ubifs") == 0) { printf("Trying to mount %s \n", v->mount_point); //Attatch UBI device & Make UBI volum int n = -1; n = ubi_attach_mtd_user(v->mount_point); if ((n != -1) && (n < 4)) { printf("Try to attatch %s \n", v->blk_device); printf("/dev/ubi%d_0 is attached \n", n); } else { LOGE("failed to attach %s\n", v->blk_device); } //Mount UBI volume const unsigned long flags = MS_NOATIME | MS_NODEV | MS_NODIRATIME; char tmp[64]; sprintf(tmp, "/dev/ubi%d_0", n); wait_for_file(tmp, 5); result = mount(tmp, v->mount_point, v->fs_type, flags, ""); if (result < 0) { ubi_detach_dev(n); return -1; } else if (result == 0) { goto mount_done; //Volume successfully mounted } } #endif if (strcmp(v->fs_type, "yaffs2") == 0) { // mount an MTD partition as a YAFFS2 filesystem. mtd_scan_partitions(); const MtdPartition* partition; partition = mtd_find_partition_by_name(v->blk_device); if (partition == NULL) { LOGE("failed to find \"%s\" partition to mount at \"%s\"\n", v->blk_device, v->mount_point); return -1; } return mtd_mount_partition(partition, v->mount_point, v->fs_type, 0); } else if (strcmp(v->fs_type, "ext4") == 0 || strcmp(v->fs_type, "squashfs") == 0 || strcmp(v->fs_type, "vfat") == 0) { mt_ensure_dev_ready(v->mount_point); result = mount(v->blk_device, v->mount_point, v->fs_type, v->flags, v->fs_options); if (result == 0) { goto mount_done; } else { result = mt_ensure_path_mounted(v); if (result == 0) goto mount_done; } LOGE("failed to mount %s (%s)\n", v->mount_point, strerror(errno)); return -1; } LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, v->mount_point); return -1; mount_done: #if defined(CACHE_MERGE_SUPPORT) if (strcmp(v->mount_point, "/data") == 0) { if (mkdir(DATA_CACHE_ROOT, 0770)) { if (errno != EEXIST) { LOGE("mkdir %s error: %s\n", DATA_CACHE_ROOT, strerror(errno)); return -1; } else if (need_clear_cache) { LOGI("cache exists, clear it...\n"); if (remove_dir(DATA_CACHE_ROOT)) { LOGE("remove_dir %s error: %s\n", DATA_CACHE_ROOT, strerror(errno)); return -1; } if (mkdir(DATA_CACHE_ROOT, 0770) != 0) { LOGE("mkdir %s error: %s\n", DATA_CACHE_ROOT, strerror(errno)); return -1; } } } if (symlink(DATA_CACHE_ROOT, "/cache")) { if (errno != EEXIST) { LOGE("create symlink from %s to %s failed(%s)\n", DATA_CACHE_ROOT, "/cache", strerror(errno)); return -1; } } need_clear_cache = 0; } #endif return 0; }
int ensure_path_mounted_at_mount_point(const char* path, const char* mount_point) { if (is_data_media_volume_path(path)) { if (ui_should_log_stdout()) { LOGI("using /data/media for %s.\n", path); } int ret; if (0 != (ret = ensure_path_mounted("/data"))) return ret; setup_data_media(); return 0; } Volume* v = volume_for_path(path); if (v == NULL) { LOGE("unknown volume for path [%s]\n", path); return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted. return 0; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } if (NULL == mount_point) mount_point = v->mount_point; const MountedVolume* mv = find_mounted_volume_by_mount_point(mount_point); if (mv) { // volume is already mounted return 0; } mkdir(mount_point, 0755); // in case it doesn't already exist if (fs_mgr_is_voldmanaged(v)) { return vold_mount_volume(mount_point, 1) == CommandOkay ? 0 : -1; } else if (strcmp(v->fs_type, "yaffs2") == 0) { // mount an MTD partition as a YAFFS2 filesystem. mtd_scan_partitions(); const MtdPartition* partition; partition = mtd_find_partition_by_name(v->blk_device); if (partition == NULL) { LOGE("failed to find \"%s\" partition to mount at \"%s\"\n", v->blk_device, mount_point); return -1; } return mtd_mount_partition(partition, mount_point, v->fs_type, 0); } else if (strcmp(v->fs_type, "ext4") == 0 || strcmp(v->fs_type, "ext3") == 0 || strcmp(v->fs_type, "rfs") == 0 || strcmp(v->fs_type, "vfat") == 0) { if ((result = try_mount(v->blk_device, mount_point, v->fs_type, v->fs_options)) == 0) return 0; if ((result = try_mount(v->blk_device, mount_point, v->fs_type2, v->fs_options2)) == 0) return 0; if ((result = try_mount(v->blk_device2, mount_point, v->fs_type2, v->fs_options2)) == 0) return 0; return result; } else { // let's try mounting with the mount binary and hope for the best. char mount_cmd[PATH_MAX]; sprintf(mount_cmd, "mount %s", mount_point); return __system(mount_cmd); } return -1; }