summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--partition.cpp53
-rw-r--r--partitionmanager.cpp2
-rw-r--r--partitions.hpp2
3 files changed, 30 insertions, 27 deletions
diff --git a/partition.cpp b/partition.cpp
index 07d717154..bdc8dcb59 100644
--- a/partition.cpp
+++ b/partition.cpp
@@ -82,7 +82,7 @@ struct flag_list {
unsigned flag;
};
-static struct flag_list mount_flags[] = {
+const struct flag_list mount_flags[] = {
{ "noatime", MS_NOATIME },
{ "noexec", MS_NOEXEC },
{ "nosuid", MS_NOSUID },
@@ -512,36 +512,40 @@ bool TWPartition::Process_Fstab_Line(string Line, bool Display_Error) {
return true;
}
-bool TWPartition::Process_FS_Flags(string& Options, int& Flags) {
- int i;
- char *p;
- char *savep;
- char fs_options[250];
+void TWPartition::Process_FS_Flags(const char *str) {
+ char *options = strdup(str);
+ char *ptr, *savep;
+
+ Mount_Options = "";
- strlcpy(fs_options, Options.c_str(), sizeof(fs_options));
- Options = "";
+ // Avoid issues with potentially nested strtok by using strtok_r
+ ptr = strtok_r(options, ",", &savep);
+ while (ptr) {
+ const struct flag_list* mount_flag = mount_flags;
- p = strtok_r(fs_options, ",", &savep);
- while (p) {
- /* Look for the flag "p" in the flag list "fl"
- * If not found, the loop exits with fl[i].name being null.
- */
- for (i = 0; mount_flags[i].name; i++) {
- if (strncmp(p, mount_flags[i].name, strlen(mount_flags[i].name)) == 0) {
- Flags |= mount_flags[i].flag;
+ for (; mount_flag->name; mount_flag++) {
+ // mount_flags are never postfixed by '=',
+ // so only match identical strings (including length)
+ if (strcmp(ptr, mount_flag->name) == 0) {
+ Mount_Flags |= mount_flag->flag;
break;
}
}
- if (!mount_flags[i].name) {
- if (Options.size() > 0)
- Options += ",";
- Options += p;
+ if (mount_flag->flag == MS_RDONLY)
+ Mount_Read_Only = true;
+
+ if (mount_flag->name != 0) {
+ if (!Mount_Options.empty())
+ Mount_Options += ",";
+ Mount_Options += mount_flag->name;
+ } else {
+ LOGINFO("Unhandled mount flag: '%s'\n", ptr);
}
- p = strtok_r(NULL, ",", &savep);
- }
- return true;
+ ptr = strtok_r(NULL, ",", &savep);
+ }
+ free(options);
}
void TWPartition::Apply_TW_Flag(const unsigned flag, const char* str, const bool val) {
@@ -578,8 +582,7 @@ void TWPartition::Apply_TW_Flag(const unsigned flag, const char* str, const bool
Can_Flash_Img = val;
break;
case TWFLAG_FSFLAGS:
- Mount_Options = str;
- Process_FS_Flags(Mount_Options, Mount_Flags);
+ Process_FS_Flags(str);
break;
case TWFLAG_IGNOREBLKID:
Ignore_Blkid = val;
diff --git a/partitionmanager.cpp b/partitionmanager.cpp
index c2ef5f563..95d2520b3 100644
--- a/partitionmanager.cpp
+++ b/partitionmanager.cpp
@@ -326,7 +326,7 @@ void TWPartitionManager::Output_Partition(TWPartition* Part) {
string back_meth = Part->Backup_Method_By_Name();
printf(" Backup_Method: %s\n", back_meth.c_str());
if (Part->Mount_Flags || !Part->Mount_Options.empty())
- printf(" Mount_Flags=0x%8x, Mount_Options=%s\n", Part->Mount_Flags, Part->Mount_Options.c_str());
+ printf(" Mount_Options: %s\n", Part->Mount_Options.c_str());
if (Part->MTP_Storage_ID)
printf(" MTP_Storage_ID: %i\n", Part->MTP_Storage_ID);
printf("\n");
diff --git a/partitions.hpp b/partitions.hpp
index 91c803698..aafc4d4b8 100644
--- a/partitions.hpp
+++ b/partitions.hpp
@@ -100,7 +100,7 @@ private:
void Apply_TW_Flag(const unsigned flag, const char* str, const bool val); // Apply custom twrp fstab flags
void Process_TW_Flags(char *flags, bool Display_Error); // Process custom twrp fstab flags
- bool Process_FS_Flags(string& Options, int& Flags); // Process standard fstab fs flags
+ void Process_FS_Flags(const char *str); // Process standard fstab fs flags
bool Is_File_System(string File_System); // Checks to see if the file system given is considered a file system
bool Is_Image(string File_System); // Checks to see if the file system given is considered an image
void Setup_File_System(bool Display_Error); // Sets defaults for a file system partition