📄 minito.c
字号:
#include <dos.h>
#include <io.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <dir.h>
#include <bios.h>
#include <conio.h>
/*#include "global.h" */
/*#include "zlib.h" */
#define MAX_DRIVE_NUM 20
#define MAX_PARTITION_NUM 100
#define MAX_TASK_NUM 10
#define DEFAULT_EVERY_VOLUME_MB 2047 /* The byte maximum of every file is 2048<FAT16>,4096<FAT32> MBs in MS-DOS */
#define DEFAULT_COMPRESS_LEVEL 6
#define ARGUMENT_DISK 1
#define ARGUMENT_PARTITION 2
#define ARGUMENT_DOSLETTER 3
#define ARGUMENT_IMAGE 4
#define PRINT_DRIVE_ALL -2
#define PRINT_DRIVE_FLOPPY -3
#define PRINT_PARTITION_ALL 0
#define PRINT_PARTITION_DOSLETTER 1
#define PRINT_PARTITION_FAT 2
#define PRINT_PARTITION_NTFS 3
#define PRINT_PARTITION_FAT_NTFS 4
#define PRINT_PARTITION_LINUX 5
#define PRINT_PARTITION_NO_HIDDEN 6
#define PRINT_PARTITION_NO_ZERO 7
#define PRINT_PARTITION_NO_ZERO_HIDDEN 8
#define PRINT_PARTITION_FLOPPY 9
#define INVALID_INDEX -1
#define INVALID_MODE -1
#define INVALID_TARGET -1
/*#define SWAP_FLAG -2 */
#define ALL_OR_THIS_TYPE -2
#define DISK_BUF_BYTE 65535
#define COMPRESS_DECOMPRESS_BUF_BYTE 65535
#define NTFSPRO 1
#define IFS 2
#define DPT 0
#define DBR 1
#define FAT 2
#define PRINTFILE 3
#define MAX_BUF_BYTE 65535
/*#define MAX_COMPRESS_BYTE 61440*/
#define MAX_SECTOR_BUF_BYTE /*64512 */ 61440
#define SAVE 0
#define RESTORE 1
#define COMPARE 2
#define REPLACE 3
#define PRINT 4
#define MAX_FAT32_VOL_SEARCH 3UL
char nextDOSletter=0;
int nextLetterNumber=0;
char miniTOtag[]="miniTO_GOTOmsdos\0";
char miniTOCMOStag[]="miniTOCMOS_GOTOmsdos\0";
/*
void help()
{
clrscr();
printf("\n");
printf("miniTO DPT/DBR/FAT/CMOS Backup Tool Version 1.8a\n");
printf("Copyright(c) by GOTOmsdos 2007\n");
printf("EMail: tdaim@sina.com\n");
printf("\n");
printf("Some common arguments:\n");
printf(" x:y = drive:partition, both begin from 1\n");
printf(" e.g. 1:2(drive 1 partition 2)\n");
printf(" floppy unsupported\n");
printf(" ?: = DOS disk letter, e.g. D:\n");
printf(" -ntfspro = support DOS letters after ntfspro\n");
printf(" -ifs = ... ifs\n");
printf(" -nohp = not get hard drive parameter\n");
printf(" -floppy = support floppy\n");
printf(" file = file to do\n");
printf("Press any to continue...");
getch();
clrscr();
printf("\n");
printf("Show Drives/Partitions info\n");
printf("Syntax:\n");
printf("miniTO -D|P[argument] [-ntfspro|ifs] [-nohp] [-floppy] [-vol]\n");
printf("\n");
printf(" -D = show all Drives\n");
printf(" -Dn = Show Drive n\n");
printf(" -Da|floppy = show all floppy Drives\n");
printf(" -P = show all Partitions\n");
printf(" -Pa|floppy = show all floppy partitions\n");
printf(" -Pf|fat = show all fat Partitions\n");
printf(" -Pn|ntfs = show all ntfs Partitions\n");
printf(" -Pfn|fatntfs = show all fat&ntfs Partitions\n");
printf(" -Pl|linux = show all linux Partitions\n");
printf(" -Pnoz|nozero = not show all 0x00-ID Partitions\n");
printf(" -Pnoh|nohidden = not show all hidden Partitions\n");
printf(" -Pnozh|nozerohidden = not show all 0x00-ID&hidden Partitions\n");
printf(" -Pn = show all Partitions of drive n\n");
printf(" -Px:y = show Partition y of drive x\n");
printf(" -P: = show all Partitions with DOS letter\n");
printf(" -vol = volume prior to label\n");
printf("Press any to continue...");
getch();
clrscr();
printf("Do DPT&DBR of all partitions of all/one drive(s) (floppy unsupported)\n");
printf("Syntax:\n");
printf("miniTO -Sall|Rall|Call [n] file [-nohp]\n");
printf("\n");
printf(" -Sall = Save DPT & DBR of all partitions to file\n");
printf(" -Rall = Restore ... from ...\n");
printf(" -Call = Compare ... with ...\n");
printf(" n = No. drive to do\n");
printf("\n");
printf("Do DPT/DBR/FAT (floppy unsupported)\n");
printf("Syntax:\n");
printf("miniTO -SDPT|SDBR|SFAT x:y|?: file [-ntfspro|ifs] [-nohp]\n");
printf("\n");
printf(" -SDPT = Save DPT to file\n");
printf(" -SDBR = ... DBR ...\n");
printf(" -SFAT = ... FAT ...\n");
printf("\n");
printf("Syntax:\n");
printf("miniTO -R|C file [-nohp]\n");
printf(" -FAT2|DBR2 [-nohp]\n");
printf("\n");
printf(" -R = Restore DPT/DBR/FAT from file\n");
printf(" -C = Compare ... with ...\n");
printf(" -FAT2 = Replace FAT 1 with FAT 2\n");
printf(" -DBR2 = Replace DBR 1 with DBR 2\n");
printf("Press any to continue...");
getch();
clrscr();
printf("\n");
printf("Do CMOS\n");
printf("Syntax:\n");
printf("miniTO -SCMOS|RCMOS|CCMOS file\n");
printf(" -CMOSkey\n");
printf("\n");
printf(" -SCMOS = Save CMOS to file\n");
printf(" -RCMOS = Restore ... from ...\n");
printf(" -CCMOS = Compare ... with ...\n");
printf(" -CMOSkey = Generate CMOS key\n");
printf("\n");
printf("Show x:y to|from ?: (floppy unsupported)\n");
printf("Syntax:\n");
printf("miniTO -Turn x:y|?: [-ntfspro|ifs] [-nohp]\n");
printf("\n");
printf(" -Turn = show x:y to|from ?:\n");
}
*/
void help()
{
clrscr();
printf("\n");
printf(" miniTO MBR/BOOT/FAT/CMOS Tool 1.0 Copyright(c) GOTOmsdos tdaim@sina.com\n");
printf(" miniTO \n [/?|/H]\n");
printf(" [/D[.]] [/P[...]] [/V] [Common]\n");
printf(" /S|/R|/E|/C|/L [n|n:n|?:] [/MBR|/BOOT|/FAT|/CMOS] [/A] [/Fxx] [/NoP] [/Y]\n");
printf(" [Common]\n");
printf(" /T n:n|?: [Common]\n");
printf(" /CMOSKEY\n");
printf(" Common:\n");
printf(" /FLOPPY : Support Floppy\n");
printf(" /NoHP : Do not get HDD Parameter\n");
printf(" /NTFSPRO : Support NTFSPRO DOS letter\n");
printf(" /IFS : ... IFS ...\n");
printf(" n : No.drive\n");
printf(" n:n : drive:partition, e.g. 1:2\n");
printf(" ?: : WIN letter, e.g. D:\n");
getch();
clrscr();
printf("\n");
printf(" /?|/H : Print help\n");
printf(" /D[.] : Print Drive info. n=drive; A=Floppy\n");
printf(" /P[...] : Print Partition info. A=Floppy; :=DOS letters; F=FAT N=NTFS\n");
printf(" FN=FAT&NTFS; L=Linux; NoH=No Hidden\n");
printf(" /V : WIN Vol prior to DOS label\n");
printf(" /S : Save\n");
printf(" /R : Restore\n");
printf(" /E : rEplace BOOT1/FAT1 with BOOT2/FAT2, FAT32 only\n");
printf(" /C : Compare with file (/MBR|/BOOT/FAT UNneeded)\n");
printf(" /L : Look info in drive/file\n");
printf(" /MBR : Master Boot Record\n");
printf(" /BOOT : DOS Boot Record. i.e. DBR\n");
printf(" /FAT : File Allocation Table\n");
printf(" /CMOS : MainBoard CMOS\n");
printf(" /A : All partitions/drives, allowed with n\n");
printf(" /Fxx : File, xx=name\n");
printf(" /NoP : Not Pause during looking, with /L\n");
printf(" /Y : Yes to write drive\n");
printf(" /T : Turn to print ?:|n:n from n:n|?:\n");
printf(" /CMOSKEY : Generate a CMOS key\n");
}
int printByte(unsigned char *buf, unsigned long num, int offsetForPrint, unsigned long *offsetAllRecord, char pause, /*int *x, int *y,*/ int *lastSpare)
{
unsigned long j=0,asc=0,k=0;
unsigned long globalOffset=*offsetAllRecord;
int frontSpaceBar=0;
int frontSpaceBar2=0;
/*char unprintFront=1; */
unsigned long previousPos=-1;
if(!*offsetAllRecord)
{
globalOffset+=offsetForPrint-(offsetForPrint%16);
frontSpaceBar=offsetForPrint%16;
frontSpaceBar2=frontSpaceBar;
}
if((*lastSpare)%16)
{
frontSpaceBar=*lastSpare;
frontSpaceBar2=frontSpaceBar;
}
if((*lastSpare)%16) gotoxy(9+2+frontSpaceBar*3+1,wherey()-1);
for(j=0,asc=0;j<num;j++)
{
if(bioskey(1)!=0)
{
if(bioskey(0)==0x11B)
{
printf("\nStopped.\n");
return -1;
}
}
if(/*(!*lastSpare && (*lastSpare)%16==0) && */(j==0 || asc))
{
/*printf("last=%d * ",*lastSpare); */
if((*lastSpare)%16==0 && globalOffset%16==0)
{
printf("%09lX ",globalOffset);
asc=0;
}
}
if(j==0 && !*lastSpare && frontSpaceBar)
{
gotoxy(9+2+frontSpaceBar*3+1,wherey());
globalOffset+=frontSpaceBar;
}
printf("%02X",buf[j]);
/*if(j+1<num) */
printf("%c",((j>0 && (j+frontSpaceBar2+1)%8==0 && (j+frontSpaceBar2+1)%16!=0) ? '-' : ' '));
globalOffset++;
if(j+1>=num && (num+frontSpaceBar2)%16!=0)
{
int l=(16-(j-previousPos+frontSpaceBar))*3;
gotoxy(wherex()+l,wherey());
}
if((j+frontSpaceBar2+1)%16==0 || j+1>=num )
{
printf(" ");
asc=previousPos+1;
if(frontSpaceBar) gotoxy(wherex()+frontSpaceBar,wherey());
for(k=0;k<j-previousPos;asc++,k++)
{
/* printf("enter k "); */
if(buf[asc]==0 ||
buf[asc]==7 ||
buf[asc]==8 ||
buf[asc]==9 ||
buf[asc]==10 ||
buf[asc]==11 ||
buf[asc]==12 ||
buf[asc]==13 ||
buf[asc]==255)
printf(".");
else printf("%c",buf[asc]);
}
printf("\n");
/*getch(); */
*lastSpare=0;
previousPos=j;
frontSpaceBar=0;
/*printf("==%lu==",globalOffset-(offsetForPrint-(offsetForPrint%16))); */
if(pause && globalOffset>(offsetForPrint-(offsetForPrint%16)) && (globalOffset-(offsetForPrint-(offsetForPrint%16)))%384==0)
{
printf("Press ESC to exit, other key to continue...");
while(bioskey(1)==0);
if(bioskey(0)==0x11B)
{
printf("\nStopped.\n");
return -1;
}
printf("\n");
}
}
}
*offsetAllRecord=globalOffset;
*lastSpare=k+(j+frontSpaceBar2<=16 && frontSpaceBar2 ? frontSpaceBar2 : 0);
return 0;
}
int compareByte(unsigned char *buf1, unsigned char *buf2, unsigned long byte, char pause, unsigned long *diff, unsigned long *offsetAllRecord)
{
unsigned long i,j;
for(i=0,j=0;i<byte;i++)
{
if(bioskey(1)!=0)
{
if(bioskey(0)==0x11B)
{
printf("\nStopped.\n");
*diff+=j;
return -1;
}
}
if(buf1[i]==buf2[i]) continue;
else
{
printf("%09lX %02X %02X\n",i+(*offsetAllRecord),buf1[i],buf2[i]);
j++;
}
if(pause)
{
if(j%24==0)
{
printf("Press ESC to exit, other key to continue...");
while(bioskey(1)==0);
if(bioskey(0)==0x11B)
{
printf("\nStopped.\n");
*diff+=j;
return -1;
}
printf("\n");
}
}
}
if(j) *diff+=j;
*offsetAllRecord+=i;
return 0;
}
typedef struct driveInfo
{
char floppy;
/* char orderNumber; */
char number;
char supportExtInt13;
unsigned long maxCylinder;
unsigned long maxHead;
unsigned long maxSectorPerTrack;
unsigned long totalSector;
char part;
}Dinfo,*DinfoP;
typedef struct partitionInfo
{
unsigned char letterNumber;
unsigned char letter;
/* unsigned char totalNumber; */
int hardDrive;
unsigned char number;
char logicDrive;
unsigned char active;
unsigned int activeOffset;
unsigned char ID;
unsigned int IDoffset;
char label[12];
unsigned long start;
unsigned long total;
unsigned long freeSpaceKB;
char error;
}Pinfo,*PinfoP;
typedef struct _commonArg
{
char argMode;
int drive;
unsigned char number;
unsigned char letter;
int index;
unsigned long totalSector;
char startToDoTRUE;
unsigned long startToDoGiven;
unsigned long startToDo;
char sectorToDoTRUE;
unsigned long sectorToDo;
char name[256];
char compressDecompress;
char compressLevel;
char keyTRUE;
char separatedVolume;
unsigned long separatedMB;
char keyEveryTRUE;
char keyEveryPromptTRUE;
unsigned long size;
unsigned long realSize;
char continueUnfinished;
unsigned long lastPos;
unsigned long *lastDoneSector;
unsigned long *unfinishedSector;
unsigned long sectorToUnfinishedVolume;
char indexToAddName;
char addONE;
char quiet;
char mute;
char ignore;
char next;
}commonArg;
int int13DriveParameter(int driveNum,
unsigned long *maxCylinder,
unsigned long *maxHead,
unsigned long *maxSector,
unsigned long *totalSector)
{
unsigned long cylinder=0;
unsigned long head=0;
unsigned long sector=0;
unsigned long totalSectorVar=0;
union REGS regs;
regs.h.ah=0x08;
regs.h.dl=driveNum;
int86(0x13,®s,®s); /*调用中断*/
if(regs.h.ah!=0) return regs.h.ah;
/*
if(regs.h.bl==0x01) printf("This is 360KB model.\n");
if(regs.h.bl==0x02) printf("This is 1.2MB model.\n");
if(regs.h.bl==0x03) printf("This is 720KB model.\n");
if(regs.h.bl==0x04) printf("This is 1.44MB model.\n"); */
/* 需先读取这些值,再赋给后面的变量,否则无效,不知何故 */
cylinder=((((unsigned int)regs.h.cl)>>6<<8) | regs.h.ch) + 1;
head=regs.h.dh+1;
sector=regs.h.cl & 0x3F;
totalSectorVar=(unsigned long)cylinder * (unsigned long)head * (unsigned long)sector;
/* printf("Cylinders=%lu Heads=%lu Sectors=%lu\nTotal sectors=%lu (%lu MB)\n\n",
cylinder,head,sector,totalSectorVar,totalSectorVar/2/1024);
*/
*maxCylinder=cylinder;
*maxHead=head;
*maxSector=sector;
*totalSector=totalSectorVar;
if(*totalSector) return 0;
return -1;
}
int checkExtInt13(int driveNum)
{
union REGS in,out;
in.h.ah=0x41;
in.h.dl=driveNum;
in.x.bx=0x55AA;
int86(0x13,&in,&out);
if(out.x.bx==0xAA55) return 1;
else return 0;
}
int extInt13DriveParameter(int driveNum,
unsigned long *maxCylinder,
unsigned long *maxHead,
unsigned long *maxSector,
unsigned long *totalSector)
{
/*
unsigned long cylinder=0;
unsigned long head=0;
unsigned long sector=0;
unsigned long totalSectorVar=0; */
union REGS regs;
struct SREGS sregs;
struct {
unsigned short size; /*地址包大小*/
unsigned short inforflags; /*信息标志*/
unsigned long cylns; /*物理柱面数*/
unsigned long heads; /*物理磁头数*/
unsigned long sects; /*物理每柱扇区数*/
unsigned long tslow; /*扇区总数低位*/
unsigned long tshi; /*扇区总数高位*/
unsigned short bps; /*每扇区字节数*/
} package; /*LBA地址包定义*/
regs.h.ah=0x48;
regs.h.dl=(unsigned char)driveNum;
sregs.ds=FP_SEG(&package); /*获得package的段地址*/
regs.x.si=FP_OFF(&package); /*获得package的偏移量*/
int86x(0x13,®s,®s,&sregs); /*调用中断*/
if(regs.h.ah!=0) return regs.h.ah;
*maxCylinder=package.cylns;
*maxHead=package.heads;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -