Get HDD size programatically on MacOS using C++
up vote
0
down vote
favorite
I am building an application and I need to get the HDD size:
I am working on Mac OS. I have tried this:
#include <sys/param.h>
#include <sys/mount.h>
float MonitoringWorker::getHDDSize()
{
struct statfs statf;
statfs(".", &statf);
std::cout << "statf.f_bsize = " << statf.f_bsize << std::endl;
std::cout << "statf.f_blocks = " << statf.f_blocks << std::endl;
std::cout << "statf.f_bavail = " << statf.f_bavail << std::endl;
std::cout << "statf.f_bfree = "<< statf.f_bfree << std::endl;
std::cout << "GB = "<< ((statf.f_bsize * statf.f_blocks) / kBytesInGB)<< std::endl;
return 0;
}
I am seeing that the result in GB is 465. However checking System Information tells me that I have 500GB
What am I doing wrong? Is this best way to get those numbers?
Note: I am using C++ on Mac OS, can't use Objective-C
Thanks in advance
macos c++11 filesystems
add a comment |
up vote
0
down vote
favorite
I am building an application and I need to get the HDD size:
I am working on Mac OS. I have tried this:
#include <sys/param.h>
#include <sys/mount.h>
float MonitoringWorker::getHDDSize()
{
struct statfs statf;
statfs(".", &statf);
std::cout << "statf.f_bsize = " << statf.f_bsize << std::endl;
std::cout << "statf.f_blocks = " << statf.f_blocks << std::endl;
std::cout << "statf.f_bavail = " << statf.f_bavail << std::endl;
std::cout << "statf.f_bfree = "<< statf.f_bfree << std::endl;
std::cout << "GB = "<< ((statf.f_bsize * statf.f_blocks) / kBytesInGB)<< std::endl;
return 0;
}
I am seeing that the result in GB is 465. However checking System Information tells me that I have 500GB
What am I doing wrong? Is this best way to get those numbers?
Note: I am using C++ on Mac OS, can't use Objective-C
Thanks in advance
macos c++11 filesystems
1
The program gets the file system capacity, not the physical capacity of the HDD.
– eprom
2 days ago
how can I get the physical capacity, then?
– RuLoViC
2 days ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am building an application and I need to get the HDD size:
I am working on Mac OS. I have tried this:
#include <sys/param.h>
#include <sys/mount.h>
float MonitoringWorker::getHDDSize()
{
struct statfs statf;
statfs(".", &statf);
std::cout << "statf.f_bsize = " << statf.f_bsize << std::endl;
std::cout << "statf.f_blocks = " << statf.f_blocks << std::endl;
std::cout << "statf.f_bavail = " << statf.f_bavail << std::endl;
std::cout << "statf.f_bfree = "<< statf.f_bfree << std::endl;
std::cout << "GB = "<< ((statf.f_bsize * statf.f_blocks) / kBytesInGB)<< std::endl;
return 0;
}
I am seeing that the result in GB is 465. However checking System Information tells me that I have 500GB
What am I doing wrong? Is this best way to get those numbers?
Note: I am using C++ on Mac OS, can't use Objective-C
Thanks in advance
macos c++11 filesystems
I am building an application and I need to get the HDD size:
I am working on Mac OS. I have tried this:
#include <sys/param.h>
#include <sys/mount.h>
float MonitoringWorker::getHDDSize()
{
struct statfs statf;
statfs(".", &statf);
std::cout << "statf.f_bsize = " << statf.f_bsize << std::endl;
std::cout << "statf.f_blocks = " << statf.f_blocks << std::endl;
std::cout << "statf.f_bavail = " << statf.f_bavail << std::endl;
std::cout << "statf.f_bfree = "<< statf.f_bfree << std::endl;
std::cout << "GB = "<< ((statf.f_bsize * statf.f_blocks) / kBytesInGB)<< std::endl;
return 0;
}
I am seeing that the result in GB is 465. However checking System Information tells me that I have 500GB
What am I doing wrong? Is this best way to get those numbers?
Note: I am using C++ on Mac OS, can't use Objective-C
Thanks in advance
macos c++11 filesystems
macos c++11 filesystems
edited Nov 10 at 16:55
Tom Harrington
51.5k596126
51.5k596126
asked Nov 10 at 11:59
RuLoViC
15512
15512
1
The program gets the file system capacity, not the physical capacity of the HDD.
– eprom
2 days ago
how can I get the physical capacity, then?
– RuLoViC
2 days ago
add a comment |
1
The program gets the file system capacity, not the physical capacity of the HDD.
– eprom
2 days ago
how can I get the physical capacity, then?
– RuLoViC
2 days ago
1
1
The program gets the file system capacity, not the physical capacity of the HDD.
– eprom
2 days ago
The program gets the file system capacity, not the physical capacity of the HDD.
– eprom
2 days ago
how can I get the physical capacity, then?
– RuLoViC
2 days ago
how can I get the physical capacity, then?
– RuLoViC
2 days ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238719%2fget-hdd-size-programatically-on-macos-using-c%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
The program gets the file system capacity, not the physical capacity of the HDD.
– eprom
2 days ago
how can I get the physical capacity, then?
– RuLoViC
2 days ago