Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 23214af7 authored by Amit Blay's avatar Amit Blay Committed by Linux Build Service Account
Browse files

Modified the mounting sequence in case that MDTP is activated.

If MDTP is activated, any mount point that requires encryption
would not be mounted to check if it is encrypted.

Change-Id: I1866273239fda95120ee0e82ff019646ff4a0bd2
parent 347a9e7a
Loading
Loading
Loading
Loading
+133 −72
Original line number Diff line number Diff line
@@ -492,6 +492,52 @@ static int handle_encryptable(struct fstab *fstab, const struct fstab_rec* rec)
    return FS_MGR_MNTALL_DEV_NOT_ENCRYPTED;
}

/*
 * Reads the kernel cmdline to check if MDTP is activated.
 * When MDTP is activated, kernel cmdline will have the word 'mdtp'.
 */
int fs_mgr_is_mdtp_activated()
{
      char cmdline[2048];
      char *ptr;
      int fd;
      static int mdtp_activated = 0;
      static int mdtp_activated_set = 0;

      if (mdtp_activated_set) {
          return mdtp_activated;
      }

      fd = open("/proc/cmdline", O_RDONLY);
      if (fd >= 0) {
          int n = read(fd, cmdline, sizeof(cmdline) - 1);
          if (n < 0) n = 0;

          /* get rid of trailing newline, it happens */
          if (n > 0 && cmdline[n-1] == '\n') n--;

          cmdline[n] = 0;
          close(fd);
      } else {
          cmdline[0] = 0;
      }

      ptr = cmdline;
      while (ptr && *ptr) {
          char *x = strchr(ptr, ' ');
          if (x != 0) *x++ = 0;
          if (!strcmp(ptr,"mdtp")) {
            mdtp_activated = 1;
            break;
          }
          ptr = x;
      }

      mdtp_activated_set = 1;

      return mdtp_activated;
}

/* When multiple fstab records share the same mount_point, it will
 * try to mount each one in turn, and ignore any duplicates after a
 * first successful mount.
@@ -547,6 +593,20 @@ int fs_mgr_mount_all(struct fstab *fstab)
                continue;
            }
        }

        if (fs_mgr_is_mdtp_activated() && ((fstab->recs[i].fs_mgr_flags & MF_FORCECRYPT) ||
            device_is_force_encrypted())) {
            INFO("%s(): mdtp activated, blkdev %s for mount %s type %s expected to be encrypted)\n",
                 __func__, fstab->recs[i].blk_device, fstab->recs[i].mount_point,
                 fstab->recs[i].fs_type);
            if (fs_mgr_do_tmpfs_mount(fstab->recs[i].mount_point) < 0) {
                ++error_count;
                continue;
            }

            encryptable = FS_MGR_MNTALL_DEV_MIGHT_BE_ENCRYPTED;

        } else {
            int last_idx_inspected;
            int top_idx = i;

@@ -634,6 +694,7 @@ int fs_mgr_mount_all(struct fstab *fstab)
                continue;
            }
        }
    }

    if (error_count) {
        return -1;
+1 −0
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ int fs_mgr_is_noemulatedsd(const struct fstab_rec *fstab);
int fs_mgr_is_notrim(struct fstab_rec *fstab);
int fs_mgr_is_formattable(struct fstab_rec *fstab);
int fs_mgr_swapon_all(struct fstab *fstab);
int fs_mgr_is_mdtp_activated(void);

int fs_mgr_do_format(struct fstab_rec *fstab);