def init_blkdev(self, file_name): # make sure image file exists if not os.path.exists(file_name): raise IOError("Image File not found: '%s'" % file_name) # open existing raw block device blkdev = RawBlockDevice(file_name, self.args.read_only) blkdev.open() # try to guess geometry geo = DiskGeometry() num_blocks = blkdev.num_blocks block_bytes = blkdev.block_bytes opts = KeyValue.parse_key_value_strings(self.opts) if geo.detect(num_blocks * block_bytes, opts) == None: raise IOError("Can't detect geometry of disk: '%s'" % file_name) blkdev.geo = geo return blkdev
def init_blkdev(self, file_name): # make sure image file exists if not os.path.exists(file_name): raise IOError("Image File not found: '%s'" % file_name) # parse opts opts = KeyValue.parse_key_value_strings(self.opts) # is a block size given in options? if yes then enforce it bs = 512 opts_bs = self._get_opts_block_size(opts) if opts_bs: bs = opts_bs # setup initial raw block dev with default block size blkdev = RawBlockDevice(file_name, self.args.read_only, block_bytes=bs) blkdev.open() # if no bs was given in options then try to find out block size # from an existing rdb if not opts_bs: rd = RDisk(blkdev) peek_bs = rd.peek_block_size() # real block size differs: re-open dev with correct size if peek_bs and peek_bs != blkdev.block_bytes: blkdev.close() blkdev = RawBlockDevice(file_name, self.args.read_only, block_bytes=peek_bs) blkdev.open() bs = peek_bs # try to guess geometry file_size = blkdev.num_blocks * blkdev.block_bytes geo = DiskGeometry(block_bytes=bs) if not geo.detect(file_size, opts): raise IOError("Can't detect geometry of disk: '%s'" % file_name) # make sure block size is still the same if geo.block_bytes != bs: raise IOError("Invalid geo block size chosen: %d" % geo.block_bytes) # keep geo blkdev.geo = geo return blkdev