8 char find_part_free_space(type)
17 char last_found_partition;
23 /* Sort the partition table */
24 sort_part_table(c(4)); /* AC000 */
27 /* Intialize free space to zero */
28 for (i = c(0); i < c(5); i++) /* AC000 */
30 free_space[i].space = u(0); /* AC000 */
31 free_space[i].start = u(0); /* AC000 */
32 free_space[i].end = u(0); /* AC000 */
33 free_space[i].mbytes_unused = f(0); /* AC000 */ /* AN000 */
34 free_space[i].percent_unused = u(0); /* AC000 */ /* AN000 */
37 /* Find space between start of disk and first partition */
38 partition_count = c(0); /* AC000 */
40 any_partition = FALSE;
41 for (i = c(0); i < c(4); i++) /* AC000 */
43 if (part_table[cur_disk][sort[i]].sys_id != uc(0)) /* AC000 */
45 /* Found a partition, get the space */
47 free_space[0].start = u(0); /* AC000 */
49 /* This is a special case - the extended partition can not start */
50 /* on cylinder 0 due too its archetecture. Protect against that here */
51 if (type == c(EXTENDED)) /* AC000 */
53 free_space[0].start = u(1); /* AC000 */
56 /* free space ends before start of next valid partition */
57 if (part_table[cur_disk][sort[i]].start_cyl > u(0)) /* AC000 */
59 free_space[0].end = part_table[cur_disk][sort[i]].start_cyl-1;
62 free_space[0].space = part_table[cur_disk][sort[i]].start_cyl;
63 free_space[0].mbytes_unused =
64 cylinders_to_mbytes(free_space[0].space,cur_disk); /* AN004 */
65 free_space[0].percent_unused = (unsigned)cylinders_to_percent(free_space[0].space,total_disk[cur_disk]); /* AN000 */
68 last_found_partition = sort[i];
73 /* See if any partitions were there */
76 /* Look for space between the rest of the partitions */
77 freespace_count = c(1); /* AC000 */
78 for (i = partition_count+1; i < c(4); i++) /* AC000 */
80 if (part_table[cur_disk][sort[i]].sys_id != uc(0)) /* AC000 */
83 /* Check to see if more than one partition on a cylinder (i.e. XENIX bad block) */
84 /* If so, leave the space at zero */
86 if (part_table[cur_disk][sort[i]].start_cyl != part_table[cur_disk][last_found_partition].end_cyl)
89 /* No, things are normal */
90 /* Get space between the end of the last one and the start of the next one */
91 free_space[freespace_count].space = part_table[cur_disk][sort[i]].start_cyl
92 - (part_table[cur_disk][last_found_partition].end_cyl+1);
94 temp_size = (part_table[cur_disk][sort[i]].start_cyl -
95 part_table[cur_disk][last_found_partition].end_cyl);
97 if (temp_size != u(0) ) /* AC000 */
99 free_space[freespace_count].space = temp_size - u(1); /* AC000 */
103 free_space[freespace_count].start = part_table[cur_disk][last_found_partition].end_cyl+1;
104 free_space[freespace_count].end = part_table[cur_disk][sort[i]].start_cyl -1;
105 free_space[freespace_count].mbytes_unused =
106 cylinders_to_mbytes(free_space[freespace_count].space,cur_disk); /* AN004 */
107 free_space[freespace_count].percent_unused = (unsigned)
108 cylinders_to_percent(free_space[freespace_count].space,total_disk[cur_disk]); /* AN000 */
112 /* update the last found partition */
113 last_found_partition = sort[i];
117 /* Find the space between the last partition and the end of the disk */
118 free_space[freespace_count].space = (total_disk[cur_disk]
119 - part_table[cur_disk][last_found_partition].end_cyl)-1;
120 free_space[freespace_count].start = part_table[cur_disk][last_found_partition].end_cyl+1;
121 free_space[freespace_count].end = total_disk[cur_disk]-1;
122 free_space[freespace_count].mbytes_unused =
123 cylinders_to_mbytes(free_space[freespace_count].space,cur_disk); /* AN004 */
124 free_space[freespace_count].percent_unused =
125 cylinders_to_percent(free_space[freespace_count].space,total_disk[cur_disk]); /* AN000 */
129 /* No partitions found, show entire space as free */
130 free_space[0].start = u(0); /* AC000 */
132 /* This is a special case - the extended partition can not start */
133 /* on cylinder 0 due too its architecture. Protect against that here */
134 if (type == c(EXTENDED)) /* AC000 */
136 free_space[0].start = u(1); /* AC000 */
138 free_space[0].end = total_disk[cur_disk]-1;
139 free_space[0].space = (free_space[0].end - free_space[0].start)+1;
140 free_space[0].mbytes_unused =
141 cylinders_to_mbytes(free_space[0].space,cur_disk); /* AN004 */
142 free_space[0].percent_unused =
143 cylinders_to_percent(free_space[0].space,total_disk[cur_disk]); /* AN000 */
148 /* Find largest free space, and verify the golden tracks while we are at it */
151 temp = u(0); /* AC000 */
153 /* Zip thru the table */
154 for (i = c(0); i < c(5); i++) /* AC000 */
156 /* Is this one bigger ? */
157 if (free_space[i].space > temp)
159 temp = free_space[i].space;
160 last_found_partition = i;
165 /* If there is any free space, go verify it */
167 if (free_space[last_found_partition].space != u(0)) /* AC000 */
170 /* Go verify the tracks */
171 temp = verify_tracks(last_found_partition,c(PRIMARY)); /* AC000 */
173 /* Move up to next golden track */
174 free_space[last_found_partition].start = free_space[last_found_partition].start+temp;
175 free_space[last_found_partition].space = free_space[last_found_partition].space-temp;
176 free_space[last_found_partition].mbytes_unused =
177 cylinders_to_mbytes(free_space[last_found_partition].space,cur_disk); /* AN004 */
178 free_space[last_found_partition].percent_unused = (unsigned)
179 cylinders_to_percent(free_space[last_found_partition].space,total_disk[cur_disk]); /* AN000 */
182 /* Repeat the loop if the start was moved due to bad tracks */
183 /* Unless we're past the end of the free space */
184 while ((temp != u(0)) && (free_space[last_found_partition].space != u(0))); /* AC000 */
186 /* Return with the pointer to the largest free space */
187 return(last_found_partition);
193 void sort_part_table(size)
203 /* Init the sorting parameters */
205 for (i=c(0); i < size; i++) /* AC000 */
210 /* Do a bubble sort */
213 /* Sort until we don't do a swap */
218 for (i=c(1); i < size; i++) /* AC000 */
221 /* Does the partition entry start before the previous one, or */
222 /* is it empty (0 ENTRY). If empty, it automatically gets shoved */
223 /* to the front, if the previous entry isn't also empty */
225 if ((part_table[cur_disk][sort[i]].end_cyl < part_table[cur_disk][sort[i-1]].end_cyl)
226 || ((part_table[cur_disk][sort[i]].num_sec == ul(0))
227 && (part_table[cur_disk][sort[i-1]].num_sec != ul(0)))) /* AC000 */
230 /* Swap the order indicators */
235 /* printf("\nI-1 =%d\n",part_table[cur_disk][sort[i-1]].start_cyl);*/
236 /* printf("I =%d\n",part_table[cur_disk][sort[i]].start_cyl);*/
237 /* printf("Sort[i-1] = %d\n",sort[i-1]);*/
238 /* printf("Sort[i] = %d\n",sort[i]); */
239 /* wait_for_ESC(); */
242 /* indicate we did a swap */
254 char find_ext_free_space()
261 char partition_count;
262 char last_found_partition;
264 char freespace_count;
268 /* Sort the partition table */
269 sort_ext_table(c(23)); /* AC000 */
272 /* Initialize free space to zero */
273 for (i = c(0); i < c(24); i++) /* AC000 */
275 free_space[i].space = u(0); /* AC000 */
276 free_space[i].start = u(0);
277 free_space[i].end = u(0); /* AC000 */
278 free_space[i].mbytes_unused = f(0); /* AN000 */
279 free_space[i].percent_unused = u(0); /* AN000 */
282 /* Find space between start of Extended partition and first volume */
283 ext_location = find_partition_location(uc(EXTENDED)); /* AC000 */
285 partition_count = c(0); /* AC000 */
287 any_partition = FALSE;
288 for (i = c(0); i < c(23); i++) /* AC000 */
290 if (ext_table[cur_disk][sort[i]].sys_id != uc(0)) /* AC000 */
292 /* Found a partition, get the space */
293 free_space[0].space = ext_table[cur_disk][sort[i]].start_cyl - part_table[cur_disk][ext_location].start_cyl;
294 free_space[0].start = part_table[cur_disk][ext_location].start_cyl;
295 free_space[0].end = ext_table[cur_disk][sort[i]].start_cyl-1;
296 free_space[0].mbytes_unused =
297 cylinders_to_mbytes(free_space[0].space,cur_disk); /* AN004 */
298 free_space[0].percent_unused = (unsigned)cylinders_to_percent(free_space[0].space,total_disk[cur_disk]); /* AN000 */
301 last_found_partition = sort[i];
302 any_partition = TRUE;
306 /* See if any partitions were there */
309 /* Look for space between the rest of the partitions */
310 freespace_count = c(1); /* AC000 */
311 for (i = partition_count+1; i < c(23); i++) /* AC000 */
313 if (ext_table[cur_disk][sort[i]].sys_id != uc(0)) /* AC000 */
316 /* Get space between the end of the last one and the start of the next one */
317 temp = ext_table[cur_disk][sort[i]].start_cyl - (ext_table[cur_disk][last_found_partition].end_cyl+1);
318 free_space[freespace_count].space = temp;
319 free_space[freespace_count].start = ext_table[cur_disk][last_found_partition].end_cyl+1;
320 free_space[freespace_count].end = ext_table[cur_disk][sort[i]].start_cyl -1;
321 free_space[freespace_count].mbytes_unused =
322 cylinders_to_mbytes(free_space[freespace_count].space,cur_disk); /* AN004 */
323 free_space[freespace_count].percent_unused = (unsigned)
324 cylinders_to_percent(free_space[freespace_count].space,total_disk[cur_disk]); /* AN000 */
327 /* update the last found partition */
328 last_found_partition = sort[i];
332 /* Find the space between the last partition and the end of the extended partition */
333 temp = part_table[cur_disk][ext_location].end_cyl - ext_table[cur_disk][last_found_partition].end_cyl;
334 free_space[freespace_count].space = temp;
335 free_space[freespace_count].start = ext_table[cur_disk][last_found_partition].end_cyl+1;
336 free_space[freespace_count].end = part_table[cur_disk][ext_location].end_cyl;
337 free_space[freespace_count].mbytes_unused =
338 cylinders_to_mbytes(free_space[freespace_count].space,cur_disk); /* AN004 */
339 free_space[freespace_count].percent_unused = (unsigned)
340 cylinders_to_percent(free_space[freespace_count].space,total_disk[cur_disk]); /* AN000 */
345 /* No partitions found, show entire space as free */
346 free_space[0].space = (part_table[cur_disk][ext_location].end_cyl - part_table[cur_disk][ext_location].start_cyl) + 1;
347 free_space[0].start = part_table[cur_disk][ext_location].start_cyl;
348 free_space[0].end = part_table[cur_disk][ext_location].end_cyl;
349 free_space[0].mbytes_unused =
350 cylinders_to_mbytes(free_space[0].space,cur_disk); /* AN004 */
351 free_space[0].percent_unused = (unsigned)cylinders_to_percent(free_space[0].space,total_disk[cur_disk]); /* AN000 */
354 /* Find largest free space */
355 temp = u(0); /* AC000 */
358 /* Find largest free space, and verify the golden tracks while we are at it */
361 temp = u(0); /* AC000 */
363 /* Zip thru the table */
364 for (i = c(0); i < c(24); i++) /* AC000 */
366 /* Is this one bigger ? */
367 if (free_space[i].space > temp)
369 temp = free_space[i].space;
370 last_found_partition = i;
373 /* If there is any free space, go verify it */
375 if (free_space[last_found_partition].space != u(0)) /* AC000 */
378 /* Go verify the tracks */
379 temp = verify_tracks(last_found_partition,c(EXTENDED)); /* AC000 */
381 /* Move up to next golden track */
382 free_space[last_found_partition].start = free_space[last_found_partition].start+temp;
383 free_space[last_found_partition].space = free_space[last_found_partition].space-temp;
384 free_space[last_found_partition].mbytes_unused =
385 cylinders_to_mbytes(free_space[last_found_partition].space,cur_disk); /* AN004 */
386 free_space[last_found_partition].percent_unused =
387 cylinders_to_percent(free_space[last_found_partition].space,total_disk[cur_disk]); /* AN000 */
389 /* Repeat the loop if the start was moved due to bad tracks */
390 /* Unless we're past the end of the free space */
391 while ((temp !=u(0)) && (free_space[last_found_partition].space!= u(0))); /* AC000 */
393 /* Return with the pointer to the largest free space */
394 return(last_found_partition);
399 void sort_ext_table(size)
409 /* Init the sorting parameters */
411 for (i=c(0); i < size; i++) /* AC000 */
416 /* Do a bubble sort */
419 /* Sort until we don't do a swap */
424 for (i=c(1); i < size; i++) /* AC000 */
427 if (ext_table[cur_disk][sort[i]].start_cyl < ext_table[cur_disk][sort[i-1]].start_cyl)
433 /* indicate we did a swap */