Ejemplo n.º 1
0
/**
 *  initialize the dot(.) and dotdot(..) dir entries for new directory
 * @param inode                inode for itself
 * @return             return 0 on success, EIO on failure
 *
 * inode must have start cluster of itself and start cluster of parent dir
 */
int init_new_dir(struct inode *inode)
{
       struct buffer_head *bh = NULL;
               struct rfs_dir_entry *dot_ep = NULL;
               struct rfs_dir_entry *dotdot_ep = NULL;
       unsigned char dummy = 0;
       int err = 0;

       /* initialize .(itself) and ..(parent) */
       dot_ep = get_entry(inode, 0, &bh);
       if (IS_ERR(dot_ep)) {
               brelse(bh);
               return -EIO;
       }

       dotdot_ep = (struct rfs_dir_entry *) (bh->b_data + DENTRY_SIZE);

       init_dir_entry(inode, dot_ep, TYPE_DIR, 
                       RFS_I(inode)->start_clu, DOT, &dummy);
       init_dir_entry(inode, dotdot_ep, TYPE_DIR, 
                       RFS_I(inode)->p_start_clu, DOTDOT, &dummy);

       rfs_mark_buffer_dirty(bh, inode->i_sb);
       brelse(bh);

       return err;
}
Ejemplo n.º 2
0
//check for file in cache, if found size will be updated, if not found
//and this is a dir, a new dir cache entry is created
void update_dir_cache(const char* path, off_t size, int isdir, int islink)
{
  debugf(DBG_LEVEL_EXTALL, KCYN "update_dir_cache(%s)", path);
  pthread_mutex_lock(&dcachemut);
  dir_cache* cw;
  dir_entry* de;
  char dir[MAX_PATH_SIZE];
  dir_for(path, dir);
  for (cw = dcache; cw; cw = cw->next)
  {
    if (!strcmp(cw->path, dir))
    {
      for (de = cw->entries; de; de = de->next)
      {
        if (!strcmp(de->full_name, path))
        {
          de->size = size;
          pthread_mutex_unlock(&dcachemut);
          debugf(DBG_LEVEL_EXTALL, "exit 0: update_dir_cache(%s)", path);
          return;
        }
      }
      de = init_dir_entry();
      de->size = size;
      de->isdir = isdir;
      de->islink = islink;
      de->name = strdup(&path[strlen(cw->path) + 1]);
      de->full_name = strdup(path);
      //fixed: the conditions below were mixed up dir -> link?
      if (islink)
        de->content_type = strdup("application/link");
      if (isdir)
        de->content_type = strdup("application/directory");
      else
        de->content_type = strdup("application/octet-stream");
      de->next = cw->entries;
      cw->entries = de;
      if (isdir)
        new_cache(path);
      break;
    }
  }
  debugf(DBG_LEVEL_EXTALL, "exit 1: update_dir_cache(%s)", path);
  pthread_mutex_unlock(&dcachemut);
}