| Line 1014... |
Line 1014... |
| 1014 |
malloc = False
|
1014 |
malloc = False
|
| 1015 |
try:
|
1015 |
try:
|
| 1016 |
self.logger.info("Reading volume %s sectors %X - %X to %s..." % (volume, sector, sector + count - 1, file))
|
1016 |
self.logger.info("Reading volume %s sectors %X - %X to %s..." % (volume, sector, sector + count - 1, file))
|
| 1017 |
while count > 0:
|
1017 |
while count > 0:
|
| 1018 |
sectors = min(count, int(buffsize / storageinfo.sectorsize))
|
1018 |
sectors = min(count, int(buffsize / storageinfo.sectorsize))
|
| 1019 |
self.emcore.storage_read_sectors_md(volume, sector, sectors, buffsize, buffer)
|
1019 |
self.emcore.storage_read_sectors_md(volume, sector, sectors, buffer)
|
| 1020 |
f.write(self.emcore.read(buffer, storageinfo.sectorsize * sectors))
|
1020 |
f.write(self.emcore.read(buffer, storageinfo.sectorsize * sectors))
|
| 1021 |
sector = sector + sectors
|
1021 |
sector = sector + sectors
|
| 1022 |
count = count - sectors
|
1022 |
count = count - sectors
|
| 1023 |
finally:
|
1023 |
finally:
|
| 1024 |
if malloc == True:
|
1024 |
if malloc == True:
|
| Line 1030... |
Line 1030... |
| 1030 |
@command
|
1030 |
@command
|
| 1031 |
def writerawstoragefile(self, volume, sector, count, file, buffsize = 0x100000, buffer = None):
|
1031 |
def writerawstoragefile(self, volume, sector, count, file, buffsize = 0x100000, buffer = None):
|
| 1032 |
"""
|
1032 |
"""
|
| 1033 |
Writes contents of <file> to <count> sectors starting at <sector> on storage <volume>,
|
1033 |
Writes contents of <file> to <count> sectors starting at <sector> on storage <volume>,
|
| 1034 |
buffering them in memory at [buffer] in chunks of [buffsize] bytes (both optional).
|
1034 |
buffering them in memory at [buffer] in chunks of [buffsize] bytes (both optional).
|
| - |
|
1035 |
If <count> is -1, the number of sectors will be determined from the file size.
|
| 1035 |
"""
|
1036 |
"""
|
| 1036 |
volume = to_int(volume)
|
1037 |
volume = to_int(volume)
|
| 1037 |
sector = to_int(sector)
|
1038 |
sector = to_int(sector)
|
| 1038 |
count = to_int(count)
|
1039 |
count = to_int(count)
|
| 1039 |
buffsize = to_int(buffsize)
|
1040 |
buffsize = to_int(buffsize)
|
| Line 1041... |
Line 1042... |
| 1041 |
f = open(file, 'rb')
|
1042 |
f = open(file, 'rb')
|
| 1042 |
except IOError:
|
1043 |
except IOError:
|
| 1043 |
raise ArgumentError("Could not open local file for reading.")
|
1044 |
raise ArgumentError("Could not open local file for reading.")
|
| 1044 |
try:
|
1045 |
try:
|
| 1045 |
storageinfo = self.emcore.storage_get_info(volume)
|
1046 |
storageinfo = self.emcore.storage_get_info(volume)
|
| - |
|
1047 |
if count == -1: count = int((os.path.getsize(file) + storageinfo.sectorsize - 1) / storageinfo.sectorsize)
|
| 1046 |
buffsize = min(buffsize, storageinfo.sectorsize * count)
|
1048 |
buffsize = min(buffsize, storageinfo.sectorsize * count)
|
| 1047 |
if buffer is None:
|
1049 |
if buffer is None:
|
| 1048 |
buffer = self.emcore.memalign(0x10, buffsize)
|
1050 |
buffer = self.emcore.memalign(0x10, buffsize)
|
| 1049 |
malloc = True
|
1051 |
malloc = True
|
| 1050 |
else:
|
1052 |
else:
|
| Line 1053... |
Line 1055... |
| 1053 |
try:
|
1055 |
try:
|
| 1054 |
self.logger.info("Writing %s to volume %s sectors %X - %X..." % (file, volume, sector, sector + count - 1))
|
1056 |
self.logger.info("Writing %s to volume %s sectors %X - %X..." % (file, volume, sector, sector + count - 1))
|
| 1055 |
while count > 0:
|
1057 |
while count > 0:
|
| 1056 |
sectors = min(count, int(buffsize / storageinfo.sectorsize))
|
1058 |
sectors = min(count, int(buffsize / storageinfo.sectorsize))
|
| 1057 |
bytes = storageinfo.sectorsize * sectors
|
1059 |
bytes = storageinfo.sectorsize * sectors
|
| 1058 |
data = f.read(bytes)
|
1060 |
data = b""
|
| 1059 |
if len(data) == 0: break
|
1061 |
while len(data) < bytes:
|
| 1060 |
while len(data) < bytes: data = data + f.read(bytes - len(data))
|
1062 |
new = f.read(bytes - len(data))
|
| - |
|
1063 |
data = data + new
|
| - |
|
1064 |
if len(new) == 0: break
|
| 1061 |
self.emcore.write(buffer, data)
|
1065 |
self.emcore.write(buffer, data)
|
| 1062 |
self.emcore.storage_write_sectors_md(volume, sector, sectors, buffsize, buffer)
|
1066 |
self.emcore.storage_write_sectors_md(volume, sector, sectors, buffer)
|
| 1063 |
sector = sector + sectors
|
1067 |
sector = sector + sectors
|
| 1064 |
count = count - sectors
|
1068 |
count = count - sectors
|
| 1065 |
finally:
|
1069 |
finally:
|
| 1066 |
if malloc == True:
|
1070 |
if malloc == True:
|
| 1067 |
self.emcore.free(buffer)
|
1071 |
self.emcore.free(buffer)
|