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

📄 formattest.c

📁 MODC驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
/********************************************************************************************/
/* formatTest: is a simple demonstration of using the FL_IOCTL_FORMAT_PHYSICAL_DRIVE IOctl  */
/*						 There are two format examples each one can be setted by the user.            */
/********************************************************************************************/

/*
------------ I N C L U D E S ---------------------------------------------------------
*/

#include <windows.h>
#include <stdio.h>
#include <diskio.h>
#include <winbase.h>
#include "CEIOCTL.h"





/*******************************************/
/*  Set by the user (hard coded):					 */
/*  -----------------------------					 */
/*  exampleNumber = FIRST_FORMAT_EXAMPLE	 */
/*  				or														 */
/*  exampleNumber = SECOND_FORMAT_EXAMPLE	 */
/*******************************************/
typedef enum _ExampleNumber{
WITHOUT_EXAMPLE,
FIRST_FORMAT_EXAMPLE,
SECOND_FORMAT_EXAMPLE	
}ExampleNumber;

/*ExampleNumber	exampleNumber = FIRST_FORMAT_EXAMPLE ;	*/
ExampleNumber exampleNumber = SECOND_FORMAT_EXAMPLE ;

/*
------------ D E F I N E S -----------------------------------------------------------
*/

#define SIGNATURE_OFFSET			8
#define BUFFER_SIZE						0x200
#define SLEEP_TIME						0x400

/*
------------ F U N C T I O N  P R O T O T Y P E S  -----------------------------------
*/
FLStatus PrintFLStatus(const FLStatus bStat) ;
void TRACE(LPCTSTR szFormat, ...) ;



/******************************************/
/******************************************/
/***     W i n M a i n									***/
/******************************************/
/******************************************/


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hInstPrev, LPWSTR pszCmdLine, int nCmdShow)
{

/*
------------ P A R A M E T E R S ---------------------------------------------------
*/

	unsigned long							  realSize ;													/* return size value */
	HANDLE											hDevice = NULL ;										/* handle to the device */
	flFormatPhysicalInput				formatPhysicalInput ;								/* input record for  FL_IOCTL_FORMAT_PHYSICAL_DRIVE */
	flOutputStatusRecord				formatPhysicalOutput ;							/* output record for  FL_IOCTL_FORMAT_PHYSICAL_DRIVE */



/*  getting the device handle */

	hDevice = CreateFile(TEXT("DSK1:"),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL) ;
	
	if(hDevice == INVALID_HANDLE_VALUE)
	{
		TRACE(TEXT("Create handle failed.")) ;
		Sleep(SLEEP_TIME) ;
		return 0 ;
	}

	TRACE(TEXT("Create succeeded\n"));


	switch (exampleNumber)
		{
		case FIRST_FORMAT_EXAMPLE:/* example of one BDK partition */
			{
/* initializing input record for  FL_IOCTL_FORMAT_PHYSICAL_DRIVE */
	
				formatPhysicalInput.formatType							= TL_FORMAT ;					/* setting the type of format */

				formatPhysicalInput.fp.percentUse						= 0x62 ;							/* setting the precentage use of the media
																																						 to be 98% in order to achive high preformance */
				formatPhysicalInput.fp.progressCallback			= NULL ;

				formatPhysicalInput.fp.vmAddressingLimit		= 0x10000l ;

				formatPhysicalInput.fp.embeddedCISlength		= 0 ;

				formatPhysicalInput.fp.embeddedCIS					= NULL ;

				formatPhysicalInput.fp.BDTLPartitionInfo		= malloc(sizeof(BDTLPartitionFormatParams)) ;
	
/* initialzing the parameters for the first BDTL partition */
				formatPhysicalInput.fp.BDTLPartitionInfo[0].length = 0x500000L ;		/* setting the partition length */
				
				formatPhysicalInput.fp.BDTLPartitionInfo[0].noOfSpareUnits	= 2;		/* setting the number of spare units
																																							 inorder to improve performance */
				formatPhysicalInput.fp.BDTLPartitionInfo[0].flags						= TL_FORMAT_FAT;/* setting the format flags */

				formatPhysicalInput.fp.BDTLPartitionInfo[0].volumeLabel			= NULL ;/* setting no label */

				formatPhysicalInput.fp.BDTLPartitionInfo[0].noOfFATcopies		= 2 ;		/* setting the FAT copies for better performance */

				formatPhysicalInput.fp.BDTLPartitionInfo[0].protectionType	= 0 ;

				memset(formatPhysicalInput.fp.BDTLPartitionInfo[0].protectionKey, 0, sizeof(formatPhysicalInput.fp.BDTLPartitionInfo[0].protectionKey)) ;

				formatPhysicalInput.fp.noOfBDTLPartitions		= 1 ;									/* setting number of BDTL partitions */

				formatPhysicalInput.fp.noOfBinaryPartitions = 1 ;									/* setting number of BDK partitions */

				formatPhysicalInput.fp.binaryPartitionInfo = malloc(sizeof(BinaryPartitionFormatParams) * 1) ;

/* initialzing input record for the one & only BDK partition */
				formatPhysicalInput.fp.binaryPartitionInfo[0].length				= 0x800000L ;	/* setting the partition length */
				
				formatPhysicalInput.fp.binaryPartitionInfo[0].sign[0]				= 'B' ;
				formatPhysicalInput.fp.binaryPartitionInfo[0].sign[1]				= 'I' ;
				formatPhysicalInput.fp.binaryPartitionInfo[0].sign[2]				= 'P' ;
				formatPhysicalInput.fp.binaryPartitionInfo[0].sign[3]				= 'O' ;				/* setting the signature of the binary format */

				formatPhysicalInput.fp.binaryPartitionInfo[0].signOffset = SIGNATURE_OFFSET ;	/* setting the signature offset */

				formatPhysicalInput.fp.binaryPartitionInfo[0].protectionType = PROTECTABLE | CHANGEABLE_PROTECTION ;
																																					/* setting the partition protection attributes */
				memset(formatPhysicalInput.fp.binaryPartitionInfo[0].protectionKey, 0, sizeof(formatPhysicalInput.fp.binaryPartitionInfo[0].protectionKey)) ;
																																					/* setting the protection key password 
																																						 of the first partition */		
				break ;
			}

		case SECOND_FORMAT_EXAMPLE:				/* example of two BDTL partitions */
			{
// initializing input record for  FL_IOCTL_FORMAT_PHYSICAL_DRIVE
	
				formatPhysicalInput.formatType							= TL_FORMAT ;			/* setting the type of format */

				formatPhysicalInput.fp.percentUse						= 0x62 ;					/* setting the precentage use of the media
																																				 to be 98% in order to achive high preformance */
				formatPhysicalInput.fp.noOfBDTLPartitions		= 2 ;							/* setting number of BDTL partitions */

				formatPhysicalInput.fp.noOfBinaryPartitions = 0 ;							/* setting number of BDK partitions */

				formatPhysicalInput.fp.binaryPartitionInfo	= NULL;

				formatPhysicalInput.fp.progressCallback			= NULL ;

				formatPhysicalInput.fp.embeddedCISlength		= 0 ;

				formatPhysicalInput.fp.vmAddressingLimit		= 0x10000l ;

				formatPhysicalInput.fp.embeddedCIS					= NULL ;

				formatPhysicalInput.fp.BDTLPartitionInfo		= malloc(sizeof(BDTLPartitionFormatParams) * 2) ;
	
/* initialzing the parameters for the first BDTL partition */
				formatPhysicalInput.fp.BDTLPartitionInfo[0].length					= 0x500000L ;	/* setting the partition length */
				
				formatPhysicalInput.fp.BDTLPartitionInfo[0].noOfSpareUnits	= 2;					/* setting the number of spare units
																																										 inorder to improve performance */
				formatPhysicalInput.fp.BDTLPartitionInfo[0].flags						= TL_FORMAT_FAT;/* setting the format flags */

				formatPhysicalInput.fp.BDTLPartitionInfo[0].volumeLabel			= NULL ;			/* setting no label */

				formatPhysicalInput.fp.BDTLPartitionInfo[0].noOfFATcopies		= 2 ;					/* setting the FAT copies for better performance */

				formatPhysicalInput.fp.BDTLPartitionInfo[0].protectionType	= PROTECTABLE | WRITE_PROTECTED  | CHANGEABLE_PROTECTION ;
																																									/* setting the partition protection attributes */
				memset(formatPhysicalInput.fp.BDTLPartitionInfo[0].protectionKey, 0, sizeof(formatPhysicalInput.fp.binaryPartitionInfo[0].protectionKey)) ;
																																									/* setting the protection key password 
																																										 of the first partition */		
/* initialzing the parameters for the second BDTL partition */
				formatPhysicalInput.fp.BDTLPartitionInfo[1].length					= 0x1000000L ;/* setting the partition length */
				
				formatPhysicalInput.fp.BDTLPartitionInfo[1].noOfSpareUnits	= 2;					/* setting the number of spare units
																																										 inorder to improve performance */
				formatPhysicalInput.fp.BDTLPartitionInfo[1].flags						= TL_FORMAT_FAT;/* setting the format flags */

				formatPhysicalInput.fp.BDTLPartitionInfo[1].volumeLabel			= NULL ;			/* setting no label */

				formatPhysicalInput.fp.BDTLPartitionInfo[1].noOfFATcopies		= 2 ;					/* setting the FAT copies for better performance */

				formatPhysicalInput.fp.BDTLPartitionInfo[1].protectionType	= PROTECTABLE ;
																																									/* setting the partition protection attributes */
				memset(formatPhysicalInput.fp.BDTLPartitionInfo[1].protectionKey, 1, sizeof(formatPhysicalInput.fp.binaryPartitionInfo[0].protectionKey)) ;
																																					/* setting the protection key password 
																																						 of the second partition */		
				break ;
			}

		case WITHOUT_EXAMPLE:
			{
	
				TRACE(TEXT("No format example was selected.\n")) ;
				break ; 
			}


		default:
			{
						
				break ;
			}

	} /* end of switch */


	if ( exampleNumber != WITHOUT_EXAMPLE )
	{
/* calling for FL_IOCTL_FORMAT_PHYSICAL_DRIVE */
	
		if(DeviceIoControl(hDevice,FL_IOCTL_FORMAT_PHYSICAL_DRIVE,&formatPhysicalInput,sizeof(flFormatPhysicalInput),&formatPhysicalOutput,sizeof(flOutputStatusRecord),&realSize,NULL)==0)
		{  /* failure */
			TRACE(TEXT("FL_IOCTL_FORMAT_PHYSICAL_DRIVE failed.\n")) ;
			PrintFLStatus( formatPhysicalOutput.status ) ;
			Sleep(SLEEP_TIME);

⌨️ 快捷键说明

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