本文整理汇总了C#中Section.Extend方法的典型用法代码示例。如果您正苦于以下问题:C# Section.Extend方法的具体用法?C# Section.Extend怎么用?C# Section.Extend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Section
的用法示例。
在下文中一共展示了Section.Extend方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MemoryFileSystem
public MemoryFileSystem(string fileName, MfsOpenMode mode, bool readOnly, MfsParameters createParams)
{
FileCreationDispositionWin32 cdWin32;
if (readOnly && mode != MfsOpenMode.Open)
throw new ArgumentException("Invalid mode for read only access.");
switch (mode)
{
case MfsOpenMode.Open:
cdWin32 = FileCreationDispositionWin32.OpenExisting;
break;
default:
case MfsOpenMode.OpenIf:
cdWin32 = FileCreationDispositionWin32.OpenAlways;
break;
case MfsOpenMode.OverwriteIf:
cdWin32 = FileCreationDispositionWin32.CreateAlways;
break;
}
using (FileHandle fhandle = FileHandle.CreateWin32(
fileName,
FileAccess.GenericRead | (!readOnly ? FileAccess.GenericWrite : 0),
FileShareMode.Read,
cdWin32
))
{
bool justCreated = false;
_readOnly = readOnly;
_protection = !readOnly ? MemoryProtection.ReadWrite : MemoryProtection.ReadOnly;
if (fhandle.FileSize == 0)
{
if (readOnly)
{
throw new MfsInvalidFileSystemException();
}
// File is too small. Make it 1 byte large and we'll deal with it soon.
fhandle.SetEnd(1);
}
_section = new Section(fhandle, _protection);
_blockSize = MfsBlockSizeBase; // fake block size to begin with; we'll fix it up later.
if (fhandle.FileSize < _blockSize)
{
if (readOnly)
{
throw new MfsInvalidFileSystemException();
}
// We're creating a new file system. We need the correct block size now.
if (createParams != null)
this._blockSize = createParams.BlockSize;
else
this._blockSize = MfsDefaultBlockSize;
this._section.Extend(this._blockSize);
using (SectionView view = this._section.MapView(0, this._blockSize, this._protection))
{
this.InitializeFs((MfsFsHeader*)view.Memory, createParams);
}
justCreated = true;
}
_header = (MfsFsHeader*)this.ReferenceBlock(0);
// Check the magic.
if (_header->Magic != MfsMagic)
throw new MfsInvalidFileSystemException();
// Set up the local constants.
_blockSize = _header->BlockSize;
_cellSize = _header->CellSize;
// Backwards compatibility.
if (_blockSize == 0)
_blockSize = MfsDefaultBlockSize;
if (_cellSize == 0)
_cellSize = MfsDefaultCellSize;
// Validate the parameters.
this.ValidateFsParameters(_blockSize, _cellSize);
_blockMask = _blockSize - 1;
_cellCount = _blockSize / _cellSize;
_dataCellDataMaxLength = _cellSize - MfsDataCell.DataOffset;
// Remap block 0 with the correct block size.
this.DereferenceBlock(0);
// If we just created a new file system, fix the section size.
if (justCreated)
_section.Extend(_blockSize);
//.........这里部分代码省略.........