Changeset 1550
- Timestamp:
- 1/18/2010 4:59:39 AM (3 years ago)
- Location:
- branches/eraser6/CodeReview/Eraser.Util
- Files:
-
- 2 edited
-
StreamInfo.cs (modified) (6 diffs)
-
VolumeInfo.cs (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/CodeReview/Eraser.Util/StreamInfo.cs
r1360 r1550 116 116 public FileAttributes Attributes 117 117 { 118 get { return (FileAttributes) KernelApi.NativeMethods.GetFileAttributes(FullName); }119 set { KernelApi.NativeMethods.SetFileAttributes(FullName, (uint)value); }118 get { return (FileAttributes)NativeMethods.GetFileAttributes(FullName); } 119 set { NativeMethods.SetFileAttributes(FullName, (uint)value); } 120 120 } 121 121 … … 127 127 get 128 128 { 129 using (SafeFileHandle handle = KernelApi.NativeMethods.CreateFile( 130 FullName, KernelApi.NativeMethods.GENERIC_READ, 131 KernelApi.NativeMethods.FILE_SHARE_READ, IntPtr.Zero, 132 KernelApi.NativeMethods.OPEN_EXISTING, 0, IntPtr.Zero)) 129 using (SafeFileHandle handle = NativeMethods.CreateFile( 130 FullName, NativeMethods.GENERIC_READ, NativeMethods.FILE_SHARE_READ, 131 IntPtr.Zero, NativeMethods.OPEN_EXISTING, 0, IntPtr.Zero)) 133 132 { 134 133 if (!handle.IsInvalid) … … 170 169 long fileSize; 171 170 using (SafeFileHandle handle = fileHandle) 172 if ( KernelApi.NativeMethods.GetFileSizeEx(handle, out fileSize))171 if (NativeMethods.GetFileSizeEx(handle, out fileSize)) 173 172 return fileSize; 174 173 … … 286 285 File.Delete(); 287 286 else 288 if (! KernelApi.NativeMethods.DeleteFile(FullName))287 if (!NativeMethods.DeleteFile(FullName)) 289 288 throw KernelApi.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); 290 289 } … … 368 367 { 369 368 case FileAccess.Read: 370 iAccess = KernelApi.NativeMethods.GENERIC_READ;369 iAccess = NativeMethods.GENERIC_READ; 371 370 break; 372 371 case FileAccess.ReadWrite: 373 iAccess = KernelApi.NativeMethods.GENERIC_READ | 374 KernelApi.NativeMethods.GENERIC_WRITE; 372 iAccess = NativeMethods.GENERIC_READ | NativeMethods.GENERIC_WRITE; 375 373 break; 376 374 case FileAccess.Write: 377 iAccess = KernelApi.NativeMethods.GENERIC_WRITE;375 iAccess = NativeMethods.GENERIC_WRITE; 378 376 break; 379 377 } … … 388 386 389 387 //Create the handle 390 SafeFileHandle result = KernelApi.NativeMethods.CreateFile(FullName, iAccess,388 SafeFileHandle result = NativeMethods.CreateFile(FullName, iAccess, 391 389 (uint)share, IntPtr.Zero, (uint)mode, (uint)options, IntPtr.Zero); 392 390 if (result.IsInvalid) -
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.
