Merge "vold: Add nvme disk support"
diff --git a/Disk.cpp b/Disk.cpp
index 2f6ed5e..3901526 100644
--- a/Disk.cpp
+++ b/Disk.cpp
@@ -73,6 +73,8 @@
 static const unsigned int kMajorBlockMmc = 179;
 static const unsigned int kMajorBlockExperimentalMin = 240;
 static const unsigned int kMajorBlockExperimentalMax = 254;
+static const unsigned int kMajorBlockDynamicMin = 234;
+static const unsigned int kMajorBlockDynamicMax = 512;
 
 static const char* kGptBasicData = "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7";
 static const char* kGptAndroidMeta = "19A710A2-B3CA-11E4-B026-10604B889DCF";
@@ -111,6 +113,12 @@
             && major <= kMajorBlockExperimentalMax;
 }
 
+static bool isNvmeBlkDevice(unsigned int major, const std::string& sysPath) {
+    return sysPath.find("nvme") != std::string::npos
+            && major >= kMajorBlockDynamicMin
+            && major <= kMajorBlockDynamicMax;
+}
+
 Disk::Disk(const std::string& eventPath, dev_t device,
         const std::string& nickname, int flags) :
         mDevice(device), mSize(-1), mNickname(nickname), mFlags(flags), mCreated(
@@ -277,6 +285,16 @@
             mLabel = "Virtual";
             break;
         }
+        if (isNvmeBlkDevice(majorId, mSysPath)) {
+            std::string path(mSysPath + "/device/model");
+            std::string tmp;
+            if (!ReadFileToString(path, &tmp)) {
+                PLOG(WARNING) << "Failed to read vendor from " << path;
+                return -errno;
+            }
+            mLabel = tmp;
+            break;
+        }
         LOG(WARNING) << "Unsupported block major type " << majorId;
         return -ENOTSUP;
     }
@@ -580,6 +598,13 @@
             // 2^4 - 1 = 15
             return 15;
         }
+        if (isNvmeBlkDevice(majorId, mSysPath)) {
+            // despite kernel nvme driver supports up to 1M minors,
+            //     #define NVME_MINORS (1U << MINORBITS)
+            // sgdisk can not support more than 127 partitions, due to
+            //     #define MAX_MBR_PARTS 128
+            return 127;
+        }
     }
     }