Solved

Getting cluster sizes in FAT32

Posted on 1997-07-27
11
569 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

VM backup deduplication is a method of reducing the amount of storage space needed to save VM backups. In most organizations, VMs contain many duplicate copies of data, such as VMs deployed from the same template, VMs with the same OS, or VMs that h…
Microservice architecture adoption brings many advantages, but can add intricacy. Selecting the right orchestration tool is most important for business specific needs.
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

829 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