]> wirehaze git hosting - MS-DOS.git/blob - v4.0/src/CMD/FDISK/MAIN.C

wirehaze git hosting

MZ is back!
[MS-DOS.git] / v4.0 / src / CMD / FDISK / MAIN.C
1
2 /* \f */
3
4 /******************* START OF SPECIFICATIONS *******************/
5 /* */
6 /* SOURCE FILE NAME: FDISK */
7 /* */
8 /* DESCRIPTIVE NAME: FIXED DISK PARTITIONING UTILITY */
9 /* */
10 /* FUNCTION: */
11 /* Allows creation and deletion of DOS related partitions */
12 /* on fixed disk devices 80-81h (int 13h BIOS defined, */
13 /* DOS). Also allows display of all partitions, and will */
14 /* allow a partition to be marked active (bootable). The */
15 /* user will be prompted for action thru a full screen */
16 /* interface. The user can also create, delete and display */
17 /* logical DOS drives within a EXTENDED DOS Partition. If a*/
18 /* regular DOS partition is created, the beginning of the */
19 /* partition will be scanned to insure a contiguous area of*/
20 /* good sectors on the disk large enough to satisfy the */
21 /* DOS system requirements. If a bad spot is found, the */
22 /* start of the partition will be moved out until a good */
23 /* area is located */
24 /* */
25 /* NOTES: The program will work by setting up a logical image */
26 /* of all relevant disk information at initilization */
27 /* time. All operations will be performed on this */
28 /* logical image, thus reducing disk accesses to only */
29 /* those required to initially set up the logical image,*/
30 /* and to write the changed information at the end. The */
31 /* user will be informed if there is a problem writing */
32 /* the logical image back to the disk. */
33 /* */
34 /* FDISK will interface with the partition table in the */
35 /* master boot record as defined in the PC-DOS technical*/
36 /* reference manual. It will also create and manage the */
37 /* EXTENDED DOS partition architecture as defined in the*/
38 /* PC-DOS 3.30 functional spec (CP/DOS spec dcr pending)*/
39 /* */
40 /* ENTRY POINTS: MAIN */
41 /* LINKAGE: [d:] [path] FDISK */
42 /* */
43 /* EXTERNAL REFERENCES: */
44 /* Fixed Disk Master Boot Record */
45 /* EXTENDED Partition Volume Boot Records */
46 /* Note: Both of the above are physical data structures on */
47 /* the surface of the disk */
48 /* */
49 /* P.S. - To whoever winds up maintaining this, I will */
50 /* apoligize in advance. I had just learned 'C' when */
51 /* writing this, so out of ignorance of the finer points*/
52 /* of the langauge I did a lot of things by brute force.*/
53 /* Hope this doesn't mess you up too much - MT 5/20/86 */
54 /******************** END OF SPECIFICATIONS ********************/
55
56 #include <dos.h> /* AN000 */
57 #include <fdisk.h> /* AN000 */
58 #include <subtype.h> /* AN000 */
59 #include <doscall.h> /* AN000 */
60 #include <ctype.h> /* AN000 */
61 #include <extern.h> /* AN000 */
62 #include <signal.h> /* AN000 */
63 #include <string.h> /* AN000 */
64 #include <fdiskmsg.h> /* AN000 */
65 #include <msgret.h> /* AN000 */
66 #include <process.h> /* AN001 */
67 #include <stdio.h> /* AN000 */
68
69 /* \f */
70 /******************* START OF SPECIFICATIONS *******************/
71 /* */
72 /* SUBROUTINE NAME: MAIN */
73 /* */
74 /* DESCRIPTIVE NAME: Main control routine */
75 /* */
76 /* FUNCTION: Main will handle call routines to handle the */
77 /* setup of the video for the full screen interface, */
78 /* get physical data on the drive characteristics, */
79 /* initilize all data fields with the current status */
80 /* of the disk partitioning information. Before the */
81 /* program is terminated, the video is reset to the */
82 /* mode it was in previous to the routine entry. It */
83 /* will also handle the case of an improper setup */
84 /* */
85 /* NOTES: FDISK requires at least 1 hardfile to operate */
86 /* */
87 /* ENTRY POINTS: main(); */
88 /* LINKAGE: */
89 /* */
90 /* INPUT: None */
91 /* */
92 /* EXIT-NORMAL: Return Code = 0 */
93 /* */
94 /* EXIT-ERROR: Return Code = 1 */
95 /* */
96 /* EFFECTS: Sets up status variables, sets up video for full */
97 /* screen interface, and then restores the video mode */
98 /* before exiting program */
99 /* */
100 /* INTERNAL REFERENCES: */
101 /* ROUTINES: */
102 /* init_video_information */
103 /* get_disk_information */
104 /* check_valid_environment */
105 /* do_main_menu */
106 /* init_partition_tables */
107 /* reset_video_information */
108 /* */
109 /* EXTERNAL REFERENCES: */
110 /* ROUTINES: */
111 /* DosExit */
112 /* */
113 /******************** END OF SPECIFICATIONS ********************/
114
115
116 /* \f */
117 /**************************************************************************/
118 /* */
119 /* UTILITY NAME: FDISK.com */
120 /* SOURCE FILE NAME: FDISK.c */
121 /* STATUS: FDISK utility, DOS 3.3 */
122 /* CHANGE HISTORY: UPDATED 5-29-87 DOS4.0 DRM */
123 /* SYNTAX (Command line) */
124 /* */
125 /* [d:][path]FDISK */
126 /* */
127 /* or */
128 /* */
129 /* [d:][path]FDISK d [/PRI:m | /EXT:n | /LOG:o | /Q ...] */
130 /* */
131 /* d: Drive to load FDISK utility from */
132 /* */
133 /* path path to the directory on specified drive to */
134 /* load FDISK from */
135 /* */
136 /* d Drive (1 or 2) that FDISK should operate on */
137 /* */
138 /* /PRI:m Size of Primary DOS partition to create in K */
139 /* */
140 /* /EXT:n Size of Extended DOS partition to create in K */
141 /* */
142 /* /LOG:o Size of Logical drive to create in K in the */
143 /* extended partition */
144 /* */
145 /* /Q This suppresses the reboot screen and returns */
146 /* FDISK to DOS even if partitons have changed. */
147 /* */
148 /* UTILITY FUNCTION: */
149 /* Allows you to create, set up, display, and delete the */
150 /* DOS partitions on a fixed disk. */
151 /* */
152 /**************************************************************************/
153 /* \f */
154 void main(argc,argv) /* AC000 */
155
156 int argc; /* AN000 */
157 char *argv[]; /* AN000 */
158
159 BEGIN
160
161 char temp; /* AN000 */
162 unsigned input;
163
164 /* DISABLE CNTL-BREAK HERE */
165 /* Gets defines from signal.h */
166 signal( (int) SIGINT, SIG_IGN ); /* AN000 */
167
168 no_fatal_error = TRUE; /* AN000 */
169
170 /* Preload messages and return */
171 if ( preload_messages() &&
172 get_yes_no_values() ) /* AN000 AC012 */
173 BEGIN /* AN000 */
174
175 /* Parse the command line for syntax and switches */
176 if(parse_command_line(argc,argv)) /* AN000 */
177
178 BEGIN /* AN000 */
179 /* check to see if switches were set */
180 if ((primary_flag == FALSE) &&
181 (extended_flag == FALSE) &&
182 (logical_flag == FALSE) &&
183 (disk_flag == FALSE)) /* AN000 */
184
185 BEGIN /* AN000 */
186 reboot_flag = FALSE;
187 /* See if running evironment is ok (Got hardfile, no network */
188 if (check_valid_environment())
189 BEGIN /* AN000 */
190 /* Get and save screen mode information */
191 init_video_information();
192 clear_screen(u(0),u(0),u(24),u(79)); /* AC006 */
193
194 /* Get disk size information */
195 good_disk[0] = TRUE;
196 good_disk[1] = TRUE;
197
198 if (get_disk_info())
199 BEGIN
200 /* build memory model of partitions */
201 init_partition_tables();
202
203 /* Go do main screen */
204 do_main_menu();
205 write_info_to_disk();
206 END
207
208 if (reboot_flag)
209 BEGIN /* AN000 */
210 reboot_system();
211 DOSEXIT((unsigned) 0,(unsigned) 0); /* AC000 */
212 END /* AN000 */
213
214 /* Nearly done, go reset screen mode */
215 if (no_fatal_error)
216 BEGIN
217 reset_video_information();
218 END /* AN000 */
219 /* this is end of check valid environment */
220 END /* AN000 */
221 /* This is end for no switches set */
222 END /* AN000 */
223
224 else /* AN000 */
225
226 BEGIN /* AN000 */
227 if ( ((primary_flag == FALSE) &&
228 (extended_flag == FALSE) &&
229 (logical_flag == FALSE)) ||
230 (disk_flag == FALSE) ) /* AN000 */
231 display_msg((int)8,(int)DosStdEr,(int)nosubcnt,(int)nosubptr,c(noinput),c(Utility_Msg_Class)); /*;AN000; AC014 AC015 */
232
233 else
234 BEGIN
235 reboot_flag = FALSE; /* AN000 */
236 /* Get disk size information */ /* AN000 */
237 good_disk[0] = TRUE; /* AN000 */
238 good_disk[1] = TRUE; /* AN000 */
239 if (get_disk_info()) /* AN000 */
240 BEGIN
241 if (number_of_drives < (cur_disk_buff+1))
242 display_msg((int)8,(int)DosStdEr,(int)nosubcnt,(int)nosubptr,c(noinput),c(Utility_Msg_Class)); /*;AN000; AC014 AC015*/
243 else
244 BEGIN /* AN000 */
245 /* build memory model of partitions */
246 init_partition_tables(); /* AN000 */
247
248 /* set cur_disk to current disk */
249 cur_disk = cur_disk_buff; /* AN000 */
250
251 /* If /PRI: was specified, create primary partition */
252 /* check to see if a primary partition already exists */
253 if ( (primary_flag == TRUE) && /* AN000 */
254 ( (!find_partition_type(uc(DOS12))) &&
255 (!find_partition_type(uc(DOS16))) &&
256 (!find_partition_type(uc(DOSNEW))) ) ) /* AC000 */
257 BEGIN
258 temp = find_part_free_space((char) PRIMARY); /* AN000 */
259 if (primary_buff >= free_space[temp].mbytes_unused) /* AN000 */
260 input = free_space[temp].space; /* AN000 */
261 else /* AN000 */
262 input = (unsigned)mbytes_to_cylinders(primary_buff,
263 cur_disk_buff); /* AN004 */
264 make_partition(input,temp,uc(ACTIVE),(char)PRIMARY); /* AN000 */
265 END
266
267 /* If /EXT: was specified, create extended partition */
268 /* Check and see if there is a primary partition before you create an extended */
269 if ( (extended_flag == TRUE) && /* AN000 */
270 ( (cur_disk == c(1)) ||
271 (find_partition_type(uc(DOS12))) ||
272 (find_partition_type(uc(DOS16))) ||
273 (find_partition_type(uc(DOSNEW))) ) ) /* AC000 */
274 BEGIN
275 /* Make sure there isn't an extended already there */
276 if (!find_partition_type(uc(EXTENDED))) /* AC000 */
277 BEGIN
278 temp = find_part_free_space((char) EXTENDED); /* AN000 */
279 if (extended_buff >= free_space[temp].mbytes_unused) /* AN000 */
280 input = free_space[temp].space; /* AN000 */
281 else /* AN000 */
282 input = (unsigned)mbytes_to_cylinders(extended_buff,
283 cur_disk_buff); /* AN004 */
284 make_partition(input,temp,(unsigned char) NUL,(char) EXTENDED); /* AN000 */
285 END
286 END
287
288 /* If /LOG: was specified, create logical partition */
289 if ( (logical_flag == TRUE) &&
290 (find_partition_type(uc(EXTENDED))) ) /* AN000 */
291 BEGIN /* AN000 */
292 temp = find_ext_free_space(); /* AN000 */
293 if (logical_buff >= free_space[temp].mbytes_unused) /* AN000 */
294 input = free_space[temp].space; /* AN000 */
295 else /* AN000 */
296 input = (unsigned)mbytes_to_cylinders(logical_buff,
297 cur_disk_buff); /* AN004 */
298 make_volume(input,temp); /* AN000 */
299 END
300
301 /* This is end of switch execution */
302 write_info_to_disk(); /* AN000 */
303 END /* AN000 */
304 /* This is the end of compare cur_disk_buff for valid drive */
305 END
306 /* This is the end of just disk_flag set */
307 END
308 /* This is end of if switch is present */
309 END
310 /* This is end of Parse command line */
311 END /* AN000 */
312 /* This end of Preload_messages function */
313 END /* AN000 */
314 cur_disk = c(0); /* AN001 */
315 if ( (quiet_flag == TRUE) &&
316 (!find_partition_type(uc(DOS12))) &&
317 (!find_partition_type(uc(DOS16))) &&
318 (!find_partition_type(uc(DOSNEW))) ) /* AN001 */
319 exit(ERR_LEVEL_1); /* AN001 */
320 else
321 BEGIN /* AN005 */
322 if ((quiet_flag == TRUE) && /* AN005 */
323 (primary_flag == FALSE) && /* AN008 */
324 (extended_flag == FALSE) && /* AN008 */
325 (logical_flag == FALSE)) /* AN008 */
326 exit(ERR_LEVEL_2); /* AN005 */
327 else /* AN005 */
328 exit(ERR_LEVEL_0); /* AN001 */
329 END /* AN005 */
330 END
331
332