#NEWLINE# def GetTSKVsPartByPathSpec( tsk_volume , path_spec ) : #NEWLINE# #INDENT# 'Retrieves the TSK volume system part object from the TSK volume object.\n\n  Args:\n    tsk_volume: a TSK volume object (instance of pytsk3.Volume_Info).\n    path_spec: the path specification (instance of PathSpec).\n\n  Returns:\n    A tuple of the TSK volume system part object (instance of\n    pytsk3.TSK_VS_PART_INFO) and the partition index. The partition index\n    is None when not available. The function return or (None, None) on error.\n  ' #NEWLINE# location = getattr ( path_spec , 'location' , None ) #NEWLINE# part_index = getattr ( path_spec , 'part_index' , None ) #NEWLINE# start_offset = getattr ( path_spec , 'start_offset' , None ) #NEWLINE# partition_index = None #NEWLINE# if ( part_index is None ) : #NEWLINE# #INDENT# if ( location is not None ) : #NEWLINE# #INDENT# if location . startswith ( '/p' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# partition_index = ( int ( location [ 2 : ] , 10 ) - 1 ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( ( partition_index is None ) or ( partition_index < 0 ) ) : #NEWLINE# #INDENT# location = None #NEWLINE# #UNINDENT# #UNINDENT# if ( ( location is None ) and ( start_offset is None ) ) : #NEWLINE# #INDENT# return ( None , None ) #NEWLINE# #UNINDENT# #UNINDENT# bytes_per_sector = TSKVolumeGetBytesPerSector ( tsk_volume ) #NEWLINE# current_part_index = 0 #NEWLINE# current_partition_index = 0 #NEWLINE# tsk_vs_part = None #NEWLINE# tsk_vs_part_list = list ( tsk_volume ) #NEWLINE# number_of_tsk_vs_parts = len ( tsk_vs_part_list ) #NEWLINE# if ( number_of_tsk_vs_parts > 0 ) : #NEWLINE# #INDENT# if ( ( part_index is not None ) and ( ( part_index < 0 ) or ( part_index >= number_of_tsk_vs_parts ) ) ) : #NEWLINE# #INDENT# return ( None , None ) #NEWLINE# #UNINDENT# for tsk_vs_part in tsk_vs_part_list : #NEWLINE# #INDENT# if TSKVsPartIsAllocated ( tsk_vs_part ) : #NEWLINE# #INDENT# if ( partition_index is not None ) : #NEWLINE# #INDENT# if ( partition_index == current_partition_index ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# current_partition_index += 1 #NEWLINE# #UNINDENT# if ( ( part_index is not None ) and ( part_index == current_part_index ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# if ( start_offset is not None ) : #NEWLINE# #INDENT# start_sector = TSKVsPartGetStartSector ( tsk_vs_part ) #NEWLINE# if ( start_sector is not None ) : #NEWLINE# #INDENT# start_sector *= bytes_per_sector #NEWLINE# if ( start_sector == start_offset ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# current_part_index += 1 #NEWLINE# #UNINDENT# #UNINDENT# if ( ( tsk_vs_part is None ) or ( current_part_index >= number_of_tsk_vs_parts ) ) : #NEWLINE# #INDENT# return ( None , None ) #NEWLINE# #UNINDENT# if ( not TSKVsPartIsAllocated ( tsk_vs_part ) ) : #NEWLINE# #INDENT# current_partition_index = None #NEWLINE# #UNINDENT# return ( tsk_vs_part , current_partition_index )