Beispiel #1
0
  def _create_node(self, node, name, meta_info, update_ts=True):
    self.ensure_entries()
    
    # make sure a default meta_info is available
    if meta_info == None:
      meta_info = MetaInfo()
      meta_info.set_current_as_mod_time()
      meta_info.set_default_protect()
    # check file name
    fn = FileName(name, is_intl=self.volume.is_intl)
    if not fn.is_valid():
      raise FSError(INVALID_FILE_NAME, file_name=name, node=self)
    # does already exist an entry in this dir with this name?
    if self.has_name(fn):
      raise FSError(NAME_ALREADY_EXISTS, file_name=name, node=self)
    # calc hash index of name
    fn_hash = fn.hash()
    hash_chain = self.name_hash[fn_hash]
    if len(hash_chain) == 0:
      hash_chain_blk = 0
    else:
      hash_chain_blk = hash_chain[0].block.blk_num
      
    # return the number of blocks required to create this node
    num_blks = node.blocks_get_create_num()
    
    # try to find free blocks
    free_blks = self.volume.bitmap.alloc_n(num_blks)
    if free_blks == None:
      raise FSError(NO_FREE_BLOCKS, node=self, file_name=name, extra="want %d" % num_blks)
      
    # now create the blocks for this node
    new_blk = node.blocks_create_new(free_blks, name, hash_chain_blk, self.block.blk_num, meta_info)

    # dircache: create record for this node
    if self.volume.is_dircache:
      ok = self._dircache_add_entry(name, meta_info, new_blk, node.get_size(), update_myself=False)
      if not ok:
        self.delete()
        raise FSError(NO_FREE_BLOCKS, node=self, file_name=name, extra="want dcache")

    # update my dir
    self.block.hash_table[fn_hash] = new_blk 
    self.block.write()
    
    # add node
    self.name_hash[fn_hash].insert(0,node)
    self.entries.append(node)
    
    # update time stamps
    if update_ts:
      self.update_dir_mod_time()
      self.volume.update_disk_time()
Beispiel #2
0
 def update_dir_mod_time(self):
   mi = MetaInfo()
   mi.set_current_as_mod_time()
   self.change_meta_info(mi)