Merge "fs_mgr: remount: add partition argument list"
This commit is contained in:
commit
4c46285e2e
2 changed files with 57 additions and 13 deletions
|
|
@ -42,13 +42,14 @@ namespace {
|
||||||
|
|
||||||
[[noreturn]] void usage(int exit_status) {
|
[[noreturn]] void usage(int exit_status) {
|
||||||
LOG(INFO) << getprogname()
|
LOG(INFO) << getprogname()
|
||||||
<< " [-h] [-R] [-T fstab_file]\n"
|
<< " [-h] [-R] [-T fstab_file] [partition]...\n"
|
||||||
"\t-h --help\tthis help\n"
|
"\t-h --help\tthis help\n"
|
||||||
"\t-R --reboot\tdisable verity & reboot to facilitate remount\n"
|
"\t-R --reboot\tdisable verity & reboot to facilitate remount\n"
|
||||||
"\t-T --fstab\tcustom fstab file location\n"
|
"\t-T --fstab\tcustom fstab file location\n"
|
||||||
|
"\tpartition\tspecific partition(s) (empty does all)\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Remount all partitions read-write.\n"
|
"Remount specified partition(s) read-write, by name or mount point.\n"
|
||||||
"-R notwithstanding, verity must be disabled.";
|
"-R notwithstanding, verity must be disabled on partition(s).";
|
||||||
|
|
||||||
::exit(exit_status);
|
::exit(exit_status);
|
||||||
}
|
}
|
||||||
|
|
@ -138,6 +139,8 @@ int main(int argc, char* argv[]) {
|
||||||
BADARG,
|
BADARG,
|
||||||
NOT_ROOT,
|
NOT_ROOT,
|
||||||
NO_FSTAB,
|
NO_FSTAB,
|
||||||
|
UNKNOWN_PARTITION,
|
||||||
|
INVALID_PARTITION,
|
||||||
VERITY_PARTITION,
|
VERITY_PARTITION,
|
||||||
BAD_OVERLAY,
|
BAD_OVERLAY,
|
||||||
NO_MOUNTS,
|
NO_MOUNTS,
|
||||||
|
|
@ -183,11 +186,6 @@ int main(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc > optind) {
|
|
||||||
LOG(ERROR) << "Bad Argument " << argv[optind];
|
|
||||||
usage(BADARG);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure we are root.
|
// Make sure we are root.
|
||||||
if (::getuid() != 0) {
|
if (::getuid() != 0) {
|
||||||
LOG(ERROR) << "must be run as root";
|
LOG(ERROR) << "must be run as root";
|
||||||
|
|
@ -211,16 +209,58 @@ int main(int argc, char* argv[]) {
|
||||||
auto overlayfs_candidates = fs_mgr_overlayfs_candidate_list(fstab);
|
auto overlayfs_candidates = fs_mgr_overlayfs_candidate_list(fstab);
|
||||||
|
|
||||||
// Generate the all remountable partitions sub-list
|
// Generate the all remountable partitions sub-list
|
||||||
android::fs_mgr::Fstab partitions;
|
android::fs_mgr::Fstab all;
|
||||||
for (auto const& entry : fstab) {
|
for (auto const& entry : fstab) {
|
||||||
if (!remountable_partition(entry)) continue;
|
if (!remountable_partition(entry)) continue;
|
||||||
if (overlayfs_candidates.empty() ||
|
if (overlayfs_candidates.empty() ||
|
||||||
GetEntryForMountPoint(&overlayfs_candidates, entry.mount_point) ||
|
GetEntryForMountPoint(&overlayfs_candidates, entry.mount_point) ||
|
||||||
(is_wrapped(overlayfs_candidates, entry) == nullptr)) {
|
(is_wrapped(overlayfs_candidates, entry) == nullptr)) {
|
||||||
partitions.emplace_back(entry);
|
all.emplace_back(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse the unique list of valid partition arguments.
|
||||||
|
android::fs_mgr::Fstab partitions;
|
||||||
|
for (; argc > optind; ++optind) {
|
||||||
|
auto partition = std::string(argv[optind]);
|
||||||
|
if (partition.empty()) continue;
|
||||||
|
if (partition == "/") partition = "/system";
|
||||||
|
auto find_part = [&partition](const auto& entry) {
|
||||||
|
const auto mount_point = system_mount_point(entry);
|
||||||
|
if (partition == mount_point) return true;
|
||||||
|
if (partition == android::base::Basename(mount_point)) return true;
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
// Do we know about the partition?
|
||||||
|
auto it = std::find_if(fstab.begin(), fstab.end(), find_part);
|
||||||
|
if (it == fstab.end()) {
|
||||||
|
LOG(ERROR) << "Unknown partition " << partition << ", skipping";
|
||||||
|
retval = UNKNOWN_PARTITION;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Is that one covered by an existing overlayfs?
|
||||||
|
auto wrap = is_wrapped(overlayfs_candidates, *it);
|
||||||
|
if (wrap) {
|
||||||
|
LOG(INFO) << "partition " << partition << " covered by overlayfs for "
|
||||||
|
<< wrap->mount_point << ", switching";
|
||||||
|
partition = system_mount_point(*wrap);
|
||||||
|
}
|
||||||
|
// Is it a remountable partition?
|
||||||
|
it = std::find_if(all.begin(), all.end(), find_part);
|
||||||
|
if (it == all.end()) {
|
||||||
|
LOG(ERROR) << "Invalid partition " << partition << ", skipping";
|
||||||
|
retval = INVALID_PARTITION;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (GetEntryForMountPoint(&partitions, it->mount_point) == nullptr) {
|
||||||
|
partitions.emplace_back(*it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (partitions.empty() && !retval) {
|
||||||
|
partitions = all;
|
||||||
|
}
|
||||||
|
|
||||||
// Check verity and optionally setup overlayfs backing.
|
// Check verity and optionally setup overlayfs backing.
|
||||||
auto reboot_later = false;
|
auto reboot_later = false;
|
||||||
for (auto it = partitions.begin(); it != partitions.end();) {
|
for (auto it = partitions.begin(); it != partitions.end();) {
|
||||||
|
|
|
||||||
|
|
@ -620,7 +620,7 @@ if [ "orange" = "`get_property ro.boot.verifiedbootstate`" -a \
|
||||||
|
|
||||||
echo "${GREEN}[ RUN ]${NORMAL} Testing adb shell su root remount -R command" >&2
|
echo "${GREEN}[ RUN ]${NORMAL} Testing adb shell su root remount -R command" >&2
|
||||||
|
|
||||||
adb_su remount -R </dev/null || true
|
adb_su remount -R system </dev/null || true
|
||||||
sleep 2
|
sleep 2
|
||||||
adb_wait 2m ||
|
adb_wait 2m ||
|
||||||
die "waiting for device after remount -R `usb_status`"
|
die "waiting for device after remount -R `usb_status`"
|
||||||
|
|
@ -1159,10 +1159,12 @@ adb_reboot &&
|
||||||
die "lost device after reboot to ro state (USB stack broken?)"
|
die "lost device after reboot to ro state (USB stack broken?)"
|
||||||
adb_sh grep " /vendor .* rw," /proc/mounts >/dev/null </dev/null &&
|
adb_sh grep " /vendor .* rw," /proc/mounts >/dev/null </dev/null &&
|
||||||
die "/vendor is not read-only"
|
die "/vendor is not read-only"
|
||||||
adb_su remount </dev/null ||
|
adb_su remount vendor </dev/null ||
|
||||||
die "remount command"
|
die "remount command"
|
||||||
adb_sh grep " /vendor .* rw," /proc/mounts >/dev/null </dev/null ||
|
adb_sh grep " /vendor .* rw," /proc/mounts >/dev/null </dev/null ||
|
||||||
die "/vendor is not read-write"
|
die "/vendor is not read-write"
|
||||||
|
adb_sh grep " /system .* rw," /proc/mounts >/dev/null </dev/null &&
|
||||||
|
die "/vendor is not read-only"
|
||||||
echo "${GREEN}[ OK ]${NORMAL} remount command works from setup" >&2
|
echo "${GREEN}[ OK ]${NORMAL} remount command works from setup" >&2
|
||||||
|
|
||||||
# Prerequisite is an overlayfs deconstructed device but with verity disabled.
|
# Prerequisite is an overlayfs deconstructed device but with verity disabled.
|
||||||
|
|
@ -1177,10 +1179,12 @@ adb_reboot &&
|
||||||
die "lost device after reboot after wipe (USB stack broken?)"
|
die "lost device after reboot after wipe (USB stack broken?)"
|
||||||
adb_sh grep " /vendor .* rw," /proc/mounts >/dev/null </dev/null &&
|
adb_sh grep " /vendor .* rw," /proc/mounts >/dev/null </dev/null &&
|
||||||
die "/vendor is not read-only"
|
die "/vendor is not read-only"
|
||||||
adb_su remount </dev/null ||
|
adb_su remount vendor </dev/null ||
|
||||||
die "remount command"
|
die "remount command"
|
||||||
adb_sh grep " /vendor .* rw," /proc/mounts >/dev/null </dev/null ||
|
adb_sh grep " /vendor .* rw," /proc/mounts >/dev/null </dev/null ||
|
||||||
die "/vendor is not read-write"
|
die "/vendor is not read-write"
|
||||||
|
adb_sh grep " /system .* rw," /proc/mounts >/dev/null </dev/null &&
|
||||||
|
die "/system is not read-only"
|
||||||
echo "${GREEN}[ OK ]${NORMAL} remount command works from scratch" >&2
|
echo "${GREEN}[ OK ]${NORMAL} remount command works from scratch" >&2
|
||||||
|
|
||||||
restore
|
restore
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue