def get_file_device_path(fname):
 fname = os.path.realpath(fname)
 mtab_dict = {}
 try:
  for ent in get_mtab():
   mtab_dict[ent.mnt_dir] = ent.mnt_fsname
 except:
  pass
 fdir = os.path.dirname(fname)
 if (fdir in mtab_dict):
  match = True
 else:
  match = False
 chrootfs = False
 while (not match):
  if (fdir == os.path.sep):
   chrootfs = True
   break
  fdir = os.path.realpath(os.path.join(fdir, os.path.pardir))
  if (fdir in mtab_dict):
   match = True
  else:
   match = False
 if (fdir != os.path.sep):
  fname = fname[len(fdir):]
 if chrootfs:
  return (':', fname)
 else:
  return (mtab_dict[fdir], fname)

def get_file_device_path ( fname ) : fname = os . path . realpath ( fname ) mtab_dict = { } try : for ent in get_mtab ( ) : mtab_dict [ ent . mnt_dir ] = ent . mnt_fsname except : pass fdir = os . path . dirname ( fname ) if ( fdir in mtab_dict ) : match = True else : match = False chrootfs = False while ( not match ) : if ( fdir == os . path . sep ) : chrootfs = True break fdir = os . path . realpath ( os . path . join ( fdir , os . path . pardir ) ) if ( fdir in mtab_dict ) : match = True else : match = False if ( fdir != os . path . sep ) : fname = fname [ len ( fdir ) : ] if chrootfs : return ( ':' , fname ) else : return ( mtab_dict [ fdir ] , fname )
what this function attempts to do is take a file and return: - the device the file is on - the path of the file relative to the device .