Linux: Use FS magic values in magic.h in file_util::GetFileSystemType().

Note: magic.h arrived in Linux 2.6.19 over 7 years ago. If this breaks
builds on very old distros, please switch to nfs_fs.h locally.

Review URL: https://codereview.chromium.org/147513003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@249340 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: f3228d1446e3461c38ec6baa278643bcc5368f9e
diff --git a/base/file_util_linux.cc b/base/file_util_linux.cc
index e4f0e28..d737b97 100644
--- a/base/file_util_linux.cc
+++ b/base/file_util_linux.cc
@@ -4,11 +4,12 @@
 
 #include "base/file_util.h"
 
-#include "base/files/file_path.h"
-
 #include <errno.h>
+#include <linux/magic.h>
 #include <sys/vfs.h>
 
+#include "base/files/file_path.h"
+
 namespace file_util {
 
 bool GetFileSystemType(const base::FilePath& path, FileSystemType* type) {
@@ -20,37 +21,36 @@
     return true;
   }
 
-  // While you would think the possible values of f_type would be available
-  // in a header somewhere, it appears that is not the case.  These values
-  // are copied from the statfs man page.
+  // Not all possible |statfs_buf.f_type| values are in linux/magic.h.
+  // Missing values are copied from the statfs man page.
   switch (statfs_buf.f_type) {
     case 0:
       *type = FILE_SYSTEM_0;
       break;
-    case 0xEF53:  // ext2, ext3.
-    case 0x4D44:  // dos
-    case 0x5346544E:  // NFTS
-    case 0x52654973:  // reiser
+    case EXT2_SUPER_MAGIC:  // Also ext3 and ext4
+    case MSDOS_SUPER_MAGIC:
+    case REISERFS_SUPER_MAGIC:
+    case BTRFS_SUPER_MAGIC:
+    case 0x5346544E:  // NTFS
     case 0x58465342:  // XFS
-    case 0x9123683E:  // btrfs
     case 0x3153464A:  // JFS
       *type = FILE_SYSTEM_ORDINARY;
       break;
-    case 0x6969:  // NFS
+    case NFS_SUPER_MAGIC:
       *type = FILE_SYSTEM_NFS;
       break;
+    case SMB_SUPER_MAGIC:
     case 0xFF534D42:  // CIFS
-    case 0x517B:  // SMB
       *type = FILE_SYSTEM_SMB;
       break;
-    case 0x73757245:  // Coda
+    case CODA_SUPER_MAGIC:
       *type = FILE_SYSTEM_CODA;
       break;
-    case 0x858458f6:  // ramfs
-    case 0x01021994:  // tmpfs
+    case HUGETLBFS_MAGIC:  // AKA ramfs
+    case TMPFS_MAGIC:
       *type = FILE_SYSTEM_MEMORY;
       break;
-    case 0x27e0eb: // CGROUP
+    case CGROUP_SUPER_MAGIC:
       *type = FILE_SYSTEM_CGROUP;
       break;
     default:
@@ -59,4 +59,4 @@
   return true;
 }
 
-}  // namespace
+}  // namespace file_util