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 8253979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:03:42+00:00 2026-06-08T01:03:42+00:00

I have written a code to calculate the hardisk size, but for some reason

  • 0

I have written a code to calculate the hardisk size, but for some reason it always gives the size lesser than the actual size.

Like, 80GB will show as 74GB, and 160GB will show as 149 GB.
Where is the catch?

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <linux/fs.h>


int main()
{

        long bytes = 0;
        int fd = open("/dev/sdb1", O_RDONLY);
        const unsigned long long a = (1024ULL* 1024ULL * 1024ULL);

        int retval = ioctl(fd, BLKGETSIZE64, &bytes);
        int hdSize = bytes / a;

        printf(" Harddisk = %lld \n",hdSize);

        return EXIT_SUCCESS;
}
  • 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-06-08T01:03:45+00:00Added an answer on June 8, 2026 at 1:03 am

    Simply different Gigabyte definitions. You use 1 GB = 230 bytes, many harddrive vendors use 109 bytes.

    For instance, an “80 GB” disk from a manufacturer using the latter definition will hold 80,000,000,000 bytes, which equals 78,125,000 KB, 76,294 MB, or (as you verified) 74.51 GB where all my units use power-of-two definitions.

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

Sidebar

Related Questions

I have written some code for displaying a drop down list, but the code
I have written a small piece of code to calculate quadratic equations, but if
Hi I have written code like this @Id @Column(nullable=false) @GeneratedValue(strategy=GenerationType.AUTO) public int getUserID() {
I have written some code that loads an XML document using an XmlDocument object
I have written some code in JSP to download .docx files which is hosted
I have written this JavaScript that calculate words, but I am unable to convert
I have written the below code to calculate mouse moved co-ordinates $(document).mousemove(function(e){ console.log(e.pageX +
I have written code that opens 16 figures at once. Currently, they all open
I have written code in Java to access web cam,and to save image... I
I have written code to perform a function that could take a while to

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.