def get_blkdev_major_minor(path, lookup_for_file=True):
 st = os.stat(path)
 if stat.S_ISBLK(st.st_mode):
  (path, st) = _get_disk_of_partition(path, st)
  return ('%d:%d' % (os.major(st.st_rdev), os.minor(st.st_rdev)))
 elif stat.S_ISCHR(st.st_mode):
  return None
 elif lookup_for_file:
  (out, _err) = execute('df', path)
  devpath = out.split('\n')[1].split()[0]
  if (devpath[0] is not '/'):
   return None
  return get_blkdev_major_minor(devpath, False)
 else:
  msg = (_("Unable to get a block device for file '%s'") % path)
  raise exception.Error(msg)

def get_blkdev_major_minor ( path , lookup_for_file = True ) : st = os . stat ( path ) if stat . S_ISBLK ( st . st_mode ) : ( path , st ) = _get_disk_of_partition ( path , st ) return ( '%d:%d' % ( os . major ( st . st_rdev ) , os . minor ( st . st_rdev ) ) ) elif stat . S_ISCHR ( st . st_mode ) : return None elif lookup_for_file : ( out , _err ) = execute ( 'df' , path ) devpath = out . split ( '\n' ) [ 1 ] . split ( ) [ 0 ] if ( devpath [ 0 ] is not '/' ) : return None return get_blkdev_major_minor ( devpath , False ) else : msg = ( _ ( "Unable to get a block device for file '%s'" ) % path ) raise exception . Error ( msg )
get major:minor number of block device .