From 8e337f36052469040d20d3322599cc4e25391480 Mon Sep 17 00:00:00 2001 From: Dees_Troy Date: Sat, 13 Oct 2012 22:07:49 -0400 Subject: Handle storage devices that are slow to mount --- partition.cpp | 15 +++++++++++++++ partitions.hpp | 1 + 2 files changed, 16 insertions(+) diff --git a/partition.cpp b/partition.cpp index 505e310c5..a7adf9984 100644 --- a/partition.cpp +++ b/partition.cpp @@ -249,6 +249,7 @@ bool TWPartition::Process_Fstab_Line(string Line, bool Display_Error) { Removable = true; #ifndef RECOVERY_SDCARD_ON_DATA Setup_AndSec(); + Mount_Storage_Retry(); #endif } #endif @@ -258,6 +259,7 @@ bool TWPartition::Process_Fstab_Line(string Line, bool Display_Error) { Storage_Path = EXPAND(TW_INTERNAL_STORAGE_PATH); #ifndef RECOVERY_SDCARD_ON_DATA Setup_AndSec(); + Mount_Storage_Retry(); #endif } #else @@ -266,6 +268,7 @@ bool TWPartition::Process_Fstab_Line(string Line, bool Display_Error) { Storage_Path = "/emmc"; #ifndef RECOVERY_SDCARD_ON_DATA Setup_AndSec(); + Mount_Storage_Retry(); #endif } #endif @@ -444,6 +447,18 @@ void TWPartition::Find_Real_Block_Device(string& Block, bool Display_Error) { } } +void TWPartition::Mount_Storage_Retry(void) { + // On some devices, storage doesn't want to mount right away, retry and sleep + if (!Mount(false)) { + int retry_count = 5; + while (retry_count > 0 && !Mount(false)) { + usleep(500000); + retry_count--; + } + Mount(true); + } +} + bool TWPartition::Find_MTD_Block_Device(string MTD_Name) { FILE *fp = NULL; char line[255]; diff --git a/partitions.hpp b/partitions.hpp index 3417b8c41..30d55119b 100644 --- a/partitions.hpp +++ b/partitions.hpp @@ -133,6 +133,7 @@ private: bool Make_Dir(string Path, bool Display_Error); // Creates a directory if it doesn't already exist bool Find_MTD_Block_Device(string MTD_Name); // Finds the mtd block device based on the name from the fstab void Recreate_AndSec_Folder(void); // Recreates the .android_secure folder + void Mount_Storage_Retry(void); // Tries multiple times with a half second delay to mount a device in case storage is slow to mount friend class TWPartitionManager; }; -- cgit v1.2.3