Skip to content

Instantly share code, notes, and snippets.

@Tasssadar
Created September 17, 2013 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tasssadar/6595084 to your computer and use it in GitHub Desktop.
Save Tasssadar/6595084 to your computer and use it in GitHub Desktop.
This is how fstab looks like:
====================================
/boot emmc /dev/block/platform/msm_sdcc.1/by-name/boot
/recovery emmc /dev/block/platform/msm_sdcc.1/by-name/recovery
/misc emmc /dev/block/platform/msm_sdcc.1/by-name/misc
#/system ext4 /dev/block/platform/msm_sdcc.1/by-name/system
#/data ext4 /dev/block/platform/msm_sdcc.1/by-name/userdata
#/cache ext4 /dev/block/platform/msm_sdcc.1/by-name/cache
/sbl1 emmc /dev/block/platform/msm_sdcc.1/by-name/sbl1
/sbl2 emmc /dev/block/platform/msm_sdcc.1/by-name/sbl2
/sbl3 emmc /dev/block/platform/msm_sdcc.1/by-name/sbl3
/tz emmc /dev/block/platform/msm_sdcc.1/by-name/tz
/rpm emmc /dev/block/platform/msm_sdcc.1/by-name/rpm
/aboot emmc /dev/block/platform/msm_sdcc.1/by-name/aboot
/sbl2b emmc /dev/block/platform/msm_sdcc.1/by-name/sbl2b
/sbl3b emmc /dev/block/platform/msm_sdcc.1/by-name/sbl3b
/tzb emmc /dev/block/platform/msm_sdcc.1/by-name/tzb
/rpmb emmc /dev/block/platform/msm_sdcc.1/by-name/rpmb
/abootb emmc /dev/block/platform/msm_sdcc.1/by-name/abootb
/usb-otg vfat /dev/block/sda1 /dev/block/sda flags=removable;storage;display=USB-OTG
/realdata ext4 /dev/block/platform/msm_sdcc.1/by-name/userdata
/data ext4 /realdata/media/0/multirom/roms/test/data flags=bindof=/realdata
/cache ext4 /realdata/media/0/multirom/roms/test/cache flags=bindof=/realdata
/system ext4 /realdata/media/0/multirom/roms/test/system flags=bindof=/realdata
diff --git a/partition.cpp b/partition.cpp
index c1c99f6..b9b0acf 100644
--- a/partition.cpp
+++ b/partition.cpp
@@ -475,6 +475,10 @@ bool TWPartition::Process_Flags(string Flags, bool Display_Error) {
} else {
Use_Userdata_Encryption = false;
}
+ } else if (ptr_len > (int)sizeof("bindof=") && strncmp(ptr, "bindof=", sizeof("bindof=")-1) == 0) {
+ ptr += sizeof("bindof=")-1;
+ Bind_Of = ptr;
+ Ignore_Blkid = true;
} else {
if (Display_Error)
LOGERR("Unhandled flag: '%s'\n", ptr);
@@ -818,6 +822,32 @@ bool TWPartition::Mount(bool Display_Error) {
Find_Actual_Block_Device();
// Check the current file system before mounting
+ if(!Bind_Of.empty())
+ {
+ TWPartition *p = PartitionManager.Find_Partition_By_Path(Bind_Of);
+ if(!p)
+ {
+ if(Display_Error)
+ LOGERR("Couldn't find bindof partition %s\n", Bind_Of.c_str());
+ else
+ LOGINFO("Couldn't find bindof partition %s\n", Bind_Of.c_str());
+ return false;
+ }
+
+ if(!p->Mount(Display_Error))
+ return false;
+
+ if(mount(Actual_Block_Device.c_str(), Mount_Point.c_str(), Fstab_File_System.c_str(), MS_BIND, NULL) < 0)
+ {
+ if(Display_Error)
+ LOGERR("Couldn't bind %s to %s\n", Actual_Block_Device.c_str(), Mount_Point.c_str());
+ else
+ LOGINFO("Couldn't bind %s to %s\n", Actual_Block_Device.c_str(), Mount_Point.c_str());
+ return false;
+ }
+ return true;
+ }
+
Check_FS_Type();
if (Current_File_System == "exfat" && TWFunc::Path_Exists("/sbin/exfat-fuse")) {
string cmd = "/sbin/exfat-fuse -o big_writes,max_read=131072,max_write=131072 " + Actual_Block_Device + " " + Mount_Point;
diff --git a/partitionmanager.cpp b/partitionmanager.cpp
index ca93a2a..275a160 100644
--- a/partitionmanager.cpp
+++ b/partitionmanager.cpp
@@ -125,7 +125,10 @@ int TWPartitionManager::Write_Fstab(void) {
return false;
}
for (iter = Partitions.begin(); iter != Partitions.end(); iter++) {
- if ((*iter)->Can_Be_Mounted) {
+ if (!(*iter)->Bind_Of.empty()) {
+ Line = (*iter)->Actual_Block_Device + " " + (*iter)->Mount_Point + " bind bind\n";
+ fputs(Line.c_str(), fp);
+ } else if ((*iter)->Can_Be_Mounted) {
Line = (*iter)->Actual_Block_Device + " " + (*iter)->Mount_Point + " " + (*iter)->Current_File_System + " rw\n";
fputs(Line.c_str(), fp);
}
@@ -237,6 +240,8 @@ void TWPartitionManager::Output_Partition(TWPartition* Part) {
printf(" Format_Block_Size: %i\n", Part->Format_Block_Size);
if (!Part->MTD_Name.empty())
printf(" MTD_Name: %s\n", Part->MTD_Name.c_str());
+ if (!Part->Bind_Of.empty())
+ printf(" Bind_Of: %s\n", Part->Bind_Of.c_str());
string back_meth = Part->Backup_Method_By_Name();
printf(" Backup_Method: %s\n\n", back_meth.c_str());
}
diff --git a/partitions.hpp b/partitions.hpp
index b1af7f8..5e9c2ec 100644
--- a/partitions.hpp
+++ b/partitions.hpp
@@ -154,6 +154,7 @@ private:
#ifdef TW_INCLUDE_CRYPTO_SAMSUNG
string EcryptFS_Password; // Have to store the encryption password to remount
#endif
+ string Bind_Of;
friend class TWPartitionManager;
friend class DataManager;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment