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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:39:53+00:00 2026-05-27T10:39:53+00:00

I am trying to write a program in C that allows me to move

  • 0

I am trying to write a program in C that allows me to move through a FAT32 file system image. However, I am having difficulty understanding and applying the equations to gather the correct data. I am using a debian distribution of linux so little-endian form is maintained. Below is pseudocode from the Microsoft website about FAT32, calculating the next cluster to access of a directory or file:

    ThisFATSecNum = BPB_ResvdSecCnt + (FATOffset / BPB_BytsPerSec);
    ThisFATEntOffset = REM(FATOffset / BPB_BytsPerSec);

    FAT32ClusEntryVal = FAT32ClusEntryVal & 0x0FFFFFFF;
    *((DWORD *) &SecBuff[ThisFATEntOffset]) =
        (*((DWORD *) &SecBuff[ThisFATEntOffset])) & 0xF0000000;
    *((DWORD *) &SecBuff[ThisFATEntOffset]) = 
        (*((DWORD *) &SecBuff[ThisFATEntOffset])) | FAT32ClusEntryVal;

I do not fully understand what the SecBuff character array is doing or what it’s accessing. DWORD is supposed to be a unsigned int and I’m not sure I understand the subsequent casts either. Any light shed is much appreciated.

If someone could also explain how we are supposed to move through the FAT32 filesystem based on clusters it would be greatly appreciated, it seems to me that going by reference of sectors is more effective even though cluster allocation ensures spatial locality. I don’t fully understand how to do the byte reading to find the next cluster for files/folders.

  • 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-27T10:39:54+00:00Added an answer on May 27, 2026 at 10:39 am

    That pseudo code is for reading and writing a cluster number from/into the file allocation table. The doc says it right between two pieces of pseudo code. It’s the only possibility here, unless you don’t have a slightest idea of how FAT12/16/32 works.

    ——8<——

    Assume this is read into an 8-bit byte array named SecBuff. Also assume that the type WORD is a 16-bit unsigned and that the type DWORD is a 32-bit unsigned.

    If(FATType == FAT16)
        FAT16ClusEntryVal = *((WORD *) &SecBuff[ThisFATEntOffset]);
    Else
        FAT32ClusEntryVal = (*((DWORD *) &SecBuff[ThisFATEntOffset])) & 0x0FFFFFFF;
    

    Fetches the contents of that cluster. To set the contents of this same cluster you do the following:

    If(FATType == FAT16)
        *((WORD *) &SecBuff[ThisFATEntOffset]) = FAT16ClusEntryVal;
    Else {
         FAT32ClusEntryVal = FAT32ClusEntryVal & 0x0FFFFFFF;
        *((DWORD *) &SecBuff[ThisFATEntOffset]) =
            (*((DWORD *) &SecBuff[ThisFATEntOffset])) & 0xF0000000;
        *((DWORD *) &SecBuff[ThisFATEntOffset]) = 
            (*((DWORD *) &SecBuff[ThisFATEntOffset])) | FAT32ClusEntryVal;
    }
    

    ——8<——

    It is these cluster numbers in the cells the above pseudo code manipulates with:

    enter image description here

    They say where the next file part is (if any), in what cluster. Every file or directory is a chain of clusters.

    SecBuff is an array containing a 512-bytes-long sector of the file allocation table. The *((DWORD *) casts are there to avoid reading/writing 32-bit values in separate 8-bit pieces.

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

Sidebar

Related Questions

I am trying to write a program that allows a binary to be run,
I'm trying to write a program that reads text from external file (string string
I'm trying to write a program that takes a large file (of any type)
I'm trying to write a program that could monitor multiple folders for file creations
I am trying to write one portion of my huge C# program that allows
I'm trying to write a program that will loop through cells of a specific
Im trying to write a simple program that takes 5 images and allows you
I am trying to write a frame program that allows you to play Texas
I'm trying to write a program that uses sockets to connect with other instances
I am trying to write a program that displays the integers between 1 and

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.