当前位置: 首页>>代码示例>>C++>>正文


C++ dir_close函数代码示例

本文整理汇总了C++中dir_close函数的典型用法代码示例。如果您正苦于以下问题:C++ dir_close函数的具体用法?C++ dir_close怎么用?C++ dir_close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了dir_close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: calloc

static BD_DIR_H *_combine_dirs(BD_DIR_H *ovl, BD_DIR_H *rom)
{
    BD_DIR_H *dp = calloc(1, sizeof(BD_DIR_H));
    BD_DIRENT entry;

    if (dp) {
        dp->read     = _comb_dir_read;
        dp->close    = _comb_dir_close;
        dp->internal = calloc(1, sizeof(COMB_DIR));
        if (!dp->internal) {
            X_FREE(dp);
            goto out;
        }

        while (!dir_read(ovl, &entry)) {
            _comb_dir_append(dp, &entry);
        }
        while (!dir_read(rom, &entry)) {
            _comb_dir_append(dp, &entry);
        }
    }

 out:
    dir_close(ovl);
    dir_close(rom);

    return dp;
}
开发者ID:Paxxi,项目名称:libbluray,代码行数:28,代码来源:disc.c

示例2: filesys_create

/* Creates a file named NAME with the given INITIAL_SIZE.
   Returns true if successful, false otherwise.
   Fails if a file named NAME already exists,
   or if internal memory allocation fails. */
bool
filesys_create (const char *name, off_t initial_size, enum file_type type) 
{
  block_sector_t inode_sector = 0;

  char * parse = parse_filename (name); 
  //get the correct dir

  struct dir *dir = dir_lookup_rec (parse);

  bool success = (dir != NULL
                  && free_map_allocate (1, &inode_sector)
                  && inode_create (inode_sector, initial_size, type)
                  && dir_add (dir, parse, inode_sector));

  if (!success && inode_sector != 0) 
    free_map_release (inode_sector, 1);
  if( success == true && type == FILE_DIR ) {
	//we want to add . and .. as well if it is a dir
		//open the created directory
		struct file * created = filesys_open(parse);
		struct dir * mydir = dir_open(file_get_inode (created));
		//add . to it
		dir_add (mydir, ".", inode_sector);
		struct inode * parent = dir_get_inode (dir);
		block_sector_t inode_sector_parent = inode_id(parent);
		//add .. to it
		dir_add (mydir, "..", inode_sector_parent);
		dir_close(mydir);
		file_close(created);
  }
  dir_close (dir);

  return success;
}
开发者ID:c22dunbar,项目名称:sven-pintos-code,代码行数:39,代码来源:filesys.c

示例3: filesys_cd

bool filesys_cd (const char* dir)
{
  bool result = false;
  char* name_;
  if (strlen(dir) == 0) {
    return false;
  } else {
    struct dir* dir_ = filesys_get_dir(dir);
    name_ = filesys_get_name(dir);
    struct inode* inode = NULL;
    bool isdir = false;

    if (strcmp(name_, "") == 0) {
      if (thread_current()->cur_dir) 
        dir_close(thread_current()->cur_dir);
      thread_current()->cur_dir = dir_;
      result = true;
    } else if (dir_lookup(dir_, name_, &inode, &isdir) ==NULL ||
               isdir == NULL) {
      dir_close(dir_);
      result = false;
    } else if (isdir != NULL){
      if (thread_current()->cur_dir)
        dir_close(thread_current()->cur_dir);
      thread_current()->cur_dir = dir_open(inode);
      dir_close(dir_);
      result = true;
    }
  }
  free(name_);
  return result;
}
开发者ID:gypintos,项目名称:np4,代码行数:32,代码来源:filesys.c

示例4: filesys_get_dir

static struct dir* filesys_get_dir (const char* path)
{
  struct dir* dir;
  int len = strlen(path);
  char *p = (char *)malloc(sizeof(char) * (len + 1));
  memcpy(p, path, len);
  p[len]='\0';

  bool openRoot = p[0]=='/' || thread_current ()->cur_dir == NULL;
  dir = openRoot ? dir_open_root() : dir_reopen(thread_current()->cur_dir);

  char *save_ptr;
  char *token = strtok_r(p, "/", &save_ptr);
  char *next_token = token!=NULL ? strtok_r(NULL, "/", &save_ptr): NULL;
  struct inode *inode;
  bool isdir;

  while (next_token!=NULL){
    if (dir_lookup(dir, token, &inode, &isdir) == NULL) return NULL;
    dir_close(dir);
    dir = dir_open(inode);
    if (isdir == false){
      dir_close(dir);
      return NULL;
    }
    token = next_token;
    next_token = strtok_r(NULL, "/", &save_ptr);
  }
  return dir;

}
开发者ID:gypintos,项目名称:np4,代码行数:31,代码来源:filesys.c

示例5: filesys_open

/* Opens the file with the given NAME.
   Returns the new file if successful or a null pointer
   otherwise.
   Fails if no file named NAME exists,
   or if an internal memory allocation fails. */
struct file *
filesys_open (const char *name)
{
  struct dir *dir;
  struct inode *inode = NULL;
  char parsed_name[NAME_MAX + 1];
  if (*name == NULL)
    {
      return NULL;
    }

  bool success = parse_path (name, &dir, parsed_name);
  if ((strlen (parsed_name) > NAME_MAX))
    {
      dir_close (dir);
      return NULL;
    }

  if (success)
  {
    if (dir != NULL)
       dir_lookup (dir, parsed_name, &inode);
    dir_close (dir);
  }
  struct file *result = file_open (inode);
  return result;
}
开发者ID:jackykschou,项目名称:pintos,代码行数:32,代码来源:filesys.c

示例6: filesys_chdir

bool filesys_chdir (const char* name)
{
  struct dir* dir = containing_dir(name);
  char* file_name = get_name(name);
  struct inode *inode = NULL;

  if (dir != NULL){
      if (strcmp(file_name, "..") == 0){
        //Check parent
        if (!dir_parent(dir, &inode)){
            free(file_name);
            return false;
          }
      }
      else if ((strlen(file_name) == 0 && (dir_is_root(dir))) || (strcmp(file_name, ".") == 0)){
        thread_current()->cur_dir = dir;
        free(file_name);
        return true;
      }else{
        dir_lookup (dir, file_name, &inode);
      }
  }

  dir_close (dir);
  free(file_name);

  dir = dir_open(inode);
  if (dir)
    {
      dir_close(thread_current()->cur_dir);
      thread_current()->cur_dir = dir;
      return true;
    }
  return false;
}
开发者ID:liyu1390,项目名称:CS162_group,代码行数:35,代码来源:filesys.c

示例7: filesys_remove

/* Deletes the file named NAME.
   Returns true if successful, false on failure.
   Fails if no file named NAME exists,
   or if an internal memory allocation fails. */
bool
filesys_remove (const char *name)
{
    char leaf_name[NAME_MAX + 1];
    if (!dir_get_leaf_name (name, leaf_name))
        return false;

    struct dir *parent_dir = dir_get_parent_dir (name);

    if (parent_dir == NULL)
        return false;

    struct inode *inode;
    if (!dir_lookup (parent_dir, leaf_name, &inode))
    {
        dir_close (parent_dir);
        return false;
    }

    bool success;
    if (!inode_is_dir(inode)) // if is file
        success = dir_remove (parent_dir, leaf_name);
    else
    {
        if (dir_is_empty (inode))
        {
            success = dir_remove (parent_dir, leaf_name);
        }
        else
            success = false;
    }

    dir_close (parent_dir);
    return success;
}
开发者ID:rahulabc,项目名称:jawpintos,代码行数:39,代码来源:filesys.c

示例8: filesys_open

/* Opens the file with the given NAME.
   Returns the new file if successful or a null pointer
   otherwise.
   Fails if no file named NAME exists,
   or if an internal memory allocation fails. */
struct file *
filesys_open (const char *name)
{
    if (strnlen (name, FULLPATH_MAX_LEN) == 0)
        return NULL;

    if (strcmp (".", name) == 0)
    {
        block_sector_t cwd = thread_current ()->cwd_sector;
        struct inode *curr = NULL;
        curr = inode_open (cwd);

        struct dir *p;
        p = dir_open (inode_open (curr->data.parent_dir_sector));

        struct dir_entry e;
        size_t ofs;

        ASSERT (p != NULL);

        for (ofs = 0;
                inode_read_at (p->inode, &e, sizeof e, ofs) == sizeof e;
                ofs += sizeof e)
        {
            if (e.inode_sector == cwd && e.in_use)
            {
                return filesys_open (e.name);
            }
        }
        return NULL;
    }
    struct inode *crr = NULL;
    crr = inode_open (thread_current ()->cwd_sector);

    struct dir *parent_dir = dir_reopen(dir_get_parent_dir (name));
    //if (crr->data.is_dir)
    //parent_dir = dir_open (inode_open (crr->data.parent_dir_sector));
    //else
    if (parent_dir == NULL)
        return NULL;

    struct inode *inode = NULL;

    char leaf_name[NAME_MAX + 1];
    if (!dir_get_leaf_name (name, leaf_name) &&
            strnlen(leaf_name, NAME_MAX) == 0)
    {
        inode = inode_reopen (dir_get_inode (parent_dir));
        dir_close (parent_dir);
        return file_open (inode);
    }

    if (parent_dir != NULL)
        dir_lookup (parent_dir, leaf_name, &inode);
    dir_close (parent_dir);

    return file_open (inode);
}
开发者ID:rahulabc,项目名称:jawpintos,代码行数:63,代码来源:filesys.c

示例9: dir_remove

/* Removes any entry for NAME in DIR.
   Returns true if successful, false on failure,
   which occurs only if there is no file with the given NAME. */
bool
dir_remove (struct dir *dir, const char *name) 
{
  struct dir_entry e;
  struct inode *inode = NULL;
  bool success = false;
  off_t ofs;

  ASSERT (dir != NULL);
  ASSERT (name != NULL);

  //lock the directory for the rest of the lookup operation
  inode_lock(dir->inode);
  name = getfilename(name);

  /* Find directory entry. */
  if (!lookup (dir, name, &e, &ofs))
    goto done;

  /* Open inode. */
  inode = inode_open (e.inode_sector);
  if (inode == NULL)
    goto done;

  //if it is still open don't allow deletion
  if(inode_type(inode) == FILE_DIR) {
	//is file in use?
	if(inode_opencnt(inode) > 1)
		goto done;
	char * temp = (char *)malloc(sizeof(char) * (NAME_MAX + 1) );
	struct dir * dirtemp = dir_open(inode);
	//is dir empty?
	if (dir_readdir(dirtemp,temp)) {
		free(temp);
		dir_close(dirtemp);
		goto done;
	}
	free(temp);
	dir_close(dirtemp);	
  }

  /* Erase directory entry. */
  e.in_use = false;
  if (inode_write_at (dir->inode, &e, sizeof e, ofs) != sizeof e) 
    goto done;

  /* Remove inode. */
  inode_remove (inode);
  success = true;

 done:
  //unlock the directory
  inode_unlock(dir->inode);
  inode_close (inode);
  return success;
}
开发者ID:c22dunbar,项目名称:sven-pintos-code,代码行数:59,代码来源:directory.c

示例10: malloc

struct dir *get_directory(const char *path, bool flag){
  if(strlen(path)==0)
    return NULL;
  struct dir *curr;
  char *word, *brkt, *buffer = malloc(strlen(path)+1), *save, *last;
  struct inode *inode;
  memcpy(buffer, path, strlen(path)+1);
  save = buffer;
  if(buffer[0]=='/'){
    curr = dir_open_root();
    last = strtok_r(buffer+1, "/", &brkt);
  }
  else{
    if(thread_current()->dir)
      curr = dir_reopen(thread_current()->dir);
    else
      curr = dir_open_root();
    last = strtok_r(buffer, "/", &brkt);
  }
  
  while(1){
    word = last;
    if(word == NULL) break;
    last = strtok_r(NULL, "/", &brkt);
    if(last == NULL && flag) break;
    if(strcmp(word,"")==0);
    else if(strcmp(word,".")==0);
    else if(strcmp(word,"..")==0){
      inode = inode_open(inode_parent_number(dir_get_inode(curr)));
      dir_close(curr);
      curr = dir_open(inode);
    }
    else{
      inode = NULL;
      if(dir_lookup(curr, word, &inode)){
        dir_close(curr);
        if(inode_is_dir(inode))
          curr = dir_open(inode);
        else{
          inode_close(inode);
          free(save);
          return NULL;
        }
      }
      else{
        dir_close(curr);
        free(save);
        return NULL;
      }
    }
  }
  free(save);
  if(inode_removed(curr->inode))
    return NULL;
  return curr;
}
开发者ID:mjy0503,项目名称:pintos,代码行数:56,代码来源:directory.c

示例11: exit_handler

void exit_handler (int status) {

  printf("%s: exit(%d)\n", &thread_current ()->name, status);

  lock_acquire(&ref_count_lock);
  struct p_data* parent = thread_current()->parent_data;
  if (parent != NULL) {
    parent->exit_status = status;
    parent->child_thread = NULL;
    sema_up(&parent->sema);
    parent->ref_count--;
    if (parent->cwd != NULL) {
      dir_close(parent->cwd);
    }
    if (parent->ref_count == 0) {
      thread_current()->parent_data = NULL;
      free(parent);

    }
  }
  if (thread_current()->cwd != NULL) {
    dir_close(thread_current()->cwd);
  }
  /* iterate through children and remove this as their parent*/
  struct list_elem* e;
  struct list *childs = &thread_current()->child_processes;
  for (e = list_begin(childs); e != list_end(childs); e = list_next(e)) {
    struct p_data* child = list_entry(e, struct p_data, elem);
    child->ref_count --;
    list_remove(e);
    if (child->ref_count == 0) {
      struct thread *t = child->child_thread;
      if (t != NULL) {
        t->parent_data = NULL;
      }
      free(child);
    }
  }

  struct list *files = &thread_current()->files;
  for (e = list_begin(files); e != list_end(files); e = list_begin(files)) {
    close_handler(list_entry(e, struct file_struct, elem)->fd);
  }
  struct file_struct *executable = thread_current()->executable;
  if (executable != NULL) {
    file_allow_write(executable->sys_file);
    file_close(executable->sys_file);
    thread_current()->executable = NULL;
    free(executable);
  }
  lock_release(&ref_count_lock);
  thread_exit();
}
开发者ID:tonychenr,项目名称:CS162-group34,代码行数:53,代码来源:syscall.c

示例12: filesys_mkdir

/* Creates directory. True if successful. */
bool 
filesys_mkdir (const char *dir)
{
  bool success = false;

  /*The string *dir cannot be empty.*/
  if (*dir == NULL)
    {
      return success;
    }

  /* Locates the directory where the new directory should be created. */
  struct dir *create_dir;
  char parsed_name[NAME_MAX + 1];
  parse_path (dir, &create_dir, parsed_name);

  block_sector_t sector;
  /*Find a free sector for the directory.*/
  if (!free_map_allocate (1, &sector))
    {
      return success;
    }

  success = dir_create (sector, 16);
  if (!success)
    {
      free_map_release (sector, 1);
      return success;
    }

  success = dir_add (create_dir, parsed_name, sector);
  if (!success)
    {
      free_map_release (sector, 1);
      return success;
    }

  /* Get the dir struct of the directory that is just created and add "." and "..". */
  struct inode *inode = inode_open (sector);
  struct dir *new_dir = dir_open (inode);

  ASSERT (inode != NULL);
  ASSERT (new_dir != NULL);

  dir_add (new_dir, ".", sector);
  dir_add (new_dir, "..", create_dir->inode->sector);
  dir_close (new_dir);
  dir_close (create_dir);

  return success; 
}
开发者ID:jackykschou,项目名称:pintos,代码行数:52,代码来源:filesys.c

示例13: filesys_open

/* Opens the file with the given NAME.
   Returns the new file if successful or a null pointer
   otherwise.
   Fails if no file named NAME exists,
   or if an internal memory allocation fails. */
struct inode *
filesys_open (const char *name)
{
  struct dir *search_dir = get_cwd(name);

  if (search_dir == NULL) {
    return NULL;
  }

  struct inode *inode = NULL;

  if (name[0] == '/') {
    inode = dir_get_inode(search_dir);
  }

  char *part = malloc(NAME_MAX + 1);
  if (part == NULL) {
    return false;
  }
  memset(part, 0, NAME_MAX + 1);
  int retrieved_next_part;
  for (retrieved_next_part = get_next_part(part, &name); retrieved_next_part > 0;
       retrieved_next_part = get_next_part(part, &name)) {
    if (dir_lookup (search_dir, part, &inode)) {
      if (!inode_is_dir(inode)) {
        break;
      } else {
        dir_close(search_dir);
        search_dir = dir_open(inode);
        if (search_dir == NULL) {
          free(part);
          return false;
        }
      }
    } else {
      inode = NULL;
      break;
    }
  }
  if (inode != NULL && inode_is_dir(inode) && get_next_part(part, &name) == 0) {
    inode = inode_reopen(inode);
  }
  dir_close(search_dir);
  
  if (inode != NULL && get_next_part(part, &name) != 0) {
    inode_close(inode);
    inode = NULL;
  }
  free(part);
  return inode;
}
开发者ID:tonychenr,项目名称:CS162-group34,代码行数:56,代码来源:filesys.c

示例14: filesys_chdir

/* changes the current working directory to path */
bool filesys_chdir(const char *path)
{
  struct dir *dir = get_containing_dir(path);
  char *file_name = get_file_name(path);
  struct inode *inode = NULL;
  struct thread *cur = thread_current();

  if (dir != NULL)
  {
    if(strcmp(file_name, "..") == 0)
    {
      if(!dir_get_parent(dir, &inode))
      {
	free(file_name);
	return false;
      }
    }
    else if(strcmp(file_name, ".") == 0)
    {
      cur->cwd = dir;
      free(file_name);
      return true;
    }
    else if(dir_is_root(dir) && strlen(file_name) == 0)
    {
      cur->cwd = dir;
      free(file_name);
      return true;
    }
    else
    {
      dir_lookup (dir, file_name, &inode);
    }
  }

  dir_close(dir);
  free(file_name);

  dir = dir_open(inode);
  if(dir != NULL) 
  {
    dir_close(cur->cwd);
    cur->cwd = dir;
    return true;
  }

  return false;
}
开发者ID:YeongjinOh,项目名称:Operating-System,代码行数:49,代码来源:filesys.c

示例15: dir_open

dir_t*
dir_open(char *path) {
    dir_t *d=0;
    int i, err = -1;
    char *p=0;
    do {
	i = strlen(path)+4;
	p = malloc(i);
	assertb(p);
	strncpy(p, path, i);
	strncat(p, "/*", i);

	d = calloc(1, sizeof(*d));
	assertb(d);
	d->h = INVALID_HANDLE_VALUE;

	d->h = FindFirstFile(p, &d->fi);
	if(d->h == INVALID_HANDLE_VALUE 
	   && GetLastError() == ERROR_NO_MORE_FILES) {
	    break;
	}
	assertb_syserr(d->h);
	d->first = 1;
	err = 0;
    } while(0);
    if( p ) {
	free(p);
    }
    if( err ) {
	dir_close(d);
	d = 0;
    }
    return d;
}
开发者ID:noelbk,项目名称:bklib,代码行数:34,代码来源:dir_win32.c


注:本文中的dir_close函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。