delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/04/11/19:30:43

From: "Matthew Smith" <matt AT the-good-stuff DOT freeserve DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Sector Editor?
Date: Sat, 12 Apr 2003 00:28:43 +0100
Lines: 101
Message-ID: <b77j3k$abn$1@news8.svr.pol.co.uk>
References: <b76ti5$fni$1 AT newsg4 DOT svr DOT pol DOT co DOT uk>
NNTP-Posting-Host: 62.137.126.100
X-Trace: news8.svr.pol.co.uk 1050103732 10615 62.137.126.100 (11 Apr 2003 23:28:52 GMT)
NNTP-Posting-Date: 11 Apr 2003 23:28:52 GMT
X-Complaints-To: abuse AT theplanet DOT net
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Matthew Smith" <matt AT the-good-stuff DOT freeserve DOT co DOT uk> wrote in message
news:b76ti5$fni$1 AT newsg4 DOT svr DOT pol DOT co DOT uk...
> Does anyone have source for a disk sector editor? With FAT32 FAT/DIR
> support preferably.
>
> Failing this, can someone show me how to read and write sectors on
an
> LBA drive using INT 13h extensions?
>

Here's my first attempt. I can't believe I'm the first person to do
this though.
Would a patch for the biosdisk() function be welcome? (or a matching
biosdisk_lba() func anyway, as the parameters would be different)



#include <bios.h>
#include <go32.h>
#include <dpmi.h>
#include <stdio.h>


/* Structure for passing parameters to Int13h extensions (from RBIL
Table #00272) */

typedef struct dap_t
{
 char dap_len __attribute__((packed));  /* length of dap, 0x10 or 0x18
*/
 char dap_rsvd __attribute__((packed));  /* 0 byte */
 short num __attribute__((packed));   /* number of blocks */
 void * buf __attribute__((packed));   /* flat 32 address */
 long long blk __attribute__((packed));  /* start block as 64 bit val
*/
 long long buf_64 __attribute__((packed)); /* buf as 64 bit address */
} dap_t;


int int13h_has_extensions=0;

int lba_test_13h_extensions(void) {
__dpmi_regs r;
 r.h.ah = 0x41;
 __dpmi_int(0x13,&r);
 int13h_has_extensions = (r.x.flags & 1) ? 0 : 1;
 return int13h_has_extensions;
}

void get_drive_params(int drive) {

}


int lba_read_sector(int drive, long long sector, void * buffer) {

 if (int13h_has_extensions)
 {
 __dpmi_regs r;
 dap_t dap;

  dap.dap_len = 0x10h;
  dap.dap_rsvd = 0;
  dap.num = 1;  /* one sector */
  dap.buf = __tb + 0x10h;  /* data buffer after dap */
  dap.blk = sector;  /* first sector */

  dosmemput( &dap, 0x10, __tb);   /* copy dap to real mode for int13h
*/

  r.h.ah = 0x42;    /* lba read */
  r.h.dl = drive;
  r.x.si = __tb & 0x0f;
  r.x.ds = __tb >>4 ;
  __dpmi_int(0x13,&r);

  dosmemget (__tb + 0x10, 512 , buffer);  /* copy from real mode
buffer to prog buffer */

  return r.h.ah;  /*return error code */

 } else {
/*
  diskinfo_t di = lba_2_di(drive,sector);  // convert lba to chs
  return biosdisk( 0x02, drive, di.head, di.track, di.sector, 1,
buffer);
*/
 }
}

int main(int argc, char *argv[])
{
 printf("Hello, world\n");

 return 0;
}




- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019