📄 userint2.c
字号:
/*
// Program: Free FDISK
// Written By: Brian E. Reifsnyder
// Module: USERINT2.C
// Module Description: Second User Interface Code Module
// Version: 1.2.1
// Copyright: 1998-2003 under the terms of the GNU GPL, Version 2
*/
/*
/////////////////////////////////////////////////////////////////////////////
// DEFINES
/////////////////////////////////////////////////////////////////////////////
*/
#define USERINT
/*
/////////////////////////////////////////////////////////////////////////////
// INCLUDES
/////////////////////////////////////////////////////////////////////////////
*/
#include <conio.h>
#include <ctype.h>
#include <dir.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include "detdl2.h"
#include "fdiskio.h"
#include "main.h"
#include "pcompute.h"
#include "pdiskio.h"
#include "userint2.h"
#include "userint1.h"
/*
/////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
/////////////////////////////////////////////////////////////////////////////
*/
int IsRecognizedFatPartition(unsigned partitiontype)
{
switch(partitiontype)
{
case 1:
case 4:
case 6:
return TRUE;
case 0x0e:
if (flags.version==W95 || flags.version==W95B || flags.version==W98)
return TRUE;
break;
case 0x0b:
if ( flags.version==W95B || flags.version==W98)
return TRUE;
break;
case 0x0c:
if ( flags.version==W95B || flags.version==W98)
return TRUE;
break;
}
return FALSE;
}
/* Ask user if they want to use large disk support (FAT 32) */
void Ask_User_About_FAT32_Support()
{
Clear_Screen(0);
Print_Centered(5,"Free FDISK is capable of using large disk support to allow you to ",0);
Print_Centered(6,"create partitions that are greater than 2,048 MB by using FAT32 ",0);
Print_Centered(7,"partitions. If you enable large disk support, any partitions or ",0);
Print_Centered(8,"logical drives greater than 512 MB will be created using FAT32. ",0);
Print_Centered(10,"IMPORTANT: If you enable large disk support, some operating systems ",0);
Print_Centered(11,"will be unable to access the partitions and logical drives that are ",0);
Print_Centered(12,"over 512 MB in size. ",0);
Print_Centered(17,"Do you want to use large disk (FAT32) support (Y/N)....? ",0);
flags.fat32=(int)Input(1,62,17,YN,0,0,NONE,1,0,NULL,NULL);
}
/* Change Current Fixed Disk Drive */
void Change_Current_Fixed_Disk_Drive()
{
int new_drive_number;
int old_drive_number=flags.drive_number;
Clear_Screen(0);
Print_Centered(0,"Change Current Fixed Disk Drive",BOLD);
Display_All_Drives();
printAt(4,21,"Enter Fixed Disk Drive Number (1-%d)......................."
,(flags.maximum_drive_number-127));
new_drive_number=(int)Input(1,62,21,NUM,1,(flags.maximum_drive_number-127)
,ESCR,(flags.drive_number-127),0,NULL,NULL);
if( (new_drive_number<=0)
|| (new_drive_number>(flags.maximum_drive_number-127)) )
{
flags.drive_number=old_drive_number;
}
else
{
flags.drive_number=new_drive_number+127;
}
}
/* Create DOS Partition Interface */
int Create_DOS_Partition_Interface(int type)
{
int numeric_type;
int partition_created=FALSE;
int partition_slot_just_used;
long maximum_partition_size_in_MB;
long maximum_possible_percentage;
unsigned long input=0;
Partition_Table *pDrive = &part_table[flags.drive_number-0x80];
maximum_partition_size_in_MB
= Max_Pri_Part_Size_In_MB(type);
if(type==PRIMARY)
{
Clear_Screen(0);
Print_Centered(4,"Create Primary DOS Partition",BOLD);
printAt(4,6,"Current fixed disk drive: ");
cprintf("%d",(flags.drive_number-127));
printAt(4,8,"Do you wish to use the maximum available size for a Primary DOS Partition");
if((flags.drive_number-128)==0)
{
printAt(4,9,"and make the partition active (Y/N).....................? ");
}
else
{
printAt(4,9,"(Y/N)...................................................? ");
}
flags.esc=FALSE;
input=Input(1,62,9,YN,0,0,ESCR,1,0,NULL,NULL);
if(flags.esc==TRUE) return(1);
if(input==1)
{
input=maximum_partition_size_in_MB;
numeric_type=6; /* Set the numeric type to 6 so that it will be */
/* decided by Partition_Type_To_Create(). */
if( (flags.fprmt==TRUE) && (type==PRIMARY) && (input>=128) && (input<=2048) )
{
printAt(4,22,"This drive is a FAT32 by default, switch to FAT16 (Y/N)? ");
flags.fat32=!Input(1,61,22,YN,0,0,NONE,1,0,NULL,NULL);
}
/* Use the maximum available free space to create a DOS Partition */
/* Adjust numeric type depending upon partition size and the FDISK */
/* version emulated. */
numeric_type=Partition_Type_To_Create(input,numeric_type);
partition_slot_just_used=Create_Primary_Partition(numeric_type,input);
if((flags.drive_number-128)==0) Set_Active_Partition(partition_slot_just_used);
partition_created=TRUE;
}
}
if(partition_created==FALSE)
{
Clear_Screen(0);
if(type==PRIMARY) Print_Centered(4,"Create Primary DOS Partition",BOLD);
else Print_Centered(4,"Create Extended DOS Partition",BOLD);
printAt(4,6,"Current fixed disk drive: ");
cprintf("%d",(flags.drive_number-127));
Display_Primary_Partition_Information_SS();
printAt(4,15,"Maximum space available for partition is ");
if( (flags.version==W95) || (flags.version==W95B) || (flags.version==W98) )
Print_UL_B(maximum_partition_size_in_MB);
else cprintf("%4d",maximum_partition_size_in_MB);
printf(" Mbytes ");
maximum_possible_percentage
= Convert_To_Percentage(maximum_partition_size_in_MB
,pDrive->total_hard_disk_size_in_MB);
cprintf("(%3d%%)",maximum_possible_percentage);
printAt(4,18,"Enter partition size in Mbytes or percent of disk space (%) to");
if(type==PRIMARY) printAt(4,19,"create a Primary DOS Partition.................................: ");
else printAt(4,19,"create an Extended DOS Partition...............................: ");
flags.esc=FALSE;
if( (flags.version==4) || (flags.version==5) || (flags.version==6) )
input=Input(4,69,19,NUMP,1,maximum_partition_size_in_MB,ESCR
,maximum_partition_size_in_MB,maximum_possible_percentage,NULL,NULL);
else input=Input(6,69,19,NUMP,1,maximum_partition_size_in_MB,ESCR
,maximum_partition_size_in_MB,maximum_possible_percentage,NULL,NULL);
if(flags.esc==TRUE) return(1);
if( (flags.fprmt==TRUE) && (type==PRIMARY) && (input>=128) && (input<=2048) )
{
printAt(4,22,"This drive is a FAT32 by default, switch to FAT16 (Y/N)? ");
flags.fat32=!Input(1,61,22,YN,0,0,NONE,1,0,NULL,NULL);
}
if(type==PRIMARY) numeric_type=Partition_Type_To_Create(input,0);
else numeric_type=5;
Create_Primary_Partition(numeric_type,input);
}
if(flags.fprmt==TRUE) flags.fat32=FALSE;
Clear_Screen(0);
if(type==PRIMARY) Print_Centered(4,"Create Primary DOS Partition",BOLD);
else Print_Centered(4,"Create Extended DOS Partition",BOLD);
printAt(4,6,"Current fixed disk drive: ");
cprintf("%d",(flags.drive_number-127));
Display_Primary_Partition_Information_SS();
Position_Cursor(4,21);
if(type==PRIMARY) cprintf("Primary DOS Partition created");
else cprintf("Extended DOS Partition created");
Input(0,0,0,ESC,0,0,ESCC,0,0,NULL,NULL);
if(type==EXTENDED) Create_Logical_Drive_Interface();
return(0);
}
/* Create Logical Drive Interface */
/* Returns a 0 if successful and a 1 if unsuccessful */
int Create_Logical_Drive_Interface()
{
long input=0;
int drive_created=FALSE;
int maximum_possible_percentage;
int numeric_type;
long maximum_partition_size_in_MB;
Partition_Table *pDrive = &part_table[flags.drive_number-0x80];
Determine_Free_Space();
if(pDrive->ext_part_largest_free_space>=2)
{
do
{
if(flags.fprmt==TRUE) flags.fat32=TRUE;
maximum_partition_size_in_MB
= Max_Log_Part_Size_In_MB();
Clear_Screen(0);
if(drive_created==TRUE)
{
cprintAt(4,22,"Logical DOS Drive created, drive letters changed or added");
}
Print_Centered(1,"Create Logical DOS Drive in the Extended DOS Partition",BOLD);
Display_Extended_Partition_Information_SS();
if('Z'==Determine_Drive_Letters())
{
printAt(4,22," ");
cprintAt(4,22,"Maximum number of Logical DOS Drives installed.");
Input(0,0,0,ESC,0,0,ESCC,0,0,NULL,NULL);
if(flags.fprmt==TRUE) flags.fat32=FALSE;
return(1);
}
printAt(4,17,"Total Extended DOS Partition size is ");
if( (flags.version==4) || (flags.version==5) || (flags.version==6) )
cprintf("%4d",pDrive->ext_part_size_in_MB);
else Print_UL_B(pDrive->ext_part_size_in_MB);
printf(" Mbytes (1 Mbyte = 1048576 bytes)");
printAt(4,18,"Maximum space available for partition is ");
if( (flags.version==4) || (flags.version==5) || (flags.version==6) )
cprintf("%4d",maximum_partition_size_in_MB);
else Print_UL_B(maximum_partition_size_in_MB);
printf(" Mbytes ");
maximum_possible_percentage
= Convert_To_Percentage(maximum_partition_size_in_MB
,pDrive->ext_part_size_in_MB);
cprintf("(%3d%%)",maximum_possible_percentage);
printAt(4,20,"Enter logical drive size in Mbytes or percent of disk space (%)...");
flags.esc=FALSE;
if( (flags.version==4) || (flags.version==5) || (flags.version==6) )
input=Input(4,70,20,NUMP,1,maximum_partition_size_in_MB,ESCR
,maximum_partition_size_in_MB,maximum_possible_percentage,NULL,NULL);
else input=Input(6,70,20,NUMP,1,maximum_partition_size_in_MB,ESCR
,maximum_partition_size_in_MB,maximum_possible_percentage,NULL,NULL);
if(flags.esc==TRUE)
{
if(flags.fprmt==TRUE) flags.fat32=FALSE;
return(1);
}
if( (flags.fprmt==TRUE) && (input>=128) && (input<=2048) )
{
printAt(4,21,"This drive is a FAT32 by default, switch to FAT16 (Y/N)? ");
flags.fat32=!Input(1,61,21,YN,0,0,NONE,1,0,NULL,NULL);
}
numeric_type=6;
numeric_type=Partition_Type_To_Create(input,numeric_type);
Create_Logical_Drive(numeric_type,input);
drive_created=TRUE;
}while(pDrive->ext_part_largest_free_space>=2);
}
Clear_Screen(0);
Print_Centered(1,"Create Logical DOS Drive in the Extended DOS Partition",BOLD);
Display_Extended_Partition_Information_SS();
cprintAt(4,22,"All available space in the Extended DOS Partition");
cprintAt(4,23,"is assigned to logical drives.");
Input(0,0,0,ESC,0,0,ESCC,0,0,NULL,NULL);
if(flags.fprmt==TRUE) flags.fat32=FALSE;
return(0);
}
/* Delete Extended DOS Partition Interface */
void Delete_Extended_DOS_Partition_Interface()
{
int input=0;
Partition_Table *pDrive = &part_table[flags.drive_number-0x80];
Clear_Screen(0);
Print_Centered(4,"Delete Extended DOS Partition",BOLD);
Display_Primary_Partition_Information_SS();
BlinkPrintAt(4,18,"WARNING!");
printf(" Data in the deleted Extended DOS Partition will be lost.");
printAt(4,19,"Do you wish to continue (Y/N).................? ");
flags.esc=FALSE;
input=(int)Input(1,52,19,YN,0,0,ESCR,0,0,NULL,NULL);
if( (flags.esc==FALSE) && (input==TRUE) )
{
Delete_Primary_Partition(int(pDrive->ptr_ext_part-pDrive->pri_part));
Clear_Extended_Partition_Table(flags.drive_number-128);
Clear_Screen(0);
Print_Centered(4,"Delete Extended DOS Partition",BOLD);
Display_Primary_Partition_Information_SS();
cprintAt(4,21,"Extended DOS Partition deleted");
printAt(4,24," ");
Input(0,0,0,ESC,0,0,ESCC,0,0,NULL,NULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -