Exemple #1
0
    def create(self):
        # create data and preset with 0xff
        self.bitmap_data = ctypes.create_string_buffer(
            self.bitmap_all_blk_bytes)
        for i in xrange(self.bitmap_all_blk_bytes):
            self.bitmap_data[i] = chr(0xff)

        # clear bit for root block
        blk_pos = self.root_blk.blk_num
        self.clr_bit(blk_pos)
        blk_pos += 1

        # create ext blocks
        for i in xrange(self.num_ext):
            bm_ext = BitmapExtBlock(self.blkdev, blk_pos)
            bm_ext.create()
            self.clr_bit(blk_pos)
            blk_pos += 1
            self.ext_blks.append(bm_ext)

        # create bitmap blocks
        for i in xrange(self.bitmap_num_blks):
            bm = BitmapBlock(self.blkdev, blk_pos)
            bm.create()
            self.clr_bit(blk_pos)
            blk_pos += 1
            self.bitmap_blks.append(bm)

        # set pointers to ext blocks
        if self.num_ext > 0:
            self.root_blk.bitmap_ext_blk = self.ext_blks[0].blk_num
            for i in xrange(self.num_ext) - 1:
                bm_ext = self.ext_blks[i]
                bm_ext_next = self.ext_blks[i + 1]
                bm_ext.bitmap_ext_blk = bm_ext_next.blk_num

        # set pointers to bitmap blocks
        cur_ext_index = 0
        cur_ext_pos = 0
        for i in xrange(self.bitmap_num_blks):
            blk_num = self.bitmap_blks[i].blk_num
            if i < self.num_blks_in_root:
                # pointers in root block
                self.root_blk.bitmap_ptrs[i] = blk_num
            else:
                # pointers in ext block
                self.ext_blks[cur_ext_index].bitmap_ptrs[cur_ext_pos] = blk_num
                cur_ext_pos += 1
                if cur_ext_pos == self.num_blks_in_ext:
                    cur_ext_pos = 0
                    cur_ext_index += 1

        self.valid = True
Exemple #2
0
  def create(self):
    # create data and preset with 0xff
    self.bitmap_data = ctypes.create_string_buffer(self.bitmap_all_blk_bytes)
    for i in xrange(self.bitmap_all_blk_bytes):
      self.bitmap_data[i] = chr(0xff)

    # clear bit for root block
    blk_pos = self.root_blk.blk_num
    self.clr_bit(blk_pos)
    blk_pos += 1
    
    # create ext blocks
    for i in xrange(self.num_ext):
      bm_ext = BitmapExtBlock(self.blkdev, blk_pos)
      bm_ext.create()
      self.clr_bit(blk_pos)
      blk_pos += 1
      self.ext_blks.append(bm_ext)
      
    # create bitmap blocks
    for i in xrange(self.bitmap_num_blks):
      bm = BitmapBlock(self.blkdev, blk_pos)
      bm.create()
      self.clr_bit(blk_pos)
      blk_pos += 1
      self.bitmap_blks.append(bm)
      
    # set pointers to ext blocks
    if self.num_ext > 0:
      self.root_blk.bitmap_ext_blk = self.ext_blks[0].blk_num
      for i in xrange(self.num_ext)-1:
        bm_ext = self.ext_blks[i]
        bm_ext_next = self.ext_blks[i+1]
        bm_ext.bitmap_ext_blk = bm_ext_next.blk_num
    
    # set pointers to bitmap blocks
    cur_ext_index = 0
    cur_ext_pos = 0
    for i in xrange(self.bitmap_num_blks):
      blk_num = self.bitmap_blks[i].blk_num
      if i < self.num_blks_in_root:
        # pointers in root block
        self.root_blk.bitmap_ptrs[i] = blk_num
      else:
        # pointers in ext block
        self.ext_blks[cur_ext_index].bitmap_ptrs[cur_ext_pos] = blk_num
        cur_ext_pos += 1
        if cur_ext_pos == self.num_blks_in_ext:
          cur_ext_pos = 0
          cur_ext_index += 1
    
    self.valid = True
Exemple #3
0
    def read(self):
        self.bitmap_blks = []
        bitmap_data = ""

        # get bitmap blocks from root block
        blocks = self.root_blk.bitmap_ptrs
        for blk in blocks:
            if blk == 0:
                break
            bm = BitmapBlock(self.blkdev, blk)
            bm.read()
            if not bm.valid:
                raise FSError(INVALID_BITMAP_BLOCK, block=bm)
            self.bitmap_blks.append(bm)
            bitmap_data += bm.get_bitmap_data()

        # now check extended bitmap blocks
        ext_blk = self.root_blk.bitmap_ext_blk
        while ext_blk != 0:
            bm_ext = BitmapExtBlock(self.blkdev, ext_blk)
            bm_ext.read()
            self.ext_blks.append(bm_ext)
            blocks = bm_ext.bitmap_ptrs
            for blk in blocks:
                if blk == 0:
                    break
                bm = BitmapBlock(self.blkdev, blk)
                bm.read()
                if not bm.valid:
                    raise FSError(INVALID_BITMAP_BLOCK, block=bm)
                bitmap_data += bm.get_bitmap_data()
                self.bitmap_blks.append(bm)
            ext_blk = bm_ext.bitmap_ext_blk

        # check bitmap data
        num_bm_blks = len(self.bitmap_blks)
        num_bytes = self.bitmap_blk_bytes * num_bm_blks
        if num_bytes != len(bitmap_data):
            raise FSError(BITMAP_SIZE_MISMATCH,
                          node=self,
                          extra="got=%d want=%d" %
                          (len(bitmap_data), num_bytes))
        if num_bm_blks != self.bitmap_num_blks:
            raise FSError(BITMAP_BLOCK_COUNT_MISMATCH,
                          node=self,
                          extra="got=%d want=%d" %
                          (self.bitmap_num_blks, num_bm_blks))

        # create a modyfiable bitmap
        self.bitmap_data = ctypes.create_string_buffer(bitmap_data)
        self.valid = True
  def read(self):
    self.bitmap_blks = []
    bitmap_data = ""
    
    # get bitmap blocks from root block
    blocks = self.root_blk.bitmap_ptrs
    for blk in blocks:
      if blk == 0:
        break
      bm = BitmapBlock(self.blkdev, blk)
      bm.read()
      if not bm.valid:
        raise FSError(INVALID_BITMAP_BLOCK, block=bm)
      self.bitmap_blks.append(bm)
      bitmap_data += bm.get_bitmap_data()
      
    # now check extended bitmap blocks
    ext_blk = self.root_blk.bitmap_ext_blk
    while ext_blk != 0:
      bm_ext = BitmapExtBlock(self.blkdev, ext_blk)
      bm_ext.read()
      self.ext_blks.append(bm_ext)
      blocks = bm_ext.bitmap_ptrs
      for blk in blocks:
        if blk == 0:
          break
        bm = BitmapBlock(self.blkdev, blk)
        bm.read()
        if not bm.valid:
          raise FSError(INVALID_BITMAP_BLOCK, block=bm)
        bitmap_data += bm.get_bitmap_data()
        self.bitmap_blks.append(bm)
      ext_blk = bm_ext.bitmap_ext_blk

    # check bitmap data
    num_bm_blks = len(self.bitmap_blks)
    num_bytes = self.bitmap_blk_bytes * num_bm_blks
    if num_bytes != len(bitmap_data):
      raise FSError(BITMAP_SIZE_MISMATCH, node=self, extra="got=%d want=%d" % (len(bitmap_data), num_bytes))
    if num_bm_blks != self.bitmap_num_blks:
      raise FSError(BITMAP_BLOCK_COUNT_MISMATCH, node=self, extra="got=%d want=%d" % (self.bitmap_num_blks, num_bm_blks))

    # create a modyfiable bitmap
    self.bitmap_data = ctypes.create_string_buffer(bitmap_data)
    self.valid = True