-
Notifications
You must be signed in to change notification settings - Fork 18
/
confighandler_unix.cpp
59 lines (49 loc) · 1.17 KB
/
confighandler_unix.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "confighandler_unix.h"
#include <sys/mount.h>
#include <errno.h>
#include <QDir>
#include <QDebug>
#define RASPLEX_MOUNT_POINT "/tmp/rasplex-mount"
ConfigHandler_unix::~ConfigHandler_unix()
{
unMount();
}
bool ConfigHandler_unix::implemented()
{
return false;
}
bool ConfigHandler_unix::mount(const QString &device)
{
int r = -1;
QString dev(device);
if (!QDir().mkpath(RASPLEX_MOUNT_POINT)) {
qDebug() << "Could not create dir" << RASPLEX_MOUNT_POINT;
return false;
}
// Use first partition
if (dev.contains("mmcblk")) {
dev.append("p1");
}
else {
dev.append("1");
}
qDebug() << "Mounting" << dev;
#if defined(Q_OS_LINUX)
r = ::mount(qPrintable(dev), RASPLEX_MOUNT_POINT, "msdos", 0, NULL);
if (r != 0) {
qDebug() << "Mount failed:" << QString(strerror(errno));
return false;
}
#else
// OSX mount() call differs from Linux. Todo
return false;
#endif
return true;
}
void ConfigHandler_unix::unMount()
{
#if defined(Q_OS_LINUX)
umount(qPrintable(RASPLEX_MOUNT_POINT)); // this doesn't work on os x
qDebug() << "Unmounted" << RASPLEX_MOUNT_POINT;
#endif
}