|
@@ -4,6 +4,8 @@ import os
|
|
|
|
|
|
SINGLE_DISK_OFFSET = 1572864
|
|
|
MAX_IMAGES_ON_DRIVE = 1000
|
|
|
LABEL_START_OFFSET = 0x2B
|
|
|
LABEL_LENGTH = 11
|
|
|
|
|
|
|
|
|
def get_or_create_empty_image(index, temp_path, size=1440):
|
|
@@ -15,6 +17,8 @@ def get_or_create_empty_image(index, tem
|
|
|
proc = subprocess.Popen(['mkfs.msdos', '-C', filename, str(size)])
|
|
|
rval = proc.wait()
|
|
|
if rval != 0:
|
|
|
print(proc.stdout.read())
|
|
|
print(proc.stderr.read())
|
|
|
raise Exception('Not created')
|
|
|
|
|
|
return filename
|
|
@@ -98,10 +102,21 @@ def list_images(device):
|
|
|
# As an additional precaution check fs type.
|
|
|
# If it's valid, then get label, otherwise consider disk unlabeled
|
|
|
if bootsector[0x36:0x3E] in (b'FAT12 ', b'FAT16 ', b'FAT '):
|
|
|
label = bootsector[0x2B:0x36].decode(encoding='cp1251')
|
|
|
label = bootsector[LABEL_START_OFFSET:LABEL_START_OFFSET + LABEL_LENGTH].decode(
|
|
|
encoding='cp1251'
|
|
|
)
|
|
|
dfile.seek(SINGLE_DISK_OFFSET - 512, 1)
|
|
|
else:
|
|
|
disksize = 0
|
|
|
dfile.seek(SINGLE_DISK_OFFSET - 512, 1)
|
|
|
rval.append((label, disksize))
|
|
|
return rval
|
|
|
|
|
|
|
|
|
def update_label(device, index, label):
|
|
|
offset = SINGLE_DISK_OFFSET * index
|
|
|
label = label[0:11]
|
|
|
label = label + ' ' * (LABEL_LENGTH - len(label))
|
|
|
with open(device, 'wb') as dfile:
|
|
|
dfile.seek(offset + LABEL_START_OFFSET, 0)
|
|
|
dfile.write(label.encode(encoding='cp1251'))
|