Skip to content

Commit 24954c7

Browse files
Add additional data-loss prevention logic
1 parent 0c1da1b commit 24954c7

File tree

5 files changed

+49
-8
lines changed

5 files changed

+49
-8
lines changed

WinDiskWriter GUI/Windows/MainWindow/MainWindow.m

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,14 @@ - (void)writeAction {
527527
[self setIsScheduledForStop: NO];
528528
[self setEnabledUIState: NO];
529529

530-
DiskInfo *destinationDiskInfo = [(IdentifiableMenuItem *)devicePickerView.selectedItem diskInfo];
531-
DiskManager *destinationDiskDM = [[DiskManager alloc] initWithBSDName:destinationDiskInfo.BSDName];
530+
// Saved information from the last device scanning operation
531+
DiskInfo *destinationSavedDiskInfo = [(IdentifiableMenuItem *)devicePickerView.selectedItem diskInfo];
532532

533-
if (destinationDiskDM == NULL || !destinationDiskInfo.isDeviceUnit) {
533+
// Making sure that the selected BSD Device name is still available
534+
DiskManager *secondVerifyingStageDiskManager = [[DiskManager alloc] initWithBSDName:destinationSavedDiskInfo.BSDName];
535+
DiskInfo *secondVerifyingStageDiskInfo = [secondVerifyingStageDiskManager diskInfo];
536+
537+
if (secondVerifyingStageDiskManager == NULL || !destinationSavedDiskInfo.isDeviceUnit) {
534538
[self displayWarningAlertWithTitle: BSD_DEVICE_IS_NO_LONGER_AVAILABLE_TITLE
535539
subtitle: PRESS_UPDATE_BUTTON_SUBTITLE
536540
icon: NSImageNameCaution];
@@ -540,6 +544,23 @@ - (void)writeAction {
540544
WriteExitForce();
541545
}
542546

547+
/* !!DATA-LOSS PREVENTION!!
548+
- We need to make sure that we will format exactly the device that was selected in the list
549+
of available devices, and not the one that managed to occupy the vacated BSD Name.
550+
- The most adequate way in this case is to verify the initialization date of the bsd device. */
551+
552+
if (destinationSavedDiskInfo.appearanceTime.doubleValue != secondVerifyingStageDiskInfo.appearanceTime.doubleValue) {
553+
[self displayWarningAlertWithTitle: BSD_DEVICE_INFO_IS_OUTDATED_OR_INVALID
554+
subtitle: PRESS_UPDATE_BUTTON_SUBTITLE
555+
icon: NSImageNameCaution];
556+
557+
[logsAutoScrollTextView appendTimestampedLine: BSD_DEVICE_INFO_IS_OUTDATED_OR_INVALID
558+
logType: ASLogTypeFatal];
559+
560+
WriteExitForce();
561+
}
562+
563+
543564
NSError *imageMountError = NULL;
544565
NSString *mountedImagePath = [HelperFunctions getWindowsSourceMountPath: windowsImageInputView.stringValue
545566
error: &imageMountError];
@@ -583,9 +604,9 @@ - (void)writeAction {
583604
logType: ASLogTypeLog];
584605

585606
NSString *diskEraseOperationText = [NSString stringWithFormat:@"Device %@ (%@ %@) is ready to be erased with the following properties: (partition_name: \"%@\", partition_scheme: \"%@\", filesystem: \"%@\", patch_security_checks: \"%d\").",
586-
destinationDiskInfo.BSDName,
587-
destinationDiskInfo.deviceVendor,
588-
destinationDiskInfo.deviceModel,
607+
destinationSavedDiskInfo.BSDName,
608+
destinationSavedDiskInfo.deviceVendor,
609+
destinationSavedDiskInfo.deviceModel,
589610
newPartitionName,
590611
selectedPartitionScheme,
591612
selectedFileSystem,
@@ -600,7 +621,7 @@ - (void)writeAction {
600621
[self setCurrentProgressTitle: @"Formatting the drive"];
601622

602623
NSError *diskEraseError = NULL;
603-
[destinationDiskDM diskUtilEraseDiskWithPartitionScheme: selectedPartitionScheme
624+
[secondVerifyingStageDiskManager diskUtilEraseDiskWithPartitionScheme: selectedPartitionScheme
604625
filesystem: selectedFileSystem
605626
newName: newPartitionName
606627
error: &diskEraseError];

windiskwriter.xcodeproj/xcuserdata/macintosh.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
99
<BreakpointContent
1010
uuid = "4DBFFC7E-88C3-4A3B-A0DF-311137DBE2FB"
11-
shouldBeEnabled = "Yes"
11+
shouldBeEnabled = "No"
1212
ignoreCount = "0"
1313
continueAfterRunningActions = "No"
1414
filePath = "windiskwriter/DiskManager/DiskManager.m"
@@ -20,5 +20,21 @@
2020
landmarkType = "7">
2121
</BreakpointContent>
2222
</BreakpointProxy>
23+
<BreakpointProxy
24+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
25+
<BreakpointContent
26+
uuid = "82B006E0-C658-4F1B-BEA4-5E77555847F0"
27+
shouldBeEnabled = "Yes"
28+
ignoreCount = "0"
29+
continueAfterRunningActions = "No"
30+
filePath = "WinDiskWriter GUI/Windows/MainWindow/MainWindow.m"
31+
startingColumnNumber = "9223372036854775807"
32+
endingColumnNumber = "9223372036854775807"
33+
startingLineNumber = "553"
34+
endingLineNumber = "553"
35+
landmarkName = "-writeAction"
36+
landmarkType = "7">
37+
</BreakpointContent>
38+
</BreakpointProxy>
2339
</Breakpoints>
2440
</Bucket>

windiskwriter/Constants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ extern NSString * const CHECK_DATA_CORRECTNESS_TITLE;
2929
extern NSString * const NO_AVAILABLE_DEVICES_TITLE;
3030
extern NSString * const PRESS_UPDATE_BUTTON_SUBTITLE;
3131
extern NSString * const BSD_DEVICE_IS_NO_LONGER_AVAILABLE_TITLE;
32+
extern NSString * const BSD_DEVICE_INFO_IS_OUTDATED_OR_INVALID;
33+
3234
extern NSString * const IMAGE_VERIFICATION_ERROR_TITLE;
3335
extern NSString * const DISK_ERASE_FAILURE_TITLE;
3436
extern NSString * const DISK_ERASE_SUCCESS_TITLE;

windiskwriter/Constants.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ @implementation Constants
2828
NSString * const NO_AVAILABLE_DEVICES_TITLE = @"No writable devices found.";
2929
NSString * const PRESS_UPDATE_BUTTON_SUBTITLE = @"Connect a compatible USB device and click on the Update button.";
3030
NSString * const BSD_DEVICE_IS_NO_LONGER_AVAILABLE_TITLE = @"Chosen Device is no longer available.";
31+
NSString * const BSD_DEVICE_INFO_IS_OUTDATED_OR_INVALID = @"The information about this device is outdated or invalid.";
32+
3133
NSString * const IMAGE_VERIFICATION_ERROR_TITLE = @"Can't verify this Image.";
3234
NSString * const DISK_ERASE_FAILURE_TITLE = @"Can't erase the destionation device.";
3335
NSString * const DISK_ERASE_SUCCESS_TITLE = @"The destination device was successfully erased.";

0 commit comments

Comments
 (0)