back to fun with pread.c

Well I know this topic keeps comming up over & over that the pread.c that I had used to build my Xenix on Qemu is long lost.

Anyways someone else was asking me for it, and I stumbled accross this Microsoft Memo:

http://support.microsoft.com/kb/100027

which means the device name I was listing was wrong… I’m unsure if it means in 2003 it change from what it was since 1991….

Anyways here is my new ‘pread’.

#include <stdio.h>
#include <stdlib.h>

define BUFFSIZE 1024*1024
void main(void)
{
FILE *disk;
FILE *ofile;
int disknumber;
char fname[255];
char oname[255];
char *buffer;
int rc;
int pass;
buffer=(char)malloc(BUFFSIZE); if(buffer==(char)NULL)
{printf("\nError allocating buffer!!\n");return;}
printf("please tell me the disk NUMBER that you want to read\n");
printf("for \\.\PhysicalDrive1 just answer 1\n\n:");
memset(fname,0x0,sizeof(fname));
scanf("%d",&disknumber);
sprintf(fname,"\\.\PhysicalDrive%d",disknumber);
printf("reading the device %s\n",fname);
disk=fopen(fname,"rb");
memset(oname,0x0,sizeof(oname));
printf("\nWhat is the output file name?\n\n:");
scanf("%s",oname);
ofile=fopen(oname,"wb");
if(ofile==NULL){printf("\n\nERROR with %s\n",oname);return;}
if(disk==NULL){printf("\n\nERROR with disk %s\n",fname);return;}
rc=5;
pass = 0;
while(rc!=0)
{
memset(buffer,0x0,sizeof(buffer));
rc=fread(buffer,1,BUFFSIZE,disk);
printf("\r%d\t%d:Megabytes processed",rc,pass);
fwrite(buffer,1,rc,ofile);
pass++;
}
fclose(disk);
fclose(ofile);
printf("\n\n\nDone!%c",7);
}

3 thoughts on “back to fun with pread.c

Leave a Reply