diff options
author | Tianjie Xu <xunchang@google.com> | 2020-07-06 21:23:45 +0000 |
---|---|---|
committer | Tianjie Xu <xunchang@google.com> | 2020-07-06 21:23:45 +0000 |
commit | 242e33af30f7aa74531d436e1609100aae3b4394 (patch) | |
tree | 048c16c3935bac60f150f676ad8f8d8493248ce1 /common/utils.cc | |
parent | 33d180914ef2cb9286595fb1fdcc3511c5fb1c34 (diff) | |
parent | 55abd3cbae6bd150b3534728a63befd1cadd6c5e (diff) |
Merge "Merge remote-tracking branch 'aosp/upstream-master' into merge"
Diffstat (limited to 'common/utils.cc')
-rw-r--r-- | common/utils.cc | 111 |
1 files changed, 5 insertions, 106 deletions
diff --git a/common/utils.cc b/common/utils.cc index fc89040c..3e3d8302 100644 --- a/common/utils.cc +++ b/common/utils.cc @@ -84,49 +84,6 @@ const int kGetFileFormatMaxHeaderSize = 32; // The path to the kernel's boot_id. const char kBootIdPath[] = "/proc/sys/kernel/random/boot_id"; -// Return true if |disk_name| is an MTD or a UBI device. Note that this test is -// simply based on the name of the device. -bool IsMtdDeviceName(const string& disk_name) { - return base::StartsWith( - disk_name, "/dev/ubi", base::CompareCase::SENSITIVE) || - base::StartsWith(disk_name, "/dev/mtd", base::CompareCase::SENSITIVE); -} - -// Return the device name for the corresponding partition on a NAND device. -// WARNING: This function returns device names that are not mountable. -string MakeNandPartitionName(int partition_num) { - switch (partition_num) { - case 2: - case 4: - case 6: { - return base::StringPrintf("/dev/mtd%d", partition_num); - } - default: { - return base::StringPrintf("/dev/ubi%d_0", partition_num); - } - } -} - -// Return the device name for the corresponding partition on a NAND device that -// may be mountable (but may not be writable). -string MakeNandPartitionNameForMount(int partition_num) { - switch (partition_num) { - case 2: - case 4: - case 6: { - return base::StringPrintf("/dev/mtd%d", partition_num); - } - case 3: - case 5: - case 7: { - return base::StringPrintf("/dev/ubiblock%d_0", partition_num); - } - default: { - return base::StringPrintf("/dev/ubi%d_0", partition_num); - } - } -} - // If |path| is absolute, or explicit relative to the current working directory, // leaves it as is. Otherwise, uses the system's temp directory, as defined by // base::GetTempDir() and prepends it to |path|. On success stores the full @@ -474,22 +431,6 @@ bool SplitPartitionName(const string& partition_name, return false; } - size_t partition_name_len = string::npos; - if (partition_name[last_nondigit_pos] == '_') { - // NAND block devices have weird naming which could be something - // like "/dev/ubiblock2_0". We discard "_0" in such a case. - size_t prev_nondigit_pos = - partition_name.find_last_not_of("0123456789", last_nondigit_pos - 1); - if (prev_nondigit_pos == string::npos || - (prev_nondigit_pos + 1) == last_nondigit_pos) { - LOG(ERROR) << "Unable to parse partition device name: " << partition_name; - return false; - } - - partition_name_len = last_nondigit_pos - prev_nondigit_pos; - last_nondigit_pos = prev_nondigit_pos; - } - if (out_disk_name) { // Special case for MMC devices which have the following naming scheme: // mmcblk0p2 @@ -502,8 +443,7 @@ bool SplitPartitionName(const string& partition_name, } if (out_partition_num) { - string partition_str = - partition_name.substr(last_nondigit_pos + 1, partition_name_len); + string partition_str = partition_name.substr(last_nondigit_pos + 1); *out_partition_num = atoi(partition_str.c_str()); } return true; @@ -520,13 +460,6 @@ string MakePartitionName(const string& disk_name, int partition_num) { return string(); } - if (IsMtdDeviceName(disk_name)) { - // Special case for UBI block devices. - // 1. ubiblock is not writable, we need to use plain "ubi". - // 2. There is a "_0" suffix. - return MakeNandPartitionName(partition_num); - } - string partition_name = disk_name; if (isdigit(partition_name.back())) { // Special case for devices with names ending with a digit. @@ -540,17 +473,6 @@ string MakePartitionName(const string& disk_name, int partition_num) { return partition_name; } -string MakePartitionNameForMount(const string& part_name) { - if (IsMtdDeviceName(part_name)) { - int partition_num; - if (!SplitPartitionName(part_name, nullptr, &partition_num)) { - return ""; - } - return MakeNandPartitionNameForMount(partition_num); - } - return part_name; -} - string ErrnoNumberAsString(int err) { char buf[100]; buf[0] = '\0'; @@ -567,33 +489,6 @@ bool IsSymlink(const char* path) { return lstat(path, &stbuf) == 0 && S_ISLNK(stbuf.st_mode) != 0; } -bool TryAttachingUbiVolume(int volume_num, int timeout) { - const string volume_path = base::StringPrintf("/dev/ubi%d_0", volume_num); - if (FileExists(volume_path.c_str())) { - return true; - } - - int exit_code; - vector<string> cmd = {"ubiattach", - "-m", - base::StringPrintf("%d", volume_num), - "-d", - base::StringPrintf("%d", volume_num)}; - TEST_AND_RETURN_FALSE(Subprocess::SynchronousExec(cmd, &exit_code, nullptr)); - TEST_AND_RETURN_FALSE(exit_code == 0); - - cmd = {"ubiblock", "--create", volume_path}; - TEST_AND_RETURN_FALSE(Subprocess::SynchronousExec(cmd, &exit_code, nullptr)); - TEST_AND_RETURN_FALSE(exit_code == 0); - - while (timeout > 0 && !FileExists(volume_path.c_str())) { - sleep(1); - timeout--; - } - - return FileExists(volume_path.c_str()); -} - bool MakeTempFile(const string& base_filename_template, string* filename, int* fd) { @@ -1083,6 +978,10 @@ string GetTimeAsString(time_t utime) { return str; } +string GetExclusionName(const string& str_to_convert) { + return base::NumberToString(base::StringPieceHash()(str_to_convert)); +} + } // namespace utils } // namespace chromeos_update_engine |