def create(self, img_file, force=True, options=None): # make sure we are allowed to overwrite existing file if os.path.exists(img_file): if not force: raise IOError("can't overwrite existing image file") # not writeable? if not os.access(img_file, os.W_OK): raise IOError("can't write image file") # detect type t = self.detect_type(img_file, options) if t == None: raise IOError("can't detect type of image file") if t == self.TYPE_RDISK: raise IOError("can't create rdisk. use rdbtool first") # create blkdev if t == self.TYPE_ADF: blkdev = ADFBlockDevice(img_file) blkdev.create() else: # determine geometry from size or chs geo = DiskGeometry() if not geo.setup(options): raise IOError("can't determine geometry of HDF image file") blkdev = HDFBlockDevice(img_file) blkdev.create(geo) return blkdev
def create(self, img_file, force=True, options=None, fobj=None): if fobj is None: # make sure we are allowed to overwrite existing file if os.path.exists(img_file): if not force: raise IOError("can't overwrite existing image file") # not writeable? if not os.access(img_file, os.W_OK): raise IOError("can't write image file") # detect type t = self.detect_type(img_file, fobj, options) if t == None: raise IOError("can't detect type of image file") if t == self.TYPE_RDISK: raise IOError("can't create rdisk. use rdbtool first") # create blkdev if t == self.TYPE_ADF: blkdev = ADFBlockDevice(img_file, fobj=fobj) blkdev.create() else: # determine geometry from size or chs geo = DiskGeometry() if not geo.setup(options): raise IOError("can't determine geometry of HDF image file") blkdev = HDFBlockDevice(img_file, fobj=fobj) blkdev.create(geo) return blkdev