Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7092723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:21:00+00:00 2026-05-28T08:21:00+00:00

I’m currently trying to get disk space in byte en used space in byte

  • 0

I’m currently trying to get disk space in byte en used space in byte with statfs().
I made a small function but i get really strange values.
(I’m working on a ubuntu 32bit system)

Here is the code:

bool
CheckDiskSpace( const CLString &devPath, ulonglong &diskSize, ulonglong &totalFreeBytes )
{
bool retVal = false;
struct statfs fs;
if( ( statfs( devPath.c_str(), &fs ) ) < 0 ) {
    printf( "Failed to stat %s: %s\n", devPath.c_str() ,strerror( errno ) );
    return false;
} else {
    diskSize = fs.f_blocks * fs.f_bsize;
    totalFreeBytes = fs.f_bfree * fs.f_bsize;
    retVal = true;
}
return retVal;
}

int main()
{
  ulonglong diskSize, totalFreeBytes;
  CheckDiskSpace( "/dev/sda5", diskSize, totalFreeBytes );
  printf( "Disk size: %llu Byte\n", diskSize );
  printf( "Free size: %llu Byte\n", totalFreeBytes );
}

And I get:

Disk size: 1798447104 Byte
Free size: 1798443008 Byte

I do really not understand this result because with “df” command I get:

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda5            111148848  47454952  58047832  45% /
udev                   1756296         4   1756292   1% /dev
tmpfs                   705324       912    704412   1% /run
none                      5120         0      5120   0% /run/lock
none                   1763300      1460   1761840   1% /run/shm

Any help is very appeciated !

PS: I have a 120 GB ssd and my partition is in Ext4.

EDIT: ulonglong is a predifined type:

typedef unsigned long long ulonglong;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:21:01+00:00Added an answer on May 28, 2026 at 8:21 am

    You are getting the result for the tmpfs mounted on /dev as the /dev/sda5 is on that filesystem. If you want to know for your root filesystem, just use / or any path not in /dev nor /run.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I want to construct a data frame in an Rcpp function, but when I
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am currently running into a problem where an element is coming back from
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.