-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDevice.cpp
103 lines (73 loc) · 2.86 KB
/
Device.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <sys/mount.h>
#include <bits/stdc++.h>
#include "Device.h"
Device::Device(){
}
Device::Device(std::string str){
std::string delimiter = " ";
std::string token;
size_t pos = 0;
std::vector<std::string> tokens;
while ((pos = str.find(delimiter)) != std::string::npos) {
token = str.substr(0, pos);
tokens.push_back(token);
str.erase(0, pos + delimiter.length());
}
devpath = tokens[0];
mpoint = tokens[1];
fs = tokens[2];
other = tokens[3];
mounted = true;
}
bool Device::unmount(){
//std::cout << "mpoint:" << mpoint << std::endl;
const char* usb = mpoint.c_str();
//can't unmount somthing that isnt mounted
std::cout << "atempting to unmount labeled: " << label
<< " usb: " << usb << std::endl
<< " mpoint: " << mpoint << std::endl;
if(mounted == false){
std::cout << label << " not mounted... =(" << std::endl;
return false;
}
if (!umount(usb)){
std::cout << devpath;
std::cout << label << "unmount successful!!=)" << std::endl;
return true;
}else{
std::cout << "Can't unmount " << strerror(errno) << std::endl;
return false;
}
}
//getter fuctions
std::string Device::get_id() { return id; }
std::string Device::get_type() { return type; }
std::string Device::get_des() { return des; }
std::string Device::get_label() { return label; }
std::string Device::get_devpath(){ return devpath; }
std::string Device::get_mpoint() { return mpoint; }
std::string Device::get_fs() { return fs; }
std::string Device::get_other() { return other; }
bool Device::is_mounted() { return mounted; }
//setter fuctions
void Device::set_id (std::string new_id ){ id = new_id ; }
void Device::set_type (std::string new_type ){ type = new_type ; }
void Device::set_des (std::string new_des ){ des = new_des ; }
void Device::set_label (std::string new_label ){ label = new_label ; }
void Device::set_devpath (std::string new_devpath){ devpath = new_devpath; }
void Device::set_mpoint (std::string new_mpoint ){ mpoint = new_mpoint ; }
void Device::set_fs (std::string new_fs ){ fs = new_fs ; }
void Device::set_other (std::string new_other ){ other = new_other ; }
void Device::set_as_mounted () { mounted = true ; }
void Device::print(){
std::cout << std::endl;
std::cout << "id : " << id << std::endl;
std::cout << "type : " << type << std::endl;
std::cout << "des : " << des << std::endl;
std::cout << "label : " << label << std::endl;
std::cout << "devpath: " << devpath << std::endl;
std::cout << "mpoint : " << mpoint << std::endl;
std::cout << "fs : " << fs << std::endl;
std::cout << "other : " << other << std::endl;
std::cout << "device mounted: " << mounted << std::endl;
}