⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmd.c

📁 fdisk source code, 是一个完整的fdisk的工具。
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
// Program:  Free FDISK
// Module:  CMD.C
// Module Description:  Command Line Switch Code Module
//                      All functions that process command line entry are
//                      here.
// Written By:  Brian E. Reifsnyder
// Version:  1.2.1
// Copyright:  1998-2002 under the terms of the GNU GPL, Version 2
*/

/*
CATS message store for cmd.c:

$set 2
1 Syntax Error
2 Program Terminated
3 All flags have been cleared
4 Flag
5 has been cleared
6 Invalid partition size specified
7 Primary DOS Partition not found
8 Extended DOS Partition not found
9 Logical drive number is out of range
10 Partition number is out of range
11 New partition type is out of range
12 Source partition number is out of range
13 Destination partition number is out of range
14 Invalid flag number
15 Flag value is out of range
16 Fixed Disk Drive Status
17 Source partition number is out of range
18 Destination partition number is out of range
19 Invalid drive designation
20 no partition deleted
*/

/*
/////////////////////////////////////////////////////////////////////////////
//  DEFINES
/////////////////////////////////////////////////////////////////////////////
*/

#define CMD

/*
/////////////////////////////////////////////////////////////////////////////
//  INCLUDES
/////////////////////////////////////////////////////////////////////////////
*/

#include <conio.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "cmd.h"
#include "fdiskio.h"
#include "main.h"
#include "pcompute.h"
#include "pdiskio.h"
#include "userint2.h"
#include "userint1.h"

/*
/////////////////////////////////////////////////////////////////////////////
//  PROTOTYPES
/////////////////////////////////////////////////////////////////////////////
*/

int Get_Options(char *arguments[],int number_of_arguments);

void Command_Line_Clear_Flag();
void Command_Line_Create_Extended_Partition();
void Command_Line_Create_Logical_DOS_Drive();
void Command_Line_Create_Primary_Partition();
void Command_Line_Delete();
void Command_Line_Info();
void Command_Line_Modify();
void Command_Line_Move();
void Command_Line_Set_Flag();
void Command_Line_Status();
void Command_Line_Swap();
void Command_Line_Test_Flag();
void Command_Line_X();
void Shift_Command_Line_Options(int number_of_places);

/*
/////////////////////////////////////////////////////////////////////////////
//  FUNCTIONS
/////////////////////////////////////////////////////////////////////////////
*/

/* /CLEARFLAG command line option */
void Command_Line_Clear_Flag()
{
  int option_count=1;

  if( (0==strcmp(arg[1].choice,"ALL")) && (arg[0].value!=0) )
    {
    printf("\n");
    printf(catgets(cat,2,1,"Syntax Error"));
    printf("\n");
    printf(catgets(cat,2,2,"Program Terminated"));
    printf("\n");
    exit(1);
    }

  if(0==strcmp(arg[1].choice,"ALL"))
    {
    int index=1;

    option_count=2;

    do
      {
      Clear_Flag(index);

      index++;
      }while(index<=64);

    printf("\n");
    printf(catgets(cat,2,3,"All flags have been cleared"));
    printf("\n");
    }
  else
    {
    Clear_Flag((int)arg[0].value);

    printf("\n");
    printf(catgets(cat,2,4,"Flag"));
    printf(" %d ",arg[0].value);
    printf(catgets(cat,2,5,"has been cleared"));
    printf("\n");
    }

  Shift_Command_Line_Options(option_count);
}

/* /EXT command line options */
void Command_Line_Create_Extended_Partition()
{ 
  int maximum_possible_percentage;

  long maximum_partition_size_in_MB;

  Partition_Table *pDrive = &part_table[flags.drive_number-0x80];

  if(arg[0].value<=0)
    {
    printf("\n");
    printf(catgets(cat,2,6,"Invalid partition size specifed"));
    printf("\n");
    printf(catgets(cat,2,2,"Program Terminated"));
    printf("\n");
    exit(9);
    }

  Determine_Free_Space();

  maximum_partition_size_in_MB = Max_Pri_Part_Size_In_MB(EXTENDED);

  maximum_possible_percentage
   = Convert_To_Percentage(maximum_partition_size_in_MB
   ,pDrive->total_hard_disk_size_in_MB);

//   ,pDrive->ext_part_size_in_MB);

  if(arg[0].extra_value==100)
    {
    /* Set limit on percentage. */
    if(arg[0].value > 100) arg[0].value = 100;
    if(arg[0].value > maximum_possible_percentage)
     arg[0].value = maximum_possible_percentage;

    /* Determine partition size. */
    arg[0].value
     = (arg[0].value * maximum_partition_size_in_MB)
     / maximum_possible_percentage;

/*
    arg[0].value = Convert_Percent_To_MB(arg[0].value
     ,(pDrive->total_cyl+1) );
*/
    }

  Create_Primary_Partition(5,arg[0].value);

  Shift_Command_Line_Options(1);
}

/* /LOG and /LOGO command line options */
void Command_Line_Create_Logical_DOS_Drive()
{
  int maximum_possible_percentage;
  int option_count=1;

//  long ext_part_size;
  long maximum_partition_size_in_MB;

  Partition_Table *pDrive = &part_table[flags.drive_number-0x80];

  if(arg[0].value<=0)
    {
    printf("\n");
    printf(catgets(cat,2,6,"Invalid partition size specifed"));
    printf("\n");
    printf(catgets(cat,2,2,"Program Terminated"));
    printf("\n");
    exit(9);
    }

  Determine_Free_Space();

  maximum_partition_size_in_MB = Max_Log_Part_Size_In_MB();

  maximum_possible_percentage
   = Convert_To_Percentage(maximum_partition_size_in_MB
   ,pDrive->ext_part_size_in_MB);

  if(arg[0].extra_value==100)
    {
    /* Set limit on percentage. */
    if(arg[0].value > 100) arg[0].value = 100;
    if(arg[0].value > maximum_possible_percentage)
     arg[0].value = maximum_possible_percentage;

    /* Determine partition size. */
    arg[0].value
     = (arg[0].value * maximum_partition_size_in_MB)
     / maximum_possible_percentage;



    /* Compute the partition size as a percentage. */

//    arg[0].value = Convert_Percent_To_MB(arg[0].value,ext_part_size);
    }

  if(0!=strcmp(arg[1].choice,"SPEC"))
    {
    /* If no special partition type is defined. */

    Create_Logical_Drive(
     Partition_Type_To_Create(arg[0].value,0),arg[0].value);
    }
  else
    {
    /* If a special partition type is defined. */
    option_count=2;

    Create_Logical_Drive((int)arg[1].value,arg[0].value);
    }

  Shift_Command_Line_Options(option_count);
}

/* /PRI and /PRIO command line options */
void Command_Line_Create_Primary_Partition()
{
  int maximum_possible_percentage;
  int option_count=1;

  long maximum_partition_size_in_MB;

  Partition_Table *pDrive = &part_table[flags.drive_number-0x80];

  if(arg[0].value<=0)
    {
    printf("\n");
    printf(catgets(cat,2,6,"Invalid partition size specifed"));
    printf("\n");
    printf(catgets(cat,2,2,"Program Terminated"));
    printf("\n");
    exit(9);
    }

  Determine_Free_Space();

  maximum_partition_size_in_MB = Max_Pri_Part_Size_In_MB(PRIMARY);

  maximum_possible_percentage
   = Convert_To_Percentage(maximum_partition_size_in_MB
   ,pDrive->total_hard_disk_size_in_MB);


  if(arg[0].extra_value==100)
    {
    /* Set limit on percentage. */
    if(arg[0].value > 100) arg[0].value = 100;
    if(arg[0].value > maximum_possible_percentage)
     arg[0].value = maximum_possible_percentage;

    /* Determine partition size. */
    arg[0].value
     = (arg[0].value * maximum_partition_size_in_MB)
     / maximum_possible_percentage;
    }

  if(0!=strcmp(arg[1].choice,"SPEC"))
    {
    /* If no special partition type is defined. */

    Set_Active_Partition_If_None_Is_Active(
     	Create_Primary_Partition(
     	Partition_Type_To_Create(arg[0].value,0),arg[0].value));
    }
  else
    {
    /* If a special partition type is defined. */
    option_count=2;

    Create_Primary_Partition((int)arg[1].value,arg[0].value);
    }


  Shift_Command_Line_Options(option_count);
}

/* /DELETE command line option */
void Command_Line_Delete()
{
  Partition_Table *pDrive = &part_table[flags.drive_number-0x80];

  /* Delete the primary partition */
  if(0==strcmp(arg[1].choice,"PRI"))
    {
    if (arg[1].value != 0)			/* specified what to delete */
      {
      if (arg[1].value < 1 || arg[1].value >4)
	{
	printf("primary partition # (%ld) must be 1..4\n",(long)arg[1].value); exit(9);}

	Delete_Primary_Partition((int)(arg[1].value - 1));
		}
	else
	  {							/* no number given, delete 'the' partition */
	  int index,found,count;

	  for (count = 0, index = 0; index < 4; index++)
	    {
	    if(IsRecognizedFatPartition(pDrive->pri_part[index].num_type))
	      {
	      count++;
	      found = index;
	      }
	    }
	    if (count == 0)
	     printf("no partition to delete found\n");	/* but continue */
	    else
	      if (count > 1)
		{
		printf("%d primary partitions found, you must specify number to delete\n",count); exit(9);
		}
	      else
		{
		Delete_Primary_Partition(found);
		}
	    }
	} /* end PRI */

  /* Delete the extended partition */
  if(0==strcmp(arg[1].choice,"EXT"))
    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -