def get_storage_number_map(drive_types=(DRIVE_REMOVABLE, DRIVE_FIXED), debug=False):
 mask = GetLogicalDrives()
 type_map = {letter: GetDriveType(((letter + u':') + os.sep)) for (i, letter) in enumerate(string.ascii_uppercase) if (mask & (1 << i))}
 drives = (letter for (letter, dt) in type_map.iteritems() if (dt in drive_types))
 ans = defaultdict(list)
 for letter in drives:
  try:
   sn = get_storage_number(((u'\\\\.\\' + letter) + u':'))
   ans[sn[:2]].append((sn[2], letter))
  except WindowsError as err:
   if debug:
    prints((u'Failed to get storage number for drive: %s with error: %s' % (letter, as_unicode(err))))
   continue
 for val in ans.itervalues():
  val.sort(key=itemgetter(0))
 return dict(ans)

def get_storage_number_map ( drive_types = ( DRIVE_REMOVABLE , DRIVE_FIXED ) , debug = False ) : mask = GetLogicalDrives ( ) type_map = { letter : GetDriveType ( ( ( letter + u':' ) + os . sep ) ) for ( i , letter ) in enumerate ( string . ascii_uppercase ) if ( mask & ( 1 << i ) ) } drives = ( letter for ( letter , dt ) in type_map . iteritems ( ) if ( dt in drive_types ) ) ans = defaultdict ( list ) for letter in drives : try : sn = get_storage_number ( ( ( u'\\\\.\\' + letter ) + u':' ) ) ans [ sn [ : 2 ] ] . append ( ( sn [ 2 ] , letter ) ) except WindowsError as err : if debug : prints ( ( u'Failed to get storage number for drive: %s with error: %s' % ( letter , as_unicode ( err ) ) ) ) continue for val in ans . itervalues ( ) : val . sort ( key = itemgetter ( 0 ) ) return dict ( ans )
get a mapping of drive letters to storage numbers for all drives on system .