def blocks_create_old(self, anon_blk): # create file header block fhb = FileHeaderBlock(self.blkdev, anon_blk.blk_num, self.volume.is_longname) fhb.set(anon_blk.data) if not fhb.valid: raise FSError(INVALID_FILE_HEADER_BLOCK, block=anon_blk) self.set_block(fhb) # retrieve data blocks and size from header self.data_blk_nums = fhb.data_blocks[:] self.data_size = fhb.byte_size # scan for extension blocks next_ext = self.block.extension while next_ext != 0: ext_blk = FileListBlock(self.block.blkdev, next_ext) ext_blk.read() if not ext_blk.valid: raise FSError(INVALID_FILE_LIST_BLOCK, block=ext_blk) self.ext_blk_nums.append(next_ext) self.ext_blks.append(ext_blk) self.data_blk_nums += ext_blk.data_blocks next_ext = ext_blk.extension # now check number of ext blocks self.num_ext_blks = self.calc_number_of_list_blks() my_num_ext_blks = len(self.ext_blks) if my_num_ext_blks != self.num_ext_blks: raise FSError(FILE_LIST_BLOCK_COUNT_MISMATCH, node=self, extra="got=%d want=%d" % (my_num_ext_blks, self.num_ext_blks)) # now check number of data blocks self.num_data_blks = self.calc_number_of_data_blks() my_num_data_blks = len(self.data_blk_nums) if my_num_data_blks != self.num_data_blks: raise FSError(FILE_DATA_BLOCK_COUNT_MISMATCH, node=self, extra="got=%d want=%d" % (my_num_data_blks, self.num_data_blks)) # calc number of total blocks occupied by this file self.total_blks = 1 + my_num_ext_blks + my_num_data_blks if self.block.comment_block_id != 0: self.total_blks += 1 return fhb
def blocks_create_old(self, anon_blk): # create file header block fhb = FileHeaderBlock(self.blkdev, anon_blk.blk_num) fhb.set(anon_blk.data) if not fhb.valid: raise FSError(INVALID_FILE_HEADER_BLOCK, block=anon_blk) self.set_block(fhb) # retrieve data blocks and size from header self.data_blk_nums = fhb.data_blocks[:] self.data_size = fhb.byte_size # scan for extension blocks next_ext = self.block.extension while next_ext != 0: ext_blk = FileListBlock(self.block.blkdev, next_ext) ext_blk.read() if not ext_blk.valid: raise FSError(INVALID_FILE_LIST_BLOCK, block=ext_blk) self.ext_blk_nums.append(next_ext) self.ext_blks.append(ext_blk) self.data_blk_nums += ext_blk.data_blocks next_ext = ext_blk.extension # now check number of ext blocks self.num_ext_blks = self.calc_number_of_list_blks() my_num_ext_blks = len(self.ext_blks) if my_num_ext_blks != self.num_ext_blks: raise FSError(FILE_LIST_BLOCK_COUNT_MISMATCH, node=self, extra="got=%d want=%d" % (my_num_ext_blks, self.num_ext_blks)) # now check number of data blocks self.num_data_blks = self.calc_number_of_data_blks() my_num_data_blks = len(self.data_blk_nums) if my_num_data_blks != self.num_data_blks: raise FSError(FILE_DATA_BLOCK_COUNT_MISMATCH, node=self, extra="got=%d want=%d" % (my_num_data_blks, self.num_data_blks)) # calc number of total blocks occupied by this file self.total_blks = 1 + my_num_ext_blks + my_num_data_blks return fhb
def blocks_create_new(self, free_blks, name, hash_chain_blk, parent_blk, meta_info): # assign block numbers fhb_num = free_blks[0] # ... for ext self.ext_blk_nums = [] for i in xrange(self.num_ext_blks): self.ext_blk_nums.append(free_blks[1+i]) # ... for data off = 1 + self.num_ext_blks self.data_blk_nums = [] for i in xrange(self.num_data_blks): self.data_blk_nums.append(free_blks[off]) off += 1 ppb = self.volume.blkdev.block_longs - 56 # data pointer per block # create file header block fhb = FileHeaderBlock(self.blkdev, fhb_num) byte_size = len(self.data) if self.num_data_blks > ppb: hdr_blks = self.data_blk_nums[0:ppb] hdr_ext = self.ext_blk_nums[0] else: hdr_blks = self.data_blk_nums hdr_ext = 0 fhb.create(parent_blk, name.get_ami_str(), hdr_blks, hdr_ext, byte_size, meta_info.get_protect(), meta_info.get_comment_ami_str(), meta_info.get_mod_ts(), hash_chain_blk) fhb.write() self.set_block(fhb) # create file list (=ext) blocks ext_off = ppb for i in xrange(self.num_ext_blks): flb = FileListBlock(self.blkdev, self.ext_blk_nums[i]) if i == self.num_ext_blks - 1: ext_blk = 0 blks = self.data_blk_nums[ext_off:] else: ext_blk = self.ext_blk_nums[i+1] blks = self.data_blk_nums[ext_off:ext_off+ppb] flb.create(fhb_num, blks, ext_blk) flb.write() self.ext_blks.append(flb) ext_off += ppb # write data blocks self.write() self.valid = True return fhb_num