2
USBドライブを0バイトで満たしてブート可能なディスクにするプログラムを書いています。今、私が持っているものUSBを0バイトで埋める
はこれです:
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バイト(とUSBファイルをいっぱいまで、/dev/sdb1
に\0
を書きです少なくともこれは私が起こっていると思うことです、私は前に間違っていました)。私がしたいのは、このファイルへの書き込みをより高速にすることです。現在、\0
1,875,615,744(1.75GB)時間の書き込みには多分時間がかかるため、これを完了するまでには10〜15分かかります。純粋なPythonを使用して、このUSBをより効率的かつ迅速にフォーマットするにはどうしたらいいですか?
あなたが探しているものがわからない場合https://stackoverflow.com/questions/27568706/format-drive-in-python –
@JoshuaNixon私はまだWindowsを実装していませんが、私はそれを保存します後で、ありがとう – mawi