Example #1
0
    def mkfs(self, parameters):
        """Create file systems in existing partitions"""
        img_path = ImagePath.parse(parameters[0])

        image = DiskImage(img_path.imagefile, "a")
        phys = createPhysicalImageFromImageType(img_path.imagetype, image)
        filesystem = phys.get_filesystem(img_path.partition)
        filesystem.format()
Example #2
0
    def dump(self, parameters):
        """Dump the details of a disk image.

        {cmd} <image_file_name> l<detail level>

        The amount of details can be controlled with the l<number> parameter.
        1  Show details about the image
        2  Show a first level of details for all contained file systems."""
        img_path = ImagePath.parse(parameters[0])

        level = int(parameters[1][1:])

        image = DiskImage(img_path.imagefile, "a")
        phys = createPhysicalImageFromImageType(img_path.imagetype, image)
        phys.dump(level=level)
Example #3
0
    def copy(self, parameters):
        """Copy a file from or to a location inside an image"""
        if len(parameters) != 2:
            print("Source and destination file are required")
            return
        # for the moment only allow copying from a real file to a location in
        # an image file
        source_file = open(parameters[0], "rb")
        if sys.version_info[0] >= 3:
            source_data = source_file.read().decode("latin-1")
        else:
            source_data = source_file.read()
        source_file.close()

        img_path = ImagePath.parse(parameters[1])

        image = DiskImage(img_path.imagefile, "a")
        phys = createPhysicalImageFromImageType(img_path.imagetype, image)
        filesystem = phys.get_filesystem(img_path.partition)

        target_file = filesystem.open(img_path.filepath, "w")
        target_file.write(source_data)
        target_file.close()
Example #4
0
    def create(self, parameters):
        """Create a new partition.

        {cmd} <image_url> start=<start_lba> end=<end_lba> type=<type number>
                 [spt=<sectors per track> hpc=<heads per cluster>]"""
        start_lba = None
        end_lba = None
        partition_type = None
        sectors_per_track = 63
        heads_per_cluster = 16

        from pyvirtualfs.image_path import ImagePath, PathParseError
        from pyvirtualfs.tools import int_ex
        try:
            image_url = ImagePath.parse(parameters[0])
        except PathParseError as p:
            print("First argument of create must be an image path with"
                  "a partition")
            print(p.msg)
            return

        for param in parameters[1:]:
            (key, value) = param.split("=")
            if key == "start":
                start_lba = int_ex(value)
            elif key == "end":
                end_lba = int_ex(value)
            elif key == "type":
                partition_type = int_ex(value)
            elif key == "spt":
                sectors_per_track = int_ex(value)
            elif key == "hpc":
                heads_per_cluster = int_ex(value)
            else:
                print("Unknown key name '%s'" % key)
                return

        if start_lba is None:
            print("Need a start LBA for this partition")
            return
        if end_lba is None:
            print("Need an end LBA for this partition")
            return
        if partition_type is None:
            print("Need a type for this partition")
            return

        from pyvirtualfs.physical import DiskImage, Harddisk
        from pyvirtualfs.tools import lba2chs

        assert image_url.imagetype == ImagePath.IMAGE_TYPE_HD
        image = DiskImage(image_url.imagefile, "a")
        hd = Harddisk(image)
        p = hd.get_partition_info(image_url.partition)
        p.type = partition_type
        p.chs_first_sector = lba2chs(start_lba, heads_per_cluster,
                                     sectors_per_track)
        p.chs_last_sector = lba2chs(end_lba, heads_per_cluster,
                                    sectors_per_track)
        p.lba_first_sector = start_lba
        p.sectors_in_partition = end_lba - start_lba + 1
        hd.set_partition_info(image_url.partition, p)

        hd.update_image(0x337a0564)
Example #5
0
 def execute(self, parameters):
     from pyvirtualfs.image_path import ImagePath
     img_path = ImagePath.parse(parameters[0])