Mail Archives: djgpp/2003/04/11/19:30:43
"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 -