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
3 // found in the LICENSE file.
5 #include "base/files/file_util.h"
8 #include <linux/magic.h>
11 #include "base/files/file_path.h"
15 bool GetFileSystemType(const FilePath
& path
, FileSystemType
* type
) {
16 struct statfs statfs_buf
;
17 if (statfs(path
.value().c_str(), &statfs_buf
) < 0) {
20 *type
= FILE_SYSTEM_UNKNOWN
;
24 // Not all possible |statfs_buf.f_type| values are in linux/magic.h.
25 // Missing values are copied from the statfs man page.
26 switch (statfs_buf
.f_type
) {
28 *type
= FILE_SYSTEM_0
;
30 case EXT2_SUPER_MAGIC
: // Also ext3 and ext4
31 case MSDOS_SUPER_MAGIC
:
32 case REISERFS_SUPER_MAGIC
:
33 case BTRFS_SUPER_MAGIC
:
34 case 0x5346544E: // NTFS
35 case 0x58465342: // XFS
36 case 0x3153464A: // JFS
37 *type
= FILE_SYSTEM_ORDINARY
;
40 *type
= FILE_SYSTEM_NFS
;
43 case 0xFF534D42: // CIFS
44 *type
= FILE_SYSTEM_SMB
;
46 case CODA_SUPER_MAGIC
:
47 *type
= FILE_SYSTEM_CODA
;
52 *type
= FILE_SYSTEM_MEMORY
;
54 case CGROUP_SUPER_MAGIC
:
55 *type
= FILE_SYSTEM_CGROUP
;
58 *type
= FILE_SYSTEM_OTHER
;