summaryrefslogtreecommitdiffstats
path: root/roots.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'roots.cpp')
-rw-r--r--roots.cpp50
1 files changed, 24 insertions, 26 deletions
diff --git a/roots.cpp b/roots.cpp
index 167499e2c..f361cb8ca 100644
--- a/roots.cpp
+++ b/roots.cpp
@@ -24,18 +24,14 @@
#include <ctype.h>
#include <fcntl.h>
-extern "C" {
#include <fs_mgr.h>
#include "mtdutils/mtdutils.h"
#include "mtdutils/mounts.h"
-}
#include "roots.h"
#include "common.h"
#include "make_ext4fs.h"
-extern "C" {
#include "wipe.h"
#include "cryptfs.h"
-}
static struct fstab *fstab = NULL;
@@ -74,11 +70,8 @@ Volume* volume_for_path(const char* path) {
return fs_mgr_get_entry_for_mount_point(fstab, path);
}
-int ensure_path_mounted(const char* path) {
- if (PartitionManager.Mount_By_Path(path, true))
- return 0;
- else
- 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);
@@ -96,14 +89,18 @@ int ensure_path_mounted(const char* path) {
return -1;
}
+ if (!mount_point) {
+ mount_point = v->mount_point;
+ }
+
const MountedVolume* mv =
- find_mounted_volume_by_mount_point(v->mount_point);
+ find_mounted_volume_by_mount_point(mount_point);
if (mv) {
// volume is already mounted
return 0;
}
- mkdir(v->mount_point, 0755); // in case it doesn't already exist
+ 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.
@@ -112,30 +109,31 @@ int ensure_path_mounted(const char* path) {
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);
+ v->blk_device, mount_point);
return -1;
}
- return mtd_mount_partition(partition, v->mount_point, v->fs_type, 0);
+ 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, v->mount_point, v->fs_type,
+ 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", v->mount_point, strerror(errno));
+ LOGE("failed to mount %s (%s)\n", mount_point, strerror(errno));
return -1;
}
- LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, v->mount_point);
+ LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, mount_point);
return -1;
}
+int ensure_path_mounted(const char* path) {
+ // Mount at the default mount point.
+ return ensure_path_mounted_at(path, nullptr);
+}
+
int ensure_path_unmounted(const char* path) {
- if (PartitionManager.UnMount_By_Path(path, true))
- return 0;
- else
- return -1;
Volume* v = volume_for_path(path);
if (v == NULL) {
LOGE("unknown volume for path [%s]\n", path);
@@ -177,11 +175,7 @@ static int exec_cmd(const char* path, char* const argv[]) {
return WEXITSTATUS(status);
}
-int format_volume(const char* volume) {
- if (PartitionManager.Wipe_By_Path(volume))
- return 0;
- else
- return -1;
+int format_volume(const char* volume, const char* directory) {
Volume* v = volume_for_path(volume);
if (v == NULL) {
LOGE("unknown volume \"%s\"\n", volume);
@@ -247,7 +241,7 @@ int format_volume(const char* volume) {
}
int result;
if (strcmp(v->fs_type, "ext4") == 0) {
- result = make_ext4fs(v->blk_device, length, volume, sehandle);
+ result = make_ext4fs_directory(v->blk_device, length, volume, sehandle, directory);
} else { /* Has to be f2fs because we checked earlier. */
if (v->key_loc != NULL && strcmp(v->key_loc, "footer") == 0 && length < 0) {
LOGE("format_volume: crypt footer + negative length (%zd) not supported on %s\n", length, v->fs_type);
@@ -279,6 +273,10 @@ int format_volume(const char* volume) {
return -1;
}
+int format_volume(const char* volume) {
+ return format_volume(volume, NULL);
+}
+
int setup_install_mounts() {
if (fstab == NULL) {
LOGE("can't set up install mounts: no fstab loaded\n");