From 4f24c813cd76bafa8d6e8e8192114c3c94b6764e Mon Sep 17 00:00:00 2001 From: lars Date: Sat, 13 Jun 2009 12:22:53 +0000 Subject: [PATCH] * changed definition of storage device: only "valid" devices are available now --- src/cryptobox/core/blockdevice.py | 43 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/cryptobox/core/blockdevice.py b/src/cryptobox/core/blockdevice.py index 0ebe35f..a37135f 100644 --- a/src/cryptobox/core/blockdevice.py +++ b/src/cryptobox/core/blockdevice.py @@ -254,32 +254,31 @@ class Blockdevice: cached = CACHE.get(cache_link) if not cached is None: return cached + result = True - if self.range > 1: + # always check the current state of "result" to skip useless checks + if result and (self.range > 1): ## partitionable blockdevice - CACHE.set(cache_link, False) - return False - if self.size < MINIMUM_STORAGE_SIZE: + result = False + if result and not self.is_valid(): + result = False + if result and (self.size < MINIMUM_STORAGE_SIZE): ## extended partition, unused loop device - CACHE.set(cache_link, False) - return False + result = False ## are we the device mapper of a luks device? - for slave in self.slaves: - if get_blockdevice(slave, self.sysblock_dir, - self.devnode_dir).is_luks(): - CACHE.set(cache_link, False) - return False - ## if we are a luks device with exactly one child, then - ## we are a storage - if (len(self.children) == 1) and self.is_luks(): - CACHE.set(cache_link, True) - return True - if self.children: - ## a parent blockdevice - CACHE.set(cache_link, False) - return False - CACHE.set(cache_link, True) - return True + if result: + for slave in self.slaves: + if get_blockdevice(slave, self.sysblock_dir, + self.devnode_dir).is_luks(): + result = False + if result and self.children: + ## if we are a luks device with exactly one child, then + ## we are a storage + if not ((len(self.children) == 1) and self.is_luks()): + ## a parent blockdevice + result = False + CACHE.set(cache_link, result) + return result def is_partitionable(self):