Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(998)

Side by Side Diff: base/file_util_linux.cc

Issue 147513003: Linux: Use FS magic values in magic.h in file_util::GetFileSystemType(). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_util.h" 5 #include "base/file_util.h"
6 6
7 #include <errno.h>
8 #include <linux/magic.h>
9 #include <sys/vfs.h>
10
7 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
8 12
9 #include <errno.h>
10 #include <sys/vfs.h>
11
12 namespace file_util { 13 namespace file_util {
13 14
14 bool GetFileSystemType(const base::FilePath& path, FileSystemType* type) { 15 bool GetFileSystemType(const base::FilePath& path, FileSystemType* type) {
15 struct statfs statfs_buf; 16 struct statfs statfs_buf;
16 if (statfs(path.value().c_str(), &statfs_buf) < 0) { 17 if (statfs(path.value().c_str(), &statfs_buf) < 0) {
17 if (errno == ENOENT) 18 if (errno == ENOENT)
18 return false; 19 return false;
19 *type = FILE_SYSTEM_UNKNOWN; 20 *type = FILE_SYSTEM_UNKNOWN;
20 return true; 21 return true;
21 } 22 }
22 23
23 // While you would think the possible values of f_type would be available 24 // Not all possible |statfs_buf.f_type| values are in linux/magic.h.
24 // in a header somewhere, it appears that is not the case. These values 25 // Missing values are copied from the statfs man page.
25 // are copied from the statfs man page.
26 switch (statfs_buf.f_type) { 26 switch (statfs_buf.f_type) {
27 case 0: 27 case 0:
28 *type = FILE_SYSTEM_0; 28 *type = FILE_SYSTEM_0;
29 break; 29 break;
30 case 0xEF53: // ext2, ext3. 30 case EXT2_SUPER_MAGIC: // Also ext3 and ext4
31 case 0x4D44: // dos 31 case MSDOS_SUPER_MAGIC:
32 case 0x5346544E: // NFTS 32 case REISERFS_SUPER_MAGIC:
33 case 0x52654973: // reiser 33 case BTRFS_SUPER_MAGIC:
34 case 0x5346544E: // NTFS
34 case 0x58465342: // XFS 35 case 0x58465342: // XFS
35 case 0x9123683E: // btrfs
36 case 0x3153464A: // JFS 36 case 0x3153464A: // JFS
37 *type = FILE_SYSTEM_ORDINARY; 37 *type = FILE_SYSTEM_ORDINARY;
38 break; 38 break;
39 case 0x6969: // NFS 39 case NFS_SUPER_MAGIC:
40 *type = FILE_SYSTEM_NFS; 40 *type = FILE_SYSTEM_NFS;
41 break; 41 break;
42 case SMB_SUPER_MAGIC:
42 case 0xFF534D42: // CIFS 43 case 0xFF534D42: // CIFS
43 case 0x517B: // SMB
44 *type = FILE_SYSTEM_SMB; 44 *type = FILE_SYSTEM_SMB;
45 break; 45 break;
46 case 0x73757245: // Coda 46 case CODA_SUPER_MAGIC:
47 *type = FILE_SYSTEM_CODA; 47 *type = FILE_SYSTEM_CODA;
48 break; 48 break;
49 case 0x858458f6: // ramfs 49 case HUGETLBFS_MAGIC: // AKA ramfs
50 case 0x01021994: // tmpfs 50 case TMPFS_MAGIC:
51 *type = FILE_SYSTEM_MEMORY; 51 *type = FILE_SYSTEM_MEMORY;
52 break; 52 break;
53 case 0x27e0eb: // CGROUP 53 case CGROUP_SUPER_MAGIC:
54 *type = FILE_SYSTEM_CGROUP; 54 *type = FILE_SYSTEM_CGROUP;
55 break; 55 break;
56 default: 56 default:
57 *type = FILE_SYSTEM_OTHER; 57 *type = FILE_SYSTEM_OTHER;
58 } 58 }
59 return true; 59 return true;
60 } 60 }
61 61
62 } // namespace 62 } // namespace file_util
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698