[videodb] remove unused seasons table from episode_view
[xbmc.git] / xbmc / platform / posix / PosixMountProvider.cpp
blobe0b679d7930a3f9198d2510d72bae324730ea016
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "PosixMountProvider.h"
11 #include "utils/RegExp.h"
12 #include "utils/URIUtils.h"
13 #include "utils/log.h"
15 #include <cstdlib>
17 CPosixMountProvider::CPosixMountProvider()
19 m_removableLength = 0;
20 PumpDriveChangeEvents(NULL);
23 void CPosixMountProvider::Initialize()
25 CLog::Log(LOGDEBUG, "Selected Posix mount as storage provider");
28 void CPosixMountProvider::GetDrives(VECSOURCES &drives)
30 std::vector<std::string> result;
32 CRegExp reMount;
33 #if defined(TARGET_DARWIN) || defined(TARGET_FREEBSD)
34 reMount.RegComp("on (.+) \\(([^,]+)");
35 #else
36 reMount.RegComp("on (.+) type ([^ ]+)");
37 #endif
38 char line[1024];
40 FILE* pipe = popen("mount", "r");
42 if (pipe)
44 while (fgets(line, sizeof(line) - 1, pipe))
46 if (reMount.RegFind(line) != -1)
48 bool accepted = false;
49 std::string mountStr = reMount.GetReplaceString("\\1");
50 std::string fsStr = reMount.GetReplaceString("\\2");
51 const char* mount = mountStr.c_str();
52 const char* fs = fsStr.c_str();
54 // Here we choose which filesystems are approved
55 if (strcmp(fs, "fuseblk") == 0 || strcmp(fs, "vfat") == 0
56 || strcmp(fs, "ext2") == 0 || strcmp(fs, "ext3") == 0
57 || strcmp(fs, "reiserfs") == 0 || strcmp(fs, "xfs") == 0
58 || strcmp(fs, "ntfs-3g") == 0 || strcmp(fs, "iso9660") == 0
59 || strcmp(fs, "exfat") == 0
60 || strcmp(fs, "fusefs") == 0 || strcmp(fs, "hfs") == 0)
61 accepted = true;
63 // Ignore root
64 if (strcmp(mount, "/") == 0)
65 accepted = false;
67 if(accepted)
68 result.emplace_back(mount);
71 pclose(pipe);
74 for (unsigned int i = 0; i < result.size(); i++)
76 CMediaSource share;
77 share.strPath = result[i];
78 share.strName = URIUtils::GetFileName(result[i]);
79 share.m_ignore = true;
80 drives.push_back(share);
84 std::vector<std::string> CPosixMountProvider::GetDiskUsage()
86 std::vector<std::string> result;
87 char line[1024];
89 #if defined(TARGET_DARWIN)
90 FILE* pipe = popen("df -hT ufs,cd9660,hfs,udf", "r");
91 #elif defined(TARGET_FREEBSD)
92 FILE* pipe = popen("df -h -t ufs,cd9660,hfs,udf,zfs", "r");
93 #else
94 FILE* pipe = popen("df -h", "r");
95 #endif
97 static const char* excludes[] = {"rootfs","devtmpfs","tmpfs","none","efivarfs","systemd-1","/dev/loop", "udev", NULL};
99 if (pipe)
101 while (fgets(line, sizeof(line) - 1, pipe))
103 bool ok=true;
104 for (int i=0;excludes[i];++i)
106 if (strstr(line,excludes[i]))
108 ok=false;
109 break;
112 if (ok)
113 result.emplace_back(line);
115 pclose(pipe);
118 return result;
121 bool CPosixMountProvider::Eject(const std::string& mountpath)
124 #if !defined(TARGET_DARWIN_EMBEDDED)
125 // just go ahead and try to umount the disk
126 // if it does umount, life is good, if not, no loss.
127 std::string cmd = "umount \"" + mountpath + "\"";
128 int status = system(cmd.c_str());
130 if (status == 0)
131 return true;
132 #endif
134 return false;
137 bool CPosixMountProvider::PumpDriveChangeEvents(IStorageEventsCallback *callback)
139 VECSOURCES drives;
140 GetRemovableDrives(drives);
141 bool changed = drives.size() != m_removableLength;
142 m_removableLength = drives.size();
143 return changed;