Solved

Getting cluster sizes in FAT32

Posted on 1997-07-27
11
566 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
  • 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
 

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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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

Give your grad a cloud of their own!

With up to 8TB of storage, give your favorite graduate their own personal cloud to centralize all their photos, videos and music in one safe place. They can save, sync and share all their stuff, and automatic photo backup helps free up space on their smartphone and tablet.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Operating an LTO on a W7 workstation 2 45
Client backup and data retention? 3 54
data center consolidation 8 90
Backup fail due to VSS errors. 4 87
Replication has always been one of those technologies that people run scared from. The main reason is usually cost. When you think of replication, your mind drifts to solutions that replicate from one disk frame to another using block level technolo…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…

911 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now