1 /************************************************************/
3 /* Header: GET_STATUS */
4 /* Purpose: To transfer information provided by FDISK */
5 /* to the DOS SELECT utility. The information */
6 /* provided will determine the status of the */
7 /* specified fixed disk. The information is */
8 /* is pertinent to determine the parameters */
9 /* displayed and utilized in SELECT panels */
10 /* that will assume default values according */
11 /* to option the user selected without viewing */
12 /* or modifying FDISK. */
14 /* The status info will be returned in the control */
15 /* block defined below: */
17 /* DISK_STATUS STRUC */
18 /* N_PART_NAME DB 0 ;partition name */
19 /* N_PART_SIZE DW 0 ;size of the above */
20 /* ;partition in (Mbytes)*/
21 /* N_PART_STATUS DB 0 ;Partition status */
22 /* P_PART_DRIVE DB ? ;drive letter assigned*/
23 /* ;to the partition */
24 /* DISK_STATUS ENDS ;(ASCII value) */
26 /*************************************************************/
28 /*************************************************************/
29 /* First check to make the ax is specified correctly to make */
30 /* the call to Get_STATUS; The value in AX should be 01 */
31 /* IF compare is true then proceed with migration */
33 /* set AX to to one and report error wrong call value */
37 /*************************************************************/
38 /*****************************************************************************/
48 void get_status(union REGS *, union REGS *, struct SREGS *);
49 void valid_stat(struct DISK_STATUS far *, union REGS *);
50 void init_partition_tables(void);
51 char read_boot_record(unsigned,unsigned char,unsigned char,unsigned char); /* AC000 */
52 char get_drive_parameters(unsigned char);
53 void sort_part_table(char);
54 void sort_ext_table(char);
55 unsigned find_part_free_space(void);
56 unsigned find_ext_free_space(void);
57 void load_logical_drive(char, unsigned char);
58 char find_logical_drive(void);
59 unsigned cylinders_to_mbytes(unsigned,unsigned char,unsigned char); /* AN000 */
60 char find_partition_location(unsigned char);
61 char find_free_partition(void);
62 char find_partition_type(unsigned char);
63 char get_disk_info(void);
64 unsigned copy_fdisk2select(unsigned, DSE far * );
65 char get_num_logical_dos_drives(void);
66 unsigned get_partition_size(unsigned char);
68 void DiskIo(union REGS *,union REGS *, struct SREGS *);
69 unsigned char find_partition_system_type(void);
71 #define DptrOf(ti) ( Dptr + (sizeof(DSE) * (ti)) )
73 void get_status(RinPtr, RoutPtr, SrPtr)
81 /* ------------- drive = regs.x.ax; */
82 /* Make drive zero based */
83 /* ------------- drive--; */
85 FP_SEG(Dptr) = SrPtr->es;
86 FP_OFF(Dptr) = RinPtr->x.di;
91 switch(RinPtr->x.ax) /* Check the value in AX */
94 case uc(FST_DRV): /* Is it a query for the first drive? */
95 case uc(SEC_DRV): /* Is it a query for the 2nd drive? */
96 cur_disk = c(RinPtr ->x.ax - 1);
98 valid_stat(Dptr,RoutPtr); /* yes than go execute */
101 default: /* otherwise - set AX to one & exit */
110 /*****************************************************************************/
111 /******************* START OF SPECIFICATIONS *******************/
113 /* SUBROUTINE NAME: VALID_STAT */
115 /* DESCRIPTIVE NAME: */
120 /* MOV AX,?? ; AX = 1 first fixed drive */
122 /* ; = 2 second fixed drive */
123 /* ; ES:DI - points to parameter block */
125 /* CALL GET_DISK_STATUS ; call to subroutine */
128 /* ; AX = 1 drive is not valid */
129 /* ; = 0 drive is valid */
130 /* ; CX = number of items in parameter block */
131 /* ; BX = status of fixed drive */
132 /* ; as defined below - */
133 /* ; more than 1 bit can be set */
134 /* ; ES:DI is filled with data */
136 /* EXIT-NORMAL: ERROR=FALSE */
138 /* EXIT-ERROR: ERROR=TRUE */
139 /* GOTO internal_program_error if invalid num */
140 /* input is returned to this level */
146 /* INTERNAL REFERENCES: */
150 /* EXTERNAL REFERENCES: */
153 /******************** END OF SPECIFICATIONS ********************/
155 void valid_stat(Dptr,RoutPtr)
161 unsigned table_count;
166 /**********************************replacement***********************************************/
167 /* Initialize the tables that will be used to store the data needed for */
168 /* SELECT. The disk_status tables will be initialized to 0 for all */
169 /* values except the logical drive value, if exist in an extended partition */
170 /* other wise the field will remain undefined. This must be done for both */
171 /* tables although it has not been established that two physical drives exist */
172 /* at this point. Additional tables needed are the tables 1) To store the */
173 /* amount of free space between each partition 2) the amount of free space */
174 /* between each logical drive (the tables are declared to integer */
175 /********************************************************************************************/
183 /* Read drives to get disk information on size, etc..... */
184 /* good_disk[] = FALSE if can't read disk */
187 if (!get_disk_info())
189 good_disk[0] = FALSE;
190 good_disk[1] = FALSE;
193 /* See if we could read the selected drive */
194 if ( !good_disk[cur_disk] )
195 RoutPtr->x.ax = 1; /* indicate disk read failed */
198 init_partition_tables();
200 /* Is there a primary ? */
202 if (find_partition_system_type() != uc(NOT_FOUND))
204 RoutPtr->x.bx |= E_DISK_PRI;
205 (Dptr+table_count) -> n_part_name = E_PART_PRI_DOS;
206 (Dptr+table_count) -> n_part_size = get_partition_size(find_partition_system_type());
208 for (i = c(0); i < c(4);i++) /* AC000 */
209 if ( (part_table[cur_disk][i].sys_id == DOS12) ||
210 (part_table[cur_disk][i].sys_id == DOS16) ||
211 (part_table[cur_disk][i].sys_id == DOSNEW) )
214 (Dptr+table_count) -> n_part_status = E_PART_UNFORMAT;
215 if (part_table[cur_disk][i].formatted)
216 (Dptr+table_count) -> n_part_status = E_PART_FORMAT;
217 (Dptr+table_count) -> p_part_drive = part_table[cur_disk][i].drive_letter;
218 for (m=u(0);m < u(4); m++)
219 (Dptr+table_count) -> n_part_level[m] = part_table[cur_disk][i].system_level[m];
225 /* if there an extended? */
227 if (find_partition_type(EXTENDED))
229 /* Found one, now fill in entry with vital stats */
230 RoutPtr->x.bx |= E_DISK_EXT_DOS;
231 (Dptr+table_count) ->n_part_name = E_PART_EXT_DOS;
232 (Dptr+table_count) ->n_part_size = get_partition_size(EXTENDED);
233 (Dptr+table_count) -> n_part_status = E_PART_UNFORMAT;
234 (Dptr+table_count) -> p_part_drive = next_letter;
235 for (m=u(0);m < u(4); m++)
236 (Dptr+table_count) -> n_part_level[m] = NUL;
240 /* Are there any logical drives */
242 if ( (find_partition_type(EXTENDED)) && (find_logical_drive()) )
243 RoutPtr->x.bx |= E_DISK_LOG_DRI;
245 /* Is there free extended partition space, and are there free entries?*/
247 if ( (temp = find_ext_free_space()) != u(0))
249 /* Indicate we have room in the extended, and build entry to show how much */
250 RoutPtr->x.bx |= E_DISK_EDOS_MEM;
251 (Dptr+table_count) ->n_part_name = uc(E_FREE_MEM_EDOS);
252 (Dptr+table_count) ->n_part_size = temp;
253 (Dptr+table_count) -> n_part_status = E_PART_UNFORMAT;
254 (Dptr+table_count) -> p_part_drive = c(' ');
255 for (m=u(0);m < u(4); m++)
256 (Dptr+table_count) -> n_part_level[m] = NUL;
260 /* Is there any free space in master boot record partitions, and free partitions? */
262 if ( (temp = find_part_free_space()) != u(0))
264 /* Indicate we have free space in the MBR partition tables */
266 RoutPtr->x.bx |= E_DISK_FREE_MEM;
267 (Dptr+table_count) ->n_part_name = uc(E_FREE_MEM_DISK);
268 (Dptr+table_count) ->n_part_size = temp;
269 for (m=u(0);m < u(4); m++)
270 (Dptr+table_count) -> n_part_level[m] = NUL;
274 /* If there is a logical drive get the drive letters and the associated */
275 /* size, and for the logical drive */
277 /* First check again to see if their is an extended partition */
278 /* and see if there exist any logical drives --- sort the logical */
279 /* drives and and get the drive and stuffit ine the table */
281 /********************************CNS******************************************/
282 if ( (find_partition_type(EXTENDED)) && (find_logical_drive()) )
283 table_count += copy_fdisk2select(table_count,Dptr); /* go fill the tables */
284 /*****************************************************************************/
285 /* Now we should get the number of items that will be returned to select */
286 /* and stuff it in CX */
287 /******************************************************************************/
288 RoutPtr->x.cx = table_count; /* number of items */
297 void init_partition_tables()
306 unsigned partition_location;
308 char more_drives_exist;
309 char num_logical_drives;
314 save_disk = cur_disk;
316 /* initialize first drive found to "C" */
317 next_letter = c('C'); /* AC000 */
319 /* Look at both disks */
320 for (j = uc(0); j < number_of_drives; j++) /* AC000 */
323 /* Initialize the cur_disk field to the drive in question so */
324 /* that the calls to the partition information routines will work */
325 cur_disk = ((char)(j));
327 /* Read in the master boot record and see if it was okay */
328 if (read_boot_record(u(0),j,uc(0),uc(1))) /* AC000 */
331 /* See if there was a valid boot record there */
332 if ((boot_record[510] == uc(0x55)) && (boot_record[511] == uc(0xAA))) /* AC000 */
335 /* What was on the disk is a valid boot record, so save it */
336 for (i=u(0);i < u(BYTES_PER_SECTOR); i++) /* AC000 */
338 master_boot_record[j][i] = boot_record[i];
341 /* We've now got a copy of the master boot record saved. Now we need */
342 /* to translate what in the boot record to the area that it's going
343 /* to be worked on (part_table) */
345 /* Read in the data from the master boot record partition entries*/
346 for (i=u(0); i < u(4); i++) /* AC000 */
351 part_table[j][i].boot_ind = master_boot_record[j][0x1BE+index];
354 part_table[j][i].start_head = master_boot_record[j][0x1BF+index];
356 /* Start sector - unscramble it from INT 13 format*/
357 part_table[j][i].start_sector= (master_boot_record[j][0x1C0+index] & 0x3F);
359 /* Start cyl - unscramble it from INT 13 format*/
360 part_table[j][i].start_cyl= ((((unsigned)master_boot_record[j][0x1C0+index]) & 0x00C0) << 2)
361 + ((unsigned)master_boot_record[j][0x1C1+index]);
364 part_table[j][i].sys_id = master_boot_record[j][0x1C2+index];
367 part_table[j][i].end_head = master_boot_record[j][0x1C3+index];
369 /* End sector - unscramble it from INT 13 format*/
370 part_table[j][i].end_sector= (master_boot_record[j][0x1C4+index] & 0x3F);
372 /* End cyl - unscramble it from INT 13 format*/
373 part_table[j][i].end_cyl= ((((unsigned)master_boot_record[j][0x1C4+index]) & 0x00C0) << 2)
374 + ((unsigned)master_boot_record[j][0x1C5+index]);
376 /* Relative sectors */
378 part_table[j][i].rel_sec =
379 ((unsigned long)master_boot_record[j][0x1C9+index]) << 24;
381 part_table[j][i].rel_sec = part_table[j][i].rel_sec +
382 (((unsigned long)master_boot_record[j][0x1C8+index]) << 16);
384 part_table[j][i].rel_sec = part_table[j][i].rel_sec +
385 (((unsigned long)master_boot_record[j][0x1C7+index]) << 8);
387 part_table[j][i].rel_sec = part_table[j][i].rel_sec +
388 ((unsigned long)master_boot_record[j][0x1C6+index]);
390 /* Number of sectors */
391 part_table[j][i].num_sec =
392 ((unsigned long)master_boot_record[j][0x1CD+index]) << 24;
394 part_table[j][i].num_sec = part_table[j][i].num_sec +
395 (((unsigned long)master_boot_record[j][0x1CC+index]) << 16);
397 part_table[j][i].num_sec = part_table[j][i].num_sec +
398 (((unsigned long)master_boot_record[j][0x1CB+index]) << 8);
400 part_table[j][i].num_sec = part_table[j][i].num_sec +
401 ((unsigned long)master_boot_record[j][0x1CA+index]);
403 part_table[j][i].mbytes_used =
404 cylinders_to_mbytes(((part_table[j][i].end_cyl-part_table[j][i].start_cyl)+1),
405 max_sector[cur_disk], max_head[cur_disk]); /* AN000 */
407 /* Set drive letter */
408 if ( (part_table[j][i].sys_id == DOS12) || /* AN000 */
409 (part_table[j][i].sys_id == DOS16) || /* AN000 */
410 (part_table[j][i].sys_id == DOSNEW) ) /* AN000 */
411 part_table[j][i].drive_letter = next_letter++; /* AN000 */
413 /* Clean out the boot_record */
414 for (m=u(0);m < u(BYTES_PER_SECTOR); m++) /* AC000 */
416 boot_record[m] = uc(0); /* AC000 */
419 part_table[j][i].formatted = FALSE;
420 for (m=u(0);m < u(4); m++)
421 part_table[j][i].system_level[m] = NUL;
422 if (read_boot_record(part_table[j][i].start_cyl, /* AN000 */
424 part_table[j][i].start_head,
425 part_table[j][i].start_sector))
427 /* See if the disk has already been formated */
428 if ((boot_record[510] == uc(0x55)) && (boot_record[511] == uc(0xAA))) /* AN000 */
430 part_table[j][i].formatted = TRUE; /* AN000 */
431 for (m=u(0);m < u(4); m++)
434 part_table[j][i].system_level[m] = boot_record[n];
437 read_boot_record(part_table[j][i].start_cyl,j,uc(0),uc(1));
443 cur_disk = save_disk;
448 /* Look at both disks */
449 for (j = uc(0); j < number_of_drives; j++) /* AC000 */
452 /* Initialize the cur_disk field to the drive in question so */
453 /* that the calls to the partition information routines will work */
454 cur_disk = ((char)(j));
456 /* Read in the master boot record and see if it was okay */
457 if (read_boot_record(u(0),j,uc(0),uc(1))) /* AC000 */
458 /* Now, go read in extended partition info */
460 if (find_partition_type(uc(EXTENDED))) /* AC000 */
462 /* Initialize the array to zero's - include one dummy entry */
463 for (i=u(0); i < u(24); i++) /* AC000 */
465 ext_table[j][i].boot_ind = uc(0); /* AC000 */
466 ext_table[j][i].start_head = uc(0); /* AC000 */
467 ext_table[j][i].start_sector = uc(0); /* AC000 */
468 ext_table[j][i].start_cyl = u(0); /* AC000 */
469 ext_table[j][i].sys_id = uc(0); /* AC000 */
470 ext_table[j][i].end_head = uc(0); /* AC000 */
471 ext_table[j][i].end_sector = uc(0); /* AC000 */
472 ext_table[j][i].end_cyl = u(0); /* AC000 */
473 ext_table[j][i].rel_sec = ul(0); /* AC000 */
474 ext_table[j][i].num_sec = ul(0); /* AC000 */
475 ext_table[j][i].mbytes_used = f(0); /* AN000 */
476 ext_table[j][i].drive_letter = NUL; /* AN000 */
478 for (m=u(0);m < u(4); m++)
479 ext_table[j][i].system_level[m] = NUL; /* AN000 */
483 /* Find where the first extended boot record is */
484 temp = find_partition_location(uc(EXTENDED)); /* AC000 */
485 partition_location = part_table[j][temp].start_cyl;
487 /* Go find extended boot records as long as there are more of them */
488 more_drives_exist = TRUE;
490 /* Init the number of logical drives, for a array index */
491 num_logical_drives = c(0); /* AC000 */
493 while (more_drives_exist)
495 /* Assume we won't find another logical drive */
496 more_drives_exist = FALSE;
498 /*Read in the extended boot record */
499 if (read_boot_record(partition_location,j,uc(0),uc(1))) /* AC000 */
501 load_logical_drive(num_logical_drives,j);
504 /* find the next logical drive */
505 for (i = u(0); i < u(4); i++) /* AC000 */
508 /* See if a sys id byte of exteneded exists */
509 if (boot_record[0x1C2+index] == uc(EXTENDED)) /* AC000 */
511 /* Found another drive, now get its location */
512 partition_location= (((((unsigned)(boot_record[0x1C0 + index])) & 0x00C0) << 2));
513 partition_location = partition_location + ((unsigned)(boot_record[0x1C1+index]));
515 /* Indicate we found another one */
516 more_drives_exist = TRUE;
518 /* Up the count of found ones */
519 num_logical_drives++;
529 cur_disk = save_disk;
535 unsigned find_part_free_space()
541 char partition_count;
542 char last_found_partition;
544 char freespace_count;
548 /* Sort the partition table */
549 sort_part_table(c(4)); /* AC000 */
552 /* Intialize free space to zero */
553 for (i = c(0); i < c(24); i++) /* AC000 */
555 free_space[i].space = u(0); /* AC000 */
556 free_space[i].start = u(0); /* AC000 */
557 free_space[i].end = u(0); /* AC000 */
558 free_space[i].mbytes_unused = u(0); /* AC000 */ /* AN000 */
561 /* Find space between start of disk and first partition */
562 partition_count = c(0); /* AC000 */
564 any_partition = FALSE;
565 for (i = c(0); i < c(4); i++) /* AC000 */
567 if (part_table[cur_disk][sort[i]].sys_id != uc(0)) /* AC000 */
569 /* Found a partition, get the space */
571 free_space[0].start = u(0); /* AC000 */
573 /* free space ends before start of next valid partition */
574 if (part_table[cur_disk][sort[i]].start_cyl > u(0)) /* AC000 */
575 free_space[0].end = part_table[cur_disk][sort[i]].start_cyl-1;
577 free_space[0].space = part_table[cur_disk][sort[i]].start_cyl;
578 free_space[0].mbytes_unused =
579 cylinders_to_mbytes(free_space[0].space,max_sector[cur_disk],max_head[cur_disk]); /* AN000 */
582 last_found_partition = sort[i];
583 any_partition = TRUE;
587 /* See if any partitions were there */
590 /* Look for space between the rest of the partitions */
591 freespace_count = c(1); /* AC000 */
592 for (i = partition_count+1; i < c(4); i++) /* AC000 */
594 if (part_table[cur_disk][sort[i]].sys_id != uc(0)) /* AC000 */
597 /* Check to see if more than one partition on a cylinder (i.e. XENIX bad block) */
598 /* If so, leave the space at zero */
600 if (part_table[cur_disk][sort[i]].start_cyl != part_table[cur_disk][last_found_partition].end_cyl)
603 /* No, things are normal */
604 /* Get space between the end of the last one and the start of the next one */
605 free_space[freespace_count].space = part_table[cur_disk][sort[i]].start_cyl
606 - (part_table[cur_disk][last_found_partition].end_cyl+1);
608 temp_size = (part_table[cur_disk][sort[i]].start_cyl -
609 part_table[cur_disk][last_found_partition].end_cyl);
611 if (temp_size != u(0) ) /* AC000 */
612 free_space[freespace_count].space = temp_size - u(1); /* AC000 */
615 free_space[freespace_count].start = part_table[cur_disk][last_found_partition].end_cyl+1;
616 free_space[freespace_count].end = part_table[cur_disk][sort[i]].start_cyl -1;
617 free_space[freespace_count].mbytes_unused =
618 cylinders_to_mbytes(free_space[freespace_count].space,max_sector[cur_disk],max_head[cur_disk]); /* AN000 */
620 /* update the last found partition */
621 last_found_partition = sort[i];
625 /* Find the space between the last partition and the end of the disk */
626 free_space[freespace_count].space = (total_disk[cur_disk]
627 - part_table[cur_disk][last_found_partition].end_cyl)-1;
628 free_space[freespace_count].start = part_table[cur_disk][last_found_partition].end_cyl+1;
629 free_space[freespace_count].end = total_disk[cur_disk]-1;
630 free_space[freespace_count].mbytes_unused =
631 cylinders_to_mbytes(free_space[freespace_count].space,max_sector[cur_disk],max_head[cur_disk]); /* AN000 */
635 /* No partitions found, show entire space as free */
636 free_space[0].start = u(0); /* AC000 */
637 free_space[0].end = total_disk[cur_disk]-1;
638 free_space[0].space = (free_space[0].end - free_space[0].start)+1;
639 free_space[0].mbytes_unused =
640 cylinders_to_mbytes(free_space[0].space,max_sector[cur_disk],max_head[cur_disk]); /* AN000 */
643 /* Find largest free space */
644 /* Zip thru the table */
645 for (i = c(0); i < c(24); i++) /* AC000 */
647 /* Is this one bigger ? */
648 if (free_space[i].space > temp)
650 temp = free_space[i].space;
651 last_found_partition = i;
655 return(free_space[last_found_partition].mbytes_unused);
659 unsigned find_ext_free_space()
662 char partition_count;
663 char last_found_partition;
665 char freespace_count;
669 /* Sort the partition table */
670 sort_ext_table(c(23)); /* AC000 */
672 /* Initialize free space to zero */
673 for (i = c(0); i < c(24); i++) /* AC000 */
675 free_space[i].space = u(0); /* AC000 */
676 free_space[i].start = u(0);
677 free_space[i].end = u(0); /* AC000 */
678 free_space[i].mbytes_unused = u(0); /* AN000 */
681 /* Find space between start of Extended partition and first volume */
682 partition_count = c(0); /* AC000 */
683 last_found_partition = c(0);
684 ext_location = find_partition_location(uc(EXTENDED)); /* AC000 */
686 if (ext_location != c(NOT_FOUND))
689 any_partition = FALSE;
690 for (i = c(0); i < c(24); i++) /* AC000 */
692 if (ext_table[cur_disk][sort[i]].sys_id != uc(0)) /* AC000 */
694 /* Found a partition, get the space */
695 free_space[0].space = ext_table[cur_disk][sort[i]].start_cyl - part_table[cur_disk][ext_location].start_cyl;
696 free_space[0].start = part_table[cur_disk][ext_location].start_cyl;
697 free_space[0].end = ext_table[cur_disk][sort[i]].start_cyl-1;
698 free_space[0].mbytes_unused =
699 cylinders_to_mbytes(free_space[0].space,max_sector[cur_disk],max_head[cur_disk]); /* AN000 */
702 last_found_partition = sort[i];
703 any_partition = TRUE;
707 /* See if any partitions were there */
710 /* Look for space between the rest of the partitions */
711 freespace_count = c(1); /* AC000 */
712 for (i = partition_count+1; i < c(24); i++) /* AC000 */
714 if (ext_table[cur_disk][sort[i]].sys_id != uc(0)) /* AC000 */
717 /* Get space between the end of the last one and the start of the next one */
718 temp = ext_table[cur_disk][sort[i]].start_cyl - (ext_table[cur_disk][last_found_partition].end_cyl+1);
719 free_space[freespace_count].space = temp;
720 free_space[freespace_count].start = ext_table[cur_disk][last_found_partition].end_cyl+1;
721 free_space[freespace_count].end = ext_table[cur_disk][sort[i]].start_cyl -1;
722 free_space[freespace_count].mbytes_unused =
723 cylinders_to_mbytes(free_space[freespace_count].space,max_sector[cur_disk],max_head[cur_disk]); /* AN000 */
726 /* update the last found partition */
727 last_found_partition = sort[i];
731 /* Find the space between the last partition and the end of the extended partition */
732 temp = part_table[cur_disk][ext_location].end_cyl - ext_table[cur_disk][last_found_partition].end_cyl;
733 free_space[freespace_count].space = temp;
734 free_space[freespace_count].start = ext_table[cur_disk][last_found_partition].end_cyl+1;
735 free_space[freespace_count].end = part_table[cur_disk][ext_location].end_cyl;
736 free_space[freespace_count].mbytes_unused =
737 cylinders_to_mbytes(free_space[freespace_count].space,max_sector[cur_disk],max_head[cur_disk]); /* AN000 */
742 /* No partitions found, show entire space as free */
743 free_space[0].space = (part_table[cur_disk][ext_location].end_cyl - part_table[cur_disk][ext_location].start_cyl) + 1;
744 free_space[0].start = part_table[cur_disk][ext_location].start_cyl;
745 free_space[0].end = part_table[cur_disk][ext_location].end_cyl;
746 free_space[0].mbytes_unused =
747 cylinders_to_mbytes(free_space[0].space,max_sector[cur_disk],max_head[cur_disk]); /* AN000 */
750 /* Find largest free space */
751 temp = u(0); /* AC000 */
753 /* Find largest free space */
754 temp = u(0); /* AC000 */
756 /* Zip thru the table */
757 for (i = c(0); i < c(24); i++) /* AC000 */
759 /* Is this one bigger ? */
760 if (free_space[i].space > temp)
762 temp = free_space[i].space;
763 last_found_partition = i;
767 /* Return with the largest free space */
768 return(free_space[last_found_partition].mbytes_unused);
771 void sort_part_table(size)
781 /* Init the sorting parameters */
783 for (i=c(0); i < size; i++) /* AC000 */
788 /* Do a bubble sort */
791 /* Sort until we don't do a swap */
796 for (i=c(1); i < size; i++) /* AC000 */
799 /* Does the partition entry start before the previous one, or */
800 /* is it empty (0 ENTRY). If empty, it automatically gets shoved */
801 /* to the front, if the previous entry isn't also empty */
803 if ((part_table[cur_disk][sort[i]].end_cyl < part_table[cur_disk][sort[i-1]].end_cyl)
804 || ((part_table[cur_disk][sort[i]].sys_id == uc(0)) && (part_table[cur_disk][sort[i-1]].sys_id != uc(0)))) /* AC000 */
807 /* Swap the order indicators */
812 /* printf("\nI-1 =%d\n",part_table[cur_disk][sort[i-1]].start_cyl);*/
813 /* printf("I =%d\n",part_table[cur_disk][sort[i]].start_cyl);*/
814 /* printf("Sort[i-1] = %d\n",sort[i-1]);*/
815 /* printf("Sort[i] = %d\n",sort[i]); */
816 /* wait_for_ESC(); */
819 /* indicate we did a swap */
832 void sort_ext_table(size)
842 /* Init the sorting parameters */
844 for (i=c(0); i < size; i++) /* AC000 */
849 /* Do a bubble sort */
852 /* Sort until we don't do a swap */
857 for (i=c(1); i < size; i++) /* AC000 */
860 if (ext_table[cur_disk][sort[i]].start_cyl < ext_table[cur_disk][sort[i-1]].start_cyl)
866 /* indicate we did a swap */
875 void load_logical_drive(point,drive)
882 char volume_label[11]; /* AN000 */
887 unsigned dx_pointer; /* AN000 */
888 unsigned partition_location; /* AN000 */
890 /* Check to see if anything is there */
891 if ((boot_record[510] == uc(0x55)) && (boot_record[511] == uc(0xAA))) /* AC000 */
893 /* The boot record is there - read in the logical drive if it is there */
894 for (i = u(0); i < u(4); i++) /* AC000 */
898 /* See if it is a defined extended drive*/
899 if ((boot_record[0x1C2 + index] != uc(0)) && (boot_record[0x1C2 + index] != uc(EXTENDED))) /* AC000 */
902 ext_table[drive][point].boot_ind = boot_record[0x1BE + index];
905 ext_table[drive][point].start_head = boot_record[0x1BF + index];
907 /* Start sector - unscramble it from INT 13 format*/
908 ext_table[drive][point].start_sector= (boot_record[0x1C0 + index] & 0x3F);
910 /* Start cyl - unscramble it from INT 13 format*/
911 ext_table[drive][point].start_cyl= ((((unsigned)boot_record[0x1C0+index]) & 0x00C0) << 2)
912 + ((unsigned)boot_record[0x1C1+index]);
916 ext_table[drive][point].sys_id = boot_record[0x1C2+index];
919 ext_table[drive][point].end_head = boot_record[0x1C3+index];
921 /* End sector - unscramble it from INT 13 format*/
922 ext_table[drive][point].end_sector= (boot_record[0x1C4+index] & 0x3F);
925 /* End cyl - unscramble it from INT 13 format*/
926 ext_table[drive][point].end_cyl= ((((unsigned)boot_record[0x1C4+index]) & 0x00C0) << 2)
927 + ((unsigned)boot_record[0x1C5+index]);
929 /* Relative sectors */
930 ext_table[drive][point].rel_sec =
931 ((unsigned long)boot_record[0x1C9+index]) << 24;
933 ext_table[drive][point].rel_sec =
934 ext_table[drive][point].rel_sec+(((unsigned long)boot_record[0x1C8+index]) << 16);
936 ext_table[drive][point].rel_sec =
937 ext_table[drive][point].rel_sec + (((unsigned long)boot_record[0x1C7+index]) << 8);
939 ext_table[drive][point].rel_sec =
940 ext_table[drive][point].rel_sec + ((unsigned long)boot_record[0x1C6+index]);
942 /* Number of sectors */
944 ext_table[drive][point].num_sec =
945 ((unsigned long)boot_record[0x1CD+index]) << 24;
947 ext_table[drive][point].num_sec =
948 ext_table[drive][point].num_sec+(((unsigned long)boot_record[0x1CC+index]) << 16);
950 ext_table[drive][point].num_sec =
951 ext_table[drive][point].num_sec + (((unsigned long)boot_record[0x1CB+index]) << 8);
953 ext_table[drive][point].num_sec =
954 ext_table[drive][point].num_sec + ((unsigned long)boot_record[0x1CA+index]);
956 ext_table[drive][point].mbytes_used =
957 cylinders_to_mbytes(((ext_table[drive][point].end_cyl - ext_table[drive][point].start_cyl)+1),
958 max_sector[drive], max_head[drive]); /* AN000 */
960 if ( (ext_table[drive][point].sys_id == DOS12) || /* AN000 */
961 (ext_table[drive][point].sys_id == DOS16) || /* AN000 */
962 (ext_table[drive][point].sys_id == DOSNEW) ) /* AN000 */
963 ext_table[drive][point].drive_letter = next_letter++; /* AN000 */
965 partition_location = ext_table[drive][point].start_cyl;
967 ext_table[drive][point].formatted = FALSE;
968 for (m=u(0);m < u(4); m++)
969 ext_table[drive][point].system_level[m] = NUL;
970 if (read_boot_record(ext_table[drive][point].start_cyl, /* AN000 */
972 ext_table[drive][point].start_head,
973 ext_table[drive][point].start_sector))
975 /* See if the disk has already been formated */
976 if ((boot_record[510] == uc(0x55)) && (boot_record[511] == uc(0xAA))) /* AN000 */
978 ext_table[drive][point].formatted = TRUE; /* AN000 */
979 for (m=u(0);m < u(4); m++)
982 ext_table[drive][point].system_level[m] = boot_record[n];
987 read_boot_record(ext_table[drive][point].start_cyl,drive,uc(0),uc(1));
998 char find_partition_location(type)
1005 /* Look at all four partition entries for system id byte that matches */
1006 for (i = c(0); i < c(4);i++) /* AC000 */
1009 /* if we find a match, do a TRUE return */
1010 if (part_table[cur_disk][i].sys_id == type)
1016 /* Did not find one, return */
1017 return(c(NOT_FOUND)); /* AC000 */
1021 FLAG find_partition_type(type)
1027 /* Look at all four partition entries for system id byte that matches */
1028 for (i = c(0); i < c(4);i++) /* AC000 */
1031 /* if we find a match, do a TRUE return */
1032 if (part_table[cur_disk][i].sys_id == type) return(TRUE);
1034 /* Did not find one, return FALSE */
1038 unsigned char find_partition_system_type()
1043 /* Look at all four partition entries for system id byte that matches */
1044 for (i = c(0); i < c(4);i++) /* AC000 */
1047 /* if we find a match, do a TRUE return */
1048 if ( (part_table[cur_disk][i].sys_id == DOS12) ||
1049 (part_table[cur_disk][i].sys_id == DOS16) ||
1050 (part_table[cur_disk][i].sys_id == DOSNEW) )
1051 return(part_table[cur_disk][i].sys_id);
1053 return(uc(NOT_FOUND)); /* AC000 */
1056 char find_logical_drive()
1061 /* See if there is a logical drive defined in Extended Partition */
1062 for (i = c(0); i < c(24); i++) /* AC000 */
1064 /* See if we find a sys id that is not 0 */
1065 if (ext_table[cur_disk][i].sys_id != uc(0)) return(TRUE); /* AC000 */
1070 /*******************************************************************************/
1071 /*Routine name: CYLINDERS_TO_MBYTES */
1072 /*******************************************************************************/
1074 /*Description: This routine will take input of cylinders and convert */
1078 /*Called Procedures: */
1081 /*Change History: Created 5/16/87 DRM */
1083 /*Input: Cylinders_in */
1085 /*Output: MBytes_out */
1089 /*******************************************************************************/
1091 unsigned cylinders_to_mbytes(cylinders_in,sectors_per_track,number_of_heads) /* AN000 */
1093 unsigned cylinders_in; /* AN000 */
1094 unsigned char number_of_heads; /* AN000 */
1095 unsigned char sectors_per_track; /* AN000 */
1099 unsigned mbytes_out; /* AN000 */
1100 unsigned long number_of_bytes; /* AN000 */
1101 unsigned long number_of_sectors; /* AN000 */
1102 unsigned long number_of_tracks; /* AN000 */
1104 number_of_tracks = ul((cylinders_in * number_of_heads)); /* AN000 */
1105 number_of_sectors = ul((number_of_tracks * sectors_per_track)); /* AN000 */
1106 number_of_bytes = ul((number_of_sectors * BYTES_PER_SECTOR)); /* AN000 */
1107 mbytes_out = u((number_of_bytes / ONE_MEG)); /* AN000 */
1108 return(mbytes_out); /* AN000 */
1114 /**********************************replacement********************************************/
1115 /* To find out how many logical drives there are, if an extended partition exist */
1116 /* copy_fdisk2select. This procedure requires a check to see if any */
1117 /* logical drives exist if so, the drives must be sorted just as the */
1118 /* partitions to distinguish the amount of free space between the current logical */
1119 /* drive and the next. The ASCII drive value for each should also be */
1120 /* determined at this point. The same calculation using the start & end */
1121 /* cylinder must be used to determine the freespace. */
1122 /*****************************************************************************************/
1124 unsigned copy_fdisk2select(table_count,Dptr)
1125 unsigned table_count;
1136 char num_logical_drives ;
1138 /* loop thru the partitions, only load stuff if it is there */
1139 drive_num = c(0); /* Current drive */
1140 drive_found = FALSE;
1142 /* Find out how many logical drives are available for this hardfile */
1143 /* To get the number of maximum times to loop thru the table */
1145 num_logical_drives = get_num_logical_dos_drives();
1146 for ( i=u(0); i < u(num_logical_drives); i++)
1148 /* See if entry exists */
1149 if ( (ext_table[cur_disk][i].sys_id == uc(DOS12)) ||
1150 (ext_table[cur_disk][i].sys_id == uc(DOS16)) ||
1151 (ext_table[cur_disk][i].sys_id == uc(DOSNEW)) ) /* AC000 */
1154 (Dptr+table_count) ->n_part_size = ext_table[cur_disk][i].mbytes_used; /* AC000 */
1155 (Dptr+table_count) ->n_part_name = E_PART_LOG_DRI; /* SET the name field to logical drive */
1156 (Dptr+table_count) -> n_part_status = E_PART_UNFORMAT;
1157 if (ext_table[cur_disk][i].formatted)
1158 (Dptr+table_count) -> n_part_status = E_PART_FORMAT;
1159 (Dptr+table_count) ->p_part_drive = ext_table[cur_disk][i].drive_letter;
1160 for (m=u(0);m < u(4); m++)
1161 (Dptr+table_count) -> n_part_level[m] = ext_table[cur_disk][i].system_level[m];
1162 drive_num++; /* Go to the next actual drive value */
1163 table_count++; /* Go to the next disk status structure */
1164 END /* End of check for logical drives */
1165 END /* End of loop to traverse thru ext_table */
1172 char get_num_logical_dos_drives()
1178 number = c(0); /* AC000 */
1179 /* See if there is a logical drive defined in Extended Partition */
1180 for (i = c(0); i < c(24);i++) /* AC000 */
1183 /* See if we find a sys id that is DOS */
1184 if ((ext_table[cur_disk][i].sys_id == uc(DOS12)) || (ext_table[cur_disk][i].sys_id == uc(DOS16)) ||
1185 (ext_table[cur_disk][i].sys_id == uc(DOSNEW))) /* AC000 */
1196 XFLOAT get_partition_size(type) /* AC000 */
1198 unsigned char type; /* AC000 */
1203 /* Look at all four partition entries for system id byte that matches */
1204 for (i = c(0); i < c(4);i++) /* AC000 */
1207 /* if we find a match, get the size */
1208 if (part_table[cur_disk][i].sys_id == type)
1210 /* Get the size of the partition from the array */
1211 return(part_table[cur_disk][i].mbytes_used); /* AC000 */
1214 /* Did not find one, something bad wrong happened */