def is_partition(self, dev):
"""
Check whether a given device path is a partition or a full disk.
"""
if not os.path.exists(dev):
raise Error('device not found', dev)
dev = os.path.realpath(dev)
if not stat.S_ISBLK(os.lstat(dev).st_mode):
raise Error('not a block device', dev)
name = self._get_dev_name(dev)
if os.path.exists(os.path.join('/sys/block', name)):
return False
# make sure it is a partition of something else
for basename in os.listdir('/sys/block'):
if os.path.exists(os.path.join('/sys/block', basename, name)):
return True
raise Error('not a disk or partition', dev)
评论列表
文章目录