Changeset 49
- Timestamp:
- Dec 3, 2010, 12:30:12 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lbatest/lbatest.c
r45 r49 1 1 /****************************************************************************** 2 2 3 lbatest.c - simple test program for os2ahci3 lbatest.c - simple (dumb) test program for os2ahci 4 4 5 5 Writes the actual LBA to each sector on a hard disk. The purpose is to … … 41 41 #include <stdio.h> 42 42 #include <stddef.h> 43 #include <stdlib.h> 43 44 #include <ctype.h> 44 45 #include <string.h> 45 46 #define SECTOR_SIZE 512 46 #include <signal.h> 47 48 #define SECTOR_SIZE 512 49 #define SECTORS_PER_WRITE 200 50 47 51 48 52 /*--- function prototypes ---------------------------------------------------*/ … … 54 58 int read_test (char *drv); 55 59 60 void signal_handler (int sig_no); 61 62 /*--- global data -----------------------------------------------------------*/ 63 64 unsigned long lba_pos; 65 unsigned long first_wrong_sector = 0xffffffff; 66 char mode; 56 67 57 68 /*--- start of code ---------------------------------------------------------*/ … … 63 74 { 64 75 char *drv; 65 char mode;66 76 HFILE hf; 67 77 … … 105 115 unsigned long action; 106 116 unsigned long cb_written; 107 char buf[SECTOR_SIZE];108 117 int rc = 0; 109 118 float gbf = 1024.0 * 1024.0 * 1024.0 / 512.0; 119 unsigned long i; 120 unsigned char *wbuf; 121 char buf[100]; 110 122 111 123 /* ask for confirmation, we destroy the drive's contents */ … … 120 132 OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR | 121 133 OPEN_FLAGS_WRITE_THROUGH | OPEN_FLAGS_NO_CACHE | 122 OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYREADWRITE | 123 OPEN_ACCESS_WRITEONLY, 134 OPEN_SHARE_DENYREADWRITE | OPEN_ACCESS_WRITEONLY, 124 135 NULL); 125 136 if (ret != NO_ERROR) { … … 137 148 } 138 149 150 /* allocate big write buffer */ 151 wbuf = calloc(SECTOR_SIZE, SECTORS_PER_WRITE); 152 139 153 /* go... */ 140 memset(buf, 0x00, sizeof(buf)); 141 for (lba = 0; ; lba++) { 142 memcpy(buf, &lba, sizeof(lba)); 143 ret = DosWrite(hf_disk, buf, SECTOR_SIZE, &cb_written); 154 for (lba = 0; ; lba += SECTORS_PER_WRITE) { 155 156 /* prepare buffer; set the first 4 bytes of each sector 157 * to its LBA */ 158 for (i = 0; i < SECTORS_PER_WRITE; i++) { 159 *((unsigned long *)(wbuf + i * SECTOR_SIZE)) = lba + i; 160 } 161 162 /* write buffer to disk */ 163 ret = DosWrite(hf_disk, wbuf, SECTOR_SIZE * SECTORS_PER_WRITE, &cb_written); 164 if (cb_written < SECTOR_SIZE * SECTORS_PER_WRITE) { 165 /* done?! */ 166 goto cleanup; 167 } 144 168 if (ret != NO_ERROR) { 145 169 fprintf(stderr, "\nFailed to write to disk %s, code %d\n", drv, ret); … … 149 173 150 174 /* write progress */ 151 if (lba % 100 == 0) { 152 printf("\r%dk sectors written (%0.02f GB)", lba / 1000, (float)lba / gbf); 153 } 175 printf("\r%dk sectors written (%0.02f GB)", lba / 1000, (float)lba / gbf); 176 154 177 } 155 178 … … 158 181 DosDevIOCtl(hf_disk, IOCTL_DISK, DSK_UNLOCKDRIVE, NULL, 0, &action, 159 182 NULL, 0, &cb_written); 160 161 183 DosClose(hf_disk); 184 free(wbuf); 162 185 return rc; 163 186 … … 169 192 int read_test(char *drv) 170 193 { 171 unsigned long lba;172 194 unsigned long ret; 173 195 HFILE hf_disk; … … 200 222 } 201 223 224 /* catch Ctrl+C */ 225 signal(SIGINT, signal_handler); 226 202 227 /* go... */ 203 228 memset(buf, 0x00, sizeof(buf)); 204 for (lba = 0; ; lba++) {229 for (lba_pos = 0; ; lba_pos++) { 205 230 ret = DosRead(hf_disk, buf, SECTOR_SIZE, &cb_read); 206 231 if (ret != NO_ERROR) { … … 210 235 } 211 236 212 if (*((unsigned long*) buf) != lba) {213 fprintf(stderr, "\nFailure: read %d from sector %d\n",214 *((unsigned long*) buf), lba);237 if (*((unsigned long*) buf) != lba_pos) { 238 printf("\nWrong sector number: read %d from sector %d\n", 239 *((unsigned long*) buf), lba_pos); 215 240 err_cnt++; 241 if (first_wrong_sector == 0xffffffff) { 242 first_wrong_sector = lba_pos; 243 } 216 244 } 217 245 218 246 /* progress */ 219 if (lba % 100 == 0) { 220 printf("\r%dk sectors read (%0.02f GB)", lba / 1000, (float)lba / gbf); 247 if (lba_pos % 100 == 0) { 248 printf("\r%dk sectors read (%0.02f GB)", lba_pos / 1000, 249 (float) lba_pos / gbf); 221 250 } 222 251 } … … 226 255 DosDevIOCtl(hf_disk, IOCTL_DISK, DSK_UNLOCKDRIVE, NULL, 0, &action, 227 256 NULL, 0, &cb_read); 228 229 257 DosClose(hf_disk); 230 258 231 printf("Found %d logical errors.\n", err_cnt); 259 /* print summary */ 260 printf("Found %d logical errors\n", err_cnt); 261 if (first_wrong_sector != 0xffffffff) { 262 printf("First wrong sector was %u.\n", err_cnt, first_wrong_sector); 263 } 264 232 265 return rc; 233 266 } … … 243 276 "where mode is either W for writing or R for reading.\n\n" 244 277 "In write mode, this program COMPLETELY DESTROYS ALL DATA on the specified\n" 245 " disc. It writes the address of each sector to the sector itself.\n\n"278 "partition/disc. It writes the address of each sector to the sector itself.\n\n" 246 279 "In read mode, each sector is read and its address verified.\n"); 247 280 } 248 281 282 283 /****************************************************************************** 284 * signal_handler for SIGINT - prints summary to STDOUT 285 */ 286 void signal_handler(int sig_no) 287 { 288 289 if (sig_no == SIGINT && mode == 'R') { 290 /* read mode interrupted; show summary */ 291 printf("\n\nLast block read: %u\n", lba_pos); 292 if (first_wrong_sector != 0xffffffff) { 293 printf("First wrong sector: %u\n", first_wrong_sector); 294 } else { 295 printf("All sectors read ok\n"); 296 } 297 } 298 299 exit(0); 300 301 }
Note:
See TracChangeset
for help on using the changeset viewer.