2
我正在編寫一個程序,它將填充0字節的USB驅動器,以便將其轉換爲可啓動磁盤(該部分將在稍後提供)。用0字節填充USB
現在我已經是這樣的:
import io
import lib
class CancelBlockCipherException(Exception): pass
class Formatter(object):
def __init__(self, usb):
self.usb = usb
def _erase_all(self, block_cipher):
with io.FileIO(self.usb, "w") as _usb:
while _usb.write(block_cipher): pass
def format_usb(self, size, default="y"):
block_cipher = b"\0" * size
confirmation = lib.settings.prompt(
"Your USB is about to be completely erased, everything on this "
"drive will be gone, are you sure you want to continue", "y/N(default '{}')".format(default)
)
if confirmation.lower().startswith("y") or confirmation == "":
lib.settings.LOGGER.warning("Erasing USB content..")
self._erase_all(block_cipher)
elif confirmation.lower() == "" or confirmation is None:
lib.settings.LOGGER.warning("Erasing USB content..")
self._erase_all(block_cipher)
else:
raise CancelBlockCipherException("User aborted block cipher.")
這將完成的是採取以字節爲USB的大小,並寫\0
到/dev/sdb1
,直到它完全以0字節填充USB文件(至少這是我認爲正在發生的事情,之前我錯了)。我想要做的就是更快地寫入文件。目前這可能需要10-15分鐘才能完成,因爲編寫\0
1,875,615,744(1.75GB)時間可能會佔用大量時間。如何使用純python成功地更高效,更快速地格式化此USB?
不知道這是你在找什麼https://stackoverflow.com/questions/27568706/format-drive-in-python –
@JoshuaNixon我還沒有實現Windows,但我將它保存爲以後,謝謝 – mawi