Subversion Repositories shark

Rev

Blame | Last modification | View Log | RSS feed

/*
 *
 *
 *
 */


#include <ll/i386/cons.h>
#include <drivers/keyb.h>

#include <fs/bdevinit.h>
#include <fs/bdev.h>

#include <string.h>

#include "common.h"

#define DISKDEVICE "ide/hda1"
#define BLOCKNUMBER 58549

__uint8_t buffer[2048] __attribute__ ((aligned (4)));

extern char *ide_error_msg[];

int main(int argc,char *argv[])
{
  __dev_t dev;
  __blkcnt_t blk;
  int res;
  //  int c;

  showmessage("This test tries to read a block from the first hard disk\n"
              "and then it tries to write it to disk\n"
              "Press [CTRL-C] to abort...");
 
  dev=bdev_find_byname(DISKDEVICE);
  if ((int)dev<0) {
    cprintf("Can't find device to operate with\n");
    cprintf("%s not present!\n",DISKDEVICE);
    return -1;
  }
  cprintf("Using device %s (dev=%04x)\n",DISKDEVICE,dev);
 
  blk=BLOCKNUMBER;

  cprintf("Reading block %li...\n",(long)blk);
  memset(buffer,0xff,sizeof(buffer));
  res=bdev_read(dev,blk,buffer);
  cprintf("Result %i\n",res);
  //cprintf("Soft reset done %i\n",ide[0].errors);
  if (res!=0) {
    cprintf("  %s\n",(char*)ide_error_msg[-res]);
    return -1;
  }
  debug_dump_buffer(buffer,64);

  cprintf("Writing block %li...\n",(long)blk);
  res=bdev_write(dev,blk,buffer);
  cprintf("Result %i\n",res);
  //cprintf("Soft reset done %i\n",ide[0].errors);
  if (res!=0) {
    cprintf("  %s\n",(char*)ide_error_msg[-res]);
  }

  waitend();
  return 0;
}