OLD | NEW |
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/files/file_util.h" | 5 #include "base/files/file_util.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <linux/magic.h> | 8 #include <linux/magic.h> |
| 9 #include <stdint.h> |
9 #include <sys/vfs.h> | 10 #include <sys/vfs.h> |
10 | 11 |
11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
12 | 13 |
13 namespace base { | 14 namespace base { |
14 | 15 |
15 bool GetFileSystemType(const FilePath& path, FileSystemType* type) { | 16 bool GetFileSystemType(const FilePath& path, FileSystemType* type) { |
16 struct statfs statfs_buf; | 17 struct statfs statfs_buf; |
17 if (statfs(path.value().c_str(), &statfs_buf) < 0) { | 18 if (statfs(path.value().c_str(), &statfs_buf) < 0) { |
18 if (errno == ENOENT) | 19 if (errno == ENOENT) |
19 return false; | 20 return false; |
20 *type = FILE_SYSTEM_UNKNOWN; | 21 *type = FILE_SYSTEM_UNKNOWN; |
21 return true; | 22 return true; |
22 } | 23 } |
23 | 24 |
24 // Not all possible |statfs_buf.f_type| values are in linux/magic.h. | 25 // Not all possible |statfs_buf.f_type| values are in linux/magic.h. |
25 // Missing values are copied from the statfs man page. | 26 // Missing values are copied from the statfs man page. |
26 switch (statfs_buf.f_type) { | 27 // In some platforms, |statfs_buf.f_type| is declared as signed, but some of |
| 28 // the values will overflow it, causing narrowing warnings. Cast to the |
| 29 // largest possible unsigned integer type to avoid it. |
| 30 switch (static_cast<uintmax_t>(statfs_buf.f_type)) { |
27 case 0: | 31 case 0: |
28 *type = FILE_SYSTEM_0; | 32 *type = FILE_SYSTEM_0; |
29 break; | 33 break; |
30 case EXT2_SUPER_MAGIC: // Also ext3 and ext4 | 34 case EXT2_SUPER_MAGIC: // Also ext3 and ext4 |
31 case MSDOS_SUPER_MAGIC: | 35 case MSDOS_SUPER_MAGIC: |
32 case REISERFS_SUPER_MAGIC: | 36 case REISERFS_SUPER_MAGIC: |
33 case BTRFS_SUPER_MAGIC: | 37 case BTRFS_SUPER_MAGIC: |
34 case 0x5346544E: // NTFS | 38 case 0x5346544E: // NTFS |
35 case 0x58465342: // XFS | 39 case 0x58465342: // XFS |
36 case 0x3153464A: // JFS | 40 case 0x3153464A: // JFS |
(...skipping 17 matching lines...) Expand all Loading... |
54 case CGROUP_SUPER_MAGIC: | 58 case CGROUP_SUPER_MAGIC: |
55 *type = FILE_SYSTEM_CGROUP; | 59 *type = FILE_SYSTEM_CGROUP; |
56 break; | 60 break; |
57 default: | 61 default: |
58 *type = FILE_SYSTEM_OTHER; | 62 *type = FILE_SYSTEM_OTHER; |
59 } | 63 } |
60 return true; | 64 return true; |
61 } | 65 } |
62 | 66 |
63 } // namespace base | 67 } // namespace base |
OLD | NEW |