OSDN Git Service

Last ditch check for partition on raw disk.
authorJeff Sharkey <jsharkey@android.com>
Fri, 26 Jun 2015 18:16:14 +0000 (11:16 -0700)
committerJeff Sharkey <jsharkey@android.com>
Fri, 26 Jun 2015 18:16:17 +0000 (11:16 -0700)
Some storage devices can be formatted as bare partitions, without an
MBR or GPT header.  If we found no partitions, try poking at the raw
disk, and treat it as a public volume if we found a valid filesystem.

Bug: 20503551
Change-Id: I80304e1ad865435321c341b667c0daf2daf4d56c

Disk.cpp

index c680a43..df53d07 100644 (file)
--- a/Disk.cpp
+++ b/Disk.cpp
@@ -36,8 +36,6 @@
 #include <sys/stat.h>
 #include <sys/mount.h>
 
-#define ENTIRE_DEVICE_FALLBACK 0
-
 using android::base::ReadFileToString;
 using android::base::WriteStringToFile;
 using android::base::StringPrintf;
@@ -306,14 +304,18 @@ status_t Disk::readPartitions() {
         }
     }
 
-#if ENTIRE_DEVICE_FALLBACK
     // Ugly last ditch effort, treat entire disk as partition
     if (table == Table::kUnknown || !foundParts) {
-        // TODO: use blkid to confirm filesystem before doing this
         LOG(WARNING) << mId << " has unknown partition table; trying entire device";
-        createPublicVolume(mDevice);
+
+        std::string fsType;
+        std::string unused;
+        if (ReadMetadataUntrusted(mDevPath, fsType, unused, unused) == OK) {
+            createPublicVolume(mDevice);
+        } else {
+            LOG(WARNING) << mId << " failed to identify, giving up";
+        }
     }
-#endif
 
     notifyEvent(ResponseCode::DiskScanned);
     mJustPartitioned = false;