2 #include "fdisk.h" /* AN000 */
3 #include "subtype.h" /* AN000 */
4 #include "dos.h" /* AN000 */
5 #include "extern.h" /* AN000 */
10 /******************************************************************************/
11 /*Routine name: MBYTES_TO_CYLINDERS */
12 /******************************************************************************/
14 /*Description: This routine will take input of MBtes and */
15 /* convert it to cylinders rounding up to the next largest */
16 /* cylinder boundry. Rounding up is done to make sure the */
17 /* requester is getting at least what he asked for to the */
18 /* next cylinder boundry. */
20 /*Called Procedures: none */
23 /*Change History: Created 5/30/87 DRM */
27 /*Output: Cylinders_out */
29 /******************************************************************************/
32 unsigned mbytes_to_cylinders(mbytes_in,which_disk) /* AN004 */
34 XFLOAT mbytes_in; /* AN000 */
35 char which_disk; /* AN004 */
41 unsigned cylinders_out; /* AN000 */
42 unsigned long cylinders_out1; /* AN000 */
43 unsigned long number_of_sectors; /* AN000 */
44 unsigned long number_of_tracks; /* AN000 */
45 unsigned long divide_by; /* AN000 */
47 /* If trying to create a 3.30 compatible 32 MB partition */
48 /* Set the 32mb limit - round down */
49 if (mbytes_in == (XFLOAT)32)
51 cylinders_out1 = ul(DOS_MAX - max_sector[which_disk]); /* AN004 */
52 divide_by = ul((max_head[which_disk]) * ul(max_sector[which_disk])); /* AN004 */
53 cylinders_out = u(cylinders_out1 / divide_by); /* AN000 */
57 number_of_sectors = ul(((mbytes_in * ONE_MEG)/BYTES_PER_SECTOR)); /* AN000 */
58 if (((int)(mbytes_in * ONE_MEG) % BYTES_PER_SECTOR) != (int)0) /* AN000 */
59 number_of_sectors++; /* AN000 */
60 number_of_tracks = ul((number_of_sectors / max_sector[which_disk])); /* AN004 */
61 if (((int)number_of_sectors % max_sector[which_disk]) != (int)0) /* AN004 */
62 number_of_tracks++; /* AN000 */
63 cylinders_out = u((number_of_tracks / max_head[which_disk])); /* AN004 */
64 if (((int)number_of_tracks % max_head[which_disk]) != (int)0) /* AN004 */
65 cylinders_out++; /* AN000 */
68 return(cylinders_out); /* AN000 */
74 /*******************************************************************************/
75 /*Routine name: CYLINDERS_TO_MBYTES */
76 /*******************************************************************************/
78 /*Description: This routine will take input of cylinders and convert */
82 /*Called Procedures: */
85 /*Change History: Created 5/16/87 DRM */
87 /*Input: Cylinders_in */
89 /*Output: MBytes_out */
93 /*******************************************************************************/
95 XFLOAT cylinders_to_mbytes(cylinders_in,which_disk) /* AN004 */
97 unsigned cylinders_in; /* AN000 */
98 char which_disk; /* AN004 */
102 unsigned mbytes_out; /* AN000 */
103 unsigned long number_of_bytes; /* AN000 */
104 unsigned long number_of_sectors; /* AN000 */
105 unsigned long number_of_tracks; /* AN000 */
106 unsigned long bytes_in_one_sector; /* AN004 */
108 bytes_in_one_sector = BYTES_PER_SECTOR; /* AN004 */
109 number_of_tracks = (ul(cylinders_in) * ul(max_head[which_disk])); /* AN004 */
110 number_of_sectors = (number_of_tracks * ul(max_sector[which_disk])); /* AN004 */
111 number_of_bytes = (ul(number_of_sectors) * ul(bytes_in_one_sector)); /* AN004 */
112 mbytes_out = f(number_of_bytes / ONE_MEG); /* AN000 */
113 if ((number_of_bytes % ONE_MEG) >= (ONE_MEG / 2)) mbytes_out++; /* AN000 */
114 return(mbytes_out); /* AN000 */
122 /*******************************************************************************/
123 /*Routine name: CYLINDERS_TO_PERCENT */
124 /*******************************************************************************/
126 /*Description: This routine will take input of cylinders and convert */
130 /*Called Procedures: */
133 /*Change History: Created 5/16/87 DRM */
135 /*Input: Cylinders_in */
137 /*Output: percent_out */
141 /*******************************************************************************/
143 unsigned cylinders_to_percent(cylinders_in,total_cylinders) /* AN000 */
145 unsigned cylinders_in; /* AN000 */
146 unsigned total_cylinders; /* AN000 */
150 unsigned percentage_out; /* AN000 */
151 double large_number; /* AN000 */
153 /* This is the same as (cyl_in / tot_cyl) * 100 to get the percentage */
154 /* because * 100 is really 100/1 which is (cyl_in*100)/(tot_cyl*1). */
156 if (total_cylinders == 0)
160 large_number = (double)((long)cylinders_in * 100l); /* AN000 */
161 percentage_out = u(large_number / total_cylinders); /* AN000 */
163 /* this should round up to the next percent if more than .5 percent */
164 if (((cylinders_in * 100) % total_cylinders) >= (total_cylinders / 2))
165 percentage_out++; /* AN000 */
166 if (percentage_out > u(100)) percentage_out = u(100); /* AN000 */
167 return(percentage_out); /* AN000 */
173 /******************************************************************************/
174 /*Routine name: PERCENT_TO_CYLINDERS */
175 /******************************************************************************/
177 /*Description: This routine will take input of percentage and */
178 /* convert it to cylinders rounding up to the next largest */
179 /* cylinder boundry. Rounding up is done to make sure the */
180 /* requester is getting at least what he asked for to the */
181 /* next cylinder boundry. */
183 /*Called Procedures: none */
186 /*Change History: Created 5/30/87 DRM */
190 /*Output: Cylinders_out */
192 /******************************************************************************/
195 XFLOAT percent_to_cylinders(percent_in,total_cylinders) /* AN000 */
197 unsigned percent_in; /* AN000 */
198 XFLOAT total_cylinders; /* AN000 */
203 XFLOAT cylinders_out; /* AN000 */
205 cylinders_out = ((percent_in * total_cylinders) / 100); /* AN000 */
207 cylinders_out = (unsigned)((ul(percent_in) * ul(total_cylinders)) / 100);
209 if (((percent_in * total_cylinders) % 100) != u(0)) /* AN000 */
210 cylinders_out++; /* AN000 */
211 return(cylinders_out); /* AN000 */
220 /*******************************************************************************/
221 /*Routine name: DOS_UPPER */
222 /*******************************************************************************/
224 /*Description: This routine will uppcase a character using get country */
225 /* information (65H) with the capitalize single character */
228 /*Called Procedures: */
232 /*Change History: Updated 5/31/87 DRM */
234 /*Input: drive_value */
236 /*Output: input_value */
238 /*******************************************************************************/
240 char dos_upper(drive_value) /* AN000 */
242 char drive_value; /* AN000 */
246 char output; /* AN000 */
248 regs.x.ax = (unsigned)CAPCHAR; /* Get extended country information - AN000 */
249 regs.h.dl = (unsigned char)drive_value; /* Move input_value to register DL - AN000 */
250 int86((int)INT21,®s,®s); /* AN000 */
251 output = (char)regs.h.dl; /* AN000 */
254 output = toupper(drive_value);
257 return(output); /* AN000 */
265 /*******************************************************************************/
266 /*Routine name: CHECK_YN_INPUT */
267 /*******************************************************************************/
269 /*Description: Get single character input, which must be a country */
270 /* dependent (Y/N). Will be verified using new uppercase table */
271 /* function calls. Will accept default value. */
273 /*Called Procedures: */
277 /*Change History: Updated 5/31/87 DRM */
279 /*Input: input_value */
284 /*******************************************************************************/
286 char check_yn_input(input_value) /* AN000 */
288 char input_value; /* AN000 */
291 char input; /* AN000 */
293 /* Get extended country information */
294 regs.x.ax = (unsigned)CAP_YN; /* AN000 */
295 /* Move input_value to register DL */
296 regs.h.dl = (unsigned char)input_value; /* AN000 */
297 int86((int)INT21,®s,®s); /* AN000 */
299 /* check carry flag for error */
300 if ((regs.x.cflag & CARRY_FLAG) == CARRY_FLAG) /* AN000 */
301 /* input will be 0 for NO and 1 for YES in AX */
302 input = c(NO_GOOD); /* input will equal not 0 or 1 */ /* AN000 */
304 input = c(regs.x.ax); /* AN000 */
309 if ( (input_value == (char) 'Y') || (input_value == (char) 'y') ) input = c(1);
310 if ( (input_value == (char) 'N') || (input_value == (char) 'n') ) input = c(0);
314 return(input); /* AN000 */
321 /*******************************************************************************/
322 /*Routine name: GET_FS_AND_VOL */
323 /*******************************************************************************/
325 /*Description: This routine will invoke INT21 44h (Block Generic IOCTL */
326 /* Subfunction) call to get volume label and file system type. */
328 /*Called Procedures: */
330 /*Change History: Created 6/01/87 DRM */
332 /*Input: input_drive */
334 /*Output: pointer to dx register */
336 /*******************************************************************************/
338 FLAG get_fs_and_vol(input_drive) /* AN000 */
340 char input_drive; /* AN000 */
346 /* Set up registers for Generic IOCTL INT21 (44h) get media ID */
347 regs.x.ax = u(GENERIC_IOCTL); /* AN000 */
348 regs.h.bh = uc(ZERO); /* AN000 */
349 regs.h.bl = (((unsigned char)input_drive - 'A') + 1); /* AN000 */
350 regs.x.cx = u(GET_MEDIA_ID); /* AN000 */
351 regs.x.dx = (unsigned)&dx_buff; /* AN000 */
353 intdosx(®s,®s,&segregs); /* AN000 */
355 /* see if carry flag was zero or one */
356 if ((regs.x.cflag & CARRY_FLAG) == CARRY_FLAG) /* AN000 */
357 output = FALSE; /* AN000 */
359 output = TRUE; /* AN000 */
361 return(output); /* AN000 */
368 /*******************************************************************************/
369 /*Routine name: GET_VOLUME_STRING */
370 /*******************************************************************************/
372 /*Description: This routine will invoke INT21 4Eh (Find First Matching File) */
373 /* and return the disk volume label. */
375 /*Called Procedures: */
377 /*Change History: Created 6/01/87 DRM */
379 /*Input: input_drive */
381 /*Output: volume_out */
383 /*******************************************************************************/
384 void get_volume_string(input_drive,vol_label_addr) /* AN000 */
385 char input_drive; /* AN000 */
386 char *vol_label_addr; /* AN000 */
389 char first_string[13]; /* AC000 */
390 char find_first_buffer[50]; /* AN000 */
391 unsigned i,j; /* AC000 */
393 /* clear out any garbage in volume label field */
394 for (i = u(0); i < u(12); i++) /* AN015 */
396 vol_label_addr[i] = u(0); /* AN015 */
399 /* Point the DTA to our buffer so we can get the FindFirst output */
400 regs.h.ah = uc(0x1A); /* AN000 */
401 regs.x.dx = (unsigned)&find_first_buffer[0]; /* AN000 */
403 intdosx(®s,®s,&segregs); /* AN000 */
405 /* Find the first volume id */
406 first_string[0] = input_drive; /* Find the vol label - AN000 */
407 first_string[1] = (char) '\0';
408 strcat(first_string,FILE_NAME); /* AN000 */
409 regs.h.ah = uc(FIND_FIRST_MATCH); /* AN000 */
410 regs.x.cx = u(VOL_LABEL); /* AN000 */
411 regs.x.dx = (unsigned)&first_string[0]; /* AN000 */
412 intdos(®s,®s); /* AN000 */
414 /* AC000 The following is modified to take care of "." in the middle of the */
417 if ((regs.x.cflag & CARRY_FLAG) != CARRY_FLAG) /* AN000 AC015 */
419 for (i=j=u(0); i < strlen (&find_first_buffer[30]) ; i++) /* AN000 */
421 if (find_first_buffer[30+i] != PERIOD) /* AN003 */
422 vol_label_addr[i-j] = find_first_buffer[30+i]; /* AN000 */
424 j = u(1); /* AN000 */
432 /*******************************************************************************/
433 /*Routine name: CHECK_FORMAT */
434 /*******************************************************************************/
436 /*Description: This routine will invoke INT21 44h (Block Generic IOCTL */
437 /* Subfunction) call to see if the drive has been previously */
438 /* formatted by using a undocumented call. */
440 /*Called Procedures: */
442 /*Change History: Created 2/07/88 DRM */
444 /*Input: input_drive */
446 /*Output: pointer to dx register */
448 /*******************************************************************************/
450 FLAG check_format(input_drive) /* AN002 */
452 char input_drive; /* AN002 */
456 char formatted; /* AN002 */
458 /* Set up registers for Generic IOCTL INT21 (44h) check media */
459 regs.x.ax = u(GENERIC_IOCTL); /* AN002 */
460 regs.h.bh = uc(ZERO); /* AN002 */
461 regs.h.bl = (((unsigned char)input_drive - 'A') + 1); /* AN002 */
462 regs.x.cx = u(SPECIAL_FUNCTION); /* AN002 */
463 regs.x.dx = (unsigned)&disk_access; /* AN002 */
464 segread(&segregs); /* AN002 */
465 intdosx(®s,®s,&segregs); /* AN002 */
467 /* see if buffer returned good or not */
468 if (disk_access.dac_access_flag == ZERO) /* AN002 */
469 formatted = FALSE; /* AN002 */
471 formatted = TRUE; /* AN002 */
473 return(formatted); /* AN002 */