📄 hdtool.c
字号:
FILE * f;
if(ext_ver > 0)
{
for(n = 0; n < LBA_sec_num; n++)
{
printf("Reading LBA block no: %lu -- ", n);
rc1 = rwv_disk_sect(2, drv, 0, 0, 0, 1, rwv_buf, ext_ver, n);
if(rc1 == 0) printf("ok!\n");
else
{
printf("error!\n");
rc++;
if(rc > 10)
{
printf("Errors > 10!\n");
return -1;
}
}
}
return 0;
}
f=fopen(FileName,"w+b");
if(f==NULL)
{
perror(FileName);
return -1;
}
for(i = 0; i < cyl_num; i++)
for(j = 0; j < head_num; j++)
for(k = 1; k <= sec_num; k++)
{
//printf("Reading cyl:%d, head:%d, sector:%d -- ", i, j, k);
rc1 = rwv_disk_sect(2, drv, i, j, k, 1, rwv_buf, 0, 0);
if(rc1 == 0)
{
//printf("ok!\n");
for (l=0;l<0x0200 ;l++ )
{
fprintf(f,"%c",rwv_buf[i]);
printf("%02X ",rwv_buf[i]);
}
//fwrite(rwv_buf,1,0x0200,f);
}
else
{
printf("error!\n");
rc++;
if(rc > 10)
{
fclose(f);
printf("Errors > 10!\n");
return -1;
}
}
}
fclose(f);
return 0;
}
int WriteFloppyFromFile(USGC drv, USGI cyl_num, USGI head_num, USGI sec_num,
int ext_ver, USGL LBA_sec_num,char * FileName)
{
int i, j, k, rc = 0, rc1,l;
USGL n;
FILE * f;
if(ext_ver > 0)
{
for(n = 0; n < LBA_sec_num; n++)
{
printf("Reading LBA block no: %lu -- ", n);
rc1 = rwv_disk_sect(2, drv, 0, 0, 0, 1, rwv_buf, ext_ver, n);
if(rc1 == 0) printf("ok!\n");
else
{
printf("error!\n");
rc++;
if(rc > 10)
{
printf("Errors > 10!\n");
return -1;
}
}
}
return 0;
}
f=fopen(FileName,"rb");
if(f==NULL)
{
perror(FileName);
return -1;
}
for(i = 0; i < cyl_num; i++)
for(j = 0; j < head_num; j++)
for(k = 1; k <= sec_num; k++)
{
//printf("Reading cyl:%d, head:%d, sector:%d -- ", i, j, k);
fread(rwv_buf,1,0x0200,f);
for (l=0;l<0x0200 ;l++ )
{
printf("%02X ",rwv_buf[l]);
}
rc1 = rwv_disk_sect(3, drv, i, j, k, 1, rwv_buf, 0, 0);
if(rc1 == 0)
{
//printf("ok!\n");
}
else
{
printf("error!\n");
rc++;
if(rc > 10)
{
fclose(f);
printf("Errors > 10!\n");
return -1;
}
}
}
fclose(f);
return 0;
}
/* ------------------------------------------------------------------------- */
int read_test_disk(USGC drv, USGI cyl_num, USGI head_num, USGI sec_num,
int ext_ver, USGL LBA_sec_num)
{
int i, j, k, rc = 0, rc1;
USGL n;
if(ext_ver > 0)
{
for(n = 0; n < LBA_sec_num; n++)
{
printf("Reading LBA block no: %lu -- ", n);
rc1 = rwv_disk_sect(2, drv, 0, 0, 0, 1, rwv_buf, ext_ver, n);
if(rc1 == 0) printf("ok!\n");
else
{
printf("error!\n");
rc++;
if(rc > 10)
{
printf("Errors > 10!\n");
return -1;
}
}
}
return 0;
}
for(i = 0; i < cyl_num; i++)
for(j = 0; j < head_num; j++)
for(k = 1; k <= sec_num; k++)
{
printf("Reading cyl:%d, head:%d, sector:%d -- ", i, j, k);
rc1 = rwv_disk_sect(2, drv, i, j, k, 1, rwv_buf, 0, 0);
if(rc1 == 0)
{
printf("ok!\n");
}
else
{
printf("error!\n");
rc++;
if(rc > 10)
{
printf("Errors > 10!\n");
return -1;
}
}
}
return 0;
}
/* ------------------------------------------------------------------------- */
int hd_clone(USGC drv1, USGI cyl_num1, USGI head_num1, USGI sec_num1,
int ext_ver1, USGL LBA_sec_num1,
USGC drv2, USGI cyl_num2, USGI head_num2, USGI sec_num2,
int ext_ver2, USGL LBA_sec_num2,
USGL LBA_begin, USGL LBA_end)
{
int i, j, k, r_err_num = 0, w_err_num = 0, rc1, rc2, disp = 0;
USGI cyl_num, head_num, sec_num;
USGL LBA_sec_num, n;
time_t timer;
struct tm *tms;
char time_buf1[20], time_buf2[20];
timer = time(NULL);
tms = localtime(&timer);
k = sprintf(time_buf1, "%4d-%02d-%02d %02d:%02d:%02d", tms->tm_year+1900,
tms->tm_mon+1, tms->tm_mday, tms->tm_hour, tms->tm_min,
tms->tm_sec);
time_buf1[k] = 0;
if(ext_ver1 != ext_ver2)
{
printf("Error: ext_ver1 != ext_ver2\n");
return -1;
}
cyl_num = min(cyl_num1, cyl_num2);
head_num = min(head_num1, head_num2);
sec_num = min(sec_num1, sec_num2);
if(sec_num > 63)
{
printf("Error: sec_num > 63\n");
return -1;
}
if(ext_ver1 > 0)
{
LBA_sec_num = min(LBA_sec_num1, LBA_sec_num2);
LBA_end = min(LBA_end, LBA_sec_num);
for(n = LBA_begin; n < LBA_end; disp++)
{
if(disp <= 0)
printf("\rCopy from LBA block no: %lu, sectors: %d -- ", n, sec_num);
rc1 = rwv_disk_sect(2, drv1, 0, 0, 0, sec_num, rwv_buf, ext_ver1, n);
if(rc1 == 0)
{
rc2 = rwv_disk_sect(3, drv2, 0, 0, 0, sec_num, rwv_buf, ext_ver2, n);
if(rc2 == 0)
{
if(disp <= 0) printf("ok! ......");
}
else
{
w_err_num++;
if(disp > 0)
printf("\nCopy from LBA block no: %lu, sectors: %d -- ",
n, sec_num);
printf("write error!\n");
}
}
else
{
r_err_num++;
if(disp > 0)
printf("\nCopy from LBA block no: %lu, sectors: %d -- ", n, sec_num);
printf("read error!\n");
}
if(r_err_num > 5)
{
printf("Read errors > 5!\n");
return -1;
}
if(w_err_num > 5)
{
printf("Write errors > 5!\n");
return -1;
}
n += sec_num;
if(disp >= 300) disp = -1;
if(n >= (LBA_end - sec_num - 1)) disp = -1;
}
}
else
{
for(i = 0; i < cyl_num; i++)
for(j = 0; j < head_num; j++)
{
k = 1;
printf("Copy from cyl:%d, head:%d, sectors:%d -- ", i, j, sec_num);
rc1 = rwv_disk_sect(2, drv1, i, j, k, sec_num, rwv_buf, 0, 0);
if(rc1 == 0)
{
rc2 = rwv_disk_sect(3, drv2, i, j, k, sec_num, rwv_buf, 0, 0);
if(rc2 == 0) printf("ok!\n");
else
{
w_err_num++;
printf("write error!\n");
}
}
else
{
r_err_num++;
printf("read error!\n");
}
if(r_err_num > 5)
{
printf("Read errors > 5!\n");
return -1;
}
if(w_err_num > 5)
{
printf("Write errors > 5!\n");
return -1;
}
}
}
printf("\nTotal errors: Read = %d, write = %d\n", r_err_num, w_err_num);
timer = time(NULL);
tms = localtime(&timer);
k = sprintf(time_buf2, "%4d-%02d-%02d %02d:%02d:%02d", tms->tm_year+1900,
tms->tm_mon+1, tms->tm_mday, tms->tm_hour, tms->tm_min,
tms->tm_sec);
time_buf2[k] = 0;
printf("Time: from %s to %s\n", time_buf1, time_buf2);
return 0;
}
/* ------------------------------------------------------------------------- */
int wrt_buf2file(char *filename, USGC *buf, USGI bytes)
{
FILE *fp;
if((fp = fopen(filename, "wb")) == NULL)
{
printf("Create file error!\n");
return -1;
}
if(fwrite(buf, 1, bytes, fp) != bytes)
{
printf("Write file error!\n");
fclose(fp);
return -1;
}
if(fclose(fp) != 0)
{
printf("Close file error!\n");
return -1;
}
printf("Ok!\n");
return 0;
}
/* ------------------------------------------------------------------------- */
int read_file2buf(char *filename, USGC *buf, USGI bytes)
{
FILE *fp;
if((fp = fopen(filename, "rb")) == NULL)
{
printf("Open file error!\n");
return -1;
}
if(fread(buf, 1, bytes, fp) != bytes)
{
printf("Read file error!\n");
fclose(fp);
return -1;
}
if(fclose(fp) != 0)
{
printf("Close file error!\n");
return -1;
}
printf("Ok!\n");
return 0;
}
/* ------------------------------------------------------------------------- */
void disp_hex(USGC *buf, int len)
{
USGC dispstr[8192];
DbgOutStrA(dispstr, buf, len, "", 4);
printf("%s", dispstr);
}
/* ------------------------------------------------------------------------- */
int sprintf_end(void *buffer, void *fmt, ...)
/*
sprintf to buffer end
M.L.Y 1999.6.2
*/
{
char tmpstr1[8192];
va_list arg_ptr;
va_start(arg_ptr, fmt);
vsprintf(tmpstr1, fmt, arg_ptr);
va_end(arg_ptr);
strcat(buffer, tmpstr1);
return 0;
}
/* ------------------------------------------------------------------------- */
int DbgOutStrA(USGC *buf, USGC *str, int str_len, char *ptr_left,
int ptr_len)
/*
Output an ASCII code string by DEBUG format to the buffer
Return: 0
M.L.Y 1995, 1999
*/
{
int j, k, ccpair = 0, ptr;
USGC buf1[1024];
buf[0] = '\0';
for(ptr = 0; ptr < str_len; ) /* pointer of this line of str */
{
if(str_len - ptr >= 16) k = 16; /* length of this line of str */
else k = str_len - ptr;
sprintf_end(buf, "%s", ptr_left);
sprintf_end(buf, "%0*X ", ptr_len, ptr);
for(j = 0; j < 16; j++) /* byte order of this line */
{
if(j < k)
{
if(j == 8) sprintf_end(buf, "-%02X", str[ptr + j]);
else sprintf_end(buf, " %02X", str[ptr + j]);
}
else sprintf_end(buf, " ");
}
sprintf_end(buf, " ");
buf1[0] = '\0';
for(j = 0; j < 16; j++)
{
if(j >= k) break;
if(j == 0 && ccpair > 0)
{
ccpair = 0;
goto dscc_dispul;
}
if(ccpair == 0)
{
if(str[ptr + j] > 0xA0 && str[ptr + j] < 0xFF)
{
if(str[ptr + j + 1] > 0xA0 && str[ptr + j + 1] < 0xFF)
{
ccpair = 1; /* DBCS left byte */
goto dscc_dispch;
}
goto dscc_dispdot;
}
if(str[ptr + j] >= 0x20 && str[ptr + j] < 0x80) goto dscc_dispch;
goto dscc_dispdot;
}
ccpair = 0; /* DBCS right byte */
goto dscc_dispch;
dscc_dispul: /* use the underline character instead */
/* sprintf_end(buf1, "_"); */
sprintf_end(buf1, "%c", 0x5F);
goto dscc_cont1;
dscc_dispch:
sprintf_end(buf1, "%c", str[ptr + j]);
goto dscc_cont1;
dscc_dispdot:
/* sprintf_end(buf1, "."); */
sprintf_end(buf1, "%c", 0x2E);
goto dscc_cont1;
dscc_dispblk:
/* sprintf_end(buf1, " "); */
sprintf_end(buf1, "%c", 0x20);
dscc_cont1:
;
}
if(ccpair > 0 && k == 16)
{
sprintf_end(buf1, "%c", str[ptr + 16]);
/* output the first byte of next line (the DBCS right byte) */
}
strcat((char *)buf, (char *)buf1);
sprintf_end(buf, "\n");
ptr = ptr + 16;
}
return 0;
}
/* End of file */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -