summaryrefslogtreecommitdiff
path: root/v4.0/src/CMD/FDISK/SPACE.C
diff options
context:
space:
mode:
Diffstat (limited to 'v4.0/src/CMD/FDISK/SPACE.C')
-rw-r--r--v4.0/src/CMD/FDISK/SPACE.C439
1 files changed, 439 insertions, 0 deletions
diff --git a/v4.0/src/CMD/FDISK/SPACE.C b/v4.0/src/CMD/FDISK/SPACE.C
new file mode 100644
index 0000000..21d10b5
--- /dev/null
+++ b/v4.0/src/CMD/FDISK/SPACE.C
@@ -0,0 +1,439 @@
1
2#include "dos.h"
3#include "fdisk.h"
4#include "extern.h"
5#include "subtype.h"
6
7/* */
8char find_part_free_space(type)
9
10char type;
11
12BEGIN
13
14
15char i;
16char partition_count;
17char last_found_partition;
18unsigned temp;
19char freespace_count;
20char any_partition;
21unsigned temp_size;
22
23 /* Sort the partition table */
24 sort_part_table(c(4)); /* AC000 */
25
26
27 /* Intialize free space to zero */
28 for (i = c(0); i < c(5); i++) /* AC000 */
29 BEGIN
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 */
35 END
36
37 /* Find space between start of disk and first partition */
38 partition_count = c(0); /* AC000 */
39
40 any_partition = FALSE;
41 for (i = c(0); i < c(4); i++) /* AC000 */
42 BEGIN
43 if (part_table[cur_disk][sort[i]].sys_id != uc(0)) /* AC000 */
44 BEGIN
45 /* Found a partition, get the space */
46
47 free_space[0].start = u(0); /* AC000 */
48
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 */
52 BEGIN
53 free_space[0].start = u(1); /* AC000 */
54 END
55
56 /* free space ends before start of next valid partition */
57 if (part_table[cur_disk][sort[i]].start_cyl > u(0)) /* AC000 */
58 BEGIN
59 free_space[0].end = part_table[cur_disk][sort[i]].start_cyl-1;
60 END
61
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 */
66
67 partition_count = i;
68 last_found_partition = sort[i];
69 any_partition = TRUE;
70 break;
71 END
72 END
73 /* See if any partitions were there */
74 if (any_partition)
75 BEGIN
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 */
79 BEGIN
80 if (part_table[cur_disk][sort[i]].sys_id != uc(0)) /* AC000 */
81 BEGIN
82
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 */
85
86 if (part_table[cur_disk][sort[i]].start_cyl != part_table[cur_disk][last_found_partition].end_cyl)
87
88 BEGIN
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);
93
94 temp_size = (part_table[cur_disk][sort[i]].start_cyl -
95 part_table[cur_disk][last_found_partition].end_cyl);
96
97 if (temp_size != u(0) ) /* AC000 */
98 BEGIN
99 free_space[freespace_count].space = temp_size - u(1); /* AC000 */
100 END
101 END
102
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 */
109
110
111
112 /* update the last found partition */
113 last_found_partition = sort[i];
114 freespace_count++;
115 END
116 END
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 */
126 END
127 else
128 BEGIN
129 /* No partitions found, show entire space as free */
130 free_space[0].start = u(0); /* AC000 */
131
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 */
135 BEGIN
136 free_space[0].start = u(1); /* AC000 */
137 END
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 */
144 END
145
146
147
148 /* Find largest free space, and verify the golden tracks while we are at it */
149 do
150 BEGIN
151 temp = u(0); /* AC000 */
152
153 /* Zip thru the table */
154 for (i = c(0); i < c(5); i++) /* AC000 */
155 BEGIN
156 /* Is this one bigger ? */
157 if (free_space[i].space > temp)
158 BEGIN
159 temp = free_space[i].space;
160 last_found_partition = i;
161
162 END
163 END
164
165 /* If there is any free space, go verify it */
166 temp = u(0);
167 if (free_space[last_found_partition].space != u(0)) /* AC000 */
168 BEGIN
169
170 /* Go verify the tracks */
171 temp = verify_tracks(last_found_partition,c(PRIMARY)); /* AC000 */
172 END
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 */
180 END
181
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 */
185
186 /* Return with the pointer to the largest free space */
187 return(last_found_partition);
188END
189
190
191
192/* */
193void sort_part_table(size)
194
195char size;
196
197BEGIN
198
199char changed;
200char temp;
201char i;
202
203 /* Init the sorting parameters */
204
205 for (i=c(0); i < size; i++) /* AC000 */
206 BEGIN
207 sort[i] = i;
208 END
209
210 /* Do a bubble sort */
211 changed = TRUE;
212
213 /* Sort until we don't do a swap */
214 while (changed)
215
216 BEGIN
217 changed = FALSE;
218 for (i=c(1); i < size; i++) /* AC000 */
219 BEGIN
220
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 */
224
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 */
228
229 BEGIN
230 /* Swap the order indicators */
231 temp = sort[i-1];
232 sort[i-1] = sort[i];
233 sort[i] = temp;
234
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(); */
240
241
242 /* indicate we did a swap */
243 changed = TRUE;
244 END
245 END
246 END
247 return;
248END
249
250
251
252
253/* */
254char find_ext_free_space()
255
256
257BEGIN
258
259
260char i;
261char partition_count;
262char last_found_partition;
263unsigned temp;
264char freespace_count;
265char any_partition;
266char ext_location;
267
268 /* Sort the partition table */
269 sort_ext_table(c(23)); /* AC000 */
270
271
272 /* Initialize free space to zero */
273 for (i = c(0); i < c(24); i++) /* AC000 */
274 BEGIN
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 */
280 END
281
282 /* Find space between start of Extended partition and first volume */
283 ext_location = find_partition_location(uc(EXTENDED)); /* AC000 */
284
285 partition_count = c(0); /* AC000 */
286
287 any_partition = FALSE;
288 for (i = c(0); i < c(23); i++) /* AC000 */
289 BEGIN
290 if (ext_table[cur_disk][sort[i]].sys_id != uc(0)) /* AC000 */
291 BEGIN
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 */
299
300 partition_count = i;
301 last_found_partition = sort[i];
302 any_partition = TRUE;
303 break;
304 END
305 END
306 /* See if any partitions were there */
307 if (any_partition)
308 BEGIN
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 */
312 BEGIN
313 if (ext_table[cur_disk][sort[i]].sys_id != uc(0)) /* AC000 */
314 BEGIN
315
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 */
325
326
327 /* update the last found partition */
328 last_found_partition = sort[i];
329 freespace_count++;
330 END
331 END
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 */
341
342 END
343 else
344 BEGIN
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 */
352 END
353
354 /* Find largest free space */
355 temp = u(0); /* AC000 */
356
357
358 /* Find largest free space, and verify the golden tracks while we are at it */
359 do
360 BEGIN
361 temp = u(0); /* AC000 */
362
363 /* Zip thru the table */
364 for (i = c(0); i < c(24); i++) /* AC000 */
365 BEGIN
366 /* Is this one bigger ? */
367 if (free_space[i].space > temp)
368 BEGIN
369 temp = free_space[i].space;
370 last_found_partition = i;
371 END
372 END
373 /* If there is any free space, go verify it */
374 temp = u(0);
375 if (free_space[last_found_partition].space != u(0)) /* AC000 */
376 BEGIN
377
378 /* Go verify the tracks */
379 temp = verify_tracks(last_found_partition,c(EXTENDED)); /* AC000 */
380 END
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 */
388 END
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 */
392
393 /* Return with the pointer to the largest free space */
394 return(last_found_partition);
395END
396
397
398/* */
399void sort_ext_table(size)
400
401char size;
402
403BEGIN
404
405char changed;
406char temp;
407char i;
408
409 /* Init the sorting parameters */
410
411 for (i=c(0); i < size; i++) /* AC000 */
412 BEGIN
413 sort[i] = i;
414 END
415
416 /* Do a bubble sort */
417 changed = TRUE;
418
419 /* Sort until we don't do a swap */
420 while (changed)
421
422 BEGIN
423 changed = FALSE;
424 for (i=c(1); i < size; i++) /* AC000 */
425 BEGIN
426
427 if (ext_table[cur_disk][sort[i]].start_cyl < ext_table[cur_disk][sort[i-1]].start_cyl)
428 BEGIN
429
430 temp = sort[i-1];
431 sort[i-1] = sort[i];
432 sort[i] = temp;
433 /* indicate we did a swap */
434 changed = TRUE;
435 END
436 END
437 END
438 return;
439END