internal static VolumeInformation GetVolumeInformation(string rootPath) { rootPath = Paths.AddTrailingSeparator(rootPath); StringBuilder volumeName = new StringBuilder(Paths.MaxPath + 1); StringBuilder fileSystemName = new StringBuilder(Paths.MaxPath + 1); uint serialNumber, maxComponentLength; FileSystemFeature flags; if (!GetVolumeInformationPrivate(rootPath, volumeName, volumeName.Capacity, out serialNumber, out maxComponentLength, out flags, fileSystemName, fileSystemName.Capacity)) { int lastError = Marshal.GetLastWin32Error(); throw GetIoExceptionForError(lastError, rootPath); } VolumeInformation info = new VolumeInformation { RootPathName = rootPath, VolumeName = volumeName.ToString(), VolumeSerialNumber = serialNumber, MaximumComponentLength = maxComponentLength, FileSystemFlags = flags, FileSystemName = fileSystemName.ToString() }; return info; }
internal static VolumeInformation GetVolumeInformation(string rootPath) { rootPath = Paths.AddTrailingSeparator(rootPath); using (var volumeName = new StringBuffer(initialCharCapacity: Paths.MaxPath + 1)) using (var fileSystemName = new StringBuffer(initialCharCapacity: Paths.MaxPath + 1)) { uint serialNumber, maxComponentLength; FileSystemFeature flags; if (!Private.GetVolumeInformationW(rootPath, volumeName, volumeName.CharCapacity, out serialNumber, out maxComponentLength, out flags, fileSystemName, 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; } }