On Time RTOS-32 Documentation
Welcome
RTTarget-32
RTKernel-32
RTFiles-32
RTFiles-32 Programming Manual
RTFiles-32 Reference Manual
Introduction
General File I/O
Information about Files
File Attributes
Directories
Finding Files
File Name Operations
Disk and Volume Management
Function RTFResetDisk
Function RTFGetDiskInfoEx
Function RTFGetPartitionInfo
Function RTFSetVolumeLabel
Function RTFFormat
Function RTFFormatExFAT
Function RTFCheckDisk
Function RTFCheckDiskBufferSize
Function RTFCreateMasterBootRecord
Function RTFSplitPartition
Function RTFCreateGPTPartition
Function RTFSplitGPTPartition
Function RTFCreateBackupGPT
Function RTFCreateBootSector
Function RTFGetDeviceIndex
Function RTFDeviceIoControl
Function RTFPartitionSectors
Function RTFPartitionStart
Miscellaneous File Functions
Raw I/O Functions
Functions for Debugging
Device Dependent Functions
Obsolete Functions
Disk Device Driver API
MTD Device Driver API
RTFiles-32 Error Codes
Code Page Reference
RTIP-32
RTPEG-32
RTUSB-32
|
Function RTFGetDiskInfoEx
RTFGetDiskInfoEx returns information about a logical drive:
int RTFGetDiskInfoEx(const char * DriveName,
RTFDiskInfo * DiskInfo,
int Flags);
ParametersDriveNameMust be a valid file name, e.g., a root directory name. Only the drive information (possibly the current default drive) is determined.
DiskInfoMust point to a structure RTFDiskInfo declared in Rtfiles.h:
typedef struct {
char Label[16];
char DriveLetter;
char Reserved[1];
WORD DeviceFlags;
DWORD SerialNumber;
RTFSector FirstPhysicalSector;
UINT FATType;
UINT FATCount;
UINT MaxDirEntries;
UINT BytesPerSector;
UINT SectorsPerCluster;
DWORD TotalClusters;
DWORD BadClusters;
DWORD FreeClusters;
DWORD Files;
DWORD FileChains;
DWORD FreeChains;
DWORD LargestFreeChain;
} RTFDiskInfo;
FlagsCan be any combination of:
Value |
Meaning |
RTF_DI_BASIC_INFO |
Returns all fields in structure RTFDiskInfo except FreeClusters, BadClusters, Files, FileChains, FreeChains, LargestFreeChain. This flag never requires a FAT scan. |
RTF_DI_FREE_SPACE |
Returns field FreeClusters. This flag may require RTFiles-32 to scan the complete FAT if the amount of free space is not known. In this case, RTF_DI_FAT_STATISTICS is returned in addition to RTF_DI_FREE_SPACE. |
RTF_DI_EXACT_FREE_SPACE |
This flag includes flag RTF_DI_FREE_SPACE and instructs RTFGetDiskInfoEx to scan the cluster bitmap on exFAT volumes to determine the exact amount of free space. On FAT volumes, this flag is identical to RTF_DI_FREE_SPACE. |
RTF_DI_FAT_STATISTICS |
Returns fields BadClusters, Files, FileChains, FreeChains, LargestFreeChain. This flag will always cause RTFiles-32 to scan the complete FAT. This flags is ignored on exFAT. |
return valueIf the function succeeds, the return value is the Flags value corresponding to the returned information, or a negative error code on failure.
RTFGetDiskInfoEx will complete significantly faster if no FAT scan is necessary. On large FAT-32 volumes, a complete FAT scan can take up to about one minute. When the FAT has been scanned, the number of free clusters is cached (on disk for FAT-32 and in RAM for all disk formats), allowing subsequent calls with RTF_DI_FREE_SPACE to return much faster.
On ISO 9660 and exFAT volumes, flag RTF_DI_FAT_STATISTICS is not supported. If it is nevertheless specified, the function's return value will have it unset.
The various fields of structure RTFDiskInfo are:
Value |
Meaning |
Label |
A zero-terminated string with the volume's label or the partition's name. The string is empty if the volume has no label. If the drive has a long file name label with more than 15 characters, this function will return the short volume label name. In this case, the corresponding long name can be retrieved with RTFFindFirstEx("\\*", RTF_ATTR_VOLUME, 0, NULL, Label, sizeof(Label)). |
DriveLetter |
The drive letter in upper case. |
DeviceFlags |
The set of flags set for this drive in the device list. Note that RTFiles-32 will automatically add flag RTF_DEVICE_REMOVABLE for removable devices. The following flags can be returned in DeviceFlags: RTF_DEVICE_SINGLE_FAT, RTF_DEVICE_LAZY_WRITE, RTF_DEVICE_MOUNT_CONTIGUOUS, RTF_DEVICE_REMOVABLE, RTF_DEVICE_NEW_LOCK, RTF_DEVICE_NO_DIAG_MSG, RTF_DEVICE_RAMDISK. |
SerialNumber |
The volume's serial number. On ISO 9660 volumes (which do not have a serial number stored on disk), the serial number is a value calculated from the disk's creation date and time. |
FirstPhysicalSector |
The LBA address of the logical drive's boot record. For diskettes, this value will be 0. |
FATType |
The type of file system found. It may have values RTF_FAT12, RTF_FAT16, RTF_FAT32, RTF_EXFAT, or RTF_ISO9660. |
FATCount |
The number of FATs on the volume. This value is zero for ISO 9660 volumes. |
MaxDirEntries |
The size of the root directory. This value is 0 for FAT-32, exFAT and ISO 9660 volumes. |
BytesPerSector |
The sector size. This value will usually be 512 for FAT/exFAT and 2048 for ISO 9660 volumes. |
SectorsPerCluster |
Specifies the size of the smallest unit of storage that can be allocated to a file in sectors. This value is always 1 for ISO 9660 volumes. |
TotalClusters |
Number of clusters for file storage on the volume. |
BadClusters |
The number of clusters which are marked bad and are unavailable for file storage. |
FreeClusters |
The number of clusters currently available. On exFAT volumes, this value is only accurate +/- 1% of the total number of clusters. To get the exact amount of free space on exFAT volumes, flag RTF_DI_EXACT_FREE_SPACE is required. |
Files |
The number of files on the volume including directories, but not counting the root directory and files with an allocated file size of 0. |
FileChains |
The number of contiguous cluster chains. On a completely unfragmented volume, this value would be identical to Files. |
FreeChains |
The number of contiguous cluster chains of free clusters. On a completely unfragmented volume, this value would be 1. |
LargestFreeChain |
The maximum allocated file size for a newly allocated contiguous file in clusters. On a completely unfragmented volume, this value would be identical to FreeClusters. |
Fields FileChains and FreeChains are good indicators for the degree of fragmentation of the volume; the example program RTFCmd defines a Fragmentation Percentage as follows: if all files and all free clusters each reside in single cluster chains (the ideal case), the fragmentation is 0%. If the average number of file chains per file is 2 (where free space is counted as one file), fragmentation is 100%. Thus, the fragmentation percentage can be calculated as follows:
100 * (FileChains + FreeChains - (Files+1)) / (Files+1)
Function RTFResetDisk
Function RTFGetPartitionInfo
|