Changeset 55
- Timestamp:
- Dec 14, 2010, 12:03:32 PM (15 years ago)
- Location:
- trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lbatest/readtest.c
r54 r55 7 7 matches its real LBA. 8 8 9 To run the test, attach a HD to an AHCI controller with os2ahci.add loaded 10 and run the test with the drive letter as a parameter. 9 To run the test, run lbatest under Linux, then attach the drive to an OS/2 10 system an create a single primary partition that stretches the entire drive. 11 Then run readtest.exe with the drive letter as a parameter. 12 11 13 12 14 Author: Markus Thielen … … 47 49 48 50 #define SECTOR_SIZE 512 49 #define SECTORS_PER_ WRITE20051 #define SECTORS_PER_READ 200 50 52 51 53 … … 62 64 unsigned long lba_pos; 63 65 unsigned long first_wrong_sector = 0xffffffff; 64 char mode; 66 65 67 66 68 /*--- start of code ---------------------------------------------------------*/ … … 71 73 int main(int argc, char **argv) 72 74 { 73 char *drv;74 75 HFILE hf; 76 char drv[50]; 75 77 76 78 if (argc < 2) { … … 79 81 } 80 82 81 drv = argv[1]; 82 if (drv[1] != ':' && drv[2] != '\0') { 83 /* we want a drive letter, which is a letter and a colon */ 83 if (isalpha(argv[1][0])) { 84 sprintf(drv, "\\\\.\\%c", toupper(argv[1][0])); 85 } else if (isdigit(argv[1][0])) { 86 sprintf(drv, "\\\\.\\Physical_Disk%c", argv[1][0]); 87 } else { 84 88 usage(); 85 89 return -1; … … 99 103 unsigned long action; 100 104 unsigned long cb_read; 101 char buf[SECTOR_SIZE];105 char *buf; 102 106 int rc = 0; 107 unsigned long cb_take = SECTOR_SIZE * SECTORS_PER_READ; 103 108 unsigned long err_cnt = 0; 104 109 float gbf = 1024.0 * 1024.0 * 1024.0 / 512.0; 105 long long lba = 0; 110 LONGLONG cbfile = {0}; 111 int s; 112 unsigned long sectors; 113 unsigned long val; 114 115 buf = calloc(SECTOR_SIZE, SECTORS_PER_READ); 106 116 107 117 /* open drive */ 108 ret = DosOpenL(drv, &hf_disk, &action, 0, 0, OPEN_ACTION_OPEN_IF_EXISTS, 109 OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR | 110 OPEN_FLAGS_WRITE_THROUGH | OPEN_FLAGS_NO_CACHE | 111 OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYREADWRITE | 112 OPEN_ACCESS_READONLY, 113 NULL); 118 ret = DosOpen(drv, &hf_disk, &action, 0, 0, 119 OPEN_ACTION_OPEN_IF_EXISTS, 120 /* OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR | */ 121 /* OPEN_FLAGS_WRITE_THROUGH | OPEN_FLAGS_NO_CACHE | */ 122 /* OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYREADWRITE | */ 123 OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY, 124 NULL); 114 125 if (ret != NO_ERROR) { 115 126 fprintf(stderr, "Failed to open disk %s for reading: %d\n", drv, ret); … … 118 129 119 130 /* lock disk */ 120 ret = DosDevIOCtl(hf_disk, IOCTL_DISK, DSK_LOCKDRIVE, NULL, 0, 121 &action, NULL, 0, &cb_read); 122 if (ret != NO_ERROR) { 123 fprintf(stderr, "Failed to lock drive, code %d\n", ret); 124 rc = -1; 125 goto cleanup; 126 } 131 /* ret = DosDevIOCtl(hf_disk, IOCTL_DISK, DSK_LOCKDRIVE, NULL, 0, */ 132 /* &action, NULL, 0, &cb_read); */ 133 /* if (ret != NO_ERROR) { */ 134 /* fprintf(stderr, "Failed to lock drive, code %d\n", ret); */ 135 /* rc = -1; */ 136 /* goto cleanup; */ 137 /* } */ 127 138 128 139 /* catch Ctrl+C */ … … 131 142 /* go... */ 132 143 memset(buf, 0x00, sizeof(buf)); 133 for (lba = 64; ; lba++) {134 ret = DosRead(hf_disk, buf, SECTOR_SIZE, &cb_read);144 for (lba_pos = 0; ; lba_pos += SECTORS_PER_READ) { 145 ret = DosRead(hf_disk, buf, cb_take, &cb_read); 135 146 if (ret != NO_ERROR) { 136 147 fprintf(stderr, "\nFailed to read from disk %s, code %d\n", drv, ret); … … 139 150 } 140 151 141 if (*((long long*) buf) != lba_pos) { 142 printf("\nWrong sector number: read %d from sector %d\n", 143 *((long long*) buf), lba_pos); 144 err_cnt++; 145 if (first_wrong_sector == 0xffffffff) { 146 first_wrong_sector = lba_pos; 152 if (cb_read == 0) { 153 goto cleanup; 154 } 155 156 sectors = cb_read / SECTOR_SIZE; 157 158 for (s = 0; s < sectors; s++) { 159 160 if (lba_pos + s < 64) { 161 continue; 147 162 } 163 164 val = *((unsigned long*) (buf + s * SECTOR_SIZE)); 165 if (val == 0xf6f6f6f6) { 166 /* appearantly, this is the funny first partition sector 167 * created by LVM - skip it */ 168 continue; 169 } 170 171 if (val != lba_pos + s) { 172 printf("\nWrong sector number: read 0x%08x from sector 0x%08x", 173 val, lba_pos + s); 174 err_cnt++; 175 if (first_wrong_sector == 0xffffffff) { 176 first_wrong_sector = lba_pos + s; 177 } 178 } 148 179 } 149 180 150 181 /* progress */ 151 if (lba_pos % 100 == 0) { 152 printf("\r%dk sectors read (%0.02f GB)", lba_pos / 1000, 153 (float) lba_pos / gbf); 154 } 182 printf("\r%dk sectors read (%0.02f GB)", lba_pos / 1000, 183 (float) lba_pos / gbf); 155 184 } 156 185 … … 160 189 NULL, 0, &cb_read); 161 190 DosClose(hf_disk); 191 free(buf); 162 192 163 193 /* print summary */ … … 176 206 { 177 207 printf("LBA (read sector number) test for os2ahci.add\n" 208 "Call with a drive letter (for logical drive) or 1-based disk number (for\n" 209 "physical drive)\n\n" 178 210 "Usage:\n\n" 179 "lbatest <drive letter >\n\n");211 "lbatest <drive letter|drive number>\n\n"); 180 212 } 181 213 … … 187 219 { 188 220 189 if (sig_no == SIGINT && mode == 'R') {221 if (sig_no == SIGINT) { 190 222 /* read mode interrupted; show summary */ 191 printf("\n\nLast block read: %u\n", lba_pos);223 printf("\n\nLast block read: 0x%08x\n", lba_pos); 192 224 if (first_wrong_sector != 0xffffffff) { 193 printf("First wrong sector: %u\n", first_wrong_sector);225 printf("First wrong sector: 0x%08x\n", first_wrong_sector); 194 226 } else { 195 227 printf("All sectors read ok\n"); -
trunk/src/os2ahci/ahci.c
r53 r55 32 32 ? atapi_##func : ata_##func 33 33 34 35 /* #define LBATEST 36 * uncomment to perform sector mapping test of first drive */ 37 34 38 #define LBATEST_SECTORS_PER_READ 64 35 39 #define LBATEST_SECTOR_SIZE 512 36 40 37 #define LBATEST38 41 39 42 /* ------------------------ typedefs and structures ------------------------ */ … … 1654 1657 DevHelp_FreePhys(phys_addr); 1655 1658 1659 LBA test compiled? 1660 1656 1661 } 1657 1662 #endif -
trunk/src/os2ahci/ata.c
r46 r55 618 618 { 619 619 IORB_EXECUTEIO _far *io = (IORB_EXECUTEIO _far *) iorb; 620 /* unsigned char _far *p; */ 621 /* u16 mode_sw; */ 620 622 621 623 io->BlocksXferred += add_workspace(iorb)->blocks; … … 628 630 /* requeue this IORB for next iteration */ 629 631 iorb_requeue(iorb); 630 } 632 /* printf("MT: IORB requeued\n"); */ 633 } 634 635 /* MT: print hex dump of first sector read */ 636 /* if (io->cSGList) { */ 637 /* if (DevHelp_PhysToVirt(io->pSGList->ppXferBuf, */ 638 /* (USHORT) io->pSGList->XferBufLen, */ 639 /* (PVOID) &p, &mode_sw)) { */ 640 /* printf("MT: failed to convert S/G pointer to virt address\n"); */ 641 /* } else { */ 642 /* phex(p, (int) io->pSGList->XferBufLen, "sector dump, RBA=0x%08lx\n", */ 643 /* io->RBA); */ 644 /* } */ 645 /* } */ 646 631 647 } 632 648 … … 778 794 779 795 rc = ata_cmd(ai, p, d, slot, 0, 780 AP_SGLIST, apt->pSGList, apt-> ppSGLIST,796 AP_SGLIST, apt->pSGList, apt->cSGList, 781 797 AP_ATA_CMD, apt->pControllerCmd, 782 798 AP_WRITE, !(apt->Flags & PT_DIRECTION_IN), -
trunk/src/os2ahci/os2ahci.def
r48 r55 1 1 library os2ahci 2 Description '$@#thi.guten (www.thiguten.de):1.00.201012 02#@OS/2 AHCI Adapter Device Driver'2 Description '$@#thi.guten (www.thiguten.de):1.00.20101214#@OS/2 AHCI Adapter Device Driver' 3 3 protmode 4 4
Note:
See TracChangeset
for help on using the changeset viewer.