public FileRegion ShrinkAndAlign(uint alignment) { long alignedStartOffset = Alignment.AlignUpPow2(Offset, alignment); long alignedEndOffset = Alignment.AlignDownPow2(GetEndOffset(), alignment); long alignedSize = alignedEndOffset - alignedStartOffset; return(new FileRegion(alignedStartOffset, alignedSize)); }
public static nuint QueryWorkBufferSize(int orderMax) { Assert.SdkRequiresInRange(orderMax, 1, OrderUpperLimit); var pageListSize = (nint)Unsafe.SizeOf <PageList>(); uint pageListAlignment = (uint)Unsafe.SizeOf <nint>(); const uint ulongAlignment = 8; return((nuint)Alignment.AlignUpPow2(pageListSize * (orderMax + 1) + pageListAlignment, ulongAlignment)); }
// ReSharper disable once UnusedMember.Local // We can't use an external buffer in C# without ensuring all allocated buffers are pinned. // This function is left here anyway for completion's sake. public static int QueryWorkBufferSize(int maxCacheCount) { Assert.SdkRequiresGreater(maxCacheCount, 0); int entryAlignment = sizeof(CacheHandle); int attrInfoAlignment = Unsafe.SizeOf <nuint>(); int entrySize = Unsafe.SizeOf <Entry>() * maxCacheCount; int attrListSize = Unsafe.SizeOf <AttrInfo>() * 0x100; return((int)Alignment.AlignUpPow2( (ulong)(entrySize + attrListSize + entryAlignment + attrInfoAlignment), 8)); }
private int CalcStringTableSize(int startOffset, PartitionFileSystemType type) { int size = 0; foreach (Entry entry in Entries) { size += entry.NameLength + 1; } int endOffset = Alignment.AlignUpPow2(startOffset + size, GetMetaDataAlignment(type)); return(endOffset - startOffset); }
public Result Initialize(UIntPtr address, nuint size, nuint blockSize, int orderMax, void *workBuffer, nuint workBufferSize) { Assert.True(workBufferSize >= QueryWorkBufferSize(orderMax)); uint pageListAlignment = (uint)Unsafe.SizeOf <nint>(); var alignedWork = (void *)Alignment.AlignUpPow2((ulong)workBuffer, pageListAlignment); ExternalFreeLists = (PageList *)alignedWork; // Note: The original code does not have a buffer size assert after adjusting for alignment. Assert.True(workBufferSize - ((nuint)alignedWork - (nuint)workBuffer) >= QueryWorkBufferSize(orderMax)); return(Initialize(address, size, blockSize, orderMax)); }
public static int QueryOrderMax(nuint size, nuint blockSize) { Assert.SdkRequiresGreaterEqual(size, blockSize); Assert.SdkRequiresGreaterEqual(blockSize, BlockSizeMin); Assert.SdkRequires(BitUtil.IsPowerOfTwo(blockSize)); int blockCount = (int)(Alignment.AlignUpPow2(size, (uint)blockSize) / blockSize); for (int order = 1; ; order++) { if (blockCount <= GetBlockCountFromOrder(order)) { return(order); } } }
public static int QueryOrderMax(nuint size, nuint blockSize) { Assert.True(size >= blockSize); Assert.True(blockSize >= BlockSizeMin); Assert.True(BitUtil.IsPowerOfTwo(blockSize)); int blockCount = (int)(Alignment.AlignUpPow2(size, (uint)blockSize) / blockSize); for (int order = 1; ; order++) { if (blockCount <= GetBlockCountFromOrder(order)) { return(order); } } }