4 /******************* START OF SPECIFICATIONS *******************/
6 /* SOURCE FILE NAME: FDISK */
8 /* DESCRIPTIVE NAME: FIXED DISK PARTITIONING UTILITY */
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 */
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. */
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)*/
40 /* ENTRY POINTS: MAIN */
41 /* LINKAGE: [d:] [path] FDISK */
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 */
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 ********************/
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 */
70 /******************* START OF SPECIFICATIONS *******************/
72 /* SUBROUTINE NAME: MAIN */
74 /* DESCRIPTIVE NAME: Main control routine */
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 */
85 /* NOTES: FDISK requires at least 1 hardfile to operate */
87 /* ENTRY POINTS: main(); */
92 /* EXIT-NORMAL: Return Code = 0 */
94 /* EXIT-ERROR: Return Code = 1 */
96 /* EFFECTS: Sets up status variables, sets up video for full */
97 /* screen interface, and then restores the video mode */
98 /* before exiting program */
100 /* INTERNAL REFERENCES: */
102 /* init_video_information */
103 /* get_disk_information */
104 /* check_valid_environment */
106 /* init_partition_tables */
107 /* reset_video_information */
109 /* EXTERNAL REFERENCES: */
113 /******************** END OF SPECIFICATIONS ********************/
117 /**************************************************************************/
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) */
125 /* [d:][path]FDISK */
129 /* [d:][path]FDISK d [/PRI:m | /EXT:n | /LOG:o | /Q ...] */
131 /* d: Drive to load FDISK utility from */
133 /* path path to the directory on specified drive to */
134 /* load FDISK from */
136 /* d Drive (1 or 2) that FDISK should operate on */
138 /* /PRI:m Size of Primary DOS partition to create in K */
140 /* /EXT:n Size of Extended DOS partition to create in K */
142 /* /LOG:o Size of Logical drive to create in K in the */
143 /* extended partition */
145 /* /Q This suppresses the reboot screen and returns */
146 /* FDISK to DOS even if partitons have changed. */
148 /* UTILITY FUNCTION: */
149 /* Allows you to create, set up, display, and delete the */
150 /* DOS partitions on a fixed disk. */
152 /**************************************************************************/
154 void main(argc,argv) /* AC000 */
156 int argc; /* AN000 */
157 char *argv[]; /* AN000 */
161 char temp; /* AN000 */
164 /* DISABLE CNTL-BREAK HERE */
165 /* Gets defines from signal.h */
166 signal( (int) SIGINT, SIG_IGN ); /* AN000 */
168 no_fatal_error = TRUE; /* AN000 */
170 /* Preload messages and return */
171 if ( preload_messages() &&
172 get_yes_no_values() ) /* AN000 AC012 */
175 /* Parse the command line for syntax and switches */
176 if(parse_command_line(argc,argv)) /* 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 */
187 /* See if running evironment is ok (Got hardfile, no network */
188 if (check_valid_environment())
190 /* Get and save screen mode information */
191 init_video_information();
192 clear_screen(u(0),u(0),u(24),u(79)); /* AC006 */
194 /* Get disk size information */
200 /* build memory model of partitions */
201 init_partition_tables();
203 /* Go do main screen */
205 write_info_to_disk();
211 DOSEXIT((unsigned) 0,(unsigned) 0); /* AC000 */
214 /* Nearly done, go reset screen mode */
217 reset_video_information();
219 /* this is end of check valid environment */
221 /* This is end for no switches set */
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 */
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 */
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*/
245 /* build memory model of partitions */
246 init_partition_tables(); /* AN000 */
248 /* set cur_disk to current disk */
249 cur_disk = cur_disk_buff; /* AN000 */
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 */
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 */
262 input = (unsigned)mbytes_to_cylinders(primary_buff,
263 cur_disk_buff); /* AN004 */
264 make_partition(input,temp,uc(ACTIVE),(char)PRIMARY); /* AN000 */
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 */
275 /* Make sure there isn't an extended already there */
276 if (!find_partition_type(uc(EXTENDED))) /* AC000 */
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 */
282 input = (unsigned)mbytes_to_cylinders(extended_buff,
283 cur_disk_buff); /* AN004 */
284 make_partition(input,temp,(unsigned char) NUL,(char) EXTENDED); /* AN000 */
288 /* If /LOG: was specified, create logical partition */
289 if ( (logical_flag == TRUE) &&
290 (find_partition_type(uc(EXTENDED))) ) /* 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 */
296 input = (unsigned)mbytes_to_cylinders(logical_buff,
297 cur_disk_buff); /* AN004 */
298 make_volume(input,temp); /* AN000 */
301 /* This is end of switch execution */
302 write_info_to_disk(); /* AN000 */
304 /* This is the end of compare cur_disk_buff for valid drive */
306 /* This is the end of just disk_flag set */
308 /* This is end of if switch is present */
310 /* This is end of Parse command line */
312 /* This end of Preload_messages function */
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 */
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 */
328 exit(ERR_LEVEL_0); /* AN001 */