-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQDiskInfo.cpp
94 lines (86 loc) · 2.24 KB
/
QDiskInfo.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
#include "QDiskInfo.h"
extern "C"
{
#include <sys/vfs.h>
}
#include <string>
QDiskInfo::QDiskInfo(const std::string &_path)
: disk_total_capacity(0), disk_used_capacity(0), disk_free_capacity(0), disk_format(DISK_FORMAT_UNKNOW), path(_path)
{
struct statfs buf;
int i = statfs(path.c_str(), &buf);
if (i < 0)
{
//printf("get disk infomation faild\n");
}
else
{
switch (buf.f_type)
{
case 0x4d44:
disk_format = DISK_FORMAT_FAT;
break;
case 0x5346544e:
case 0X65735546:
disk_format = DISK_FORMAT_NTFS;
break;
case 0xEF53:
case 0xEF51:
disk_format = DISK_FORMAT_EXT2;
break;
default:
disk_format = DISK_FORMAT_UNKNOW;
break;
}
disk_total_capacity = (((long long)buf.f_bsize * (long long)buf.f_blocks));
disk_free_capacity = (((long long)buf.f_bsize * (long long)buf.f_bfree));
disk_used_capacity = disk_total_capacity - disk_free_capacity;
}
}
QDiskInfo::~QDiskInfo() {}
void QDiskInfo::refreshInfo()
{
struct statfs buf;
int i = statfs(path.c_str(), &buf);
if (i < 0)
{
//printf("refresh get disk infomation faild\n");
return;
}
switch (buf.f_type)
{
case 0x4d44:
disk_format = DISK_FORMAT_FAT;
break;
case 0x5346544e:
case 0X65735546:
disk_format = DISK_FORMAT_NTFS;
break;
case 0xEF53:
case 0xEF51:
disk_format = DISK_FORMAT_EXT2;
break;
default:
disk_format = DISK_FORMAT_UNKNOW;
break;
}
disk_total_capacity = (((long long)buf.f_bsize * (long long)buf.f_blocks));
disk_free_capacity = (((long long)buf.f_bsize * (long long)buf.f_bfree));
disk_used_capacity = disk_total_capacity - disk_free_capacity;
}
long long QDiskInfo::getTotalSize()
{
return disk_total_capacity;
}
long long QDiskInfo::getUsedSize()
{
return disk_used_capacity;
}
long long QDiskInfo::getLeftSize()
{
return disk_free_capacity;
}
DISK_FORMAT QDiskInfo::getDiskFormat()
{
return disk_format;
}