summaryrefslogtreecommitdiff
path: root/rtslib/utils.py
diff options
context:
space:
mode:
authorAndy Grover <agrover@redhat.com>2013-06-22 15:52:36 -0700
committerAndy Grover <agrover@redhat.com>2013-06-22 15:52:36 -0700
commit644141ec4ea0d38337c09752c580df269fcbbece (patch)
tree996497dc8d9c3f0972baf0bb4671c6190deedaed /rtslib/utils.py
parent44223d7bd966164387fbaaade7da58fad617f427 (diff)
downloadrtslib-fb-644141ec4ea0d38337c09752c580df269fcbbece.tar.gz
Fix get_disk_size to handle partitions
Rename to get_block_size, as well. Resolves 27. Signed-off-by: Andy Grover <agrover@redhat.com>
Diffstat (limited to 'rtslib/utils.py')
-rw-r--r--rtslib/utils.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/rtslib/utils.py b/rtslib/utils.py
index baee30a..21f2cf3 100644
--- a/rtslib/utils.py
+++ b/rtslib/utils.py
@@ -109,11 +109,17 @@ def is_dev_in_use(path):
os.close(file_fd)
return False
-def get_disk_size(path):
+def get_block_size(path):
'''
Returns the size in blocks of a disk-type block device.
'''
- return int(fread("/sys/block/%s/size" % os.path.basename(os.path.realpath(path))))
+ name = os.path.basename(os.path.realpath(path))
+
+ m = re.search(r'([a-z]+)(\d+)$', name)
+ if not m:
+ return int(fread("/sys/block/%s/size" % name))
+ else:
+ return int(fread("/sys/block/%s/%s/size" % (m.groups()[0], m.group())))
def get_block_numbers(path):
'''