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
Nov 11 at 15:57
how can I get the physical capacity, then?
– RuLoViC
Nov 11 at 19:16
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.9k599128
51.9k599128
asked Nov 10 at 11:59
RuLoViC
18113
18113
1
The program gets the file system capacity, not the physical capacity of the HDD.
– eprom
Nov 11 at 15:57
how can I get the physical capacity, then?
– RuLoViC
Nov 11 at 19:16
add a comment |
1
The program gets the file system capacity, not the physical capacity of the HDD.
– eprom
Nov 11 at 15:57
how can I get the physical capacity, then?
– RuLoViC
Nov 11 at 19:16
1
1
The program gets the file system capacity, not the physical capacity of the HDD.
– eprom
Nov 11 at 15:57
The program gets the file system capacity, not the physical capacity of the HDD.
– eprom
Nov 11 at 15:57
how can I get the physical capacity, then?
– RuLoViC
Nov 11 at 19:16
how can I get the physical capacity, then?
– RuLoViC
Nov 11 at 19:16
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
The program gets the file system capacity, not the physical capacity of the HDD.
– eprom
Nov 11 at 15:57
how can I get the physical capacity, then?
– RuLoViC
Nov 11 at 19:16