def carve(self, freespace=True):

        if not _util.command_exists('photorec'):
            logger.warning("photorec is not installed, could not carve volume")
            return False

        if not self._make_mountpoint(var_name='carvepoint', suffix="carve"):
            return False

        # if no slot, we need to make a loopback that we can use to carve the volume
        loopback_was_created_for_carving = False
        if not self.slot:
            if not self.loopback:
                if not self._find_loopback():
                    logger.error("Can't carve if volume has no slot number and can't be mounted on loopback.")
                    return False
                loopback_was_created_for_carving = True

            # noinspection PyBroadException
            try:
                _util.check_call_(["photorec", "/d", self.carvepoint + os.sep, "/cmd", self.loopback,
                                  ("freespace," if freespace else "") + "search"])

                # clean out the loop device if we created it specifically for carving
                if loopback_was_created_for_carving:
                    # noinspection PyBroadException
                    try:
                        _util.check_call_(['losetup', '-d', self.loopback])
                    except Exception:
                        pass
                    else:
                        self.loopback = ""

                return True
            except Exception:
                logger.exception("Failed carving the volume.")
                return False
        else:
            # noinspection PyBroadException
            try:
                _util.check_call_(["photorec", "/d", self.carvepoint + os.sep, "/cmd", self.get_raw_path(),
                                  str(self.slot) + (",freespace" if freespace else "") + ",search"])
                return True

            except Exception:
                logger.exception("Failed carving the volume.")
                return False
Call this method to carve the free space of the volume for (deleted) files. Note that photorec has its
dataset/ETHPy150Open ralphje/imagemounter/imagemounter/volume.py/Volume.carve