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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:05:56+00:00 2026-05-27T11:05:56+00:00

I have a question which is confusing me and my task is to work

  • 0

I have a question which is confusing me and my task is to work out fragmentation.

stat() for a file:
st_size = 10520
st_blksize = 4096
st_blocks = 24

I have read in some places that st_blksize is the general block size of the file system which in this case is 4096 but that file would fit into 3 blocks, 10520 / 512 is 20.5 meaning that there are 3.5 blocks of unused space, even though it is allocated. Does this mean that there are 1792 unused bytes in this file (fragmentation)?

As I have mentioned I read into this a fair bit and have read a lot of contradicting texts, would like someone to clear this up once and for all!

  • 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-27T11:05:57+00:00Added an answer on May 27, 2026 at 11:05 am

    I don’t think your project is really solvable at the stat(2) API layer. Consider the case of a file 4096 bytes long. Presume it was created by iteratively appending 512 byte blocks over and over again. Presume that the filesystem was completely full, except for one 512 byte block, for each and every write. Presume that the 512 byte block available for each write was located in a randomly available spot on the disk.

    This file is 100% fragmented — no two blocks are near each other.

    And yet, a measure based solely on the stat(2) variables might well show that there are no wasted blocks anywhere in the file.

    When trying to track down an answer to your actual question, I got as far as ext3_write_begin() before being called away — hope this is a useful starting point for your search.

    Update

    If you’re interested in finding fragmentation, I think the place to start is the bmap command from the debugfs(8) program:

    debugfs:  bmap sars_first_radio_show.zip 0
    94441752
    debugfs:  bmap sars_first_radio_show.zip 1
    94441781
    debugfs:  bmap sars_first_radio_show.zip 2
    94441782
    debugfs:  bmap sars_first_radio_show.zip 3
    94441783
    debugfs:  bmap sars_first_radio_show.zip 4
    94441784
    debugfs:  bmap sars_first_radio_show.zip 5
    94459905
    debugfs:  bmap sars_first_radio_show.zip 6
    95126019
    debugfs:  bmap sars_first_radio_show.zip 7
    95126020
    debugfs:  bmap sars_first_radio_show.zip 8
    95126021
    debugfs:  bmap sars_first_radio_show.zip 9
    95126022
    debugfs:  
    

    This shows the first ten blocks for the file sars_first_radio_show.zip; you can see that the blocks aren’t all contiguous: 944417{52,81,82,83,84}, 94459905, 951260{19,20,21,22}.

    You could either script an answer around debugfs(8) or you could use the libext2fs library routines yourself. It would be a significant step up in complexity compared to the stat(2) exercises you were going through — but the answers would mean something, rather than just be a vague guess.

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

Sidebar

Related Questions

I have an SQL question which may be basic to some but is confusing
I have a small question which is confusing me, I have a variable of
I have a question which is described below: What problems would arise for testing
I have a question which I think involves conditional entropy in the field of
I have a question which may be somewhat silly because I'm pretty sure I
this is my first time posting here, I have a question which I have
I have this question in which I have a SQL Server Compact Edition database
I have few Question for which I am not able to get a proper
I am learning JPA and have one question: In which situations we need more
I have a pretty simple question which perhaps someone familiar with Server/Client design &

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.