| Line 608... |
Line 608... |
| 608 |
self.ipodclassic_hddaccess(1, sector, count, tempaddr + offset)
|
608 |
self.ipodclassic_hddaccess(1, sector, count, tempaddr + offset)
|
| 609 |
|
609 |
|
| 610 |
@command()
|
610 |
@command()
|
| 611 |
def storage_get_info(self, volume):
|
611 |
def storage_get_info(self, volume):
|
| 612 |
""" Get information about a storage device """
|
612 |
""" Get information about a storage device """
|
| - |
|
613 |
self.logger.debug("Getting storage information\n")
|
| 613 |
result = self.lib.monitorcommand(struct.pack("IIII", 27, volume, 0, 0), "IIIIIIII", ("version", None, None, "sectorsize", "numsectors", "vendorptr", "productptr", "revisionptr"))
|
614 |
result = self.lib.monitorcommand(struct.pack("IIII", 27, volume, 0, 0), "IIIIIIII", ("version", None, None, "sectorsize", "numsectors", "vendorptr", "productptr", "revisionptr"))
|
| 614 |
if result.version != 1:
|
615 |
if result.version != 1:
|
| 615 |
raise ValueError("Unknown version of storage_info struct: %d" % result.version)
|
616 |
raise ValueError("Unknown version of storage_info struct: %d" % result.version)
|
| 616 |
result.vendor = self.readstring(result.vendorptr)
|
617 |
result.vendor = self.readstring(result.vendorptr)
|
| 617 |
result.product = self.readstring(result.productptr)
|
618 |
result.product = self.readstring(result.productptr)
|
| 618 |
result.revision = self.readstring(result.revisionptr)
|
619 |
result.revision = self.readstring(result.revisionptr)
|
| - |
|
620 |
self.logger.debug("Got storage information:\n")
|
| - |
|
621 |
self.logger.debug("Vendor: %s\n" % result.vendor)
|
| - |
|
622 |
self.logger.debug("Product: %s\n" % result.product)
|
| - |
|
623 |
self.logger.debug("Revision: %s\n" % result.revision)
|
| - |
|
624 |
self.logger.debug("Sector size: %d\n" % result.sectorsize)
|
| - |
|
625 |
self.logger.debug("Number of sectors: %d\n" % result.numsectors)
|
| 619 |
return result
|
626 |
return result
|
| 620 |
|
627 |
|
| 621 |
@command(timeout = 50000)
|
628 |
@command(timeout = 50000)
|
| 622 |
def storage_read_sectors_md(self, volume, sector, count, addr):
|
629 |
def storage_read_sectors_md(self, volume, sector, count, addr):
|
| 623 |
""" Read sectors from as storage device """
|
630 |
""" Read sectors from as storage device """
|
| - |
|
631 |
self.logger.debug("Reading %d sectors from disk at volume %d, sector %d to memory at 0x%x\n" % (count, volume, sector, addr)
|
| 624 |
result = self.lib.monitorcommand(struct.pack("IIQIIII", 28, volume, sector, count, addr, 0, 0), "III", ("rc", None, None))
|
632 |
result = self.lib.monitorcommand(struct.pack("IIQIIII", 28, volume, sector, count, addr, 0, 0), "III", ("rc", None, None))
|
| - |
|
633 |
self.logger.debug("Read sectors, result: 0x%x\n" % result.rc)
|
| 625 |
if result.rc > 0x80000000:
|
634 |
if result.rc > 0x80000000:
|
| 626 |
raise DeviceError("storage_read_sectors_md(volume=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (volume, sector, count, addr, rc))
|
635 |
raise DeviceError("storage_read_sectors_md(volume=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (volume, sector, count, addr, rc))
|
| 627 |
|
636 |
|
| 628 |
@command(timeout = 50000)
|
637 |
@command(timeout = 50000)
|
| 629 |
def storage_write_sectors_md(self, volume, sector, count, addr):
|
638 |
def storage_write_sectors_md(self, volume, sector, count, addr):
|
| 630 |
""" Read sectors from as storage device """
|
639 |
""" Read sectors from as storage device """
|
| - |
|
640 |
self.logger.debug("Writing %d sectors from memory at 0x%x to disk at volume %d, sector %d\n" % (count, addr, volume, sector)
|
| 631 |
result = self.lib.monitorcommand(struct.pack("IIQIIII", 29, volume, sector, count, addr, 0, 0), "III", ("rc", None, None))
|
641 |
result = self.lib.monitorcommand(struct.pack("IIQIIII", 29, volume, sector, count, addr, 0, 0), "III", ("rc", None, None))
|
| - |
|
642 |
self.logger.debug("Wrote sectors, result: 0x%x\n" % result.rc)
|
| 632 |
if result.rc > 0x80000000:
|
643 |
if result.rc > 0x80000000:
|
| 633 |
raise DeviceError("storage_write_sectors_md(volume=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (volume, sector, count, addr, rc))
|
644 |
raise DeviceError("storage_write_sectors_md(volume=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (volume, sector, count, addr, rc))
|
| 634 |
|
645 |
|
| 635 |
@command(timeout = 30000)
|
646 |
@command(timeout = 30000)
|
| 636 |
def fat_enable_flushing(self, state):
|
647 |
def fat_enable_flushing(self, state):
|
| 637 |
""" Enables/disables flushing the FAT cache after every transaction """
|
648 |
""" Enables/disables flushing the FAT cache after every transaction """
|
| - |
|
649 |
if state != 0: self.logger.debug("Enabling FAT flushing\n")
|
| - |
|
650 |
else: self.logger.debug("Disabling FAT flushing\n")
|
| 638 |
self.lib.monitorcommand(struct.pack("IIII", 58, state, 0, 0), "III", (None, None, None))
|
651 |
self.lib.monitorcommand(struct.pack("IIII", 58, state, 0, 0), "III", (None, None, None))
|
| - |
|
652 |
if state != 0: self.logger.debug("Enabled FAT flushing\n")
|
| - |
|
653 |
else: self.logger.debug("Disabled FAT flushing\n")
|
| 639 |
|
654 |
|
| 640 |
@command(timeout = 30000)
|
655 |
@command(timeout = 30000)
|
| 641 |
def file_open(self, filename, mode):
|
656 |
def file_open(self, filename, mode):
|
| 642 |
""" Opens a file and returns the handle """
|
657 |
""" Opens a file and returns the handle """
|
| - |
|
658 |
self.logger.debug("Opening remote file %s with mode %s\n" % (filename, mode))
|
| 643 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 30, mode, 0, 0, filename, 0), "III", ("fd", None, None))
|
659 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 30, mode, 0, 0, filename, 0), "III", ("fd", None, None))
|
| 644 |
if result.fd > 0x80000000:
|
660 |
if result.fd > 0x80000000:
|
| 645 |
raise DeviceError("file_open(filename=\"%s\", mode=0x%X) failed with RC=0x%08X, errno=%d" % (filename, mode, result.fd, self.errno()))
|
661 |
raise DeviceError("file_open(filename=\"%s\", mode=0x%X) failed with RC=0x%08X, errno=%d" % (filename, mode, result.fd, self.errno()))
|
| - |
|
662 |
self.logger.debug("Opened file as handle 0x%x\n" % result.fd)
|
| 646 |
return result.fd
|
663 |
return result.fd
|
| 647 |
|
664 |
|
| 648 |
@command(timeout = 30000)
|
665 |
@command(timeout = 30000)
|
| 649 |
def file_size(self, fd):
|
666 |
def file_size(self, fd):
|
| 650 |
""" Gets the size of a file referenced by a handle """
|
667 |
""" Gets the size of a file referenced by a handle """
|
| - |
|
668 |
self.logger.debug("Getting file size of handle 0x%x\n" % fd)
|
| 651 |
result = self.lib.monitorcommand(struct.pack("IIII", 31, fd, 0, 0), "III", ("size", None, None))
|
669 |
result = self.lib.monitorcommand(struct.pack("IIII", 31, fd, 0, 0), "III", ("size", None, None))
|
| 652 |
if result.size > 0x80000000:
|
670 |
if result.size > 0x80000000:
|
| 653 |
raise DeviceError("file_size(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.size, self.errno()))
|
671 |
raise DeviceError("file_size(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.size, self.errno()))
|
| - |
|
672 |
self.logger.debug("Got file size: %d bytes\n" % result.size)
|
| 654 |
return result.size
|
673 |
return result.size
|
| 655 |
|
674 |
|
| 656 |
@command(timeout = 30000)
|
675 |
@command(timeout = 30000)
|
| 657 |
def file_read(self, fd, size, addr = None):
|
676 |
def file_read(self, fd, size, addr = None):
|
| 658 |
""" Reads data from a file referenced by a handle. If addr is not given it allocates a buffer itself. """
|
677 |
""" Reads data from a file referenced by a handle. If addr is not given it allocates a buffer itself. """
|
| 659 |
if addr is None:
|
678 |
if addr is None:
|
| 660 |
addr = self.malloc(size)
|
679 |
addr = self.malloc(size)
|
| 661 |
malloc = True
|
680 |
malloc = True
|
| 662 |
else:
|
681 |
else:
|
| 663 |
malloc = False
|
682 |
malloc = False
|
| - |
|
683 |
self.logger.debug("Reading %d bytes from file handle 0x%x to 0x%x\n" % (size, fd, addr))
|
| 664 |
try:
|
684 |
try:
|
| 665 |
result = self.lib.monitorcommand(struct.pack("IIII", 32, fd, addr, size), "III", ("rc", None, None))
|
685 |
result = self.lib.monitorcommand(struct.pack("IIII", 32, fd, addr, size), "III", ("rc", None, None))
|
| 666 |
if result.rc > 0x80000000:
|
686 |
if result.rc > 0x80000000:
|
| 667 |
raise DeviceError("file_read(fd=%d, addr=0x%08X, size=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, addr, size, result.rc, self.errno()))
|
687 |
raise DeviceError("file_read(fd=%d, addr=0x%08X, size=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, addr, size, result.rc, self.errno()))
|
| 668 |
except:
|
688 |
except:
|
| 669 |
if malloc == True:
|
689 |
if malloc == True:
|
| 670 |
self.free(addr)
|
690 |
self.free(addr)
|
| 671 |
raise
|
691 |
raise
|
| - |
|
692 |
self.logger.debug("File read result: 0x%x\n" % result.rc)
|
| 672 |
return Bunch(rc = result.rc, addr = addr)
|
693 |
return Bunch(rc = result.rc, addr = addr)
|
| 673 |
|
694 |
|
| 674 |
@command(timeout = 30000)
|
695 |
@command(timeout = 30000)
|
| 675 |
def file_write(self, fd, size, addr):
|
696 |
def file_write(self, fd, size, addr):
|
| 676 |
""" Writes data from a file referenced by a handle. """
|
697 |
""" Writes data from a file referenced by a handle. """
|
| - |
|
698 |
self.logger.debug("Writing %d bytes from 0x%x to file handle 0x%x\n" % (size, addr, fd))
|
| 677 |
result = self.lib.monitorcommand(struct.pack("IIII", 33, fd, addr, size), "III", ("rc", None, None))
|
699 |
result = self.lib.monitorcommand(struct.pack("IIII", 33, fd, addr, size), "III", ("rc", None, None))
|
| 678 |
if result.rc > 0x80000000:
|
700 |
if result.rc > 0x80000000:
|
| 679 |
raise DeviceError("file_write(fd=%d, addr=0x%08X, size=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, addr, size, result.rc, self.errno()))
|
701 |
raise DeviceError("file_write(fd=%d, addr=0x%08X, size=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, addr, size, result.rc, self.errno()))
|
| - |
|
702 |
self.logger.debug("File write result: 0x%x\n" % result.rc)
|
| 680 |
return result.rc
|
703 |
return result.rc
|
| 681 |
|
704 |
|
| 682 |
@command(timeout = 30000)
|
705 |
@command(timeout = 30000)
|
| 683 |
def file_seek(self, fd, offset, whence):
|
706 |
def file_seek(self, fd, offset, whence):
|
| 684 |
""" Seeks the file handle to the specified position in the file """
|
707 |
""" Seeks the file handle to the specified position in the file """
|
| - |
|
708 |
self.logger.debug("Seeking file handle 0x%x to whence=%d, offset=0x%x\n" % (fd, whence, offset))
|
| 685 |
result = self.lib.monitorcommand(struct.pack("IIII", 34, fd, offset, whence), "III", ("rc", None, None))
|
709 |
result = self.lib.monitorcommand(struct.pack("IIII", 34, fd, offset, whence), "III", ("rc", None, None))
|
| 686 |
if result.rc > 0x80000000:
|
710 |
if result.rc > 0x80000000:
|
| 687 |
raise DeviceError("file_seek(fd=%d, offset=0x%08X, whence=%d) failed with RC=0x%08X, errno=%d" % (fd, offset, whence, result.rc, self.errno()))
|
711 |
raise DeviceError("file_seek(fd=%d, offset=0x%08X, whence=%d) failed with RC=0x%08X, errno=%d" % (fd, offset, whence, result.rc, self.errno()))
|
| - |
|
712 |
self.logger.debug("File seek result: 0x%x\n" % (result.rc))
|
| 688 |
return result.rc
|
713 |
return result.rc
|
| 689 |
|
714 |
|
| 690 |
@command(timeout = 30000)
|
715 |
@command(timeout = 30000)
|
| 691 |
def file_truncate(self, fd, length):
|
716 |
def file_truncate(self, fd, length):
|
| 692 |
""" Truncates a file referenced by a handle to a specified length """
|
717 |
""" Truncates a file referenced by a handle to a specified length """
|
| - |
|
718 |
self.logger.debug("Truncating file with handle 0x%x to 0x%x bytes\n" % (fd, length))
|
| 693 |
result = self.lib.monitorcommand(struct.pack("IIII", 35, fd, offset, 0), "III", ("rc", None, None))
|
719 |
result = self.lib.monitorcommand(struct.pack("IIII", 35, fd, offset, 0), "III", ("rc", None, None))
|
| 694 |
if result.rc > 0x80000000:
|
720 |
if result.rc > 0x80000000:
|
| 695 |
raise DeviceError("file_truncate(fd=%d, length=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, length, result.rc, self.errno()))
|
721 |
raise DeviceError("file_truncate(fd=%d, length=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, length, result.rc, self.errno()))
|
| - |
|
722 |
self.logger.debug("File truncate result: 0x%x\n" % (result.rc))
|
| 696 |
return result.rc
|
723 |
return result.rc
|
| 697 |
|
724 |
|
| 698 |
@command(timeout = 30000)
|
725 |
@command(timeout = 30000)
|
| 699 |
def file_sync(self, fd):
|
726 |
def file_sync(self, fd):
|
| 700 |
""" Flushes a file handles' buffers """
|
727 |
""" Flushes a file handles' buffers """
|
| - |
|
728 |
self.logger.debug("Flushing buffers of file with handle 0x%x\n" % (fd))
|
| 701 |
result = self.lib.monitorcommand(struct.pack("IIII", 36, fd, 0, 0), "III", ("rc", None, None))
|
729 |
result = self.lib.monitorcommand(struct.pack("IIII", 36, fd, 0, 0), "III", ("rc", None, None))
|
| 702 |
if result.rc > 0x80000000:
|
730 |
if result.rc > 0x80000000:
|
| 703 |
raise DeviceError("file_sync(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
|
731 |
raise DeviceError("file_sync(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
|
| - |
|
732 |
self.logger.debug("File flush result: 0x%x\n" % (result.rc))
|
| 704 |
return result.rc
|
733 |
return result.rc
|
| 705 |
|
734 |
|
| 706 |
@command(timeout = 30000)
|
735 |
@command(timeout = 30000)
|
| 707 |
def file_close(self, fd):
|
736 |
def file_close(self, fd):
|
| 708 |
""" Closes a file handle """
|
737 |
""" Closes a file handle """
|
| - |
|
738 |
self.logger.debug("Closing file handle 0x%x\n" % (fd))
|
| 709 |
result = self.lib.monitorcommand(struct.pack("IIII", 37, fd, 0, 0), "III", ("rc", None, None))
|
739 |
result = self.lib.monitorcommand(struct.pack("IIII", 37, fd, 0, 0), "III", ("rc", None, None))
|
| 710 |
if result.rc > 0x80000000:
|
740 |
if result.rc > 0x80000000:
|
| 711 |
raise DeviceError("file_close(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
|
741 |
raise DeviceError("file_close(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
|
| - |
|
742 |
self.logger.debug("File close result: 0x%x\n" % (result.rc))
|
| 712 |
return result.rc
|
743 |
return result.rc
|
| 713 |
|
744 |
|
| 714 |
@command(timeout = 30000)
|
745 |
@command(timeout = 30000)
|
| 715 |
def file_close_all(self):
|
746 |
def file_close_all(self):
|
| 716 |
""" Closes all file handles opened through the debugger """
|
747 |
""" Closes all file handles opened through the debugger """
|
| - |
|
748 |
self.logger.debug("Closing all files that were opened via USB\n")
|
| 717 |
result = self.lib.monitorcommand(struct.pack("IIII", 38, 0, 0, 0), "III", ("rc", None, None))
|
749 |
result = self.lib.monitorcommand(struct.pack("IIII", 38, 0, 0, 0), "III", ("rc", None, None))
|
| 718 |
if result.rc > 0x80000000:
|
750 |
if result.rc > 0x80000000:
|
| 719 |
raise DeviceError("file_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
751 |
raise DeviceError("file_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
| - |
|
752 |
self.logger.debug("Closed %d files\n" % (result.rc))
|
| 720 |
return result.rc
|
753 |
return result.rc
|
| 721 |
|
754 |
|
| 722 |
@command(timeout = 30000)
|
755 |
@command(timeout = 30000)
|
| 723 |
def file_kill_all(self):
|
756 |
def file_kill_all(self, volume):
|
| 724 |
""" Kills all file handles (in the whole system) """
|
757 |
""" Kills all file handles of a volume (in the whole system) """
|
| - |
|
758 |
self.logger.debug("Killing all file handles of volume %d\n" % (volume))
|
| 725 |
result = self.lib.monitorcommand(struct.pack("IIII", 39, 0, 0, 0), "III", ("rc", None, None))
|
759 |
result = self.lib.monitorcommand(struct.pack("IIII", 39, volume, 0, 0), "III", ("rc", None, None))
|
| 726 |
if result.rc > 0x80000000:
|
760 |
if result.rc > 0x80000000:
|
| 727 |
raise DeviceError("file_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
761 |
raise DeviceError("file_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
| - |
|
762 |
self.logger.debug("Closed %d files\n" % (result.rc))
|
| 728 |
return result.rc
|
763 |
return result.rc
|
| 729 |
|
764 |
|
| 730 |
@command(timeout = 30000)
|
765 |
@command(timeout = 30000)
|
| 731 |
def file_unlink(self, filename):
|
766 |
def file_unlink(self, filename):
|
| 732 |
""" Removes a file """
|
767 |
""" Removes a file """
|
| - |
|
768 |
self.logger.debug("Deleting file %s\n" % (filename))
|
| 733 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 40, 0, 0, 0, filename, 0), "III", ("rc", None, None))
|
769 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 40, 0, 0, 0, filename, 0), "III", ("rc", None, None))
|
| 734 |
if result.rc > 0x80000000:
|
770 |
if result.rc > 0x80000000:
|
| 735 |
raise DeviceError("file_unlink(filename=\"%s\") failed with RC=0x%08X, errno=%d" % (filename, result.rc, self.errno()))
|
771 |
raise DeviceError("file_unlink(filename=\"%s\") failed with RC=0x%08X, errno=%d" % (filename, result.rc, self.errno()))
|
| - |
|
772 |
self.logger.debug("Delete file result: 0x%x\n" % (result.rc))
|
| 736 |
return result.rc
|
773 |
return result.rc
|
| 737 |
|
774 |
|
| 738 |
@command(timeout = 30000)
|
775 |
@command(timeout = 30000)
|
| 739 |
def file_rename(self, oldname, newname):
|
776 |
def file_rename(self, oldname, newname):
|
| 740 |
""" Renames a file """
|
777 |
""" Renames a file """
|
| - |
|
778 |
self.logger.debug("Renaming file %s to %s\n" % (oldname, newname))
|
| 741 |
result = self.lib.monitorcommand(struct.pack("IIII248s%dsB" % min(247, len(newname)), 41, 0, 0, 0, oldname, newname, 0), "III", ("rc", None, None))
|
779 |
result = self.lib.monitorcommand(struct.pack("IIII248s%dsB" % min(247, len(newname)), 41, 0, 0, 0, oldname, newname, 0), "III", ("rc", None, None))
|
| 742 |
if result.rc > 0x80000000:
|
780 |
if result.rc > 0x80000000:
|
| 743 |
raise DeviceError("file_rename(oldname=\"%s\", newname=\"%s\") failed with RC=0x%08X, errno=%d" % (oldname, newname, result.rc, self.errno()))
|
781 |
raise DeviceError("file_rename(oldname=\"%s\", newname=\"%s\") failed with RC=0x%08X, errno=%d" % (oldname, newname, result.rc, self.errno()))
|
| - |
|
782 |
self.logger.debug("Rename file result: 0x%x\n" % (result.rc))
|
| 744 |
return result.rc
|
783 |
return result.rc
|
| 745 |
|
784 |
|
| 746 |
@command(timeout = 30000)
|
785 |
@command(timeout = 30000)
|
| 747 |
def dir_open(self, dirname):
|
786 |
def dir_open(self, dirname):
|
| 748 |
""" Opens a directory and returns the handle """
|
787 |
""" Opens a directory and returns the handle """
|
| - |
|
788 |
self.logger.debug("Opening directory %s\n" % (dirname))
|
| 749 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 42, 0, 0, 0, dirname, 0), "III", ("handle", None, None))
|
789 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 42, 0, 0, 0, dirname, 0), "III", ("handle", None, None))
|
| 750 |
if result.handle == 0:
|
790 |
if result.handle == 0:
|
| 751 |
raise DeviceError("dir_open(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.handle, self.errno()))
|
791 |
raise DeviceError("dir_open(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.handle, self.errno()))
|
| - |
|
792 |
self.logger.debug("Opened directory as handle 0x%x\n" % (result.handle))
|
| 752 |
return result.handle
|
793 |
return result.handle
|
| 753 |
|
794 |
|
| 754 |
@command(timeout = 30000)
|
795 |
@command(timeout = 30000)
|
| 755 |
def dir_read(self, handle):
|
796 |
def dir_read(self, handle):
|
| 756 |
""" Reads the next entry from a directory """
|
797 |
""" Reads the next entry from a directory """
|
| - |
|
798 |
self.logger.debug("Reading next entry of directory handle 0x%x\n" % (handle))
|
| 757 |
result = self.lib.monitorcommand(struct.pack("IIII", 43, handle, 0, 0), "III", ("version", "maxpath", "ptr"))
|
799 |
result = self.lib.monitorcommand(struct.pack("IIII", 43, handle, 0, 0), "III", ("version", "maxpath", "ptr"))
|
| 758 |
if result.ptr == 0:
|
800 |
if result.ptr == 0:
|
| 759 |
raise DeviceError("dir_read(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.ptr, self.errno()))
|
801 |
raise DeviceError("dir_read(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.ptr, self.errno()))
|
| 760 |
if result.version != 1:
|
802 |
if result.version != 1:
|
| 761 |
raise ValueError("Unknown version of dirent struct: %d" % result.version)
|
803 |
raise ValueError("Unknown version of dirent struct: %d" % result.version)
|
| 762 |
dirent = self.read(result.ptr, result.maxpath + 16)
|
804 |
dirent = self.read(result.ptr, result.maxpath + 16)
|
| 763 |
ret = Bunch()
|
805 |
ret = Bunch()
|
| 764 |
(ret.name, ret.attributes, ret.size, ret.startcluster, ret.wrtdate, ret.wrttime) = struct.unpack("%dsIIIHH" % result.maxpath, dirent)
|
806 |
(ret.name, ret.attributes, ret.size, ret.startcluster, ret.wrtdate, ret.wrttime) = struct.unpack("%dsIIIHH" % result.maxpath, dirent)
|
| 765 |
ret.name = ret.name[:ret.name.index('\x00')]
|
807 |
ret.name = ret.name[:ret.name.index('\x00')]
|
| - |
|
808 |
self.logger.debug("Read directory entry:\n")
|
| - |
|
809 |
self.logger.debug("Name: %s\n" % ret.name)
|
| - |
|
810 |
self.logger.debug("Attributes: 0x%x\n" % ret.attributes)
|
| - |
|
811 |
self.logger.debug("Size: %d\n" % ret.size)
|
| - |
|
812 |
self.logger.debug("Start cluster: %d\n" % ret.startcluster)
|
| - |
|
813 |
self.logger.debug("Last written date: 0x%x\n" % ret.wrtdate)
|
| - |
|
814 |
self.logger.debug("Last written time: 0x%x\n" % ret.wrttime)
|
| 766 |
return ret
|
815 |
return ret
|
| 767 |
|
816 |
|
| 768 |
@command(timeout = 30000)
|
817 |
@command(timeout = 30000)
|
| 769 |
def dir_close(self, handle):
|
818 |
def dir_close(self, handle):
|
| 770 |
""" Closes a directory handle """
|
819 |
""" Closes a directory handle """
|
| - |
|
820 |
self.logger.debug("Closing directory handle 0x%x\n" % (handle))
|
| 771 |
result = self.lib.monitorcommand(struct.pack("IIII", 44, handle, 0, 0), "III", ("rc", None, None))
|
821 |
result = self.lib.monitorcommand(struct.pack("IIII", 44, handle, 0, 0), "III", ("rc", None, None))
|
| 772 |
if result.rc > 0x80000000:
|
822 |
if result.rc > 0x80000000:
|
| 773 |
raise DeviceError("dir_close(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.rc, self.errno()))
|
823 |
raise DeviceError("dir_close(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.rc, self.errno()))
|
| - |
|
824 |
self.logger.debug("Close directory result: 0x%x\n" % (result.rc))
|
| 774 |
return result.rc
|
825 |
return result.rc
|
| 775 |
|
826 |
|
| 776 |
@command(timeout = 30000)
|
827 |
@command(timeout = 30000)
|
| 777 |
def dir_close_all(self):
|
828 |
def dir_close_all(self):
|
| 778 |
""" Closes all directory handles opened through the debugger """
|
829 |
""" Closes all directory handles opened through the debugger """
|
| - |
|
830 |
self.logger.debug("Closing all directories that were opened via USB\n")
|
| 779 |
result = self.lib.monitorcommand(struct.pack("IIII", 45, 0, 0, 0), "III", ("rc", None, None))
|
831 |
result = self.lib.monitorcommand(struct.pack("IIII", 45, 0, 0, 0), "III", ("rc", None, None))
|
| 780 |
if result.rc > 0x80000000:
|
832 |
if result.rc > 0x80000000:
|
| 781 |
raise DeviceError("dir_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
833 |
raise DeviceError("dir_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
| - |
|
834 |
self.logger.debug("Closed %d directories\n" % (result.rc))
|
| 782 |
return result.rc
|
835 |
return result.rc
|
| 783 |
|
836 |
|
| 784 |
@command(timeout = 30000)
|
837 |
@command(timeout = 30000)
|
| 785 |
def dir_kill_all(self):
|
838 |
def dir_kill_all(self, volume):
|
| 786 |
""" Kills all directory handles (in the whole system) """
|
839 |
""" Kills all directory handles of a volume (in the whole system) """
|
| - |
|
840 |
self.logger.debug("Closing all directories of volume %d\n" % (volume))
|
| 787 |
result = self.lib.monitorcommand(struct.pack("IIII", 46, 0, 0, 0), "III", ("rc", None, None))
|
841 |
result = self.lib.monitorcommand(struct.pack("IIII", 46, volume, 0, 0), "III", ("rc", None, None))
|
| 788 |
if result.rc > 0x80000000:
|
842 |
if result.rc > 0x80000000:
|
| 789 |
raise DeviceError("dir_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
843 |
raise DeviceError("dir_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
| - |
|
844 |
self.logger.debug("Closed %d directories\n" % (result.rc))
|
| 790 |
return result.rc
|
845 |
return result.rc
|
| 791 |
|
846 |
|
| 792 |
@command(timeout = 30000)
|
847 |
@command(timeout = 30000)
|
| 793 |
def dir_create(self, dirname):
|
848 |
def dir_create(self, dirname):
|
| 794 |
""" Creates a directory """
|
849 |
""" Creates a directory """
|
| - |
|
850 |
self.logger.debug("Creating directory %s\n" % (dirname))
|
| 795 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 47, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
|
851 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 47, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
|
| 796 |
if result.rc > 0x80000000:
|
852 |
if result.rc > 0x80000000:
|
| 797 |
raise DeviceError("dir_create(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
|
853 |
raise DeviceError("dir_create(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
|
| - |
|
854 |
self.logger.debug("Create directory result: 0x%x\n" % (result.rc))
|
| 798 |
return result.rc
|
855 |
return result.rc
|
| 799 |
|
856 |
|
| 800 |
@command(timeout = 30000)
|
857 |
@command(timeout = 30000)
|
| 801 |
def dir_remove(self, dirname):
|
858 |
def dir_remove(self, dirname):
|
| 802 |
""" Removes an (empty) directory """
|
859 |
""" Removes an (empty) directory """
|
| - |
|
860 |
self.logger.debug("Removing directory %s\n" % (dirname))
|
| 803 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 48, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
|
861 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 48, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
|
| 804 |
if result.rc > 0x80000000:
|
862 |
if result.rc > 0x80000000:
|
| 805 |
raise DeviceError("dir_remove(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
|
863 |
raise DeviceError("dir_remove(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
|
| - |
|
864 |
self.logger.debug("Remove directory result: 0x%x\n" % (result.rc))
|
| 806 |
return result.rc
|
865 |
return result.rc
|
| 807 |
|
866 |
|
| 808 |
@command()
|
867 |
@command()
|
| 809 |
def errno(self):
|
868 |
def errno(self):
|
| 810 |
""" Returns the number of the last error that happened """
|
869 |
""" Returns the number of the last error that happened """
|
| - |
|
870 |
self.logger.debug("Getting last error number\n")
|
| 811 |
result = self.lib.monitorcommand(struct.pack("IIII", 49, 0, 0, 0), "III", ("errno", None, None))
|
871 |
result = self.lib.monitorcommand(struct.pack("IIII", 49, 0, 0, 0), "III", ("errno", None, None))
|
| - |
|
872 |
self.logger.debug("Last error: 0x%x\n" % (result.errno))
|
| 812 |
return result.errno
|
873 |
return result.errno
|
| 813 |
|
874 |
|
| 814 |
@command()
|
875 |
@command()
|
| 815 |
def disk_mount(self, volume):
|
876 |
def disk_mount(self, volume):
|
| 816 |
""" Mounts a volume """
|
877 |
""" Mounts a volume """
|
| - |
|
878 |
self.logger.debug("Mounting volume %d\n" % (volume))
|
| 817 |
result = self.lib.monitorcommand(struct.pack("IIII", 50, volume, 0, 0), "III", ("rc", None, None))
|
879 |
result = self.lib.monitorcommand(struct.pack("IIII", 50, volume, 0, 0), "III", ("rc", None, None))
|
| 818 |
if result.rc > 0x80000000:
|
880 |
if result.rc > 0x80000000:
|
| 819 |
raise DeviceError("disk_mount(volume=%d) failed with RC=0x%08X, errno=%d" % (volume, result.rc, self.errno()))
|
881 |
raise DeviceError("disk_mount(volume=%d) failed with RC=0x%08X, errno=%d" % (volume, result.rc, self.errno()))
|
| - |
|
882 |
self.logger.debug("Mount volume result: 0x%x\n" % (result.rc))
|
| 820 |
return result.rc
|
883 |
return result.rc
|
| 821 |
|
884 |
|
| 822 |
@command()
|
885 |
@command()
|
| 823 |
def disk_unmount(self, volume):
|
886 |
def disk_unmount(self, volume):
|
| 824 |
""" Unmounts a volume """
|
887 |
""" Unmounts a volume """
|
| - |
|
888 |
self.logger.debug("Unmounting volume %d\n" % (volume))
|
| 825 |
result = self.lib.monitorcommand(struct.pack("IIII", 51, volume, 0, 0), "III", ("rc", None, None))
|
889 |
result = self.lib.monitorcommand(struct.pack("IIII", 51, volume, 0, 0), "III", ("rc", None, None))
|
| 826 |
if result.rc > 0x80000000:
|
890 |
if result.rc > 0x80000000:
|
| 827 |
raise DeviceError("disk_unmount(volume=%d) failed with RC=0x%08X, errno=%d" % (volume, result.rc, self.errno()))
|
891 |
raise DeviceError("disk_unmount(volume=%d) failed with RC=0x%08X, errno=%d" % (volume, result.rc, self.errno()))
|
| - |
|
892 |
self.logger.debug("Unmount volume result: 0x%x\n" % (result.rc))
|
| 828 |
return result.rc
|
893 |
return result.rc
|
| 829 |
|
894 |
|
| 830 |
@command()
|
895 |
@command()
|
| 831 |
def malloc(self, size):
|
896 |
def malloc(self, size):
|
| 832 |
""" Allocates 'size' bytes and returns a pointer to the allocated memory """
|
897 |
""" Allocates 'size' bytes and returns a pointer to the allocated memory """
|