Changeset 50


Ignore:
Timestamp:
Dec 3, 2010, 6:56:33 PM (15 years ago)
Author:
markus
Message:

started rewrite of lbatest (old version is limited to 2GB...)

File:
1 edited

Legend:

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

    r49 r50  
    4747
    4848#define SECTOR_SIZE        512
    49 #define SECTORS_PER_WRITE  200
     49#define SECTORS_PER_WRITE  32
    5050
    5151
     
    6262/*--- global data -----------------------------------------------------------*/
    6363
    64 unsigned long lba_pos;
    65 unsigned long first_wrong_sector = 0xffffffff;
    66 char mode;
     64DEVICEPARAMETERBLOCK dev_parms;
     65
    6766
    6867/*--- start of code ---------------------------------------------------------*/
     
    9594  }
    9695
     96  /* determine physical drive layout */
     97  get_drive_layout(drv);
     98
    9799  if (mode == 'W') {
    98100    return write_test(drv);
     
    104106  return 0;
    105107}
     108
     109/******************************************************************************
     110 * determine CHS layout of the drive we're running on
     111 */
     112void get_drive_layout(char *disk)
     113{
     114 
     115
     116}
     117
    106118
    107119/******************************************************************************
     
    120132  unsigned char *wbuf;
    121133  char buf[100];
     134  unsigned long cbtake = SECTOR_SIZE * SECTORS_PER_WRITE;
     135  unsigned long cb;
    122136
    123137  /* ask for confirmation, we destroy the drive's contents */
     
    156170    /* prepare buffer; set the first 4 bytes of each sector
    157171     * to its LBA */
    158       for (i = 0; i < SECTORS_PER_WRITE; i++) {
    159         *((unsigned long *)(wbuf + i * SECTOR_SIZE)) = lba + i;
     172    for (i = 0; i < SECTORS_PER_WRITE; i++) {
     173      *((unsigned long *)(wbuf + i * SECTOR_SIZE)) = lba + i;
     174    }
     175
     176    /* write buffer to disk */
     177    cb = cbtake;
     178    while (cb) {
     179      ret = DosWrite(hf_disk, wbuf + cbtake - cb, cb, &cb_written);
     180      if (ret != NO_ERROR) {
     181        fprintf(stderr, "\nFailed to write to disk %s, code %d\n", drv, ret);
     182        rc = -1;
     183        goto cleanup;
    160184      }
    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     }
    168     if (ret != NO_ERROR) {
    169       fprintf(stderr, "\nFailed to write to disk %s, code %d\n", drv, ret);
    170       rc = -1;
    171       goto cleanup;
     185      if (cb_written >= cb) {
     186        break;
     187      }
     188
     189      if (cb_written == 0) {
     190        /* what the heck... */
     191        fprintf(stderr, "\nWrote 0 bytes of %u, no error return code\n",
     192                cb);
     193        ret = DosSetFilePtr(hf_disk, lba * SECTOR_SIZE + cbtake - cb,
     194                            FILE_BEGIN, &action);
     195        if (ret != NO_ERROR) {
     196          fprintf(stderr, "Failed to set file pointer after writing "
     197                  "0 bytes: %d\n", ret);
     198          goto cleanup;
     199        }
     200      }
     201      cb -= cb_written;
    172202    }
    173203
Note: See TracChangeset for help on using the changeset viewer.