- add sources.
[platform/framework/web/crosswalk.git] / src / base / file_util_linux.cc
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.
4
5 #include "base/file_util.h"
6
7 #include "base/files/file_path.h"
8
9 #include <errno.h>
10 #include <sys/vfs.h>
11
12 namespace file_util {
13
14 bool GetFileSystemType(const base::FilePath& path, FileSystemType* type) {
15   struct statfs statfs_buf;
16   if (statfs(path.value().c_str(), &statfs_buf) < 0) {
17     if (errno == ENOENT)
18       return false;
19     *type = FILE_SYSTEM_UNKNOWN;
20     return true;
21   }
22
23   // While you would think the possible values of f_type would be available
24   // in a header somewhere, it appears that is not the case.  These values
25   // are copied from the statfs man page.
26   switch (statfs_buf.f_type) {
27     case 0:
28       *type = FILE_SYSTEM_0;
29       break;
30     case 0xEF53:  // ext2, ext3.
31     case 0x4D44:  // dos
32     case 0x5346544E:  // NFTS
33     case 0x52654973:  // reiser
34     case 0x58465342:  // XFS
35     case 0x9123683E:  // btrfs
36     case 0x3153464A:  // JFS
37       *type = FILE_SYSTEM_ORDINARY;
38       break;
39     case 0x6969:  // NFS
40       *type = FILE_SYSTEM_NFS;
41       break;
42     case 0xFF534D42:  // CIFS
43     case 0x517B:  // SMB
44       *type = FILE_SYSTEM_SMB;
45       break;
46     case 0x73757245:  // Coda
47       *type = FILE_SYSTEM_CODA;
48       break;
49     case 0x858458f6:  // ramfs
50     case 0x01021994:  // tmpfs
51       *type = FILE_SYSTEM_MEMORY;
52       break;
53     case 0x27e0eb: // CGROUP
54       *type = FILE_SYSTEM_CGROUP;
55       break;
56     default:
57       *type = FILE_SYSTEM_OTHER;
58   }
59   return true;
60 }
61
62 }  // namespace