summaryrefslogtreecommitdiff
path: root/v4.0/src/CMD/FDISK/MAKEPART.C
diff options
context:
space:
mode:
Diffstat (limited to 'v4.0/src/CMD/FDISK/MAKEPART.C')
-rw-r--r--v4.0/src/CMD/FDISK/MAKEPART.C282
1 files changed, 282 insertions, 0 deletions
diff --git a/v4.0/src/CMD/FDISK/MAKEPART.C b/v4.0/src/CMD/FDISK/MAKEPART.C
new file mode 100644
index 0000000..b33e091
--- /dev/null
+++ b/v4.0/src/CMD/FDISK/MAKEPART.C
@@ -0,0 +1,282 @@
1
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 */
7
8/* */
9
10void make_partition(size,free_pointer,bootable,type)
11
12unsigned size;
13char free_pointer;
14unsigned char bootable;
15char type;
16
17BEGIN
18
19char table_pointer;
20unsigned i;
21unsigned char temp;
22unsigned long total_sectors;
23
24 /* Find a free spot to put it in */
25 table_pointer = find_free_partition();
26
27 if (table_pointer != ((char)(NOT_FOUND)))
28 BEGIN
29 /* found a free partition, now lets go fill it up */
30
31 /* Do we need to make it active? */
32 if (bootable == ((unsigned char)(ACTIVE)))
33 BEGIN
34
35 /* Go clear out a previously active one */
36 for (i=u(0); i <u(4); i++) /* AC000 */
37 BEGIN
38 if (part_table[cur_disk][i].boot_ind == uc(0x80)) /* AC000 */
39 BEGIN
40 part_table[cur_disk][i].changed = TRUE;
41 part_table[cur_disk][i].boot_ind = uc(0); /* AC000 */
42 END
43 END
44
45 /* Now mark the new one active */
46 part_table[cur_disk][table_pointer].boot_ind = uc(0x80); /* AC000 */
47 END
48 else
49 BEGIN
50 /* Mark it as not active, leaving the others alone */
51 part_table[cur_disk][table_pointer].boot_ind = uc(0); /* AC000 */
52 END
53
54 /* Go get the start cylinder */
55 part_table[cur_disk][table_pointer].start_cyl = free_space[free_pointer].start;
56
57 /* Setup end cylinder */
58 part_table[cur_disk][table_pointer].end_cyl = part_table[cur_disk][table_pointer].start_cyl + size - 1;
59
60 /* Start sector is always 1 */
61 part_table[cur_disk][table_pointer].start_sector = uc(1); /* AC000 */
62
63 /* End sector is always the last sector */
64 part_table[cur_disk][table_pointer].end_sector = max_sector[cur_disk];
65
66 /* End head is always the last head */
67 part_table[cur_disk][table_pointer].end_head = uc(max_head[cur_disk] -1); /* AC004 */
68
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 */
72 BEGIN
73 temp = uc(1); /* AC000 */
74 END
75 part_table[cur_disk][table_pointer].start_head = temp;
76
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 */
82
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));
86
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];
89
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 */
93
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) *
97 max_sector[cur_disk];
98 part_table[cur_disk][table_pointer].num_sec = total_sectors;
99
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 */
106
107 /* Start cyl will work because it is zero based */
108 total_sectors = ((unsigned long)part_table[cur_disk][table_pointer].start_cyl);
109
110 /* Get sectors up to head 0 of the partition */
111 total_sectors = total_sectors * max_sector[cur_disk] * max_head[cur_disk];
112
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];
117
118 /* Save it! */
119 part_table[cur_disk][table_pointer].rel_sec = total_sectors;
120
121 /* Setup the system id byte */
122 if (type == ((char)(EXTENDED)))
123 BEGIN
124 temp = uc(EXTENDED); /* AC000 */
125 END
126 else
127 BEGIN
128 if (type == ((char)(PRIMARY)))
129 BEGIN
130 /* Always set to 06h - let format worry about setting to correct value */
131 temp = uc(DOSNEW); /* AC000 */ /* AN000 */
132 END
133 else
134 BEGIN
135 internal_program_error();
136 END
137 END
138
139 /* We got the sys id, now put it in */
140 part_table[cur_disk][table_pointer].sys_id = temp;
141
142 /* Set the changed flag */
143 part_table[cur_disk][table_pointer].changed = TRUE;
144
145 /* Set the mbytes used */
146 part_table[cur_disk][table_pointer].mbytes_used =
147 cylinders_to_mbytes(size,cur_disk); /* AN004 */
148
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 */
153 END
154 else
155
156 BEGIN
157 /* This should not have happened */
158 internal_program_error();
159 return;
160 END
161
162 return;
163END
164
165
166/* */
167char make_volume(size,free_pointer)
168
169unsigned size;
170char free_pointer;
171
172BEGIN
173
174char table_pointer;
175unsigned i;
176unsigned ext_part_num; /* AN000 */
177unsigned char temp;
178unsigned long total_sectors;
179
180 /* Find a free spot to put it in */
181 table_pointer = find_free_ext();
182
183 if (table_pointer != ((char)(NOT_FOUND)))
184 BEGIN
185 /* found a free partition, now lets go fill it up */
186
187
188 /* This can never be marked active */
189 ext_table[cur_disk][table_pointer].boot_ind = uc(0); /* AC000 */
190
191
192 /* Go get the start cylinder */
193 ext_table[cur_disk][table_pointer].start_cyl = free_space[free_pointer].start;
194
195 /* Setup end cylinder */
196 ext_table[cur_disk][table_pointer].end_cyl = ext_table[cur_disk][table_pointer].start_cyl + size - 1;
197
198 /* Start sector is always 1 */
199 ext_table[cur_disk][table_pointer].start_sector = uc(1); /* AC000 */
200
201 /* End sector is always the last sector */
202 ext_table[cur_disk][table_pointer].end_sector = max_sector[cur_disk];
203
204 /* End head is always the last head */
205 ext_table[cur_disk][table_pointer].end_head = uc(max_head[cur_disk]-1); /* AC004 */
206
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 */
211
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 */
217
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));
221
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];
224
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 */
228
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]));
233
234 ext_table[cur_disk][table_pointer].num_sec = total_sectors;
235
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 */
242
243 /* Save it! */
244 ext_table[cur_disk][table_pointer].rel_sec = ((unsigned long)(max_sector[cur_disk]));
245
246 /* Setup the system id byte */
247 /* Set to 06h - format will fix later on */
248 temp = uc(DOSNEW); /* AC000 */ /* AN000 */
249
250 /* We got the sys id, now put it in */
251 ext_table[cur_disk][table_pointer].sys_id = temp;
252
253 /* Set the changed flag */
254 ext_table[cur_disk][table_pointer].changed = TRUE;
255
256 /* Set the mbytes used */
257 ext_table[cur_disk][table_pointer].mbytes_used =
258 cylinders_to_mbytes(size,cur_disk); /* AN004 */
259
260 /* find the number of the extended partiton to figure out percent */
261 ext_part_num = find_partition_location(uc(EXTENDED)); /* AN000 */
262
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 */
267
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 */
271
272 END
273 else
274
275 BEGIN
276 /* This should not have happened */
277 internal_program_error();
278 END
279
280 return(table_pointer);
281END
282