Exemple #1
0
DualErr 
Volume::InitMountedVars(PGPUInt8 drive, PDCB pDcb)
{
	DualErr derr;

	pgpAssert(IsLegalDriveNumber(drive));
	pgpAssert(Unmounted());
	pgpAssertAddrValid(pDcb, DCB);

	// Allocate a buffer for bootblock and devparam requests.
	if (derr.IsntError())
	{
		derr = GetByteBuffer(ExtractBlockSize(pDcb), (PGPUInt8 **) &mBBlock);
	}

	if (derr.IsntError())
	{
		mMountState = kVol_Mounted;
		mDrive = drive;

		mPDcb = pDcb;
	}

	return derr;
}
DualErr 
FatParser::ExpandFragArray()
{
	DualErr		derr;
	PFileFrag	temp;

	// Get memory for more fragments.
	derr = GetByteBuffer(
		(mSizeFragArray + kFPFragArrayChunkSize) * sizeof(FileFrag), 
		(PGPUInt8 **) &temp);

	if (derr.IsntError())
	{
		// Copy the old fragments to the new memory.
		pgpCopyMemory(mFragArray, temp, mSizeFragArray*sizeof(FileFrag));

		// Delete the old memory.
		FreeByteBuffer((PGPUInt8 *) mFragArray);

		mFragArray = temp;
		mSizeFragArray += kFPFragArrayChunkSize;
	}

	return derr;
}
FatParser::FatParser(LPCSTR path, PGPUInt8 hostDrive, PGPUInt32 bytesFile)
	 : FileSystemParser(path, hostDrive, bytesFile)
{
	pgpAssert(mHost.Mounted());
	pgpAssert(IsFatVolume(mFsId));

	mDataBuf		= NULL;
	mNumFragsInUse	= 0;
	mSizeFragArray	= 0;
	mFragArray		= NULL;

	mFatParserReq.isInUse = FALSE;

	mInitErr = FileSystemParser::mInitErr;

	// Note how we allocate space for one extra sector in the main sector
	// buffer. This is because FAT12 sectors can overflow sector boundaries.

	if (mInitErr.IsntError())
	{
		mInitErr = GetByteBuffer((kFPDataBufSize + 1) * mHost.GetBlockSize(), 
			&mDataBuf);
	}

	if (mInitErr.IsntError())
	{
		mInitErr = GetByteBuffer(kFPFragArrayChunkSize*sizeof(FileFrag), 
			(PGPUInt8 **) &mFragArray);

		mSizeFragArray = kFPFragArrayChunkSize;
	}

	if (mInitErr.IsntError())
	{
		mInitErr = GetFatData();
	}

	if (mInitErr.IsntError())
	{
		mInitErr = MakeFatFrags();
	}

#if PGP_DEBUG
	if (mInitErr.IsntError())
		DumpFrags();
#endif	// PGP_DEBUG
}
///////////////////////////////////////////////////////////////////////////////
//
// Open()
//
// Purpose:     Open a file resource
//
// Parameters:  hInstance      - instance handle for the resource.  A value of 
//                               NULL specifies the exe (default).
//              lpszResId      - resource name or id (passed via MAKEINTRESOURCE)
//              lpszResType    - resource type string to look for
//              eConvertAction - convert action to take
//              eBomAction     - action to take with BOM
//
// Returns:     BOOL           - returns TRUE if resource opened ok, otherwise FALSE
//
BOOL CResourceTextFile::Open(HINSTANCE hInstance, 
							 LPCTSTR lpszResId, 
							 LPCTSTR lpszResType /*= _T("TEXT")*/,
							 ConvertAction eConvertAction /*= NoConvertAction*/,
							 BomAction eBomAction /*= NoBomAction*/)
{
	BOOL rc = FALSE;

	Close();

	_ASSERTE(lpszResId);
	_ASSERTE(lpszResType);

	m_eConvertAction = eConvertAction;
	TRACE(_T("m_eConvertAction=%d\n"), m_eConvertAction);
	m_eBomAction = eBomAction;
	TRACE(_T("m_eBomAction=%d\n"), m_eBomAction);

	if (lpszResId && lpszResType)
	{
		rc = CResourceFile::Open(hInstance, lpszResId, lpszResType);

		if (rc)
		{
			TCHAR *cp = (TCHAR *) GetByteBuffer();
			DWORD dwSize = (DWORD) GetLength();
			TRACE(_T("dwSize=%d\n"), dwSize);

			rc = SetTextBuffer(cp, dwSize, 
					eConvertAction, eBomAction);

			if (rc)
			{
				m_bText = TRUE;
			}
			else
			{
				TRACE(_T("ERROR SetTextBuffer failed\n"));
				Close();
			}
		}
		else
		{
			TRACE(_T("ERROR Open failed\n"));
		}
	}

	return rc;
}
Exemple #5
0
DualErr 
Volume::CreateReasonableWriteBuffer(
	PGPUInt32 blocksData, 
	PGPUInt8 **buf, 
	PGPUInt32 *pBlocksSizeBuf)
{
	DualErr		derr;
	PGPUInt32	blocksSizeBuf;

	pgpAssert(blocksData > 0);
	pgpAssertAddrValid(buf, PGPUInt8 *);
	pgpAssertAddrValid(pBlocksSizeBuf, PGPUInt32);

	// Calculate the ideal size of the buffer to create.
	blocksSizeBuf = blocksData/kIdealNumWritesPerData;

	if (blocksSizeBuf < kMinBlocksPerWrite)
	{
		blocksSizeBuf = kMinBlocksPerWrite;
	}
	else if (blocksSizeBuf > kMaxBlocksPerWrite)
	{
		blocksSizeBuf = kMaxBlocksPerWrite;
	}

	// Create the largest buffer we can that's closest to our ideal size.
	while (TRUE)
	{
		derr = GetByteBuffer(blocksSizeBuf*kDefaultBlockSize, buf);

		if (derr.IsntError())
		{
			(* pBlocksSizeBuf) = blocksSizeBuf;
			break;
		}
		else
		{
			blocksSizeBuf /= 2;

			if (blocksSizeBuf < kMinBlocksPerWrite)
				break;
		}
	}

	return derr;
}
Exemple #6
0
PGPdisk::PGPdisk() : VolFile(), mSmContextA(sizeof(CipherContext)), 
	mSmContextB(sizeof(CipherContext))
{
	mContextA	= NULL;
	mContextB	= NULL;

	mDataBuf = NULL;

	mPGPdiskReq.isInUse = FALSE;

	mInitErr = VolFile::mInitErr;

	if (mInitErr.IsntError())
	{
		mInitErr = mSmContextA.mInitErr;
	}

	if (mInitErr.IsntError())
	{
		mInitErr = mSmContextB.mInitErr;
	}

	// Get our data buffer.
	if (mInitErr.IsntError())
	{
		mInitErr = GetByteBuffer(kPGDBlocksPerOp*kDefaultBlockSize, 
			&mDataBuf);
	}

	if (mInitErr.IsntError())
	{
		// Use placement new.
		mContextA	= new (mSmContextA.GetPtr()) CipherContext;	
		mContextB	= new (mSmContextB.GetPtr()) CipherContext;
	}
}
Exemple #7
0
DualErr 
Volume::Format()
{
	DualErr		derr;
	FatData		fat;
	PGPBoolean	allocedBlockBuf, lockedForFormat;
	PGPUInt8	*blockBuf;
	PGPUInt64	megsDisk;

	pgpAssert(Mounted());
	pgpAssert(!LockedForReadWrite() || !LockedForFormat());

	allocedBlockBuf = lockedForFormat = FALSE;
	megsDisk = (GetTotalBlocks() * kDefaultBlockSize) / kBytesPerMeg;

	// Can only format drives with standard block sizes.
	if (GetBlockSize() != kDefaultBlockSize)
		derr = DualErr(kPGDMinorError_CantFormatDrive);

	// Too big for format?
	if (derr.IsntError())
	{
		if (GetBlockSize() > kMaxBlocksDiskWeFormat)
			derr = DualErr(kPGDMinorError_DiskTooBigToFormat);
	}

	// Get block buffer.
	if (derr.IsntError())
	{
		derr = GetByteBuffer(kDefaultBlockSize, &blockBuf);
		allocedBlockBuf = derr.IsntError();
	}

	// Lock the volume for format.
	if (derr.IsntError())
	{
		derr = LockVolumeForFormat();
		lockedForFormat = derr.IsntError();
	}

	if (derr.IsntError())
	{
		// Initialize FAT data.
		fat.fdFsId = kFS_FAT16;

		if (megsDisk < 2)
		{
			fat.fdFsId = kFS_FAT12;
		}
		else if ((megsDisk >= kMinFat32Megs) && 
			IsWin95OSR2CompatibleMachine())
		{
			fat.fdFsId = kFS_FAT32;
		}

		InitFatData(&fat, GetBlockSize());

		derr = ClearBlocks(0, fat.fdFirstSecData);
	}

	// Write out the FAT data structures.
	if (derr.IsntError())
	{
		BigFatBootFSInfo	bfInfo;
		BootSector12		bb12;
		BootSector16		bb16;
		BootSector32		bb32;
		PGPUInt32			fat16Sig;
		PGPUInt64			pos;

		pgpAssert(sizeof(bb12) == kDefaultBlockSize);
		pgpAssert(sizeof(bb16) == kDefaultBlockSize);
		pgpAssert(sizeof(bb32) == kDefaultBlockSize);

		pgpClearMemory(blockBuf, kDefaultBlockSize);

		pos = 0;

		switch (fat.fdFsId)
		{

		case kFS_FAT12:
			// Init the boot block.
			InitFAT12BootBlock(GetBlockSize(), &fat, &bb12);

			// Write the boot block.
			derr = Write((PGPUInt8 *) &bb12, pos, 1);

			// Write the first FAT.
			if (derr.IsntError())
			{
				pgpCopyMemory((PGPUInt8 *) &kFat12Sig, blockBuf, 
					sizeof(kFat12Sig));

				pos += fat.fdReservedSecs;
				derr = Write(blockBuf, pos, 1);
			}

			// Write the second FAT.
			if (derr.IsntError())
			{
				pos += fat.fdFatSize;
				derr = Write(blockBuf, pos, 1);
			}
			break;

		case kFS_FAT16:
			// Init the boot block.
			InitFAT16BootBlock(GetBlockSize(), &fat, &bb16);

			// Decide on a FAT signature.
			fat16Sig = (megsDisk < 16 ? kUnder16MbFat16Sig : 
				kOver16MbFat16Sig);

			// Write the boot block.
			derr = Write((PGPUInt8 *) &bb16, pos, 1);

			// Write the first FAT.
			if (derr.IsntError())
			{
				pgpCopyMemory((PGPUInt8 *) &fat16Sig, blockBuf, 
					sizeof(fat16Sig));

				pos += fat.fdReservedSecs;
				derr = Write(blockBuf, pos, 1);
			}

			// Write the second FAT.
			if (derr.IsntError())
			{
				pos += fat.fdFatSize;
				derr = Write(blockBuf, pos, 1);
			}
			break;

		case kFS_FAT32:
			// Init the boot block.
			InitFAT32BootBlock(GetBlockSize(), &fat, &bb32, &bfInfo);

			// Write the boot block.
			derr = Write((PGPUInt8 *) &bb32, pos, 1);

			// Write the BigFatBootInfo structure.
			if (derr.IsntError())
			{
				pgpCopyMemory((PGPUInt8 *) &bfInfo, blockBuf, 
					sizeof(bfInfo));

				pos += bb32.bsFsInfoSec;
				derr = Write(blockBuf, pos, 1);
			}

			if (derr.IsntError())
			{
				PGPUInt32 threeClusts[3];

				threeClusts[0] = kFat32Clust1;
				threeClusts[1] = kFat32Clust2;
				threeClusts[2] = kFat32Clust3;

				pgpClearMemory(blockBuf, kDefaultBlockSize);
				pgpCopyMemory((PGPUInt8 *) &threeClusts, blockBuf, 
					sizeof(threeClusts));

				// Write the first FAT.
				pos = fat.fdReservedSecs;
				derr = Write(blockBuf, pos, 1);

				// Write the second FAT.
				if (derr.IsntError())
				{
					pos += fat.fdFatSize;
					derr = Write(blockBuf, pos, 1);
				}
			}
			break;

		default:
			pgpAssert(FALSE);
			break;
		}
	}

	// Unlock the volume.
	if (lockedForFormat)
	{
		UnlockVolume();
	}

	// Free our block buffer.
	if (allocedBlockBuf)
	{
		FreeByteBuffer(blockBuf);
	}

	return derr;
}