Changeset 49


Ignore:
Timestamp:
Dec 3, 2010, 12:30:12 PM (15 years ago)
Author:
markus
Message:

sped up writing (larger buffer)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lbatest/lbatest.c

    r45 r49  
    11/******************************************************************************
    22
    3   lbatest.c - simple test program for os2ahci
     3  lbatest.c - simple (dumb) test program for os2ahci
    44
    55  Writes the actual LBA to each sector on a hard disk. The purpose is to
     
    4141#include <stdio.h>
    4242#include <stddef.h>
     43#include <stdlib.h>
    4344#include <ctype.h>
    4445#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
    4751
    4852/*--- function prototypes ---------------------------------------------------*/
     
    5458int           read_test        (char *drv);
    5559
     60void          signal_handler   (int sig_no);
     61
     62/*--- global data -----------------------------------------------------------*/
     63
     64unsigned long lba_pos;
     65unsigned long first_wrong_sector = 0xffffffff;
     66char mode;
    5667
    5768/*--- start of code ---------------------------------------------------------*/
     
    6374{
    6475  char *drv;
    65   char mode;
    6676  HFILE hf;
    6777
     
    105115  unsigned long action;
    106116  unsigned long cb_written;
    107   char buf[SECTOR_SIZE];
    108117  int rc = 0;
    109118  float gbf = 1024.0 * 1024.0 * 1024.0 / 512.0;
     119  unsigned long i;
     120  unsigned char *wbuf;
     121  char buf[100];
    110122
    111123  /* ask for confirmation, we destroy the drive's contents */
     
    120132                OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR |
    121133                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,
    124135                NULL);
    125136  if (ret != NO_ERROR) {
     
    137148  }
    138149
     150  /* allocate big write buffer */
     151  wbuf = calloc(SECTOR_SIZE, SECTORS_PER_WRITE);
     152
    139153  /* 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    }
    144168    if (ret != NO_ERROR) {
    145169      fprintf(stderr, "\nFailed to write to disk %s, code %d\n", drv, ret);
     
    149173
    150174    /* 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   
    154177  }
    155178
     
    158181  DosDevIOCtl(hf_disk, IOCTL_DISK, DSK_UNLOCKDRIVE, NULL, 0, &action,
    159182              NULL, 0, &cb_written);
    160 
    161183  DosClose(hf_disk);
     184  free(wbuf);
    162185  return rc;
    163186
     
    169192int read_test(char *drv)
    170193{
    171   unsigned long lba;
    172194  unsigned long ret;
    173195  HFILE hf_disk;
     
    200222  }
    201223
     224  /* catch Ctrl+C */
     225  signal(SIGINT, signal_handler);
     226
    202227  /* go... */
    203228  memset(buf, 0x00, sizeof(buf));
    204   for (lba = 0; ; lba++) {
     229  for (lba_pos = 0; ; lba_pos++) {
    205230    ret = DosRead(hf_disk, buf, SECTOR_SIZE, &cb_read);
    206231    if (ret != NO_ERROR) {
     
    210235    }
    211236
    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);
    215240      err_cnt++;
     241      if (first_wrong_sector == 0xffffffff) {
     242        first_wrong_sector = lba_pos;
     243      }
    216244    }
    217245
    218246    /* 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);
    221250    }
    222251  }
     
    226255  DosDevIOCtl(hf_disk, IOCTL_DISK, DSK_UNLOCKDRIVE, NULL, 0, &action,
    227256              NULL, 0, &cb_read);
    228 
    229257  DosClose(hf_disk);
    230258
    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
    232265  return rc;
    233266}
     
    243276         "where mode is either W for writing or R for reading.\n\n"
    244277         "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"
    246279         "In read mode, each sector is read and its address verified.\n");
    247280}
    248281
     282
     283/******************************************************************************
     284 * signal_handler for SIGINT - prints summary to STDOUT
     285 */
     286void 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.