2 #include "dos.h" /* AN000 */
3 #include "fdisk.h" /* AN000 */
4 #include "extern.h" /* AN000 */
5 #include "subtype.h" /* AN000 */
6 #include "string.h" /* AN000 */
10 void make_partition(size,free_pointer,bootable,type)
14 unsigned char bootable;
22 unsigned long total_sectors;
24 /* Find a free spot to put it in */
25 table_pointer = find_free_partition();
27 if (table_pointer != ((char)(NOT_FOUND)))
29 /* found a free partition, now lets go fill it up */
31 /* Do we need to make it active? */
32 if (bootable == ((unsigned char)(ACTIVE)))
35 /* Go clear out a previously active one */
36 for (i=u(0); i <u(4); i++) /* AC000 */
38 if (part_table[cur_disk][i].boot_ind == uc(0x80)) /* AC000 */
40 part_table[cur_disk][i].changed = TRUE;
41 part_table[cur_disk][i].boot_ind = uc(0); /* AC000 */
45 /* Now mark the new one active */
46 part_table[cur_disk][table_pointer].boot_ind = uc(0x80); /* AC000 */
50 /* Mark it as not active, leaving the others alone */
51 part_table[cur_disk][table_pointer].boot_ind = uc(0); /* AC000 */
54 /* Go get the start cylinder */
55 part_table[cur_disk][table_pointer].start_cyl = free_space[free_pointer].start;
57 /* Setup end cylinder */
58 part_table[cur_disk][table_pointer].end_cyl = part_table[cur_disk][table_pointer].start_cyl + size - 1;
60 /* Start sector is always 1 */
61 part_table[cur_disk][table_pointer].start_sector = uc(1); /* AC000 */
63 /* End sector is always the last sector */
64 part_table[cur_disk][table_pointer].end_sector = max_sector[cur_disk];
66 /* End head is always the last head */
67 part_table[cur_disk][table_pointer].end_head = uc(max_head[cur_disk] -1); /* AC004 */
69 /* Start head is always 0 unless this is track 0 - then it is 1 */
70 temp = uc(0); /* AC000 */
71 if (part_table[cur_disk][table_pointer].start_cyl == u(0)) /* AC000 */
73 temp = uc(1); /* AC000 */
75 part_table[cur_disk][table_pointer].start_head = temp;
77 /* Figure out the total number of sectors */
78 /* Total sectors in partition = */
79 /* [(end_cyl - start_cyl)*(max_sector)*(max_head)] */
80 /* - [start_head * max_sector] */
81 /* Note: This is assuming a track or cylinder aligned partition */
83 /* First - get the total size in Cylinders assuming head 0 start*/
84 total_sectors = ((unsigned long)(part_table[cur_disk][table_pointer].end_cyl -
85 part_table[cur_disk][table_pointer].start_cyl+1));
87 /* Now multiply it by the number of sectors and heads per track */
88 total_sectors = total_sectors * max_sector[cur_disk] * max_head[cur_disk];
90 /* This will give us the total of sectors if it is cyl aligned */
91 /* Now, if it isn't aligned on head 0, we need to subtract off */
92 /* the skipped tracks in the first cylinder */
94 /* Because the head is zero based, we can get the total number of */
95 /* skipped sectors by multipling the head number by sectors per track */
96 total_sectors = total_sectors - ((unsigned long)part_table[cur_disk][table_pointer].start_head) *
98 part_table[cur_disk][table_pointer].num_sec = total_sectors;
100 /* Get the relative sector */
101 /* Figure out the total number of sectors */
102 /* Total sectors before partition = */
103 /* (start_cyl)*(max_sector)*(max_head)] */
104 /* + [start_head * max_sector] */
105 /* Note: This is assuming a track or cylinder aligned partition */
107 /* Start cyl will work because it is zero based */
108 total_sectors = ((unsigned long)part_table[cur_disk][table_pointer].start_cyl);
110 /* Get sectors up to head 0 of the partition */
111 total_sectors = total_sectors * max_sector[cur_disk] * max_head[cur_disk];
113 /* Because the head is zero based, we can get the total number of */
114 /* skipped sectors by multipling the head number by sectors per track */
115 total_sectors = total_sectors + ((unsigned long)part_table[cur_disk][table_pointer].start_head) *
116 max_sector[cur_disk];
119 part_table[cur_disk][table_pointer].rel_sec = total_sectors;
121 /* Setup the system id byte */
122 if (type == ((char)(EXTENDED)))
124 temp = uc(EXTENDED); /* AC000 */
128 if (type == ((char)(PRIMARY)))
130 /* Always set to 06h - let format worry about setting to correct value */
131 temp = uc(DOSNEW); /* AC000 */ /* AN000 */
135 internal_program_error();
139 /* We got the sys id, now put it in */
140 part_table[cur_disk][table_pointer].sys_id = temp;
142 /* Set the changed flag */
143 part_table[cur_disk][table_pointer].changed = TRUE;
145 /* Set the mbytes used */
146 part_table[cur_disk][table_pointer].mbytes_used =
147 cylinders_to_mbytes(size,cur_disk); /* AN004 */
149 /* Set the percent used */
150 part_table[cur_disk][table_pointer].percent_used =
151 cylinders_to_percent(((part_table[cur_disk][table_pointer].end_cyl-part_table[cur_disk][table_pointer].start_cyl)+1),
152 total_disk[cur_disk]); /* AN000 */
157 /* This should not have happened */
158 internal_program_error();
167 char make_volume(size,free_pointer)
176 unsigned ext_part_num; /* AN000 */
178 unsigned long total_sectors;
180 /* Find a free spot to put it in */
181 table_pointer = find_free_ext();
183 if (table_pointer != ((char)(NOT_FOUND)))
185 /* found a free partition, now lets go fill it up */
188 /* This can never be marked active */
189 ext_table[cur_disk][table_pointer].boot_ind = uc(0); /* AC000 */
192 /* Go get the start cylinder */
193 ext_table[cur_disk][table_pointer].start_cyl = free_space[free_pointer].start;
195 /* Setup end cylinder */
196 ext_table[cur_disk][table_pointer].end_cyl = ext_table[cur_disk][table_pointer].start_cyl + size - 1;
198 /* Start sector is always 1 */
199 ext_table[cur_disk][table_pointer].start_sector = uc(1); /* AC000 */
201 /* End sector is always the last sector */
202 ext_table[cur_disk][table_pointer].end_sector = max_sector[cur_disk];
204 /* End head is always the last head */
205 ext_table[cur_disk][table_pointer].end_head = uc(max_head[cur_disk]-1); /* AC004 */
207 /* Start head is always 1 - NOTE: This is a shortcut for PC-DOS */
208 /* If this is being modified for IFS drivers this may not be the */
209 /* the case - use caution */
210 ext_table[cur_disk][table_pointer].start_head = uc(1); /* AC000 */
212 /* Figure out the total number of sectors */
213 /* Total sectors in partition = */
214 /* [(end_cyl - start_cyl)*(max_sector)*(max_head)] */
215 /* - [start_head * max_sector] */
216 /* Note: This is assuming a track or cylinder aligned partition */
218 /* First - get the total size in Cylinders assuming head 0 start*/
219 total_sectors = ((unsigned long)(ext_table[cur_disk][table_pointer].end_cyl -
220 ext_table[cur_disk][table_pointer].start_cyl+1));
222 /* Now multiply it by the number of sectors and heads per track */
223 total_sectors = total_sectors * max_sector[cur_disk] * max_head[cur_disk];
225 /* This will give us the total of sectors if it is cyl aligned */
226 /* Now, if it isn't aligned on head 0, we need to subtract off */
227 /* the skipped tracks in the first cylinder */
229 /* Because the head is zero based, we can get the total number of */
230 /* skipped sectors by multipling the head number by sectors per track */
231 total_sectors = total_sectors - ((unsigned long)(ext_table[cur_disk][table_pointer].start_head *
232 max_sector[cur_disk]));
234 ext_table[cur_disk][table_pointer].num_sec = total_sectors;
236 /* Get the relative sector */
237 /* Figure out the total number of sectors */
238 /* Total sectors before partition = max_sector */
239 /* NOTE: Again, this is a PC-DOS 3.30 shortcut - by definition */
240 /* a logical drive always starts on head 1, so there is always */
241 /* one tracks worth of sectors before it. Hence, max_sector */
244 ext_table[cur_disk][table_pointer].rel_sec = ((unsigned long)(max_sector[cur_disk]));
246 /* Setup the system id byte */
247 /* Set to 06h - format will fix later on */
248 temp = uc(DOSNEW); /* AC000 */ /* AN000 */
250 /* We got the sys id, now put it in */
251 ext_table[cur_disk][table_pointer].sys_id = temp;
253 /* Set the changed flag */
254 ext_table[cur_disk][table_pointer].changed = TRUE;
256 /* Set the mbytes used */
257 ext_table[cur_disk][table_pointer].mbytes_used =
258 cylinders_to_mbytes(size,cur_disk); /* AN004 */
260 /* find the number of the extended partiton to figure out percent */
261 ext_part_num = find_partition_location(uc(EXTENDED)); /* AN000 */
263 /* Set the percent used */
264 ext_table[cur_disk][table_pointer].percent_used =
265 cylinders_to_percent(((ext_table[cur_disk][table_pointer].end_cyl-ext_table[cur_disk][table_pointer].start_cyl)+1),
266 ((part_table[cur_disk][ext_part_num].end_cyl-part_table[cur_disk][ext_part_num].start_cyl)+1)); /* AN000 */
268 /* set the system to unknown and volume label to blanks */
269 strcpy(ext_table[cur_disk][table_pointer].system,NOFORMAT); /* AN000 */
270 strcpy(ext_table[cur_disk][table_pointer].vol_label,NOVOLUME); /* AN000 */
276 /* This should not have happened */
277 internal_program_error();
280 return(table_pointer);