Exemplo n.º 1
0
 def init_blkdev(self, file_name):
     # do not overwrite an existing image file
     if not os.path.exists(file_name):
         raise IOError("Image File does not exist: '%s'" % file_name)
     # make sure size is given
     if len(self.opts) < 1:
         print(
             "Usage: resize ( size=<n> | chs=<c,h,s> | from=<img> ) [bs=<n>]"
         )
         return None
     # determine disk geometry
     opts = KeyValue.parse_key_value_strings(self.opts)
     geo = DiskGeometry()
     if not geo.setup(opts):
         raise IOError("Can't set geometry of disk: '%s'" % file_name)
     # grow or shrink image file
     cur_size = ImageFile.get_image_size(file_name)
     new_size = geo.get_num_bytes()
     if cur_size == new_size:
         print("Image size unchanged")
     elif cur_size < new_size:
         print("Growing image")
     else:
         print("Shrinking image")
     new_blocks = new_size // geo.block_bytes
     blkdev = RawBlockDevice(file_name, block_bytes=geo.block_bytes)
     blkdev.resize(new_blocks)
     blkdev.geo = geo
     return blkdev
Exemplo n.º 2
0
 def init_blkdev(self, image_file):
   opts = KeyValue.parse_key_value_strings(self.opts[1:])
   f = BlkDevFactory()
   blkdev = f.open(image_file, options=opts, read_only=False,
                   none_if_missing=True)
   if not blkdev:
     return f.create(image_file, options=opts, force=self.args.force)
Exemplo n.º 3
0
 def init_blkdev(self, image_file):
     opts = KeyValue.parse_key_value_strings(self.opts[1:])
     f = BlkDevFactory()
     blkdev = f.open(image_file,
                     options=opts,
                     read_only=False,
                     none_if_missing=True)
     if not blkdev:
         return f.create(image_file, options=opts, force=self.args.force)
Exemplo n.º 4
0
 def init_rdisk(self, blkdev):
     opts = KeyValue.parse_key_value_strings(self.opts)
     # number of cylinders for RDB
     if 'rdb_cyls' in opts:
         rdb_cyls = int(opts['rdb_cyls'])
     else:
         rdb_cyls = 1
     rdisk = RDisk(blkdev)
     rdisk.create(blkdev.geo, rdb_cyls=rdb_cyls)
     return rdisk
Exemplo n.º 5
0
 def init_rdisk(self, blkdev):
   opts = KeyValue.parse_key_value_strings(self.opts)
   # number of cylinders for RDB
   if opts.has_key('rdb_cyls'):
     rdb_cyls = int(opts['rdb_cyls'])
   else:
     rdb_cyls = 1
   rdisk = RDisk(blkdev)
   rdisk.create(blkdev.geo, rdb_cyls=rdb_cyls)
   return rdisk
Exemplo n.º 6
0
 def __init__(self, args, opts):
   Command.__init__(self, args, opts, edit=True)
   n = len(self.opts)
   if n == 0:
     print("Usage: repack <src_path> [in_size]")
     self.exit_code = 1
   in_img = self.opts[0]
   in_opts = KeyValue.parse_key_value_strings(self.opts[1:])
   self.repacker = Repacker(in_img, in_opts)
   if not self.repacker.create_in():
     self.exit_code = 2
Exemplo n.º 7
0
 def __init__(self, args, opts):
     Command.__init__(self, args, opts, edit=True)
     n = len(self.opts)
     if n == 0:
         print "Usage: repack <src_path> [in_size]"
         self.exit_code = 1
     in_img = self.opts[0]
     in_opts = KeyValue.parse_key_value_strings(self.opts[1:])
     self.repacker = Repacker(in_img, in_opts)
     if not self.repacker.create_in():
         self.exit_code = 2
Exemplo n.º 8
0
 def handle_rdisk(self, rdisk):
     # arguments
     if len(self.opts) < 1:
         print("Usage: remap secs=<secs> heads=<heads>")
         return None
     opts = KeyValue.parse_key_value_strings(self.opts)
     geo = DiskGeometry()
     c, h, s = rdisk.get_cyls_heads_secs()
     if not geo.setup(opts, cyls=c, heads=h, sectors=s):
         raise ValueError("Can't set new geometry!")
     if geo.cyls != c:
         raise ValueError("Do not change cylinders!")
     print("Remap to", geo.heads, "heads and", geo.secs, "sectors")
     rdisk.remap(geo.heads, geo.secs)
     return 0
Exemplo n.º 9
0
 def handle_rdisk(self, rdisk):
     self.parse_opts()
     valid_flags = FSHeaderDeviceNode.valid_flags
     if len(self.opts) < 1:
         flag_info = ["[%s=<n>]" % x for x in valid_flags]
         flag_info = " ".join(flag_info)
         print(
             "Usage: fsadd <file_name> [dostype=<n|tag>] [version=<n.m>] " +
             flag_info)
         return 1
     else:
         # parse options
         opts = KeyValue.parse_key_value_strings(self.opts)
         # read file data
         file_name = self.opts[0]
         f = open(file_name, "rb")
         data = f.read()
         f.close()
         # get version from binary
         tag = VerTag.find(data)
         ver = None
         if tag != None:
             ver = VerTag.get_version(tag)
         if ver == None:
             ver = (0, 0)
         # overwrite version from options
         if 'version' in opts:
             vstr = opts['version']
             pos = vstr.find('.')
             if pos != -1:
                 ver = (int(vstr[:pos]), int(vstr[pos + 1:]))
         # valid fs flags
         dev_flags = []
         for key in opts:
             if key in valid_flags:
                 dev_flags.append((key, opts[key]))
         # add fs
         version = ver[0] << 16 | ver[1]
         # get dostype
         dostype = self.get_dos_type()
         if rdisk.add_filesystem(data,
                                 dos_type=dostype,
                                 version=version,
                                 dev_flags=dev_flags):
             return 0
         else:
             print("ERROR adding filesystem! (no space in RDB left)")
             return 1
Exemplo n.º 10
0
 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
Exemplo n.º 11
0
 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
Exemplo n.º 12
0
 def init_blkdev(self, file_name):
     # do not overwrite an existing image file
     if os.path.exists(file_name) and not self.args.force:
         raise IOError("Image File already exists: '%s'" % file_name)
     # make sure size is given
     if len(self.opts) < 1:
         print("Usage: create ( size=<n> | chs=<c,h,s> ) [bs=<n>]")
         return None
     # determine disk geometry
     opts = KeyValue.parse_key_value_strings(self.opts)
     geo = DiskGeometry()
     if not geo.setup(opts):
         raise IOError("Can't set geometry of disk: '%s'" % file_name)
     # create new empty image file for geometry
     blkdev = RawBlockDevice(file_name, block_bytes=geo.block_bytes)
     blkdev.create(geo.get_num_blocks())
     blkdev.geo = geo
     return blkdev
Exemplo n.º 13
0
 def init_blkdev(self, file_name):
   # do not overwrite an existing image file
   if os.path.exists(file_name) and not self.args.force:
     raise IOError("Image File already exists: '%s'" % file_name)
   # make sure size is given
   if len(self.opts) < 1:
     print("Usage: create ( size=<n> | chs=<c,h,s> ) [bs=<n>]")
     return None
   # determine disk geometry
   opts = KeyValue.parse_key_value_strings(self.opts)
   geo = DiskGeometry()
   if not geo.setup(opts):
     raise IOError("Can't set geometry of disk: '%s'" % file_name)
   # create new empty image file for geometry
   blkdev = RawBlockDevice(file_name, block_bytes=geo.block_bytes)
   blkdev.create(geo.get_num_blocks())
   blkdev.geo = geo
   return blkdev
Exemplo n.º 14
0
 def handle_rdisk(self, rdisk):
   self.parse_opts()
   valid_flags = FSHeaderDeviceNode.valid_flags
   if len(self.opts) < 1:
     flag_info = map(lambda x : "[%s=<n>]" % x, valid_flags)
     flag_info = " ".join(flag_info)
     print("Usage: fsadd <file_name> [dostype=<n|tag>] [version=<n.m>] " + flag_info)
     return 1
   else:
     # parse options
     opts = KeyValue.parse_key_value_strings(self.opts)
     # read file data
     file_name = self.opts[0]
     f = open(file_name,"rb")
     data = f.read()
     f.close()
     # get version from binary
     tag = VerTag.find(data)
     ver = None
     if tag != None:
       ver = VerTag.get_version(tag)
     if ver == None:
       ver = (0,0)
     # overwrite version from options
     if opts.has_key('version'):
       vstr = opts['version']
       pos = vstr.find('.')
       if pos != -1:
         ver = (int(vstr[:pos]),int(vstr[pos+1:]))
     # valid fs flags
     dev_flags = []
     for key in opts:
       if key in valid_flags:
         dev_flags.append((key,opts[key]))
     # add fs
     version = ver[0] << 16 | ver[1]
     # get dostype
     dostype = self.get_dos_type()
     if rdisk.add_filesystem(data, dos_type=dostype, version=version, dev_flags=dev_flags):
       return 0
     else:
       print("ERROR adding filesystem! (no space in RDB left)")
       return 1
Exemplo n.º 15
0
 def handle_rdisk(self, rdisk):
     if len(self.opts) < 2:
         print("Usage: fsflags <fid> [ clear | key=<val> ... ]")
         return 1
     else:
         fs = rdisk.find_filesystem_by_string(self.opts[0])
         if fs != None:
             opts = KeyValue.parse_key_value_strings(self.opts[1:])
             valid_flags = fs.get_valid_flag_names()
             flags = []
             clear = False
             for o in opts:
                 if o in valid_flags:
                     flags.append((o, opts[o]))
                 elif o == 'clear':
                     clear = True
             fs.set_flags(flags, clear)
             return 0
         else:
             print("ERROR finding filesystem: '%s'" % self.opts[0])
             return 1
Exemplo n.º 16
0
 def handle_rdisk(self, rdisk):
   if len(self.opts) < 2:
     print("Usage: fsflags <fid> [ clear | key=<val> ... ]")
     return 1
   else:
     fs = rdisk.find_filesystem_by_string(self.opts[0])
     if fs != None:
       opts = KeyValue.parse_key_value_strings(self.opts[1:])
       valid_flags = fs.get_valid_flag_names()
       flags = []
       clear = False
       for o in opts:
         if o in valid_flags:
           flags.append((o,opts[o]))
         elif o == 'clear':
           clear = True
       fs.set_flags(flags, clear)
       return 0
     else:
       print("ERROR finding filesystem: '%s'" % self.opts[0])
       return 1
Exemplo n.º 17
0
 def handle_rdisk(self, rdisk):
     # arguments
     if len(self.opts) < 1:
         print("Usage: adjust ( auto [force] | lo=<cyl> hi=<cyl> [phys] )")
         return None
     opts = KeyValue.parse_key_value_strings(self.opts)
     if "auto" in opts:
         # automatic mode
         # get max cyl from image
         total_blocks = self.blkdev.geo.get_num_blocks()
         c, h, s = rdisk.get_cyls_heads_secs()
         num_cyl = total_blocks // (h * s)
         if num_cyl > 65535:
             if "force" not in opts:
                 print("ERROR: cylinder count too high:", num_cyl)
                 return 1
         lo_cyl = None
         hi_cyl = num_cyl - 1
         phys = True
     else:
         # manual mode
         if "lo" in opts:
             lo_cyl = int(opts["lo"])
         else:
             lo_cyl = None
         if "hi" in opts:
             hi_cyl = int(opts["hi"])
         else:
             hi_cyl = None
         if "phys" in opts:
             phys = opts["phys"]
         else:
             phys = False
     # try to resize
     if lo_cyl or hi_cyl:
         rdisk.resize(lo_cyl, hi_cyl, phys)
     else:
         print("ERROR: no adjust options given!")
         return 1
     return 0
Exemplo n.º 18
0
 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
Exemplo n.º 19
0
 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
Exemplo n.º 20
0
 def __init__(self, args, opts):
     Command.__init__(self, args, opts, edit=True)
     self.imager = Imager()
     n = len(self.opts)
     if n == 0:
         print "Usage: pack <in_path> [dos_type] [out_size]"
         self.exit_code = 1
     else:
         self.in_path = self.opts[0]
         blkdev_opts = None
         dos_type = None
         if n > 1:
             # is a dostype given?
             dos_str = opts[1]
             dos_type = DosType.parse_dos_type_str(dos_str)
             if dos_type is not None:
                 begin = 2
             else:
                 begin = 1
             # take remainder as blkdev opts
             blkdev_opts = KeyValue.parse_key_value_strings(opts[begin:])
         self.blkdev_opts = blkdev_opts
         self.dos_type = dos_type
         self.imager.pack_begin(self.in_path)
Exemplo n.º 21
0
 def __init__(self, args, opts):
   Command.__init__(self, args, opts, edit=True)
   self.imager = Imager()
   n = len(self.opts)
   if n == 0:
     print("Usage: pack <in_path> [dos_type] [out_size]")
     self.exit_code = 1
   else:
     self.in_path = self.opts[0]
     blkdev_opts = None
     dos_type = None
     if n > 1:
       # is a dostype given?
       dos_str = opts[1]
       dos_type = DosType.parse_dos_type_str(dos_str)
       if dos_type is not None:
         begin = 2
       else:
         begin = 1
       # take remainder as blkdev opts
       blkdev_opts = KeyValue.parse_key_value_strings(opts[begin:])
     self.blkdev_opts = blkdev_opts
     self.dos_type = dos_type
     self.imager.pack_begin(self.in_path)
Exemplo n.º 22
0
 def parse_opts(self):
   self.popts = KeyValue.parse_key_value_strings(self.opts)
Exemplo n.º 23
0
 def parse_opts(self, rdisk):
   self.popts = KeyValue.parse_key_value_strings(self.opts)
   self.rdisk = rdisk
Exemplo n.º 24
0
 def init_blkdev(self, image_file):
   opts = KeyValue.parse_key_value_strings(self.opts)
   f = BlkDevFactory()
   return f.open(image_file, options=opts, read_only=self.args.read_only)
Exemplo n.º 25
0
 def init_blkdev(self, image_file):
   opts = KeyValue.parse_key_value_strings(self.opts[1:])
   f = BlkDevFactory()
   return f.create(image_file, options=opts, force=self.args.force)
Exemplo n.º 26
0
 def init_blkdev(self, image_file):
     opts = KeyValue.parse_key_value_strings(self.opts[1:])
     f = BlkDevFactory()
     return f.create(image_file, options=opts, force=self.args.force)
Exemplo n.º 27
0
 def init_blkdev(self, image_file):
     opts = KeyValue.parse_key_value_strings(self.opts)
     f = BlkDevFactory()
     return f.open(image_file, options=opts, read_only=self.args.read_only)
Exemplo n.º 28
0
def main():
    a = sys.argv
    n = len(a)
    if n < 3:
        print "Usage: (detect <size|file> [options] | setup <options> | open <file> [options] | create <file> <options>)"
        print """Options:
             size=<size>
             chs=<n>,<n>,<n>
             c=<n> h=<n> s=<n>
             algo=1|2
             """
        return 1
    else:
        cmd = a[1]
        # detect disk geometry from given image file
        if cmd == 'detect':
            if os.path.exists(a[2]):
                # its a file
                size = os.path.getsize(a[2])
            else:
                # parse size string
                size = ByteSize.parse_byte_size_str(a[2])
            if size == None:
                print "Invalid size!"
            else:
                d = DiskGeometry()
                opts = None
                if n > 3:
                    opts = KeyValue.parse_key_value_strings(a[3:])
                print "size:  ", size
                print "opts:  ", opts
                size = d.detect(size, opts)
                if size != None:
                    print "geo:   ", d
                else:
                    print "FAILED"
        # setup a new disk geometry from options
        elif cmd == 'setup':
            d = DiskGeometry()
            opts = KeyValue.parse_key_value_strings(a[2:])
            print "opts:  ", opts
            size = d.setup(opts)
            if size != None:
                print "setup: ", size, ByteSize.to_byte_size_str(size)
                print "geo:   ", d
            else:
                print "FAILED"
        # open a blkdev and detect geometry
        elif cmd == 'open':
            opts = None
            if n > 3:
                opts = KeyValue.parse_key_value_strings(a[3:])
            print "opts:   ", opts
            f = BlkDevFactory()
            blkdev = f.open(a[2], options=opts)
            if blkdev != None:
                print "blkdev: ", blkdev.__class__.__name__
                print "geo:    ", blkdev.get_geometry()
                blkdev.close()
            else:
                print "FAILED"
        # create a new blkdev with setup geometry
        elif cmd == 'create':
            opts = KeyValue.parse_key_value_strings(a[3:])
            print "opts:   ", opts
            f = BlkDevFactory()
            blkdev = f.create(a[2], options=opts)
            if blkdev != None:
                print "blkdev: ", blkdev.__class__.__name__
                print "geo:    ", blkdev.get_geometry()
                blkdev.close()
            else:
                print "FAILED"
        return 0
Exemplo n.º 29
0
 def parse_opts(self, rdisk):
     self.popts = KeyValue.parse_key_value_strings(self.opts)
     self.rdisk = rdisk
Exemplo n.º 30
0
 def parse_opts(self):
     self.popts = KeyValue.parse_key_value_strings(self.opts)
Exemplo n.º 31
0
def main(args=None):
    if not args:
        a = sys.argv
    else:
        a = args
    n = len(a)
    if n < 3:
        print(
            "Usage: (detect <size|file> [options] | setup <options> | open <file> [options] | create <file> <options>)"
        )
        print("""Options:
             size=<size>
             chs=<n>,<n>,<n>
             c=<n> h=<n> s=<n>
             algo=1|2
             """)
        return 1
    else:
        cmd = a[1]
        # detect disk geometry from given image file
        if cmd == "detect":
            if os.path.exists(a[2]):
                # its a file
                size = os.path.getsize(a[2])
            else:
                # parse size string
                size = ByteSize.parse_byte_size_str(a[2])
            if size == None:
                print("Invalid size!")
            else:
                d = DiskGeometry()
                opts = None
                if n > 3:
                    opts = KeyValue.parse_key_value_strings(a[3:])
                print("size:  ", size)
                print("opts:  ", opts)
                size = d.detect(size, opts)
                if size != None:
                    print("geo:   ", d)
                else:
                    print("FAILED")
        # setup a new disk geometry from options
        elif cmd == "setup":
            d = DiskGeometry()
            opts = KeyValue.parse_key_value_strings(a[2:])
            print("opts:  ", opts)
            size = d.setup(opts)
            if size != None:
                print("setup: ", size, ByteSize.to_byte_size_str(size))
                print("geo:   ", d)
            else:
                print("FAILED")
        # open a blkdev and detect geometry
        elif cmd == "open":
            opts = None
            if n > 3:
                opts = KeyValue.parse_key_value_strings(a[3:])
            print("opts:   ", opts)
            f = BlkDevFactory()
            blkdev = f.open(a[2], options=opts)
            if blkdev != None:
                print("blkdev: ", blkdev.__class__.__name__)
                print("geo:    ", blkdev.get_geometry())
                blkdev.close()
            else:
                print("FAILED")
        # create a new blkdev with setup geometry
        elif cmd == "create":
            opts = KeyValue.parse_key_value_strings(a[3:])
            print("opts:   ", opts)
            f = BlkDevFactory()
            blkdev = f.create(a[2], options=opts)
            if blkdev != None:
                print("blkdev: ", blkdev.__class__.__name__)
                print("geo:    ", blkdev.get_geometry())
                blkdev.close()
            else:
                print("FAILED")
        return 0
Exemplo n.º 32
0
def main():
  a = sys.argv
  n = len(a)
  if n < 3:
    print "Usage: (detect <size|file> [options] | setup <options> | open <file> [options] | create <file> <options>)"
    print """Options:
             size=<size>
             chs=<n>,<n>,<n>
             c=<n> h=<n> s=<n>
             algo=1|2
             """
    return 1
  else:
    cmd = a[1]
    # detect disk geometry from given image file
    if cmd == 'detect':
      if os.path.exists(a[2]):
        # its a file
        size = os.path.getsize(a[2])
      else:
        # parse size string
        size = ByteSize.parse_byte_size_str(a[2])
      if size == None:
        print "Invalid size!"
      else:
        d = DiskGeometry()
        opts = None
        if n > 3:
          opts = KeyValue.parse_key_value_strings(a[3:])
        print "size:  ",size
        print "opts:  ",opts
        size = d.detect(size, opts)
        if size != None:
          print "geo:   ",d
        else:
          print "FAILED"
    # setup a new disk geometry from options
    elif cmd == 'setup' :
      d = DiskGeometry()
      opts = KeyValue.parse_key_value_strings(a[2:])
      print "opts:  ",opts
      size = d.setup(opts)
      if size != None:
        print "setup: ",size,ByteSize.to_byte_size_str(size)
        print "geo:   ",d
      else:
        print "FAILED"
    # open a blkdev and detect geometry
    elif cmd == 'open':
      opts = None
      if n > 3:
        opts = KeyValue.parse_key_value_strings(a[3:])
      print "opts:   ",opts
      f = BlkDevFactory()
      blkdev = f.open(a[2], options=opts)
      if blkdev != None:
        print "blkdev: ",blkdev.__class__.__name__
        print "geo:    ",blkdev.get_geometry()
        blkdev.close()
      else:
        print "FAILED"
    # create a new blkdev with setup geometry
    elif cmd == 'create':
      opts = KeyValue.parse_key_value_strings(a[3:])
      print "opts:   ",opts
      f = BlkDevFactory()
      blkdev = f.create(a[2], options=opts)
      if blkdev != None:
        print "blkdev: ",blkdev.__class__.__name__
        print "geo:    ",blkdev.get_geometry()
        blkdev.close()
      else:
        print "FAILED"
    return 0