Exemple #1
0
int dopen(const char *name)
{
	iop_file_t *f = get_new_file();
	char *filename;
	int res;

	if (!f)
		return -EMFILE;

	if ((filename = find_iop_device(name, &f->unit, &f->device)) == (char *)-1)
	{
        f->device = NULL;
		return -ENODEV;
	}

	f->mode = 8;	/* Indicates a directory.  */
	if ((res = f->device->ops->dopen(f, filename)) >= 0)
		res = (int)(f - file_table);
	else
	{
        f->mode = 0;
        f->device = NULL;
	}

	return res;
}
Exemple #2
0
int open(const char *name, int flags, int mode)
{
	iop_file_t *f = get_new_file();
	char *filename;
	int res = -ENOSYS;

	if (!f)
	{
		return -EMFILE;
	}

	if ((filename = find_iop_device(name, &f->unit, &f->device)) == (char *)-1)
	{
        f->device = NULL;
		return -ENODEV;
	}

	f->mode = flags;
	if ((res = f->device->ops->open(f, filename, flags, mode)) >= 0)
	{
		res = (int)(f - file_table);
	}
	else
	{
        f->mode = 0;
        f->device = NULL;
	}

	return res;
}
static void get_first_unit(file_list_dir_t *p_dir, file_list_t *p_list)
{
  if (p_dir->ready_cnt == 0 && p_dir->all_ready == FALSE)
  {
    p_dir->p_priv_list
      = mtos_malloc(sizeof(priv_list_t) + p_dir->unit_cnt * sizeof(media_file_t));
    CHECK_FAIL_RET_VOID(p_dir->p_priv_list != NULL);
    p_dir->p_priv_list->p_file = (media_file_t *)((u32)p_dir->p_priv_list + sizeof(priv_list_t));
    p_dir->p_priv_list->p_next = NULL;

    p_dir->ready_cnt = get_new_file(p_dir, p_dir->p_priv_list->p_file);
    p_dir->p_priv_list->index = 0;
    if (p_dir->ready_cnt < p_dir->unit_cnt)
    {
      p_dir->all_ready = TRUE;

      if (p_dir->ready_cnt == 0)
      {
        mtos_free(p_dir->p_priv_list);
        p_dir->p_priv_list = NULL;
      }
    }
  }

  if (p_dir->ready_cnt == 0)
  {
    p_list->p_file = NULL;
    p_list->file_count = 0;
    return ;
  }

  p_dir->cur_index = 0;
  p_list->p_file = p_dir->p_priv_list->p_file;
  p_list->file_count
    = (p_dir->ready_cnt < p_dir->unit_cnt ? p_dir->ready_cnt : p_dir->unit_cnt);

}
static void get_last_unit(file_list_dir_t *p_dir, file_list_t *p_list)
{
  priv_list_t *p_priv_list = NULL;
  u32 file_cnt = 0;
  u16 last_idx = 0;

  if (p_dir->ready_cnt == 0)
  {
    p_list->p_file = NULL;
    p_list->file_count = 0;
    return ;
  }

  last_idx = (p_dir->ready_cnt - 1) / p_dir->unit_cnt;
  p_priv_list = p_dir->p_priv_list;
  while (p_priv_list != NULL)
  {
    if (last_idx == p_priv_list->index)
    {
      if (p_dir->all_ready == TRUE)
      {
        p_dir->cur_index = last_idx;
        p_list->p_file = p_priv_list->p_file;
        file_cnt = p_dir->cur_index * p_dir->unit_cnt;
        file_cnt = p_dir->ready_cnt - file_cnt;
        p_list->file_count = (file_cnt < p_dir->unit_cnt ? file_cnt : p_dir->unit_cnt);
        return ;
      }
      else
      {
        break;
      }
    }

    p_priv_list = p_priv_list->p_next;
  }

  while (p_dir->all_ready == FALSE)
  {
    p_priv_list->p_next
      = mtos_malloc(sizeof(priv_list_t) + p_dir->unit_cnt * sizeof(media_file_t));
    CHECK_FAIL_RET_VOID(p_priv_list->p_next != NULL);
    p_priv_list->p_next->p_file = (media_file_t *)(p_priv_list->p_next + sizeof(priv_list_t));

    file_cnt = get_new_file(p_dir, p_priv_list->p_next->p_file);
    if (file_cnt < p_dir->unit_cnt)
    {
      p_dir->all_ready = TRUE;
      if (file_cnt > 0)
      {
        p_priv_list = p_priv_list->p_next;
        p_priv_list->index = p_dir->cur_index + 1;
        p_priv_list->p_next = NULL;
        p_list->p_file = p_priv_list->p_file;
        p_list->file_count = file_cnt;
      }
      else
      {
        p_list->p_file = p_priv_list->p_file;
        p_list->file_count = p_dir->unit_cnt;
        mtos_free(p_priv_list->p_next);
        p_priv_list->p_next = NULL;
      }
      return ;
    }
    else
    {
      p_priv_list = p_priv_list->p_next;
      p_priv_list->index = p_dir->cur_index + 1;
      p_priv_list->p_next = NULL;
    }
  }

}