fixed and tested the free space overflow issue
This commit is contained in:
parent
1cce74631c
commit
ba3eb640ec
1 changed files with 5 additions and 4 deletions
9
data.cpp
9
data.cpp
|
@ -10,6 +10,7 @@
|
|||
#include <sys/vfs.h>
|
||||
#include <libgen.h>
|
||||
#include <ctype.h>
|
||||
#include <stdint.h>
|
||||
|
||||
class Space {
|
||||
public:
|
||||
|
@ -281,7 +282,7 @@ void get_available_space(std::vector<Space> &space) {
|
|||
std::vector<std::string> mounts;
|
||||
struct statfs stats;
|
||||
std::string fullname, name, mountpoint;
|
||||
fsblkcnt_t free_space, total_space;
|
||||
uint64_t free_blocks, total_blocks;
|
||||
int ptr, len;
|
||||
size_t str_pos;
|
||||
bool OK;
|
||||
|
@ -346,11 +347,11 @@ void get_available_space(std::vector<Space> &space) {
|
|||
|
||||
// figure out free and total space
|
||||
statfs(mountpoint.c_str(), &stats);
|
||||
free_space = stats.f_bfree * stats.f_bsize;
|
||||
total_space = stats.f_blocks * stats.f_bsize;
|
||||
free_blocks = stats.f_bfree;
|
||||
total_blocks = stats.f_blocks;
|
||||
|
||||
// pass it on
|
||||
space.push_back(Space(name.c_str(), free_space, total_space));
|
||||
space.push_back(Space(name.c_str(), free_blocks * stats.f_bsize, total_blocks * stats.f_bsize));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue