summaryrefslogtreecommitdiffstats
path: root/partition.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--partition.cpp53
1 files changed, 28 insertions, 25 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;