summaryrefslogtreecommitdiff
path: root/install/fuse_install.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'install/fuse_install.cpp')
-rw-r--r--install/fuse_install.cpp80
1 files changed, 78 insertions, 2 deletions
diff --git a/install/fuse_install.cpp b/install/fuse_install.cpp
index 143b5d3f..91d5d1bd 100644
--- a/install/fuse_install.cpp
+++ b/install/fuse_install.cpp
@@ -30,8 +30,10 @@
#include <string>
#include <vector>
+#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/strings.h>
+#include <cutils/properties.h>
#include "bootloader_message/bootloader_message.h"
#include "fuse_provider.h"
@@ -39,6 +41,11 @@
#include "install/install.h"
#include "recovery_utils/roots.h"
+#define MMC_0_TYPE_PATH "/sys/block/mmcblk0/device/type"
+#define SDCARD_BLK_0_PATH "/dev/block/mmcblk0p1"
+#define MMC_1_TYPE_PATH "/sys/block/mmcblk1/device/type"
+#define SDCARD_BLK_1_PATH "/dev/block/mmcblk1p1"
+
static constexpr const char* SDCARD_ROOT = "/sdcard";
// How long (in seconds) we wait for the fuse-provided package file to
// appear, before timing out.
@@ -204,10 +211,79 @@ InstallResult InstallWithFuseFromPath(std::string_view path, RecoveryUI* ui) {
return result;
}
+// Check whether the mmc type of provided path (/sys/block/mmcblk*/device/type)
+// is SD (sdcard) or not.
+static int check_mmc_is_sdcard (const char* mmc_type_path)
+{
+ std::string mmc_type;
+
+ LOG(INFO) << "Checking mmc type for path : " << mmc_type_path;
+
+ if (!android::base::ReadFileToString(mmc_type_path, &mmc_type)) {
+ LOG(ERROR) << "Failed to read mmc type : " << strerror(errno);
+ return -1;
+ }
+ LOG(INFO) << "MMC type is : " << mmc_type.c_str();
+ if (!strncmp(mmc_type.c_str(), "SD", strlen("SD")))
+ return 0;
+ else
+ return -1;
+}
+
+// Gather mount point and other info from fstab, find the right block
+// path where sdcard is mounted, and try mounting it.
+static int do_sdcard_mount() {
+ int rc = 0;
+
+ Volume *v = volume_for_mount_point("/sdcard");
+ if (v == nullptr) {
+ LOG(ERROR) << "Unknown volume for /sdcard. Check fstab\n";
+ goto error;
+ }
+ if (strncmp(v->fs_type.c_str(), "vfat", sizeof("vfat"))) {
+ LOG(ERROR) << "Unsupported format on the sdcard: "
+ << v->fs_type.c_str() << "\n";
+ goto error;
+ }
+
+ if (check_mmc_is_sdcard(MMC_0_TYPE_PATH) == 0) {
+ LOG(INFO) << "Mounting sdcard on " << SDCARD_BLK_0_PATH;
+ rc = mount(SDCARD_BLK_0_PATH,
+ v->mount_point.c_str(),
+ v->fs_type.c_str(),
+ v->flags,
+ v->fs_options.c_str());
+ }
+ else if (check_mmc_is_sdcard(MMC_1_TYPE_PATH) == 0) {
+ LOG(INFO) << "Mounting sdcard on " << SDCARD_BLK_1_PATH;
+ rc = mount(SDCARD_BLK_1_PATH,
+ v->mount_point.c_str(),
+ v->fs_type.c_str(),
+ v->flags,
+ v->fs_options.c_str());
+ }
+ else {
+ LOG(ERROR) << "Unable to get the block path for sdcard.";
+ goto error;
+ }
+
+ if (rc) {
+ LOG(ERROR) << "Failed to mount sdcard: " << strerror(errno) << "\n";
+ goto error;
+ }
+ LOG(INFO) << "Done mounting sdcard\n";
+ return 0;
+
+error:
+ return -1;
+}
+
InstallResult ApplyFromSdcard(Device* device) {
auto ui = device->GetUI();
- if (ensure_path_mounted(SDCARD_ROOT) != 0) {
- LOG(ERROR) << "\n-- Couldn't mount " << SDCARD_ROOT << ".\n";
+ ui->Print("Update via sdcard. Mounting sdcard\n");
+
+ if (do_sdcard_mount() != 0) {
+ LOG(ERROR) << "\nFailed to mount sdcard\n";
return INSTALL_ERROR;
}