This example reads to a physical disk using the raw file system and DosListIO.
#define INCL_ERRORS #define INCL_DOS #define INCL_NOPMAPI #include <os2.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <bsedev.h> #include "listio.h" #define EightK 8*1024 #define FourK 4*1024 #define LISTIO_NUM 1000 #define PAGE_RAND_MAX 100 CHAR Buf[EightK]; LISTIO ListIO[LISTIO_NUM]; ULONG seed = 1; ULONG page_rand(void); int main (VOID) { CHAR *BufAligned; ULONG rc; ULONG Loop = LISTIO_NUM, i, j; ULONG Action, Actual; HFILE hFile; /* Make sure buffer is page aligned */ BufAligned = (UCHAR *)(((LONG)Buf + FourK) & 0xFFFFF000); /* Open a raw file system disk */ rc = DosOpen((PSZ)"\\\\.\\Physical_Disk2", &hFile, &Action, 0L, FILE_NORMAL, OPEN_ACTION_OPEN_IF_EXISTS, OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE, 0L); if (rc != NO_ERROR) { printf("DosOpen error: rc = %u\n", rc); return(1); } /* if */ /*************************************/ /* Perform Random READ using DosRead */ /*************************************/ for(i = 0; i < Loop ; i++) { /* Loop for Random Read */ rc = DosSetFilePtr(hFile, /* file's handle */ page_rand()*FourK, /* offset */ FILE_BEGIN, /* from beginning of file */ &Actual); if (rc != NO_ERROR) { printf("DosSetFilePtr error: rc = %u\n", rc); return(1); } /* if */ rc = DosRead( hFile, /* file's handle */ BufAligned, /* buffer pointer */ FourK, /* size to read */ &Actual); if (rc != NO_ERROR) { printf("DosRead error: rc = %u\n", rc); return(1); } /* if */ } /* for i */ /****************************************/ /* Perform Random Read using DosListIO */ /****************************************/ for (i = 0; i < Loop; i++) { ListIO[i].hFile = hFile; ListIO[i].CmdFlag = LISTIO_READ | FILE_BEGIN; ListIO[i].Offset = page_rand()*FourK; ListIO[i].pBuffer = BufAligned; ListIO[i].NumBytes = FourK; } /* for i */ rc = DosListIO( LISTIO_UNORDERED, /* unordered mode */ Loop, /* number of reads */ ListIO); /* array of control blocks */ if (rc != NO_ERROR) { printf("DosListIO error: rc = %u\n", rc); for (i = 0; i < Loop; i++) { if ((ListIO[i].Actual != FourK) || (ListIO[i].RetCode != NO_ERROR)) { printf("DosListIO error: i = %d, Actual = %d, RetCode = %u\n", I, ListIO[i].Actual, ListIO[i].RetCode); } /* if */ } /* for i */ return(1); } /* if */ /* Close file */ rc = DosClose(hFile); if (rc != NO_ERROR) { printf("DosClose error: rc = %u\n", rc); return(1); } return(NO_ERROR); } /********************************************************/ /* */ /* FUNCTION: page_rand */ /* */ /* DESCRIPTION: Generate random number in range */ /* [0,PAGE_RAND_MAX-1] */ /* */ /********************************************************/ ULONG page_rand() { seed = seed * 1103515245 + 12345; return(((ULONG)(seed/(2*PAGE_RAND_MAX)) % PAGE_RAND_MAX)); }