system/vold
Revision | 1a6fe4a008591c35c476c4f95ff18532341fb8a9 (tree) |
---|---|
Time | 2019-12-17 14:19:56 |
Author | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
Move kMajor* constants to a header file
Currently each cpp defines its own kMajor* that can't be shared.
Move the kMajor* to a header to avoid duplicate definitions.
Change isVirtioBlkDevice() to be a public static method of Disk
so that the logic could be shared as well.
@@ -94,10 +94,6 @@ static const std::string kEmptyString(""); | ||
94 | 94 | /* 512MiB is large enough for testing purposes */ |
95 | 95 | static const unsigned int kSizeVirtualDisk = 536870912; |
96 | 96 | |
97 | -static const unsigned int kMajorBlockMmc = 179; | |
98 | -static const unsigned int kMajorBlockExperimentalMin = 240; | |
99 | -static const unsigned int kMajorBlockExperimentalMax = 254; | |
100 | - | |
101 | 97 | VolumeManager* VolumeManager::sInstance = NULL; |
102 | 98 | |
103 | 99 | VolumeManager* VolumeManager::Instance() { |
@@ -218,9 +214,8 @@ void VolumeManager::handleBlockEvent(NetlinkEvent* evt) { | ||
218 | 214 | // emulator-specific; see Disk.cpp for details) devices are SD, |
219 | 215 | // and that everything else is USB |
220 | 216 | int flags = source->getFlags(); |
221 | - if (major == kMajorBlockMmc || (android::vold::IsRunningInEmulator() && | |
222 | - major >= (int)kMajorBlockExperimentalMin && | |
223 | - major <= (int)kMajorBlockExperimentalMax)) { | |
217 | + if (major == android::vold::Disk::kMajorBlockMmc || | |
218 | + android::vold::Disk::isVirtioBlkDevice(major)) { | |
224 | 219 | flags |= android::vold::Disk::Flags::kSd; |
225 | 220 | } else { |
226 | 221 | flags |= android::vold::Disk::Flags::kUsb; |
@@ -56,29 +56,6 @@ static const char* kSysfsLoopMaxMinors = "/sys/module/loop/parameters/max_part"; | ||
56 | 56 | static const char* kSysfsMmcMaxMinorsDeprecated = "/sys/module/mmcblk/parameters/perdev_minors"; |
57 | 57 | static const char* kSysfsMmcMaxMinors = "/sys/module/mmc_block/parameters/perdev_minors"; |
58 | 58 | |
59 | -static const unsigned int kMajorBlockLoop = 7; | |
60 | -static const unsigned int kMajorBlockScsiA = 8; | |
61 | -static const unsigned int kMajorBlockScsiB = 65; | |
62 | -static const unsigned int kMajorBlockScsiC = 66; | |
63 | -static const unsigned int kMajorBlockScsiD = 67; | |
64 | -static const unsigned int kMajorBlockScsiE = 68; | |
65 | -static const unsigned int kMajorBlockScsiF = 69; | |
66 | -static const unsigned int kMajorBlockScsiG = 70; | |
67 | -static const unsigned int kMajorBlockScsiH = 71; | |
68 | -static const unsigned int kMajorBlockScsiI = 128; | |
69 | -static const unsigned int kMajorBlockScsiJ = 129; | |
70 | -static const unsigned int kMajorBlockScsiK = 130; | |
71 | -static const unsigned int kMajorBlockScsiL = 131; | |
72 | -static const unsigned int kMajorBlockScsiM = 132; | |
73 | -static const unsigned int kMajorBlockScsiN = 133; | |
74 | -static const unsigned int kMajorBlockScsiO = 134; | |
75 | -static const unsigned int kMajorBlockScsiP = 135; | |
76 | -static const unsigned int kMajorBlockMmc = 179; | |
77 | -static const unsigned int kMajorBlockExperimentalMin = 240; | |
78 | -static const unsigned int kMajorBlockExperimentalMax = 254; | |
79 | -static const unsigned int kMajorBlockDynamicMin = 234; | |
80 | -static const unsigned int kMajorBlockDynamicMax = 512; | |
81 | - | |
82 | 59 | static const char* kGptBasicData = "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7"; |
83 | 60 | static const char* kGptAndroidMeta = "19A710A2-B3CA-11E4-B026-10604B889DCF"; |
84 | 61 | static const char* kGptAndroidExpand = "193D1EA4-B3CA-11E4-B075-10604B889DCF"; |
@@ -89,7 +66,7 @@ enum class Table { | ||
89 | 66 | kGpt, |
90 | 67 | }; |
91 | 68 | |
92 | -static bool isVirtioBlkDevice(unsigned int major) { | |
69 | +bool Disk::isVirtioBlkDevice(unsigned int major) { | |
93 | 70 | /* |
94 | 71 | * The new emulator's "ranchu" virtual board no longer includes a goldfish |
95 | 72 | * MMC-based SD card device; instead, it emulates SD cards with virtio-blk, |
@@ -117,8 +94,8 @@ static bool isVirtioBlkDevice(unsigned int major) { | ||
117 | 94 | } |
118 | 95 | |
119 | 96 | static bool isNvmeBlkDevice(unsigned int major, const std::string& sysPath) { |
120 | - return sysPath.find("nvme") != std::string::npos && major >= kMajorBlockDynamicMin && | |
121 | - major <= kMajorBlockDynamicMax; | |
97 | + return sysPath.find("nvme") != std::string::npos && major >= Disk::kMajorBlockDynamicMin && | |
98 | + major <= Disk::kMajorBlockDynamicMax; | |
122 | 99 | } |
123 | 100 | |
124 | 101 | Disk::Disk(const std::string& eventPath, dev_t device, const std::string& nickname, int flags) |
@@ -40,6 +40,31 @@ class Disk { | ||
40 | 40 | Disk(const std::string& eventPath, dev_t device, const std::string& nickname, int flags); |
41 | 41 | virtual ~Disk(); |
42 | 42 | |
43 | + enum { | |
44 | + kMajorBlockLoop = 7, | |
45 | + kMajorBlockScsiA = 8, | |
46 | + kMajorBlockScsiB = 65, | |
47 | + kMajorBlockScsiC = 66, | |
48 | + kMajorBlockScsiD = 67, | |
49 | + kMajorBlockScsiE = 68, | |
50 | + kMajorBlockScsiF = 69, | |
51 | + kMajorBlockScsiG = 70, | |
52 | + kMajorBlockScsiH = 71, | |
53 | + kMajorBlockScsiI = 128, | |
54 | + kMajorBlockScsiJ = 129, | |
55 | + kMajorBlockScsiK = 130, | |
56 | + kMajorBlockScsiL = 131, | |
57 | + kMajorBlockScsiM = 132, | |
58 | + kMajorBlockScsiN = 133, | |
59 | + kMajorBlockScsiO = 134, | |
60 | + kMajorBlockScsiP = 135, | |
61 | + kMajorBlockMmc = 179, | |
62 | + kMajorBlockExperimentalMin = 240, | |
63 | + kMajorBlockExperimentalMax = 254, | |
64 | + kMajorBlockDynamicMin = 234, | |
65 | + kMajorBlockDynamicMax = 512, | |
66 | + }; | |
67 | + | |
43 | 68 | enum Flags { |
44 | 69 | /* Flag that disk is adoptable */ |
45 | 70 | kAdoptable = 1 << 0, |
@@ -81,6 +106,8 @@ class Disk { | ||
81 | 106 | virtual status_t partitionPrivate(); |
82 | 107 | virtual status_t partitionMixed(int8_t ratio); |
83 | 108 | |
109 | + static bool isVirtioBlkDevice(unsigned int major); | |
110 | + | |
84 | 111 | protected: |
85 | 112 | /* ID that uniquely references this disk */ |
86 | 113 | std::string mId; |
@@ -41,8 +41,6 @@ using android::base::StringPrintf; | ||
41 | 41 | namespace android { |
42 | 42 | namespace vold { |
43 | 43 | |
44 | -static const unsigned int kMajorBlockMmc = 179; | |
45 | - | |
46 | 44 | PrivateVolume::PrivateVolume(dev_t device, const std::string& keyRaw) |
47 | 45 | : VolumeBase(Type::kPrivate), mRawDevice(device), mKeyRaw(keyRaw) { |
48 | 46 | setId(StringPrintf("private:%u,%u", major(device), minor(device))); |
@@ -180,7 +178,7 @@ status_t PrivateVolume::doFormat(const std::string& fsType) { | ||
180 | 178 | if (fsType == "auto") { |
181 | 179 | // For now, assume that all MMC devices are flash-based SD cards, and |
182 | 180 | // give everyone else ext4 because sysfs rotational isn't reliable. |
183 | - if ((major(mRawDevice) == kMajorBlockMmc) && f2fs::IsSupported()) { | |
181 | + if ((major(mRawDevice) == Disk::kMajorBlockMmc) && f2fs::IsSupported()) { | |
184 | 182 | resolvedFsType = "f2fs"; |
185 | 183 | } else { |
186 | 184 | resolvedFsType = "ext4"; |