Category : UNIX Files
Archive   : MINIX15D.ZIP
Filename : RAWRITE.C
rawrite.c Write a binary image to a 360K diskette.
By Mark Becker
Usage:
MS-DOS prompt> RAWRITE
And follow the prompts.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#define FALSE 0
#define TRUE (!FALSE)
#define SECTORSIZE 512
#define NSECTORS 9
#define NCYLINDERS 40
#define NHEADS 2
#define DISKBUFSIZE (NSECTORS*SECTORSIZE)
int done;
/*
Catch ^C and ^Break.
*/
int handler(void)
{
done = TRUE;
return(0);
}
void main(void)
{
char fname[MAXPATH];
unsigned char buffer[DISKBUFSIZE];
int fdin, drive, head, track, status;
puts("RaWrite - Write disk file to raw floppy diskette\n");
ctrlbrk(handler);
printf("Enter source file name: ");
scanf("%s", fname);
_fmode = O_BINARY;
if ((fdin = open(fname, O_RDONLY)) <= 0) {
perror(fname);
exit(1);
}
printf("Enter destination drive: ");
scanf("%s", fname);
drive = fname[0];
drive = (islower(drive) ? toupper(drive) : drive) - 'A';
printf("Please insert a formatted 360K diskette into ");
printf("drive %c: and press -ENTER- :", drive + 'A');
while (bioskey(1) == 0) ; /* Wait... */
if ((bioskey(0) & 0x7F) == 3) exit(1); /* Check for ^C */
putchar('\n');
done = FALSE;
biosdisk(0, drive, 0, 0, 0, 0, 0); /* Reset drive */
/*
* Would like to make sure this diskette is a DS/DD type. Try reading
* from sector 10. If successful then this isn't the right kind of
* diskette.
*/
status = biosdisk(2, drive, 0, 0, 10, 1, buffer);
switch (status) {
case 0: printf("Diskette is not a 360K type.\n"); exit(1);
case 4: break;
default: printf("Drive error (open door, bad diskette, etc)\n");
printf("Correct problem and re-run.\n");
exit(1);
}
if (status == 0) {
printf("Diskette not a 360K DS/DD type.\n");
exit(1);
}
printf("Writing image to drive %c:. Press ^C to abort.\n", drive+'A');
/*
* Start writing data. Note: For 360K DS/DD diskettes there are 9
* sectors/track, two tracks per cylinder and 40 cylinders.
*/
for (track = 0; track < NCYLINDERS && !done; ++track) {
for (head = 0; head < NHEADS && !done; ++head) {
printf("Track:%2d Head:%d \r", head, track);
if (read(fdin, buffer, DISKBUFSIZE) <= 0) done = TRUE;
else {
status = biosdisk(3, drive, head, track, 1, NSECTORS, buffer);
if (status != 0) {
fprintf(stderr, "Write failed. Error code %d\n", status);
done = TRUE;
}
}
}
}
if (eof(fdin)) {
printf("\nDone.\n");
biosdisk(2, drive, 0, 0, 1, 1, buffer); /* Retract head */
}
} /* end main */
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/