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 RTFFormat
Function RTFFormat formats a logical drive with a FAT-12. FAT-16, or FAT-32 file system:
int RTFFormat(const char * DriveName,
UINT MinSectorsPerCluster,
RTFFormatCallback Progress,
DWORD Flags);
ParametersDriveNameMust be a logical drive file name in the form "\\.\X:", where "X" is replaced with the drive letter of the logical drive to be formatted. To format a hard disk as a Super Floppy, use a physical disk name in the form "\\.\PHYSICALDRIVEx" where "x" is the hard disk index.
MinSectorsPerClusterSpecifies the minimum number of sectors per cluster RTFFormat should set up. This parameter should be 0 to use a default cluster size, 1 to always use the smallest possible cluster size, or any other power of two. Cluster sizes up to 64 sectors are compatible with other operating systems, 128 is compatible with Windows NT/2000/XP/Vista/7/8/10. RTFiles-32 supports cluster sizes up to 32768 sectors (extended cluster sizes), but such volumes cannot be mounted by any other OS. If the specified cluster size is too small, RTFiles-32 will automatically increase it. This may become necessary on FAT-12 or FAT-16 volumes to avoid exceeding the maximum supported number of clusters. For most applications, the default cluster size is recommended (set MinSectorsPerCluster to 0).
ProgressA callback to supply progress information:
typedef void (__cdecl * RTFFormatCallback)(const char * DeviceName,
int Action,
DWORD Total,
DWORD Completed);
It will be called periodically by RTFFormat. Parameter Action can have one of the following values:
Value |
Meaning |
RTF_FMT_PGS_LOW_FMT |
Low-level formatting is in progress. |
RTF_FMT_PGS_HIGH_FMT |
High-level formatting is in progress. |
RTF_FMT_PGS_CLEAR_MEDIUM |
The data area of the drive is being deleted. |
Total indicates how many sectors must be processed. Completed indicates how many sectors have been processed successfully.
The Progress parameter for RTFFormat is optional and may be set to NULL.
FlagsControls various options about how to format the drive. It can have any combination of the following flags:
Value |
Meaning |
RTF_FPLY_DRIVE_360,
RTF_FPLY_DRIVE_1200,
RTF_FPLY_DRIVE_720,
RTF_FPLY_DRIVE_1440,
RTF_FPLY_DRIVE_2880 |
These flags specify the type of floppy disk that should be formatted. If none of these flags is specified, the maximum capacity of the floppy disk drive is assumed. For example, if you want to format a 720k diskette in a 1.44M diskette drive, you must specify flag RTF_FPLY_DRIVE_720. If it is omitted, RTFFormat would attempt to format the diskette for 1.44M. |
RTF_FMT_SINGLE_FAT |
RTFFormat should create only a single FAT. By default, two FATs are created. This flag is not compatible with all other operating systems. However, drives formatted with a single FAT have a larger capacity and better write performance. In particular, this flag should be used for Flash or RAM disks to improve performance and efficiency. |
RTF_FMT_FORCE_LOW_LEVEL |
This flag forces RTFFormat to do a low-level format. By default, RTFFormat will do a low-level format only if writing to the device fails. Hard disks are never low-level formatted by RTFFormat. If you need to low-level format a hard disk, use the respective raw I/O functions. |
RTF_FMT_NO_LOW_LEVEL |
Prevent RTFFormat from low-level formatting a device. If writing to the device fails, the function returns with an error. |
RTF_FMT_FAT_12 |
Set up a FAT-12 file system. |
RTF_FMT_FAT_16 |
Set up a FAT-16 file system. |
RTF_FMT_FAT_32 |
Set up a FAT-32 file system. |
RTF_FMT_NO_FAT_32 |
Set up a FAT-12 or FAT-16 file system, depending on the drive's size. |
RTF_FMT_LARGE_BUFFER |
This flag instructs RTFFormat to temporarily heap-allocate and use a 64k disk buffer instead of its stack-allocated 512 byte buffer. RTF_FMT_LARGE_BUFFER can dramatically improve the speed of formatting and is generally recommended. This flag is mandatory for disks with a sector size larger than 512 bytes. |
RTF_FMT_NO_ALIGN |
This flag instructs RTFFormat not to align data clusters. by default, data clusters are aligned with the applied cluster size. |
RTF_FMT_ALIGN_4K |
This flag instructs RTFFormat to align data clusters on 4k byte boundaries. |
RTF_FMT_ALIGN_BUFFSIZE |
This flag instructs RTFFormat to align data clusters according to the currently used buffer size (RTF_BUFFER_SIZE), which is 4k by default but may be changed through file <Rtfdata.c>. |
If none of the RTF_FMT_FAT_... flags is specified, RTFFormat will select a FAT type automatically. Drives with less than 16M size will be formatted as FAT-12 and drives with less than 512M will be formatted as FAT-16. Larger drives are formatted as FAT-32.
return valueIf the function succeeds, the return value is the FAT type set up (RTF_FAT12, RTF_FAT16, or RTF_FAT32). If it fails, the return value is a negative error code. Demo programs RTFCmd and PartDemo use this function.
Please note that some combinations of MinSectorsPerCluster and Flags can prevent RTFFormat from setting up a valid file system. For example, a FAT-16 drive must have at least 4085 clusters. However, if a drive has only 10000 sectors, MinSectorsPerCluster is set to 4, and flag RTF_FMT_FAT_16 is specified, RTFFormat will return error RTF_INVALID_FILE_SYSTEM.
RTFFormat does not perform a surface scan on the volume. Only if writing to any system portion of the drive fails, the function returns the respective error code.
Function RTFSetVolumeLabel
Function RTFFormatExFAT
|