Solved

Getting cluster sizes in FAT32

Posted on 1997-07-27
11
575 Views
Last Modified: 2013-12-04
For part of my program, I need to find out how many bytes per cluster are used on any of the disks.  So far, I have used the Win32 API function GetDiskFreeSpace(), which worked well under normal versions of Windows95.  Then, I upgraded my computer and now have Windows95 OSR2 release, which means I have a FAT32 hard disk that is over 2GB and uses 4k clusters.  When I realized the results from the program were incorrect, I checked the online help, and found that GetDiskFreeSpace() does not work on OSR2 machines.   It lists a replacement for it, GetDiskFreeSpaceEx(), but this only returns the number of bytes free, and not the sectors and cluster information, meaning it's useless for my purposes.  

Can you please help me get the bytes per cluster information in any way that I can?  I can either use a different method only for OSR2, or I can just use it all the time.  Please Help!
0
Comment
Question by:Vertigo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +2
11 Comments
 
LVL 3

Expert Comment

by:jaba
ID: 1402159
Look into knowledge base , article "Description of FAT32 File System" , Article ID: Q154997
It describing FAT32 file system. In this article you can read - cluster size in FAT 32 is 4k. What why you should to use GetDiskFreeSpaceEx in you programms.

/--------------------------------------------------------------------------------------
Remarks

Note that the values obtained by this function are of type ULARGE_INTEGER. Be careful not to truncate these values to 32 bits.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Windows 95 OSR 2: 

The GetDiskFreeSpaceEx function is available on Windows 95 systems beginning with OEM Service Release 2 (OSR 2).
/--------------------------------------------------------------------------------------
0
 

Author Comment

by:Vertigo
ID: 1402160
If you also happen to notice on this page, it says:
-------------
(that is, 4K clusters for drives up to 8 GB in size)
-------------
and OSR2 supports drives of up to 2 terrabytes.   While most people would not have drives over 8GB, I don't want to limit it to that.  
0
 
LVL 1

Expert Comment

by:mosfet
ID: 1402161
Load the boot sector of the hard disk (normally the first sector).

Here is the format for the beginning of the boot sector:

JMP 3 bytes
OEM 8 bytes
;Start of Bios Parameter block
Sector Size 1 word
Cluster Size 1 byte

You don't need the rest of the boot sector.

The cluster size is in sectors. The Sector size is in bytes.
So, size of a Cluster in bytes would be:

Cluster Size(bytes)=Cluster Size(sectors) * Sector Size(bytes)

A byte is 8 bits, a word is 16 bits.
In C++ or C, a byte would be the equivilant of a char,
             a word would be the equivilant of an int.
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:Vertigo
ID: 1402162
How do I get this information??
0
 
LVL 1

Expert Comment

by:mosfet
ID: 1402163
You need to use a function that will read sectors from a disk. In C++ this function is biosdisk for physical sectors, and something like absread/write for logical sectors. If this is too over your head, there are normally some functions included with your compiler that will read this information for you without doing all the disk editing.
0
 

Author Comment

by:Vertigo
ID: 1402164
By the way, I am using Visual C++ 5.0.  
0
 
LVL 4

Expert Comment

by:emmons
ID: 1402165
have you tried Get_ExtFreeSpace

[Windows 95 only.]
A structure used by Int 21h Function 7303h Get_ExtFreeSpace (FAT32). The structure contains information about the drive's total disk space and free disk space.
This structure is implemented in Windows OEM Service Release 2 and later.
ExtGetDskFreSpcStruc STRUC
    ExtFree_Size                      DW    ?
    ExtFree_Level                     DW    ?
    ExtFree_SectorsPerCluster         DD    ?
    ExtFree_BytesPerSector            DD    ?
    ExtFree_AvailableClusters         DD    ?
    ExtFree_TotalClusters             DD    ?
    ExtFree_AvailablePhysSectors      DD    ?
    ExtFree_TotalPhysSectors          DD    ?
    ExtFree_AvailableAllocationUnits  DD    ?
    ExtFree_TotalAllocationUnits      DD    ?
    ExtFree_Rsvd                      DD    2 DUP (?)
ExtGetDskFreSpcStruc ENDS
 
Members
ExtFree_Size
A return value that represents the size of the ExtGetDskFreSpcStruc structure, in bytes. The Get_ExtFreeSpace sub-function returns the size value to this field. This member is used only as a return value.
ExtFree_Level
An input and return level value. This must be initialized to zero.
ExtFree_SectorsPerCluster
The number of sectors per cluster.
ExtFree_BytesPerSector
The number of bytes per sector.
ExtFree_AvailClusters
The number of available clusters.
ExtFree_TotalClusters
The total number of clusters on the drive.
ExtFree_AvailablePhysSectors
The number of physical sectors available on the drive, without adjustment for compression.
ExtFree_TotalPhysSectors
The total number of physical sectors on the drive, without adjustment for compression.
ExtFree_AvailableAllocationUnits
The number of available allocation units on the drive, without adjustment for compression.
ExtFree_TotalAllocationUnits
The total number of allocation units on the drive, without adjustment for compression.
ExtFree_Rsvd
Reserved field.

0
 

Author Comment

by:Vertigo
ID: 1402166
That would provide the information I need..however I have no idea how to use that in a program.  I am not very familer with using this type of thing, and even less so under Windows.. Do you know of any example of something like this I could look at?
0
 
LVL 4

Expert Comment

by:emmons
ID: 1402167
[Windows 95 only.]
Returns the total disk space and the free disk space.
mov  dx, seg Buffer
mov  es, dx
mov  di, offset Buffer    ;See below
mov  es:[di].ExtGetDskFreSpcStruc.ExtFree_Level, ExpectLevel
mov  cx, BufferSize       ;See below
 
mov  dx, seg DriveName    ;See below
mov  ds, dx
mov  dx, offset DriveName ;See below

mov  ax, 7303h            ;Get_ExtFreeSpace
int  21h

jc  error_handler         ;carry set means error

Parameters
Buffer
The address of the buffer at ES:DI that will receive the disk space information.
BufferSize
The size (in bytes) of the buffer.
DriveName
The address of a null terminated string at DS:DX. In real mode, this must be in standard form ("C:\"). In Windows, either the standard name or a universal naming convention form ("\\Server\Share") is acceptable.
Return Values
Clears the carry flag and returns the total disk space and the free disk space of the specified drive, in the form of an ExtGetDskFreSpcStruc (FAT32) structure, to a buffer at ES:DI. It is recommended to initialize the buffer to the level value the application expects to receive.

0
 

Author Comment

by:Vertigo
ID: 1402168
Can you give me any more help about actually using this in a C++ program...  I have no idea how to get at any of the information that is mentioned.  The important information I need is bytes per sector and sectors per cluster.  

0
 
LVL 1

Accepted Solution

by:
cph earned 200 total points
ID: 1402169
Well, in front of the code written by emmons, you just have to type the keyword asm.

It will look like this:
asm {mov dx, seg Buffer
              mov es, dx
              mov di, offset Buffer ;See below
              mov es:[di].ExtGetDskFreSpcStruc.ExtFree_Level, ExpectLevel
              mov cx, BufferSize ;See below
               
              mov dx, seg DriveName ;See below
              mov ds, dx
              mov dx, offset DriveName ;See below

              mov ax, 7303h ;Get_ExtFreeSpace
              int 21h

              jc error_handler ;carry set means error
}

Put this in a function or where ever you want...
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick step-by-step overview of installing and configuring Carbonite Server Backup.
By default, Carbonite Server Backup manages your encryption key for you using Advanced Encryption Standard (AES) 128-bit encryption. If you choose to manage your private encryption key, your backups will be encrypted using AES 256-bit encryption.
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question