2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
20 #include "PosixMountProvider.h"
21 #include "utils/RegExp.h"
22 #include "utils/StdString.h"
23 #include "utils/URIUtils.h"
24 #include "utils/log.h"
26 CPosixMountProvider::CPosixMountProvider()
28 m_removableLength = 0;
29 PumpDriveChangeEvents(NULL);
32 void CPosixMountProvider::Initialize()
34 CLog::Log(LOGDEBUG, "Selected Posix mount as storage provider");
37 void CPosixMountProvider::GetDrives(VECSOURCES &drives)
39 std::vector<CStdString> result;
42 #if defined(TARGET_DARWIN)
43 reMount.RegComp("on (.+) \\(([^,]+)");
45 reMount.RegComp("on (.+) type ([^ ]+)");
49 FILE* pipe = popen("mount", "r");
53 while (fgets(line, sizeof(line) - 1, pipe))
55 if (reMount.RegFind(line) != -1)
57 bool accepted = false;
58 std::string mountStr = reMount.GetReplaceString("\\1");
59 std::string fsStr = reMount.GetReplaceString("\\2");
60 const char* mount = mountStr.c_str();
61 const char* fs = fsStr.c_str();
63 // Here we choose which filesystems are approved
64 if (strcmp(fs, "fuseblk") == 0 || strcmp(fs, "vfat") == 0
65 || strcmp(fs, "ext2") == 0 || strcmp(fs, "ext3") == 0
66 || strcmp(fs, "reiserfs") == 0 || strcmp(fs, "xfs") == 0
67 || strcmp(fs, "ntfs-3g") == 0 || strcmp(fs, "iso9660") == 0
68 || strcmp(fs, "exfat") == 0
69 || strcmp(fs, "fusefs") == 0 || strcmp(fs, "hfs") == 0)
73 if (strcmp(mount, "/") == 0)
77 result.push_back(mount);
83 for (unsigned int i = 0; i < result.size(); i++)
86 share.strPath = result[i];
87 share.strName = URIUtils::GetFileName(result[i]);
88 share.m_ignore = true;
89 drives.push_back(share);
93 std::vector<CStdString> CPosixMountProvider::GetDiskUsage()
95 std::vector<CStdString> result;
98 #if defined(TARGET_DARWIN)
99 FILE* pipe = popen("df -hT ufs,cd9660,hfs,udf", "r");
100 #elif defined(TARGET_FREEBSD)
101 FILE* pipe = popen("df -h -t ufs,cd9660,hfs,udf,zfs", "r");
103 FILE* pipe = popen("df -h", "r");
106 static const char* excludes[] = {"rootfs","devtmpfs","tmpfs","none","/dev/loop", "udev", NULL};
110 while (fgets(line, sizeof(line) - 1, pipe))
113 for (int i=0;excludes[i];++i)
115 if (strstr(line,excludes[i]))
122 result.push_back(line);
130 bool CPosixMountProvider::PumpDriveChangeEvents(IStorageEventsCallback *callback)
133 GetRemovableDrives(drives);
134 bool changed = drives.size() != m_removableLength;
135 m_removableLength = drives.size();