Fix NTFS ID modification implementation

fixes
Vadim vtroshchinskiy 2024-10-25 22:55:07 +02:00
parent 5242f3519a
commit a6242b4b39
1 changed files with 16 additions and 6 deletions

View File

@ -211,18 +211,23 @@ class NTFSLibrary:
IOError: If there is an error opening or writing to the device file.
"""
ntfs_uuid_offset = 48
ntfs_uuid_offset = 0x48
ntfs_uuid_length = 8
binary_uuid = self._hex_to_bin(uuid)
binary_uuid = bytearray.fromhex(uuid)
binary_uuid.reverse()
self.logger.info(f"Changing UUID on {device} to {uuid}")
with open(device, 'r+b') as ntfs_dev:
ntfs_dev.seek(ntfs_uuid_offset)
#prev_uuid = ntfs_dev.read(ntfs_uuid_length)
#prev_uuid_hex = self._bin_to_hex(prev_uuid)
#self.logger.debug(f"Previous UUID: {prev_uuid_hex}")
self.logger.debug("Reading %i bytes from offset %i", ntfs_uuid_length, ntfs_uuid_offset)
ntfs_dev.seek(ntfs_uuid_offset)
prev_uuid = bytearray(ntfs_dev.read(ntfs_uuid_length))
prev_uuid.reverse()
prev_uuid_hex = bytearray.hex(prev_uuid)
self.logger.debug(f"Previous UUID: {prev_uuid_hex}")
self.logger.debug("Writing...")
ntfs_dev.seek(ntfs_uuid_offset)
ntfs_dev.write(binary_uuid)
@ -1743,6 +1748,8 @@ if __name__ == '__main__':
parser.add_argument("--test-restore-metadata-destructive", type=str, metavar="DIR", help="Test metadata restoration, destructive parts only")
parser.add_argument("--test-clone-metadata", type=str, metavar="REPO", help="Test metadata cloning")
parser.add_argument("-m", "--message", type=str, metavar="MSG", help="Commit message")
parser.add_argument("--test-set-ntfsid", type=str, metavar="ID", help="Set NTFS ID")
parser.add_argument("--device", type=str, metavar="DEV", help="Device to set the UUID on")
parser.add_argument("-v", "--verbose", action="store_true", help = "Verbose console output")
@ -1805,6 +1812,9 @@ if __name__ == '__main__':
og_git._restore_metadata(path = args.test_restore_metadata_destructive, destructive_only=True) # pylint: disable=protected-access
elif args.test_clone_metadata:
og_git._get_repo_metadata(args.test_clone_metadata) # pylint: disable=protected-access
elif args.test_set_ntfsid:
ntfs = NTFSLibrary(ntfs_impl)
ntfs.modify_uuid(args.device, args.test_set_ntfsid)
else:
print("Debe especificar una acción")
#