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

📄 scwfbiggie.c

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 C
字号:
/*__________________________________________________________________________
 Copyright (C) 2002 PGP Corporation
 All rights reserved.
 
 $Id: SCwfBiggie.c,v 1.12 2002/11/16 08:55:23 wjb Exp $
__________________________________________________________________________*/
#include "precomp.h"

// BiggieWipeFreeClusters
//
#define WRITEMEM	  1024*1024 // 1 meg

DWORD BiggieWipeFreeClusters( VOLINFO *vi)
{
	DWORD						dwClusterSize;
	char						*PatternBuf;
	size_t						BytesWritten;
	DWORD						RetVal;
	HANDLE						hFile;
	char						szFileName[MAX_PATH];
	DWORD						dwAmtWritten,writeamt;
	int							maxcluster,writecluster;
	DWORD						dwBreathingRoom;
	BOOL						rst;

	RetVal=WFE_NOERROR;
	dwAmtWritten=0;
	vi->extracount=0;
	hFile=NULL;

	dwClusterSize=vi->sectors_per_clus*vi->sector_size;

//	vi->bNTFSInternal=TRUE;

	if(vi->bNTFSInternal)
		dwBreathingRoom=dwClusterSize-1;
	else
		dwBreathingRoom=300*1024*1024;

	maxcluster=WRITEMEM/dwClusterSize;

	PatternBuf=(char *)malloc(WRITEMEM);

	if(PatternBuf==0)
	{
		RetVal=WFE_OUTOFMEMORY;
	}
	else
	{
		WritePattern(PatternBuf,vi->pattern_buffer,WRITEMEM);

		StatusMessage(vi,"Wiping free space with space fill method...", FALSE);

		{
			ULARGE_INTEGER FreeBytesAvailableToCaller; // receives the number of bytes
			ULARGE_INTEGER TotalNumberOfBytes;    // receives the number of bytes on disk
			ULARGE_INTEGER TotalNumberOfFreeBytes; // receives the free bytes on disk

			do
			{
				BOOL rst;

				if((hFile==NULL)||(dwAmtWritten>2000000000)) // A little less than 2GB
				{
					// We don't want to hit the 2GB limit, so start
					// a new file,
					if(hFile!=NULL)
					{
						FlushFileBuffers( hFile );

						CloseHandle( hFile );
					}

					dwAmtWritten=0;
					sprintf(szFileName,
						"%c:\\PGPwipepattern%X.tmp",vi->vol0+'A',vi->extracount);
	
					hFile = CreateFile(	szFileName, 
						GENERIC_WRITE,
						0, 
						NULL,
						CREATE_ALWAYS, 
						FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING, 
						NULL );

					vi->extracount++;

					if(hFile==0)
					{
						// Unlikely, but maybe we really are full?
						vi->extracount--;
						writeamt=0;
						continue;
					}
				}

				GetDiskFreeSpaceEx(vi->drivestr,
					&FreeBytesAvailableToCaller,
					&TotalNumberOfBytes,
					&TotalNumberOfFreeBytes);

				writecluster=(int)(((TotalNumberOfFreeBytes.QuadPart)-(dwBreathingRoom))/
					dwClusterSize);

				if(writecluster>maxcluster)
					writecluster=maxcluster;

				writeamt=BytesWritten=0;

				if(writecluster>0)
				{
					writeamt=dwClusterSize*writecluster;

					rst=WriteFile(hFile,
						PatternBuf,              
						writeamt,     
						&BytesWritten, 
						NULL);

					vi->dwClustersWritten=vi->dwClustersWritten+writecluster;
					dwAmtWritten=dwAmtWritten+writeamt;
				}

				if(vi->bCancel)
					RetVal=WFE_USERCANCEL;
			}
			while((writeamt!=0)&&(writeamt==BytesWritten)&&(RetVal==WFE_NOERROR)&&
				((TotalNumberOfFreeBytes.QuadPart)>(dwBreathingRoom))); // space for OS
			
			if(hFile!=0)
			{
				FlushFileBuffers( hFile );
				CloseHandle( hFile );
				hFile=NULL;
			}
		}

		if(vi->bNTFSInternal)
		{
			StatusMessage(vi,"Wiping NTFS internal data structures...", FALSE);

			writeamt=dwBreathingRoom;

			if(writeamt<4096)
				writeamt=4096;

			do
			{
				dwAmtWritten=0;
				sprintf(szFileName,
					"%c:\\PGPwipepattern%X.tmp",vi->vol0+'A',vi->extracount);

				hFile = CreateFile(	szFileName, 
					GENERIC_WRITE,
					0, 
					NULL,
					CREATE_ALWAYS, 
					FILE_ATTRIBUTE_NORMAL, 
					NULL );

				if(hFile==0)
				{
					// Can't even create the file?
					writeamt=0;
				}
				else
				{
					vi->extracount++;

					do
					{
						BytesWritten=0;

						WriteFile(hFile,
							PatternBuf,              
							writeamt,     
							&BytesWritten, 
							NULL);

						if(vi->bCancel)
							RetVal=WFE_USERCANCEL;

						if(BytesWritten!=0)
						{
							writeamt=BytesWritten;
							rst=TRUE;
						}
						else
						{
							writeamt--;
							rst=FALSE;
						}
					} while((!rst)&&(RetVal==WFE_NOERROR)&&(writeamt!=0));

					FlushFileBuffers( hFile );
					CloseHandle( hFile );
				}
			} while((writeamt!=0)&&(RetVal==WFE_NOERROR));
		}
		free(PatternBuf);
	}

	return RetVal;
}

BOOL FreeBiggie( VOLINFO *vi)
{
	int extraindex;
	char szFileName[MAX_PATH];

	// Wipe all the extra files
	if((vi->extracount)!=0)
	{
		for(extraindex=0;extraindex<(vi->extracount);extraindex++)
		{
			sprintf(szFileName,
				"%c:\\PGPwipepattern%X.tmp",vi->vol0+'A',extraindex);

			remove(szFileName);
		}
	}

	return TRUE;
}

/*__Editor_settings____

	Local Variables:
	tab-width: 4
	End:
	vi: ts=4 sw=4
	vim: si
_____________________*/

⌨️ 快捷键说明

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