Rewrite FS fstab flag processing
* If 'ro' fsflag detected, set Mount_Read_Only = true * Only output human readable Mount_Options to log * Match fsflags identically (not just first n chars) since there are no fs_flags which take arguments * Match new processing method introduced in TW fstab flag processing Change-Id: Iefdb76016be90a131b0d627d0cd3f18d2eb1a008
This commit is contained in:
+29
-26
@@ -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;
|
||||
|
||||
strlcpy(fs_options, Options.c_str(), sizeof(fs_options));
|
||||
Options = "";
|
||||
Mount_Options = "";
|
||||
|
||||
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;
|
||||
// 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;
|
||||
|
||||
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;
|
||||
}
|
||||
p = strtok_r(NULL, ",", &savep);
|
||||
}
|
||||
if (mount_flag->flag == MS_RDONLY)
|
||||
Mount_Read_Only = true;
|
||||
|
||||
return 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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -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");
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user