summaryrefslogtreecommitdiff
path: root/v4.0/src/SELECT/GET_STAT.C
diff options
context:
space:
mode:
Diffstat (limited to 'v4.0/src/SELECT/GET_STAT.C')
-rw-r--r--v4.0/src/SELECT/GET_STAT.C1216
1 files changed, 1216 insertions, 0 deletions
diff --git a/v4.0/src/SELECT/GET_STAT.C b/v4.0/src/SELECT/GET_STAT.C
new file mode 100644
index 0000000..aeab764
--- /dev/null
+++ b/v4.0/src/SELECT/GET_STAT.C
@@ -0,0 +1,1216 @@
1 /************************************************************/
2 /* */
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. */
13 /* */
14 /* The status info will be returned in the control */
15 /* block defined below: */
16 /* */
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) */
25 /* */
26 /*************************************************************/
27
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 */
32 /* ELSE */
33 /* set AX to to one and report error wrong call value */
34 /* ENDIF */
35 /* */
36 /* */
37 /*************************************************************/
38/*****************************************************************************/
39
40#include "stdio.h"
41#include "stdlib.h"
42#include "string.h"
43#include "dos.h"
44#include "get_stat.h"
45#include "extern.h"
46
47
48void get_status(union REGS *, union REGS *, struct SREGS *);
49void valid_stat(struct DISK_STATUS far *, union REGS *);
50void init_partition_tables(void);
51char read_boot_record(unsigned,unsigned char,unsigned char,unsigned char); /* AC000 */
52char get_drive_parameters(unsigned char);
53void sort_part_table(char);
54void sort_ext_table(char);
55unsigned find_part_free_space(void);
56unsigned find_ext_free_space(void);
57void load_logical_drive(char, unsigned char);
58char find_logical_drive(void);
59unsigned cylinders_to_mbytes(unsigned,unsigned char,unsigned char); /* AN000 */
60char find_partition_location(unsigned char);
61char find_free_partition(void);
62char find_partition_type(unsigned char);
63char get_disk_info(void);
64unsigned copy_fdisk2select(unsigned, DSE far * );
65char get_num_logical_dos_drives(void);
66unsigned get_partition_size(unsigned char);
67
68void DiskIo(union REGS *,union REGS *, struct SREGS *);
69unsigned char find_partition_system_type(void);
70
71#define DptrOf(ti) ( Dptr + (sizeof(DSE) * (ti)) )
72
73void get_status(RinPtr, RoutPtr, SrPtr)
74 union REGS *RinPtr;
75 union REGS *RoutPtr;
76 struct SREGS *SrPtr;
77
78BEGIN
79 DSE (far * Dptr);
80
81 /* ------------- drive = regs.x.ax; */
82 /* Make drive zero based */
83 /* ------------- drive--; */
84
85 FP_SEG(Dptr) = SrPtr->es;
86 FP_OFF(Dptr) = RinPtr->x.di;
87
88 RoutPtr->x.bx = 0;
89 RoutPtr->x.cx = 0;
90
91 switch(RinPtr->x.ax) /* Check the value in AX */
92 BEGIN
93
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);
97 RoutPtr->x.ax = 0;
98 valid_stat(Dptr,RoutPtr); /* yes than go execute */
99 break;
100
101 default: /* otherwise - set AX to one & exit */
102 RoutPtr->x.ax = 1;
103 break;
104 END
105
106 return;
107
108END
109
110/*****************************************************************************/
111/******************* START OF SPECIFICATIONS *******************/
112/* */
113/* SUBROUTINE NAME: VALID_STAT */
114/* */
115/* DESCRIPTIVE NAME: */
116/* */
117/* FUNCTION: */
118/* ENTRY: */
119/* */
120/* MOV AX,?? ; AX = 1 first fixed drive */
121/* */
122/* ; = 2 second fixed drive */
123/* ; ES:DI - points to parameter block */
124/* ; */
125/* CALL GET_DISK_STATUS ; call to subroutine */
126/* ; */
127/* ; EXIT: */
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 */
135/* */
136/* EXIT-NORMAL: ERROR=FALSE */
137/* */
138/* EXIT-ERROR: ERROR=TRUE */
139/* GOTO internal_program_error if invalid num */
140/* input is returned to this level */
141/* */
142/* EFFECTS: */
143/* */
144/* */
145/* */
146/* INTERNAL REFERENCES: */
147/* ROUTINES: */
148/* */
149/* */
150/* EXTERNAL REFERENCES: */
151/* ROUTINES: */
152/* */
153/******************** END OF SPECIFICATIONS ********************/
154
155void valid_stat(Dptr,RoutPtr)
156 DSE (far * Dptr);
157 union REGS *RoutPtr;
158
159BEGIN
160
161unsigned table_count;
162char i;
163unsigned m;
164unsigned temp;
165
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/********************************************************************************************/
176
177
178 /* Init variables */
179 RoutPtr->x.bx = 0;
180 RoutPtr->x.cx = 0;
181 table_count = 0;
182
183 /* Read drives to get disk information on size, etc..... */
184 /* good_disk[] = FALSE if can't read disk */
185 good_disk[0] = TRUE;
186 good_disk[1] = TRUE;
187 if (!get_disk_info())
188 BEGIN
189 good_disk[0] = FALSE;
190 good_disk[1] = FALSE;
191 END
192
193 /* See if we could read the selected drive */
194 if ( !good_disk[cur_disk] )
195 RoutPtr->x.ax = 1; /* indicate disk read failed */
196 else
197 BEGIN
198 init_partition_tables();
199
200 /* Is there a primary ? */
201
202 if (find_partition_system_type() != uc(NOT_FOUND))
203 BEGIN
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());
207
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) )
212 break;
213
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];
220
221
222 table_count++;
223 END
224
225 /* if there an extended? */
226
227 if (find_partition_type(EXTENDED))
228 BEGIN
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;
237 table_count++;
238 END
239
240 /* Are there any logical drives */
241
242 if ( (find_partition_type(EXTENDED)) && (find_logical_drive()) )
243 RoutPtr->x.bx |= E_DISK_LOG_DRI;
244
245 /* Is there free extended partition space, and are there free entries?*/
246
247 if ( (temp = find_ext_free_space()) != u(0))
248 BEGIN
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;
257 table_count++;
258 END
259
260 /* Is there any free space in master boot record partitions, and free partitions? */
261
262 if ( (temp = find_part_free_space()) != u(0))
263 BEGIN
264 /* Indicate we have free space in the MBR partition tables */
265 RoutPtr->x.ax = 0;
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;
271 table_count++;
272 END
273
274 /* If there is a logical drive get the drive letters and the associated */
275 /* size, and for the logical drive */
276
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 */
280
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 */
289 regs.x.ax = u(0);
290
291 END
292
293 return;
294
295END
296
297void init_partition_tables()
298BEGIN
299
300unsigned i;
301unsigned char j;
302unsigned k;
303unsigned l;
304unsigned m;
305unsigned n;
306unsigned partition_location;
307char temp;
308char more_drives_exist;
309char num_logical_drives;
310unsigned insert;
311unsigned index;
312char save_disk;
313
314 save_disk = cur_disk;
315
316 /* initialize first drive found to "C" */
317 next_letter = c('C'); /* AC000 */
318
319 /* Look at both disks */
320 for (j = uc(0); j < number_of_drives; j++) /* AC000 */
321 BEGIN
322
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));
326
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 */
329 BEGIN
330
331 /* See if there was a valid boot record there */
332 if ((boot_record[510] == uc(0x55)) && (boot_record[511] == uc(0xAA))) /* AC000 */
333 BEGIN
334
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 */
337 BEGIN
338 master_boot_record[j][i] = boot_record[i];
339 END
340 END
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) */
344
345 /* Read in the data from the master boot record partition entries*/
346 for (i=u(0); i < u(4); i++) /* AC000 */
347 BEGIN
348 index = i*16;
349
350 /* Get boot ind */
351 part_table[j][i].boot_ind = master_boot_record[j][0x1BE+index];
352
353 /* Start head */
354 part_table[j][i].start_head = master_boot_record[j][0x1BF+index];
355
356 /* Start sector - unscramble it from INT 13 format*/
357 part_table[j][i].start_sector= (master_boot_record[j][0x1C0+index] & 0x3F);
358
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]);
362
363 /* System id */
364 part_table[j][i].sys_id = master_boot_record[j][0x1C2+index];
365
366 /* End head */
367 part_table[j][i].end_head = master_boot_record[j][0x1C3+index];
368
369 /* End sector - unscramble it from INT 13 format*/
370 part_table[j][i].end_sector= (master_boot_record[j][0x1C4+index] & 0x3F);
371
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]);
375
376 /* Relative sectors */
377
378 part_table[j][i].rel_sec =
379 ((unsigned long)master_boot_record[j][0x1C9+index]) << 24;
380
381 part_table[j][i].rel_sec = part_table[j][i].rel_sec +
382 (((unsigned long)master_boot_record[j][0x1C8+index]) << 16);
383
384 part_table[j][i].rel_sec = part_table[j][i].rel_sec +
385 (((unsigned long)master_boot_record[j][0x1C7+index]) << 8);
386
387 part_table[j][i].rel_sec = part_table[j][i].rel_sec +
388 ((unsigned long)master_boot_record[j][0x1C6+index]);
389
390 /* Number of sectors */
391 part_table[j][i].num_sec =
392 ((unsigned long)master_boot_record[j][0x1CD+index]) << 24;
393
394 part_table[j][i].num_sec = part_table[j][i].num_sec +
395 (((unsigned long)master_boot_record[j][0x1CC+index]) << 16);
396
397 part_table[j][i].num_sec = part_table[j][i].num_sec +
398 (((unsigned long)master_boot_record[j][0x1CB+index]) << 8);
399
400 part_table[j][i].num_sec = part_table[j][i].num_sec +
401 ((unsigned long)master_boot_record[j][0x1CA+index]);
402
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 */
406
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 */
412
413 /* Clean out the boot_record */
414 for (m=u(0);m < u(BYTES_PER_SECTOR); m++) /* AC000 */
415 BEGIN
416 boot_record[m] = uc(0); /* AC000 */
417 END
418
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 */
423 j,
424 part_table[j][i].start_head,
425 part_table[j][i].start_sector))
426 BEGIN /* AN000 */
427 /* See if the disk has already been formated */
428 if ((boot_record[510] == uc(0x55)) && (boot_record[511] == uc(0xAA))) /* AN000 */
429 BEGIN
430 part_table[j][i].formatted = TRUE; /* AN000 */
431 for (m=u(0);m < u(4); m++)
432 BEGIN
433 n = (m + u(7));
434 part_table[j][i].system_level[m] = boot_record[n];
435 END
436 END
437 read_boot_record(part_table[j][i].start_cyl,j,uc(0),uc(1));
438 END
439 END
440 END
441 else
442 BEGIN
443 cur_disk = save_disk;
444 return;
445 END
446 END
447
448 /* Look at both disks */
449 for (j = uc(0); j < number_of_drives; j++) /* AC000 */
450 BEGIN
451
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));
455 BEGIN
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 */
459 BEGIN
460 if (find_partition_type(uc(EXTENDED))) /* AC000 */
461 BEGIN
462 /* Initialize the array to zero's - include one dummy entry */
463 for (i=u(0); i < u(24); i++) /* AC000 */
464 BEGIN
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 */
477
478 for (m=u(0);m < u(4); m++)
479 ext_table[j][i].system_level[m] = NUL; /* AN000 */
480
481 END
482
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;
486
487 /* Go find extended boot records as long as there are more of them */
488 more_drives_exist = TRUE;
489
490 /* Init the number of logical drives, for a array index */
491 num_logical_drives = c(0); /* AC000 */
492
493 while (more_drives_exist)
494 BEGIN
495 /* Assume we won't find another logical drive */
496 more_drives_exist = FALSE;
497
498 /*Read in the extended boot record */
499 if (read_boot_record(partition_location,j,uc(0),uc(1))) /* AC000 */
500 BEGIN
501 load_logical_drive(num_logical_drives,j);
502
503
504 /* find the next logical drive */
505 for (i = u(0); i < u(4); i++) /* AC000 */
506 BEGIN
507 index = i*16;
508 /* See if a sys id byte of exteneded exists */
509 if (boot_record[0x1C2+index] == uc(EXTENDED)) /* AC000 */
510 BEGIN
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]));
514
515 /* Indicate we found another one */
516 more_drives_exist = TRUE;
517
518 /* Up the count of found ones */
519 num_logical_drives++;
520 break;
521 END
522 END
523 END
524 END
525 END
526 END
527 END
528 END
529 cur_disk = save_disk;
530 return;
531END
532
533
534/* */
535unsigned find_part_free_space()
536
537BEGIN
538
539
540char i;
541char partition_count;
542char last_found_partition;
543unsigned temp;
544char freespace_count;
545char any_partition;
546unsigned temp_size;
547
548 /* Sort the partition table */
549 sort_part_table(c(4)); /* AC000 */
550
551
552 /* Intialize free space to zero */
553 for (i = c(0); i < c(24); i++) /* AC000 */
554 BEGIN
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 */
559 END
560
561 /* Find space between start of disk and first partition */
562 partition_count = c(0); /* AC000 */
563
564 any_partition = FALSE;
565 for (i = c(0); i < c(4); i++) /* AC000 */
566 BEGIN
567 if (part_table[cur_disk][sort[i]].sys_id != uc(0)) /* AC000 */
568 BEGIN
569 /* Found a partition, get the space */
570
571 free_space[0].start = u(0); /* AC000 */
572
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;
576
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 */
580
581 partition_count = i;
582 last_found_partition = sort[i];
583 any_partition = TRUE;
584 break;
585 END
586 END
587 /* See if any partitions were there */
588 if (any_partition)
589 BEGIN
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 */
593 BEGIN
594 if (part_table[cur_disk][sort[i]].sys_id != uc(0)) /* AC000 */
595 BEGIN
596
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 */
599
600 if (part_table[cur_disk][sort[i]].start_cyl != part_table[cur_disk][last_found_partition].end_cyl)
601
602 BEGIN
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);
607
608 temp_size = (part_table[cur_disk][sort[i]].start_cyl -
609 part_table[cur_disk][last_found_partition].end_cyl);
610
611 if (temp_size != u(0) ) /* AC000 */
612 free_space[freespace_count].space = temp_size - u(1); /* AC000 */
613 END
614
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 */
619
620 /* update the last found partition */
621 last_found_partition = sort[i];
622 freespace_count++;
623 END
624 END
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 */
632 END
633 else
634 BEGIN
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 */
641 END
642
643 /* Find largest free space */
644 /* Zip thru the table */
645 for (i = c(0); i < c(24); i++) /* AC000 */
646 BEGIN
647 /* Is this one bigger ? */
648 if (free_space[i].space > temp)
649 BEGIN
650 temp = free_space[i].space;
651 last_found_partition = i;
652 END
653 END
654
655 return(free_space[last_found_partition].mbytes_unused);
656END
657
658/* */
659unsigned find_ext_free_space()
660BEGIN
661char i;
662char partition_count;
663char last_found_partition;
664unsigned temp;
665char freespace_count;
666char any_partition;
667char ext_location;
668
669 /* Sort the partition table */
670 sort_ext_table(c(23)); /* AC000 */
671
672 /* Initialize free space to zero */
673 for (i = c(0); i < c(24); i++) /* AC000 */
674 BEGIN
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 */
679 END
680
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 */
685
686 if (ext_location != c(NOT_FOUND))
687 BEGIN
688
689 any_partition = FALSE;
690 for (i = c(0); i < c(24); i++) /* AC000 */
691 BEGIN
692 if (ext_table[cur_disk][sort[i]].sys_id != uc(0)) /* AC000 */
693 BEGIN
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 */
700
701 partition_count = i;
702 last_found_partition = sort[i];
703 any_partition = TRUE;
704 break;
705 END
706 END
707 /* See if any partitions were there */
708 if (any_partition)
709 BEGIN
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 */
713 BEGIN
714 if (ext_table[cur_disk][sort[i]].sys_id != uc(0)) /* AC000 */
715 BEGIN
716
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 */
724
725
726 /* update the last found partition */
727 last_found_partition = sort[i];
728 freespace_count++;
729 END
730 END
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 */
738
739 END
740 else
741 BEGIN
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 */
748 END
749
750 /* Find largest free space */
751 temp = u(0); /* AC000 */
752
753 /* Find largest free space */
754 temp = u(0); /* AC000 */
755
756 /* Zip thru the table */
757 for (i = c(0); i < c(24); i++) /* AC000 */
758 BEGIN
759 /* Is this one bigger ? */
760 if (free_space[i].space > temp)
761 BEGIN
762 temp = free_space[i].space;
763 last_found_partition = i;
764 END
765 END
766 END
767 /* Return with the largest free space */
768 return(free_space[last_found_partition].mbytes_unused);
769END
770/* */
771void sort_part_table(size)
772
773char size;
774
775BEGIN
776
777char changed;
778char temp;
779char i;
780
781 /* Init the sorting parameters */
782
783 for (i=c(0); i < size; i++) /* AC000 */
784 BEGIN
785 sort[i] = i;
786 END
787
788 /* Do a bubble sort */
789 changed = TRUE;
790
791 /* Sort until we don't do a swap */
792 while (changed)
793
794 BEGIN
795 changed = FALSE;
796 for (i=c(1); i < size; i++) /* AC000 */
797 BEGIN
798
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 */
802
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 */
805
806 BEGIN
807 /* Swap the order indicators */
808 temp = sort[i-1];
809 sort[i-1] = sort[i];
810 sort[i] = temp;
811
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(); */
817
818
819 /* indicate we did a swap */
820 changed = TRUE;
821 END
822 END
823 END
824 return;
825END
826
827
828
829
830/* */
831/* */
832void sort_ext_table(size)
833
834char size;
835
836BEGIN
837
838char changed;
839char temp;
840char i;
841
842 /* Init the sorting parameters */
843
844 for (i=c(0); i < size; i++) /* AC000 */
845 BEGIN
846 sort[i] = i;
847 END
848
849 /* Do a bubble sort */
850 changed = TRUE;
851
852 /* Sort until we don't do a swap */
853 while (changed)
854
855 BEGIN
856 changed = FALSE;
857 for (i=c(1); i < size; i++) /* AC000 */
858 BEGIN
859
860 if (ext_table[cur_disk][sort[i]].start_cyl < ext_table[cur_disk][sort[i-1]].start_cyl)
861 BEGIN
862
863 temp = sort[i-1];
864 sort[i-1] = sort[i];
865 sort[i] = temp;
866 /* indicate we did a swap */
867 changed = TRUE;
868 END
869 END
870 END
871 return;
872END
873
874/* */
875void load_logical_drive(point,drive)
876
877char point;
878unsigned char drive;
879
880BEGIN
881
882char volume_label[11]; /* AN000 */
883unsigned i;
884unsigned m;
885unsigned n;
886unsigned index;
887unsigned dx_pointer; /* AN000 */
888unsigned partition_location; /* AN000 */
889
890 /* Check to see if anything is there */
891 if ((boot_record[510] == uc(0x55)) && (boot_record[511] == uc(0xAA))) /* AC000 */
892 BEGIN
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 */
895 BEGIN
896
897 index = i*16;
898 /* See if it is a defined extended drive*/
899 if ((boot_record[0x1C2 + index] != uc(0)) && (boot_record[0x1C2 + index] != uc(EXTENDED))) /* AC000 */
900 BEGIN
901 /* Get boot ind */
902 ext_table[drive][point].boot_ind = boot_record[0x1BE + index];
903
904 /* Start head */
905 ext_table[drive][point].start_head = boot_record[0x1BF + index];
906
907 /* Start sector - unscramble it from INT 13 format*/
908 ext_table[drive][point].start_sector= (boot_record[0x1C0 + index] & 0x3F);
909
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]);
913
914
915 /* System id */
916 ext_table[drive][point].sys_id = boot_record[0x1C2+index];
917
918 /* End head */
919 ext_table[drive][point].end_head = boot_record[0x1C3+index];
920
921 /* End sector - unscramble it from INT 13 format*/
922 ext_table[drive][point].end_sector= (boot_record[0x1C4+index] & 0x3F);
923
924
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]);
928
929 /* Relative sectors */
930 ext_table[drive][point].rel_sec =
931 ((unsigned long)boot_record[0x1C9+index]) << 24;
932
933 ext_table[drive][point].rel_sec =
934 ext_table[drive][point].rel_sec+(((unsigned long)boot_record[0x1C8+index]) << 16);
935
936 ext_table[drive][point].rel_sec =
937 ext_table[drive][point].rel_sec + (((unsigned long)boot_record[0x1C7+index]) << 8);
938
939 ext_table[drive][point].rel_sec =
940 ext_table[drive][point].rel_sec + ((unsigned long)boot_record[0x1C6+index]);
941
942 /* Number of sectors */
943
944 ext_table[drive][point].num_sec =
945 ((unsigned long)boot_record[0x1CD+index]) << 24;
946
947 ext_table[drive][point].num_sec =
948 ext_table[drive][point].num_sec+(((unsigned long)boot_record[0x1CC+index]) << 16);
949
950 ext_table[drive][point].num_sec =
951 ext_table[drive][point].num_sec + (((unsigned long)boot_record[0x1CB+index]) << 8);
952
953 ext_table[drive][point].num_sec =
954 ext_table[drive][point].num_sec + ((unsigned long)boot_record[0x1CA+index]);
955
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 */
959
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 */
964
965 partition_location = ext_table[drive][point].start_cyl;
966
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 */
971 drive,
972 ext_table[drive][point].start_head,
973 ext_table[drive][point].start_sector))
974 BEGIN /* AN000 */
975 /* See if the disk has already been formated */
976 if ((boot_record[510] == uc(0x55)) && (boot_record[511] == uc(0xAA))) /* AN000 */
977 BEGIN
978 ext_table[drive][point].formatted = TRUE; /* AN000 */
979 for (m=u(0);m < u(4); m++)
980 BEGIN
981 n = (m + u(7));
982 ext_table[drive][point].system_level[m] = boot_record[n];
983 END
984 END
985
986
987 read_boot_record(ext_table[drive][point].start_cyl,drive,uc(0),uc(1));
988 END
989 END
990 END
991 END
992
993 return;
994
995END
996
997/* */
998char find_partition_location(type)
999
1000unsigned char type;
1001
1002BEGIN
1003 char i;
1004
1005/* Look at all four partition entries for system id byte that matches */
1006 for (i = c(0); i < c(4);i++) /* AC000 */
1007 BEGIN
1008
1009 /* if we find a match, do a TRUE return */
1010 if (part_table[cur_disk][i].sys_id == type)
1011 BEGIN
1012 return(i);
1013 break;
1014 END
1015 END
1016 /* Did not find one, return */
1017 return(c(NOT_FOUND)); /* AC000 */
1018END
1019
1020/* */
1021FLAG find_partition_type(type)
1022unsigned char type;
1023
1024BEGIN
1025char i;
1026
1027/* Look at all four partition entries for system id byte that matches */
1028 for (i = c(0); i < c(4);i++) /* AC000 */
1029 BEGIN
1030
1031 /* if we find a match, do a TRUE return */
1032 if (part_table[cur_disk][i].sys_id == type) return(TRUE);
1033 END
1034 /* Did not find one, return FALSE */
1035 return(FALSE);
1036END
1037/* */
1038unsigned char find_partition_system_type()
1039
1040BEGIN
1041char i;
1042
1043/* Look at all four partition entries for system id byte that matches */
1044 for (i = c(0); i < c(4);i++) /* AC000 */
1045 BEGIN
1046
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);
1052 END
1053 return(uc(NOT_FOUND)); /* AC000 */
1054END
1055/* */
1056char find_logical_drive()
1057
1058BEGIN
1059char i;
1060
1061 /* See if there is a logical drive defined in Extended Partition */
1062 for (i = c(0); i < c(24); i++) /* AC000 */
1063 BEGIN
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 */
1066 END
1067 return(FALSE);
1068END
1069/* */
1070/*******************************************************************************/
1071/*Routine name: CYLINDERS_TO_MBYTES */
1072/*******************************************************************************/
1073/* */
1074/*Description: This routine will take input of cylinders and convert */
1075/* it to MBytes. */
1076/* */
1077/* */
1078/*Called Procedures: */
1079/* */
1080/* */
1081/*Change History: Created 5/16/87 DRM */
1082/* */
1083/*Input: Cylinders_in */
1084/* */
1085/*Output: MBytes_out */
1086/* */
1087/* */
1088/* */
1089/*******************************************************************************/
1090
1091unsigned cylinders_to_mbytes(cylinders_in,sectors_per_track,number_of_heads) /* AN000 */
1092
1093unsigned cylinders_in; /* AN000 */
1094unsigned char number_of_heads; /* AN000 */
1095unsigned char sectors_per_track; /* AN000 */
1096
1097BEGIN /* AN000 */
1098
1099unsigned mbytes_out; /* AN000 */
1100unsigned long number_of_bytes; /* AN000 */
1101unsigned long number_of_sectors; /* AN000 */
1102unsigned long number_of_tracks; /* AN000 */
1103
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 */
1109
1110END /* AN000 */
1111
1112
1113
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/*****************************************************************************************/
1123
1124unsigned copy_fdisk2select(table_count,Dptr)
1125 unsigned table_count;
1126 DSE (far * Dptr);
1127
1128BEGIN
1129
1130unsigned i;
1131unsigned m;
1132unsigned x;
1133FLAG drive_found;
1134char drive_num;
1135char first_stuff;
1136char num_logical_drives ;
1137
1138 /* loop thru the partitions, only load stuff if it is there */
1139 drive_num = c(0); /* Current drive */
1140 drive_found = FALSE;
1141
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 */
1144
1145 num_logical_drives = get_num_logical_dos_drives();
1146 for ( i=u(0); i < u(num_logical_drives); i++)
1147 BEGIN
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 */
1152 BEGIN
1153 drive_found = TRUE;
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 */
1166
1167 return(drive_num);
1168
1169END
1170
1171/* */
1172char get_num_logical_dos_drives()
1173BEGIN
1174
1175char i;
1176char number;
1177
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 */
1181 BEGIN
1182
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 */
1186 BEGIN
1187 number++;
1188 END
1189 END
1190 return(number);
1191END
1192
1193/* */
1194
1195/* */
1196XFLOAT get_partition_size(type) /* AC000 */
1197
1198unsigned char type; /* AC000 */
1199
1200BEGIN
1201 char i;
1202
1203 /* Look at all four partition entries for system id byte that matches */
1204 for (i = c(0); i < c(4);i++) /* AC000 */
1205 BEGIN
1206
1207 /* if we find a match, get the size */
1208 if (part_table[cur_disk][i].sys_id == type)
1209 BEGIN
1210 /* Get the size of the partition from the array */
1211 return(part_table[cur_disk][i].mbytes_used); /* AC000 */
1212 END
1213 END
1214 /* Did not find one, something bad wrong happened */
1215 return(f(0));
1216END