2 #include "stdio.h" /* ;AN000; */
3 #include "stdlib.h" /* ;AN000; */
4 #include "string.h" /* ;AN000; */
5 #include "dos.h" /* ;AN000; */
6 #include "get_stat.h" /* ;AN000; */
7 #include "extern.h" /* ;AN000; */
9 char read_boot_record(unsigned,unsigned char,unsigned char,unsigned char); /* ;AN000; */
10 void DiskIo(union REGS *,union REGS *, struct SREGS *); /* ;AN000; */
11 unsigned cylinders_to_mbytes(unsigned,unsigned char,unsigned char); /* ;AN000; */
12 char get_drive_parameters(unsigned char); /* ;AN000; */
13 char get_disk_info(void); /* ;AN000; */
15 /*
\f */ /* ;AN000; */
16 char get_disk_info() /* ;AN000; */
20 unsigned char i; /* ;AN000; */
22 /* Initialize values */ /* ;AN000; */
23 number_of_drives = uc(0); /* ;AN000; */
24 for (i=uc(0); i < uc(2); i++) /* ;AN000; */
26 total_disk[i] = u(0); /* ;AN000; */
27 total_mbytes[i] = f(0); /* ;AN000; */
28 max_sector[i] = uc(0); /* ;AN000; */
29 max_head[0] = uc(0); /* ;AN000; */
32 /* See how many drives there are */ /* ;AN000; */
33 if (get_drive_parameters(uc(0x80))) /* ;AN000; */
36 /* Get the drive parameters for all drives */ /* ;AN000; */
37 for (i = uc(0); i < number_of_drives;i++) /* ;AN000; */
40 if (get_drive_parameters(uc(0x80)+i)) /* ;AN000; */
43 /* Save drive parameters */ /* ;AN000; */
44 max_sector[i] = ((unsigned char)(regs.h.cl & 0x3F)); /* ;AN000; */
45 max_head[i] = ((unsigned char)(regs.h.dh +1)); /* ;AN000; */
46 total_disk[i] = ((((unsigned)(regs.h.cl & 0xC0 )) & 0x00C0) << 2)+ ((unsigned)regs.h.ch) +1; /* ;AN000; */
47 total_mbytes[i] = cylinders_to_mbytes(total_disk[i], max_sector[i], max_head[i]); /* ;AN000; */
51 good_disk[i] = FALSE; /* ;AN000; */
52 return(FALSE); /* ;AN000; */
55 return(TRUE); /* ;AN000; */
58 /* No drives present */ /* ;AN000; */
60 no_fatal_error = FALSE; /* ;AN000; */
61 return(FALSE); /* ;AN000; */
68 /*
\f */ /* ;AN000; */
69 char get_drive_parameters(drive) /* ;AN000; */
71 unsigned char drive; /* ;AN000; */
74 /* See how many drives there are */ /* ;AN000; */
75 regs.h.ah = uc(DISK_INFO); /* ;AN000; */
76 regs.h.dl = drive; /* ;AN000; */
77 DiskIo(®s,®s,&segregs); /* ;AN000; */
79 /* See if any drives exist */ /* ;AN000; */
80 if ((regs.h.dl == uc(0)) || ((regs.x.cflag & 1) == u(1))) /* ;AN000; */
82 return(FALSE); /* ;AN000; */
86 /* Save the number of drives */ /* ;AN000; */
87 number_of_drives = regs.h.dl; /* ;AN000; */
88 if (number_of_drives < 2) good_disk[1] = FALSE; /* ;AN000; */
89 if (number_of_drives < 1) good_disk[0] = FALSE; /* ;AN000; */
90 return(TRUE); /* ;AN000; */
95 /*
\f */ /* ;AN000; */
96 char read_boot_record(cylinder,which_disk,which_head,which_sector) /* ;AN000; */
98 unsigned cylinder; /* ;AN000; */
99 unsigned char which_disk; /* ;AN000; */
100 unsigned char which_head; /* ;AN000; */
101 unsigned char which_sector; /* ;AN000; */
105 char far *buffer_pointer = boot_record; /* ;AN000; */
107 /* Setup read, always on a cylinder boundary */ /* ;AN000; */
108 regs.h.ah = uc(READ_DISK); /* ;AN000; */
109 regs.h.al = uc(1); /* ;AN000; */
110 regs.h.dh = which_head; /* ;AN000; */
111 regs.h.cl = which_sector; /* ;AN000; */
113 /* Specify the disk */ /* ;AN000; */
114 regs.h.dl = which_disk + 0x80; /* ;AN000; */
116 /* Need to scramble CX so that sectors and cyl's are in INT 13 format */ /* ;AN000; */
118 if (cylinder > u(255)) /* ;AN000; */
120 regs.h.cl = regs.h.cl | ((char)((cylinder /256) << 6)); /* ;AN000; */
122 regs.h.ch = (unsigned char)(cylinder & 0xFF); /* ;AN000; */
124 /* Point at the place to write the boot record */ /* ;AN000; */
125 regs.x.bx = FP_OFF(buffer_pointer); /* ;AN000; */
126 segregs.es = FP_SEG(buffer_pointer); /* ;AN000; */
128 /* read in the boot record */ /* ;AN000; */
129 DiskIo(®s,®s,&segregs); /* ;AN000; */
130 /* Check for error reading it */ /* ;AN000; */
131 if ((regs.x.cflag & 1) != u(1)) /* ;AN000; */
133 return(TRUE); /* ;AN000; */
137 /* Tell user there was an error */ /* ;AN000; */
138 good_disk[which_disk] = FALSE; /* ;AN000; */
139 return(FALSE); /* ;AN000; */
143 /*
\f */ /* ;AN000; */
144 void DiskIo(InRegs,OutRegs,SegRegs) /* ;AN000; */
145 union REGS *InRegs; /* ;AN000; */
146 union REGS *OutRegs; /* ;AN000; */
147 struct SREGS *SegRegs; /* ;AN000; */
151 char *WritePtr; /* ;AN000; */
153 #ifdef DEBUG /* ;AN000; */
155 switch(InRegs->h.ah) /* ;AN000; */
157 case 0: /* ;AN000; */
158 case 1: /* ;AN000; */
159 case 2: /* ;AN000; */
160 case 4: /* ;AN000; */
161 case 8: /* ;AN000; */
162 case 15: /* ;AN000; */
163 case 16: /* ;AN000; */
164 int86x((int)DISK,InRegs,OutRegs,SegRegs); /* ;AN000; */
167 default: /* ;AN000; */
168 WritePtr = getenv("WRITE"); /* ;AN000; */
169 if (strcmpi(WritePtr,"ON") != 0) /* ;AN000; */
171 printf("\nDisallowing Disk I/O Request\n"); /* ;AN000; */
172 printf("AX:%04X BX:%04X CX:%04X DX:%04X ES:%04X\n", /* ;AN000; */
173 InRegs->x.ax,InRegs->x.bx,InRegs->x.cx,InRegs->x.dx,SegRegs->es); /* ;AN000; */
175 OutRegs->h.ah = (unsigned char) 0; /* ;AN000; */
176 OutRegs->x.cflag = (unsigned) 0; /* ;AN000; */
178 else int86x((int)DISK,InRegs,OutRegs,SegRegs); /* ;AN000; */
186 int86x((int)DISK,InRegs,OutRegs,SegRegs); /* ;AN000; */
190 return; /* ;AN000; */