SMPProgAdd - Raw File System
Reprint Courtesy of International Business Machines Corporation, © International Business Machines Corporation
The OS/2 Raw File System provides an interface for applications to efficiently manage data on the logical partitions or physical hard drives installed in a system. Some of the Raw File System function is available by using a combination of the DosPhysicalDisk and DosDevIOCtl functions. However, the Raw File System provides a significant step forward in usability and performance.
The Raw File System provides a programming abstraction that treats each logical partition or physical disk as one large file that can be opened, locked, seeked, read from, written to, and closed.
Logical partitions are identified using the Universal Naming Convention (UNC) in the form of
\\.\X:
where X can be substituted with the letter corresponding the logical partition desired on any hard drive, floppy disk or CD-ROM drive.
Physical disks are identified using a UNC name in the form of
\\.\Physical_Disk#
where # is replaced with the physical disk number corresponding to the number found in the FDISK utility. The Raw File System recognizes up to 128 physical disks, thus eliminating the limit of 26 drives in previous versions of OS/2.
The use of the universal naming convention coupled with the ability to access any physical or logical drive using the common file system functions in OS/2, provides a greatly simplified migration path for applications.
Traditionally, raw file systems have been utilized by applications that manage large amounts of data under heavy workloads. Typically, this has been commercial database servers performing on-line transaction processing. Disk I/O can become a bottleneck under these conditions and the use of an efficient raw file system can be very useful in improving system performance, through reduced path length and serialization. The chapter describes the Raw File System functions in detail.
Programming Recommendations
As an aid to those who wish to develop using the Raw File System, here are a few recommendations based on the implementation that will help make the most of your efforts.
Note: Be careful when using the Raw File System! While it can be very useful and powerful, it will not stop you from destroying the data on your disks if you are not careful.
- Physical vs. Logical Disks
- Physical disk refers to the actual hard disk drives installed in the system. The Raw File System supports up to 128 installed physical disks. Logical disks refers to partitions located on the physical disks, including floppy and CD-ROM drives, that have been formatted for a specific file system, such as FAT or HPFS. OS/2 is limited to 26 such partitions, the first two of which are reserved for floppy drives.
- Physical Disk Numbering
- Physical disk numbers directly correspond with the number assigned using the FDISK utility program.
- Physical Disk Formatting
- When using the Raw File System to manage data on a physical disk, the disk should not be formatted for use by another file system. The FDISK utility will show the disk as unformatted.
- Drive Locking
- To make a physical disk accessible only by the current process, use the OPEN_SHARE_DENYREADWRITE flag on the DosOpen call. The lock will automatically be released when DosClose is called.
- In order to lock a logical partition, a call to DosDevIOCtl with category 8, function DSK_LOCKDRIVE must be called. This must be done before any reads or writes can succeed. Upon completion, DosDevIOCtl with category 8, function DSK_UNLOCKDRIVE must be called before DosClose in order to unlock the disk.
- Memory Buffer Sizes
- The Raw File System supports large memory buffers for reading and writing. For best performance, keep your memory buffers less than 64KB in size. Buffers larger than this are broken up into multiple requests in order not to overload the system buffers.
- Aligned Memory Buffers
- The Raw File System is implemented with performance-critical applications in mind. Implementation details dictate that memory buffers used for I/O should begin on page boundaries in order to achieve maximum performance. Unaligned memory buffers will result in poorer performance. See the example code in the DosListIO function to see how to align a buffer.
- DosListIO Function
- The DosListIO function should be used when multiple reads and writes are necessary. This will greatly reduce the number of instructions needed to perform the I/O operations and as a result help minimize utilization of system resources. This is most beneficial under heavy workloads.
- Disks Larger than 2 GB
- The Raw File System supports physical disks up to 1 TB (terabyte) in size. To allow easier addressing of such large disks, a new mode bit, FILE_SECTOR, has been added to DosSetFilePtr and DosListIO which allows offsets to be specified in sectors rather than bytes.
- For Maximum Performance...
- To achieve maximum performance using the Raw File System, the application should use the DosListIO function with page-aligned memory buffers less than 64 KB in size directed to data on physical drives.