Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
what code can be used to check for write protection. none of these checks show any difference between write protect on or off:
}int Check_FloppyDrive ()
{
struct diskinfo_t di;
unsigned short status1;
unsigned short status2;
unsigned short status3;di.drive = di.head = di.track = di.sector = 0;
di.nsectors = 1;
di.buffer = NULL;
status1 = _bios_disk( _DISK_STATUS, &di );
status2 = _bios_disk( _DISK_VERIFY, &di );
status3 = _bios_disk( _DISK_WRITE, &di );return status;
}

Here's an example I've just modified for this purpose.
WARNING!!!
Try it on an empty diskette; when you have tried it, format the disk again.
This program (it's simply an example) overwrites the FAT.#include
#includeint main(void)
{
struct diskinfo_t dinfo;
int result;
static char dbuf[512];dinfo.drive = 0; /* drive number for A: */
dinfo.head = 0; /* disk head number */
dinfo.track = 0; /* track number */
dinfo.sector = 1; /* sector number */
dinfo.nsectors = 1; /* sector count */
dinfo.buffer = dbuf; /* data buffer */printf("Attempting to write to drive A:\n");
result = _bios_disk(_DISK_WRITE, &dinfo);
if ((result & 0x0300) == 0)
{
printf("Disk write to A: successful.\n");
}
else
printf("Write protected disk\n");
return 0;
}

thanks but is there a way to check for write protection or a bad disk without writing to it? i want my code to be able to use the floppy right after the check. DISK_STATUS or DISK_VERIFY doesn't do it. DISK_WRITE seems dangerous.

I've tried with _DISK_VERIFY: yes, it works. Just replace _DISK_WRITE with _DISK_VERIFY in the example and you'll see that it works; if it doesn't, let me know.

I tried DISK_VERIFY on a Jaz drive and it doesn't know the difference between a write protected disk or one that is not write protected. I am in need of some code that I can use in an embedded aplication to detect status of Jaz disk.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |