#NEWLINE# def carve( self , freespace = True ) : #NEWLINE# #INDENT# 'Call this method to carve the free space of the volume for (deleted) files. Note that photorec has its\n        own interface that temporarily takes over the shell.\n\n        :param freespace: indicates whether the entire volume should be carved (False) or only the free space (True)\n        :type freespace: bool\n        :return: boolean indicating whether the command succeeded\n        ' #NEWLINE# if ( not _util . command_exists ( 'photorec' ) ) : #NEWLINE# #INDENT# logger . warning ( 'photorec is not installed, could not carve volume' ) #NEWLINE# return False #NEWLINE# #UNINDENT# if ( not self . _make_mountpoint ( var_name = 'carvepoint' , suffix = 'carve' ) ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# loopback_was_created_for_carving = False #NEWLINE# if ( not self . slot ) : #NEWLINE# #INDENT# if ( not self . loopback ) : #NEWLINE# #INDENT# if ( not self . _find_loopback ( ) ) : #NEWLINE# #INDENT# logger . error ( "Can't carve if volume has no slot number and can't be mounted on loopback." ) #NEWLINE# return False #NEWLINE# #UNINDENT# loopback_was_created_for_carving = True #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# _util . check_call_ ( [ 'photorec' , '/d' , ( self . carvepoint + os . sep ) , '/cmd' , self . loopback , ( ( 'freespace,' if freespace else '' ) + 'search' ) ] ) #NEWLINE# if loopback_was_created_for_carving : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# _util . check_call_ ( [ 'losetup' , '-d' , loopback_was_created_for_carving . loopback ] ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . loopback = '' #NEWLINE# #UNINDENT# #UNINDENT# return True #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# logger . exception ( 'Failed carving the volume.' ) #NEWLINE# return False #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# _util . check_call_ ( [ 'photorec' , '/d' , ( self . carvepoint + os . sep ) , '/cmd' , self . get_raw_path ( ) , ( ( str ( self . slot ) + ( ',freespace' if freespace else '' ) ) + ',search' ) ] ) #NEWLINE# return True #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# logger . exception ( 'Failed carving the volume.' ) #NEWLINE# return False