Changeset 1550 for branches/eraser6/CodeReview/Eraser.Util/VolumeInfo.cs
 Timestamp:
 1/18/2010 4:59:39 AM (5 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/eraser6/CodeReview/Eraser.Util/VolumeInfo.cs
r1530 r1550 48 48 uint returnLength = 0; 49 49 StringBuilder pathNamesBuffer = new StringBuilder(); 50 pathNamesBuffer.EnsureCapacity( KernelApi.NativeMethods.MaxPath);51 while (! KernelApi.NativeMethods.GetVolumePathNamesForVolumeName(VolumeId,50 pathNamesBuffer.EnsureCapacity(NativeMethods.MaxPath); 51 while (!NativeMethods.GetVolumePathNamesForVolumeName(VolumeId, 52 52 pathNamesBuffer, (uint)pathNamesBuffer.Capacity, out returnLength)) 53 53 { … … 85 85 86 86 //Fill up the remaining members of the structure: file system, label, etc. 87 StringBuilder volumeName = new StringBuilder( KernelApi.NativeMethods.MaxPath * sizeof(char)),88 fileSystemName = new StringBuilder( KernelApi.NativeMethods.MaxPath * sizeof(char));87 StringBuilder volumeName = new StringBuilder(NativeMethods.MaxPath * sizeof(char)), 88 fileSystemName = new StringBuilder(NativeMethods.MaxPath * sizeof(char)); 89 89 uint serialNumber, maxComponentLength, filesystemFlags; 90 if (! KernelApi.NativeMethods.GetVolumeInformation(volumeId, volumeName,91 KernelApi.NativeMethods.MaxPath, out serialNumber, out maxComponentLength,92 out filesystemFlags, fileSystemName, KernelApi.NativeMethods.MaxPath))90 if (!NativeMethods.GetVolumeInformation(volumeId, volumeName, NativeMethods.MaxPath, 91 out serialNumber, out maxComponentLength, out filesystemFlags, fileSystemName, 92 NativeMethods.MaxPath)) 93 93 { 94 94 int lastError = Marshal.GetLastWin32Error(); … … 115 115 { 116 116 uint clusterSize, sectorSize, freeClusters, totalClusters; 117 if ( KernelApi.NativeMethods.GetDiskFreeSpace(VolumeId, out clusterSize,117 if (NativeMethods.GetDiskFreeSpace(VolumeId, out clusterSize, 118 118 out sectorSize, out freeClusters, out totalClusters)) 119 119 { … … 137 137 { 138 138 List<VolumeInfo> result = new List<VolumeInfo>(); 139 StringBuilder nextVolume = new StringBuilder( 140 KernelApi.NativeMethods.LongPath * sizeof(char)); 141 SafeHandle handle = KernelApi.NativeMethods.FindFirstVolume(nextVolume, 142 KernelApi.NativeMethods.LongPath); 139 StringBuilder nextVolume = new StringBuilder(NativeMethods.LongPath * sizeof(char)); 140 SafeHandle handle = NativeMethods.FindFirstVolume(nextVolume, NativeMethods.LongPath); 143 141 if (handle.IsInvalid) 144 142 return result; … … 147 145 do 148 146 result.Add(new VolumeInfo(nextVolume.ToString())); 149 while (KernelApi.NativeMethods.FindNextVolume(handle, nextVolume, 150 KernelApi.NativeMethods.LongPath)); 147 while (NativeMethods.FindNextVolume(handle, nextVolume, NativeMethods.LongPath)); 151 148 152 149 //Close the handle 153 150 if (Marshal.GetLastWin32Error() == 18 /*ERROR_NO_MORE_FILES*/) 154 KernelApi.NativeMethods.FindVolumeClose(handle);151 NativeMethods.FindVolumeClose(handle); 155 152 156 153 return result.AsReadOnly(); … … 174 171 if (currentDir.Length > 0 && currentDir[currentDir.Length  1] != '\\') 175 172 currentDir += '\\'; 176 if (KernelApi.NativeMethods.GetVolumeNameForVolumeMountPoint(currentDir, 177 volumeID, 50)) 173 if (NativeMethods.GetVolumeNameForVolumeMountPoint(currentDir, volumeID, 50)) 178 174 { 179 175 return new VolumeInfo(volumeID.ToString()); … … 223 219 get 224 220 { 225 return (DriveType) KernelApi.NativeMethods.GetDriveType(VolumeId);221 return (DriveType)NativeMethods.GetDriveType(VolumeId); 226 222 } 227 223 } … … 235 231 { 236 232 uint clusterSize, sectorSize, freeClusters, totalClusters; 237 if ( KernelApi.NativeMethods.GetDiskFreeSpace(VolumeId, out clusterSize,233 if (NativeMethods.GetDiskFreeSpace(VolumeId, out clusterSize, 238 234 out sectorSize, out freeClusters, out totalClusters)) 239 235 { … … 253 249 { 254 250 uint clusterSize, sectorSize, freeClusters, totalClusters; 255 if ( KernelApi.NativeMethods.GetDiskFreeSpace(VolumeId, out clusterSize,251 if (NativeMethods.GetDiskFreeSpace(VolumeId, out clusterSize, 256 252 out sectorSize, out freeClusters, out totalClusters)) 257 253 { … … 271 267 { 272 268 ulong freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes; 273 if ( KernelApi.NativeMethods.GetDiskFreeSpaceEx(VolumeId, out freeBytesAvailable,269 if (NativeMethods.GetDiskFreeSpaceEx(VolumeId, out freeBytesAvailable, 274 270 out totalNumberOfBytes, out totalNumberOfFreeBytes)) 275 271 { … … 299 295 { 300 296 ulong result, dummy; 301 if (KernelApi.NativeMethods.GetDiskFreeSpaceEx(VolumeId, out dummy, 302 out dummy, out result)) 297 if (NativeMethods.GetDiskFreeSpaceEx(VolumeId, out dummy, out dummy, out result)) 303 298 { 304 299 return (long)result; … … 317 312 { 318 313 ulong result, dummy; 319 if (KernelApi.NativeMethods.GetDiskFreeSpaceEx(VolumeId, out dummy, 320 out result, out dummy)) 314 if (NativeMethods.GetDiskFreeSpaceEx(VolumeId, out dummy, out result, out dummy)) 321 315 { 322 316 return (long)result; … … 335 329 { 336 330 ulong result, dummy; 337 if (KernelApi.NativeMethods.GetDiskFreeSpaceEx(VolumeId, out result, 338 out dummy, out dummy)) 331 if (NativeMethods.GetDiskFreeSpaceEx(VolumeId, out result, out dummy, out dummy)) 339 332 { 340 333 return (long)result; … … 354 347 { 355 348 List<VolumeInfo> result = new List<VolumeInfo>(); 356 StringBuilder nextMountpoint = new StringBuilder( 357 KernelApi.NativeMethods.LongPath * sizeof(char)); 358 359 SafeHandle handle = KernelApi.NativeMethods.FindFirstVolumeMountPoint(VolumeId, 360 nextMountpoint, KernelApi.NativeMethods.LongPath); 349 StringBuilder nextMountpoint = new StringBuilder(NativeMethods.LongPath * sizeof(char)); 350 351 SafeHandle handle = NativeMethods.FindFirstVolumeMountPoint(VolumeId, 352 nextMountpoint, NativeMethods.LongPath); 361 353 if (handle.IsInvalid) 362 354 return result; 363 355 364 356 //Iterate over the volume mountpoints 365 while ( KernelApi.NativeMethods.FindNextVolumeMountPoint(handle,366 nextMountpoint, KernelApi.NativeMethods.LongPath))357 while (NativeMethods.FindNextVolumeMountPoint(handle, nextMountpoint, 358 NativeMethods.LongPath)) 367 359 { 368 360 result.Add(new VolumeInfo(nextMountpoint.ToString())); … … 371 363 //Close the handle 372 364 if (Marshal.GetLastWin32Error() == 18 /*ERROR_NO_MORE_FILES*/) 373 KernelApi.NativeMethods.FindVolumeMountPointClose(handle);365 NativeMethods.FindVolumeMountPointClose(handle); 374 366 375 367 return result.AsReadOnly(); … … 458 450 { 459 451 case FileAccess.Read: 460 iAccess = KernelApi.NativeMethods.GENERIC_READ;452 iAccess = NativeMethods.GENERIC_READ; 461 453 break; 462 454 case FileAccess.ReadWrite: 463 iAccess = KernelApi.NativeMethods.GENERIC_READ  464 KernelApi.NativeMethods.GENERIC_WRITE; 455 iAccess = NativeMethods.GENERIC_READ  NativeMethods.GENERIC_WRITE; 465 456 break; 466 457 case FileAccess.Write: 467 iAccess = KernelApi.NativeMethods.GENERIC_WRITE;458 iAccess = NativeMethods.GENERIC_WRITE; 468 459 break; 469 460 } … … 481 472 if (openPath.Length > 0 && openPath[openPath.Length  1] == '\\') 482 473 openPath = openPath.Remove(openPath.Length  1); 483 SafeFileHandle result = KernelApi.NativeMethods.CreateFile(openPath, iAccess,474 SafeFileHandle result = NativeMethods.CreateFile(openPath, iAccess, 484 475 (uint)share, IntPtr.Zero, (uint)FileMode.Open, (uint)options, IntPtr.Zero); 485 476 if (result.IsInvalid) … … 502 493 { 503 494 uint result = 0; 504 for (int i = 0; ! KernelApi.NativeMethods.DeviceIoControl(stream.SafeFileHandle,505 KernelApi.NativeMethods.FSCTL_LOCK_VOLUME, IntPtr.Zero, 0, IntPtr.Zero,495 for (int i = 0; !NativeMethods.DeviceIoControl(stream.SafeFileHandle, 496 NativeMethods.FSCTL_LOCK_VOLUME, IntPtr.Zero, 0, IntPtr.Zero, 506 497 0, out result, IntPtr.Zero); ++i) 507 498 { … … 534 525 535 526 uint result = 0; 536 if (! KernelApi.NativeMethods.DeviceIoControl(Stream.SafeFileHandle,537 KernelApi.NativeMethods.FSCTL_UNLOCK_VOLUME, IntPtr.Zero, 0, IntPtr.Zero,527 if (!NativeMethods.DeviceIoControl(Stream.SafeFileHandle, 528 NativeMethods.FSCTL_UNLOCK_VOLUME, IntPtr.Zero, 0, IntPtr.Zero, 538 529 0, out result, IntPtr.Zero)) 539 530 {
Note: See TracChangeset
for help on using the changeset viewer.