Example #1
0
    def doNTFSshrink(self, device, partnum, size, partstart, diskinfo):
        """Shrink selected NTFS partition. First the file-system is shrunk,
        then the partition containing it. size and partstart are in sectors.
        """
        dev = "%s%d" % (device, partnum)
        ## This rounding to whole clusters may well not be necessary
        #clus = int(s * 1e6) / self.ntfs_cluster_size
        #newsize = clus * self.ntfs_cluster_size
        newsize = size * diskinfo[3]
        # First a test run
        info = PopupInfo(_("Test run ..."), _("Shrink NTFS partition"))
        res = self.xcall("ntfs-testrun %s %s" % (dev, newsize))
        info.drop()
        if res:
            return res

        # Now the real thing, resize the file-system
        info = PopupInfo(_("This is for real, shrinking file-system ..."),
                _("Shrink NTFS partition"))
        res = self.xcall("ntfs-resize %s %s" % (dev, newsize))

        info.drop()
        if res:
            return res

        # Now resize the actual partition, so that it ends at a cylinder
        # boundary after the end of the ntfs filesystem.
        cylsize = diskinfo[2]
        end = int((partstart + size + 2*cylsize) / cylsize) * cylsize
        info = PopupInfo(_("Resizing partition ..."),
                _("Shrink NTFS partition"))
        res = self.xcall("part-resize %s %d %d" %
                (device, partnum, end - partstart))
        info.drop()
        if res:
            return res

        # And finally expand the ntfs file-system into the new partition
        info = PopupInfo(_("Fitting file-system to new partition ..."),
                _("Shrink NTFS partition"))
        res = self.xcall("ntfs-growfit %s" % dev)
        info.drop()
        return res
Example #2
0
    def doNTFSshrink(self, s):
        """Shrink selected NTFS partition. First the file-system is shrunk,
        then the partition containing it. The given size is in MB.
        """
        # This rounding to whole clusters may well not be necessary
        clus = int(s * 1e6) / self.ntfs_cluster_size
        newsize = clus * self.ntfs_cluster_size

        dev = self.selectedDevice()

        # First a test run
        info = PopupInfo(_("Test run ..."), _("Shrink NTFS partition"))
        res = self.xcall("ntfs-testrun %s1 %s" % (dev, newsize))
        info.drop()
        if res:
            return res

        # Now the real thing, resize the file-system
        info = PopupInfo(_("This is for real, shrinking file-system ..."),
                _("Shrink NTFS partition"))
        res = self.xcall("ntfs-resize %s1 %s" % (dev, newsize))
        info.drop()
        if res:
            return res

        # Now resize the actual partition

        # Get new start of following partition - even cylinder boundary,
        # doing quite a safe rounding up.
        newcyl = (int((newsize / 1e6) / self.cylinderMB + 2) / 2) * 2

        info = PopupInfo(_("Resizing partition ..."),
                _("Shrink NTFS partition"))
        res = self.xcall("part1-resize %s %d" % (dev, newcyl))
        info.drop()
        if res:
            return res

        # And finally expand the ntfs file-system into the new partition
        info = PopupInfo(_("Fitting file-system to new partition ..."),
                _("Shrink NTFS partition"))
        res = self.xcall("ntfs-growfit %s1" % dev)
        info.drop()
        self.getDeviceInfo(dev)
        return res