internal static VolumeInformation GetVolumeInformation(string rootPath) { rootPath = Paths.AddTrailingSeparator(rootPath); using (var volumeName = new StringBuffer(initialMinCapacity: Paths.MaxPath + 1)) using (var fileSystemName = new StringBuffer(initialMinCapacity: Paths.MaxPath + 1)) { uint serialNumber, maxComponentLength; FileSystemFeature flags; if (!Private.GetVolumeInformationW(rootPath, volumeName, (uint)volumeName.CharCapacity, out serialNumber, out maxComponentLength, out flags, fileSystemName, (uint)fileSystemName.CharCapacity)) { int lastError = Marshal.GetLastWin32Error(); throw GetIoExceptionForError(lastError, rootPath); } volumeName.SetLengthToFirstNull(); fileSystemName.SetLengthToFirstNull(); VolumeInformation info = new VolumeInformation { RootPathName = rootPath, VolumeName = volumeName.ToString(), VolumeSerialNumber = serialNumber, MaximumComponentLength = maxComponentLength, FileSystemFlags = flags, FileSystemName = fileSystemName.ToString() }; return(info); } }
public unsafe void SetLengthToFirstNullTests(string content, ulong startLength, ulong endLength) { using (var buffer = new StringBuffer(content)) { // With existing content buffer.Length.Should().Be(startLength); buffer.SetLengthToFirstNull(); buffer.Length.Should().Be(endLength); // Clear the buffer & manually copy in buffer.Length = 0; fixed (char* contentPointer = content) { Buffer.MemoryCopy(contentPointer, buffer.CharPointer, (long)buffer.CharCapacity * 2, content.Length * sizeof(char)); } buffer.Length.Should().Be(0); buffer.SetLengthToFirstNull(); buffer.Length.Should().Be(endLength); } }
public unsafe void SetLengthToFirstNullEmptyBuffer() { using (var buffer = new StringBuffer()) { buffer.SetLengthToFirstNull(); buffer.Length.Should().Be(0); } }
public unsafe void SetLengthToFirstNullNoNull() { using (var buffer = new StringBuffer("A")) { // Wipe out the last null buffer.CharPointer[buffer.Length] = 'B'; buffer.SetLengthToFirstNull(); buffer.Length.Should().Be(1); } }