|
@@ -241,17 +241,15 @@ namespace DiskAccessLibrary
|
|
|
|
|
|
public static VirtualHardDisk Create(string path, long length)
|
|
|
{
|
|
|
+#if Win32
|
|
|
+
|
|
|
+
|
|
|
+ bool hasManageVolumePrivilege = SecurityUtils.ObtainManageVolumePrivilege();
|
|
|
+#endif
|
|
|
FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None);
|
|
|
try
|
|
|
{
|
|
|
stream.SetLength(length + 512);
|
|
|
-#if Win32
|
|
|
- bool hasManageVolumePrivilege = SecurityUtils.ObtainManageVolumePrivilege();
|
|
|
- if (hasManageVolumePrivilege)
|
|
|
- {
|
|
|
- FileStreamUtils.SetValidLength(stream, length + 512);
|
|
|
- }
|
|
|
-#endif
|
|
|
}
|
|
|
catch (IOException)
|
|
|
{
|
|
@@ -267,6 +265,19 @@ namespace DiskAccessLibrary
|
|
|
throw;
|
|
|
}
|
|
|
|
|
|
+#if Win32
|
|
|
+ if (hasManageVolumePrivilege)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ FileStreamUtils.SetValidLength(stream, length + 512);
|
|
|
+ }
|
|
|
+ catch (IOException)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
VHDFooter footer = new VHDFooter();
|
|
|
footer.OriginalSize = (ulong)length;
|
|
|
footer.CurrentSize = (ulong)length;
|