summaryrefslogtreecommitdiff
path: root/v4.0/src/CMD/FDISK/CONVERT.C
diff options
context:
space:
mode:
Diffstat (limited to 'v4.0/src/CMD/FDISK/CONVERT.C')
-rw-r--r--v4.0/src/CMD/FDISK/CONVERT.C478
1 files changed, 478 insertions, 0 deletions
diff --git a/v4.0/src/CMD/FDISK/CONVERT.C b/v4.0/src/CMD/FDISK/CONVERT.C
new file mode 100644
index 0000000..60ec6a1
--- /dev/null
+++ b/v4.0/src/CMD/FDISK/CONVERT.C
@@ -0,0 +1,478 @@
1
2#include "fdisk.h" /* AN000 */
3#include "subtype.h" /* AN000 */
4#include "dos.h" /* AN000 */
5#include "extern.h" /* AN000 */
6#include "string.h"
7#include "ctype.h"
8
9
10/******************************************************************************/
11/*Routine name: MBYTES_TO_CYLINDERS */
12/******************************************************************************/
13/* */
14/*Description: This routine will take input of MBtes and */
15/* convert it to cylinders rounding up to the next largest */
16/* cylinder boundry. Rounding up is done to make sure the */
17/* requester is getting at least what he asked for to the */
18/* next cylinder boundry. */
19/* */
20/*Called Procedures: none */
21/* */
22/* */
23/*Change History: Created 5/30/87 DRM */
24/* */
25/*Input: Input */
26/* */
27/*Output: Cylinders_out */
28/* */
29/******************************************************************************/
30
31
32unsigned mbytes_to_cylinders(mbytes_in,which_disk) /* AN004 */
33
34XFLOAT mbytes_in; /* AN000 */
35char which_disk; /* AN004 */
36
37
38
39BEGIN /* AN000 */
40
41unsigned cylinders_out; /* AN000 */
42unsigned long cylinders_out1; /* AN000 */
43unsigned long number_of_sectors; /* AN000 */
44unsigned long number_of_tracks; /* AN000 */
45unsigned long divide_by; /* AN000 */
46
47 /* If trying to create a 3.30 compatible 32 MB partition */
48 /* Set the 32mb limit - round down */
49 if (mbytes_in == (XFLOAT)32)
50 BEGIN
51 cylinders_out1 = ul(DOS_MAX - max_sector[which_disk]); /* AN004 */
52 divide_by = ul((max_head[which_disk]) * ul(max_sector[which_disk])); /* AN004 */
53 cylinders_out = u(cylinders_out1 / divide_by); /* AN000 */
54 END
55 else
56 BEGIN
57 number_of_sectors = ul(((mbytes_in * ONE_MEG)/BYTES_PER_SECTOR)); /* AN000 */
58 if (((int)(mbytes_in * ONE_MEG) % BYTES_PER_SECTOR) != (int)0) /* AN000 */
59 number_of_sectors++; /* AN000 */
60 number_of_tracks = ul((number_of_sectors / max_sector[which_disk])); /* AN004 */
61 if (((int)number_of_sectors % max_sector[which_disk]) != (int)0) /* AN004 */
62 number_of_tracks++; /* AN000 */
63 cylinders_out = u((number_of_tracks / max_head[which_disk])); /* AN004 */
64 if (((int)number_of_tracks % max_head[which_disk]) != (int)0) /* AN004 */
65 cylinders_out++; /* AN000 */
66 END
67
68 return(cylinders_out); /* AN000 */
69END /* AN000 */
70
71
72
73/* */
74/*******************************************************************************/
75/*Routine name: CYLINDERS_TO_MBYTES */
76/*******************************************************************************/
77/* */
78/*Description: This routine will take input of cylinders and convert */
79/* it to MBytes. */
80/* */
81/* */
82/*Called Procedures: */
83/* */
84/* */
85/*Change History: Created 5/16/87 DRM */
86/* */
87/*Input: Cylinders_in */
88/* */
89/*Output: MBytes_out */
90/* */
91/* */
92/* */
93/*******************************************************************************/
94
95XFLOAT cylinders_to_mbytes(cylinders_in,which_disk) /* AN004 */
96
97unsigned cylinders_in; /* AN000 */
98char which_disk; /* AN004 */
99
100BEGIN /* AN000 */
101
102unsigned mbytes_out; /* AN000 */
103unsigned long number_of_bytes; /* AN000 */
104unsigned long number_of_sectors; /* AN000 */
105unsigned long number_of_tracks; /* AN000 */
106unsigned long bytes_in_one_sector; /* AN004 */
107
108 bytes_in_one_sector = BYTES_PER_SECTOR; /* AN004 */
109 number_of_tracks = (ul(cylinders_in) * ul(max_head[which_disk])); /* AN004 */
110 number_of_sectors = (number_of_tracks * ul(max_sector[which_disk])); /* AN004 */
111 number_of_bytes = (ul(number_of_sectors) * ul(bytes_in_one_sector)); /* AN004 */
112 mbytes_out = f(number_of_bytes / ONE_MEG); /* AN000 */
113 if ((number_of_bytes % ONE_MEG) >= (ONE_MEG / 2)) mbytes_out++; /* AN000 */
114 return(mbytes_out); /* AN000 */
115
116END /* AN000 */
117
118
119
120
121/* */
122/*******************************************************************************/
123/*Routine name: CYLINDERS_TO_PERCENT */
124/*******************************************************************************/
125/* */
126/*Description: This routine will take input of cylinders and convert */
127/* it to Percent. */
128/* */
129/* */
130/*Called Procedures: */
131/* */
132/* */
133/*Change History: Created 5/16/87 DRM */
134/* */
135/*Input: Cylinders_in */
136/* */
137/*Output: percent_out */
138/* */
139/* */
140/* */
141/*******************************************************************************/
142
143unsigned cylinders_to_percent(cylinders_in,total_cylinders) /* AN000 */
144
145unsigned cylinders_in; /* AN000 */
146unsigned total_cylinders; /* AN000 */
147
148BEGIN /* AN000 */
149
150unsigned percentage_out; /* AN000 */
151double large_number; /* AN000 */
152
153 /* This is the same as (cyl_in / tot_cyl) * 100 to get the percentage */
154 /* because * 100 is really 100/1 which is (cyl_in*100)/(tot_cyl*1). */
155
156 if (total_cylinders == 0)
157 percentage_out = 0;
158 else
159 BEGIN
160 large_number = (double)((long)cylinders_in * 100l); /* AN000 */
161 percentage_out = u(large_number / total_cylinders); /* AN000 */
162 END
163 /* this should round up to the next percent if more than .5 percent */
164 if (((cylinders_in * 100) % total_cylinders) >= (total_cylinders / 2))
165 percentage_out++; /* AN000 */
166 if (percentage_out > u(100)) percentage_out = u(100); /* AN000 */
167 return(percentage_out); /* AN000 */
168END /* AN000 */
169
170
171
172/* */
173/******************************************************************************/
174/*Routine name: PERCENT_TO_CYLINDERS */
175/******************************************************************************/
176/* */
177/*Description: This routine will take input of percentage and */
178/* convert it to cylinders rounding up to the next largest */
179/* cylinder boundry. Rounding up is done to make sure the */
180/* requester is getting at least what he asked for to the */
181/* next cylinder boundry. */
182/* */
183/*Called Procedures: none */
184/* */
185/* */
186/*Change History: Created 5/30/87 DRM */
187/* */
188/*Input: Input */
189/* */
190/*Output: Cylinders_out */
191/* */
192/******************************************************************************/
193
194
195XFLOAT percent_to_cylinders(percent_in,total_cylinders) /* AN000 */
196
197unsigned percent_in; /* AN000 */
198XFLOAT total_cylinders; /* AN000 */
199
200
201BEGIN /* AN000 */
202
203 XFLOAT cylinders_out; /* AN000 */
204#if IBMCOPYRIGHT
205 cylinders_out = ((percent_in * total_cylinders) / 100); /* AN000 */
206#else
207 cylinders_out = (unsigned)((ul(percent_in) * ul(total_cylinders)) / 100);
208#endif
209 if (((percent_in * total_cylinders) % 100) != u(0)) /* AN000 */
210 cylinders_out++; /* AN000 */
211 return(cylinders_out); /* AN000 */
212END /* AN000 */
213
214
215
216
217
218
219/* */
220/*******************************************************************************/
221/*Routine name: DOS_UPPER */
222/*******************************************************************************/
223/* */
224/*Description: This routine will uppcase a character using get country */
225/* information (65H) with the capitalize single character */
226/* call (20H). */
227/* */
228/*Called Procedures: */
229/* */
230/* */
231/* */
232/*Change History: Updated 5/31/87 DRM */
233/* */
234/*Input: drive_value */
235/* */
236/*Output: input_value */
237/* */
238/*******************************************************************************/
239
240char dos_upper(drive_value) /* AN000 */
241
242char drive_value; /* AN000 */
243
244BEGIN /* AN000 */
245
246 char output; /* AN000 */
247
248 regs.x.ax = (unsigned)CAPCHAR; /* Get extended country information - AN000 */
249 regs.h.dl = (unsigned char)drive_value; /* Move input_value to register DL - AN000 */
250 int86((int)INT21,&regs,&regs); /* AN000 */
251 output = (char)regs.h.dl; /* AN000 */
252
253#ifdef DEBUG
254 output = toupper(drive_value);
255#endif
256
257 return(output); /* AN000 */
258END /* AN000 */
259
260
261
262
263
264/* */
265/*******************************************************************************/
266/*Routine name: CHECK_YN_INPUT */
267/*******************************************************************************/
268/* */
269/*Description: Get single character input, which must be a country */
270/* dependent (Y/N). Will be verified using new uppercase table */
271/* function calls. Will accept default value. */
272/* */
273/*Called Procedures: */
274/* */
275/* */
276/* */
277/*Change History: Updated 5/31/87 DRM */
278/* */
279/*Input: input_value */
280/* */
281/*Output: input */
282/* valid_input */
283/* */
284/*******************************************************************************/
285
286char check_yn_input(input_value) /* AN000 */
287
288 char input_value; /* AN000 */
289
290BEGIN
291 char input; /* AN000 */
292
293 /* Get extended country information */
294 regs.x.ax = (unsigned)CAP_YN; /* AN000 */
295 /* Move input_value to register DL */
296 regs.h.dl = (unsigned char)input_value; /* AN000 */
297 int86((int)INT21,&regs,&regs); /* AN000 */
298
299 /* check carry flag for error */
300 if ((regs.x.cflag & CARRY_FLAG) == CARRY_FLAG) /* AN000 */
301 /* input will be 0 for NO and 1 for YES in AX */
302 input = c(NO_GOOD); /* input will equal not 0 or 1 */ /* AN000 */
303 else /* AN000 */
304 input = c(regs.x.ax); /* AN000 */
305
306#ifdef DEBUG
307
308 input = NO_GOOD;
309 if ( (input_value == (char) 'Y') || (input_value == (char) 'y') ) input = c(1);
310 if ( (input_value == (char) 'N') || (input_value == (char) 'n') ) input = c(0);
311
312#endif
313
314 return(input); /* AN000 */
315END /* AN000 */
316
317
318
319
320/* */
321/*******************************************************************************/
322/*Routine name: GET_FS_AND_VOL */
323/*******************************************************************************/
324/* */
325/*Description: This routine will invoke INT21 44h (Block Generic IOCTL */
326/* Subfunction) call to get volume label and file system type. */
327/* */
328/*Called Procedures: */
329/* */
330/*Change History: Created 6/01/87 DRM */
331/* */
332/*Input: input_drive */
333/* */
334/*Output: pointer to dx register */
335/* */
336/*******************************************************************************/
337
338FLAG get_fs_and_vol(input_drive) /* AN000 */
339
340 char input_drive; /* AN000 */
341
342BEGIN /* AN000 */
343
344 char output;
345
346 /* Set up registers for Generic IOCTL INT21 (44h) get media ID */
347 regs.x.ax = u(GENERIC_IOCTL); /* AN000 */
348 regs.h.bh = uc(ZERO); /* AN000 */
349 regs.h.bl = (((unsigned char)input_drive - 'A') + 1); /* AN000 */
350 regs.x.cx = u(GET_MEDIA_ID); /* AN000 */
351 regs.x.dx = (unsigned)&dx_buff; /* AN000 */
352 segread(&segregs);
353 intdosx(&regs,&regs,&segregs); /* AN000 */
354
355 /* see if carry flag was zero or one */
356 if ((regs.x.cflag & CARRY_FLAG) == CARRY_FLAG) /* AN000 */
357 output = FALSE; /* AN000 */
358 else /* AN000 */
359 output = TRUE; /* AN000 */
360
361 return(output); /* AN000 */
362 /* AN000 */
363END
364
365
366
367/* */
368/*******************************************************************************/
369/*Routine name: GET_VOLUME_STRING */
370/*******************************************************************************/
371/* */
372/*Description: This routine will invoke INT21 4Eh (Find First Matching File) */
373/* and return the disk volume label. */
374/* */
375/*Called Procedures: */
376/* */
377/*Change History: Created 6/01/87 DRM */
378/* */
379/*Input: input_drive */
380/* */
381/*Output: volume_out */
382/* */
383/*******************************************************************************/
384void get_volume_string(input_drive,vol_label_addr) /* AN000 */
385 char input_drive; /* AN000 */
386 char *vol_label_addr; /* AN000 */
387BEGIN /* AN000 */
388
389 char first_string[13]; /* AC000 */
390 char find_first_buffer[50]; /* AN000 */
391 unsigned i,j; /* AC000 */
392
393 /* clear out any garbage in volume label field */
394 for (i = u(0); i < u(12); i++) /* AN015 */
395 BEGIN /* AN015 */
396 vol_label_addr[i] = u(0); /* AN015 */
397 END /* AN015 */
398
399 /* Point the DTA to our buffer so we can get the FindFirst output */
400 regs.h.ah = uc(0x1A); /* AN000 */
401 regs.x.dx = (unsigned)&find_first_buffer[0]; /* AN000 */
402 segread(&segregs);
403 intdosx(&regs,&regs,&segregs); /* AN000 */
404
405 /* Find the first volume id */
406 first_string[0] = input_drive; /* Find the vol label - AN000 */
407 first_string[1] = (char) '\0';
408 strcat(first_string,FILE_NAME); /* AN000 */
409 regs.h.ah = uc(FIND_FIRST_MATCH); /* AN000 */
410 regs.x.cx = u(VOL_LABEL); /* AN000 */
411 regs.x.dx = (unsigned)&first_string[0]; /* AN000 */
412 intdos(&regs,&regs); /* AN000 */
413
414/* AC000 The following is modified to take care of "." in the middle of the */
415/*name */
416
417 if ((regs.x.cflag & CARRY_FLAG) != CARRY_FLAG) /* AN000 AC015 */
418 BEGIN /* AN000 */
419 for (i=j=u(0); i < strlen (&find_first_buffer[30]) ; i++) /* AN000 */
420 BEGIN /* AN000 */
421 if (find_first_buffer[30+i] != PERIOD) /* AN003 */
422 vol_label_addr[i-j] = find_first_buffer[30+i]; /* AN000 */
423 else /* AN000 */
424 j = u(1); /* AN000 */
425 END /* AN000 */
426 END /* AN000 */
427 return; /* AN000 */
428END /* AN000 */
429
430
431/* */
432/*******************************************************************************/
433/*Routine name: CHECK_FORMAT */
434/*******************************************************************************/
435/* */
436/*Description: This routine will invoke INT21 44h (Block Generic IOCTL */
437/* Subfunction) call to see if the drive has been previously */
438/* formatted by using a undocumented call. */
439/* */
440/*Called Procedures: */
441/* */
442/*Change History: Created 2/07/88 DRM */
443/* */
444/*Input: input_drive */
445/* */
446/*Output: pointer to dx register */
447/* */
448/*******************************************************************************/
449
450FLAG check_format(input_drive) /* AN002 */
451
452 char input_drive; /* AN002 */
453
454BEGIN /* AN002 */
455
456 char formatted; /* AN002 */
457
458 /* Set up registers for Generic IOCTL INT21 (44h) check media */
459 regs.x.ax = u(GENERIC_IOCTL); /* AN002 */
460 regs.h.bh = uc(ZERO); /* AN002 */
461 regs.h.bl = (((unsigned char)input_drive - 'A') + 1); /* AN002 */
462 regs.x.cx = u(SPECIAL_FUNCTION); /* AN002 */
463 regs.x.dx = (unsigned)&disk_access; /* AN002 */
464 segread(&segregs); /* AN002 */
465 intdosx(&regs,&regs,&segregs); /* AN002 */
466
467 /* see if buffer returned good or not */
468 if (disk_access.dac_access_flag == ZERO) /* AN002 */
469 formatted = FALSE; /* AN002 */
470 else /* AN002 */
471 formatted = TRUE; /* AN002 */
472
473 return(formatted); /* AN002 */
474
475END /* AN002 */
476
477
478