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


C++ dir_open函数代码示例

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


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

示例1: 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 inode *inode = NULL;

    /* Null file name not allowed. */
    if (name[0] == '\0')
    {
        return NULL;
    }

    /* Root directory is special case. */
    if (!strcmp (name, "/"))
    {
        return (struct file *) dir_open (inode_open (ROOT_DIR_SECTOR));
    }

    /* Lookup file name and get its inode. */
    if (!(recursive_dir_lookup (name, &inode)))
    {
        return NULL;
    }

    /* Check if it is file or directory and open accordingly. */
    if (get_is_file (name))
    {
        return file_open (inode);
    }
    else
    {
        return (struct file *) dir_open (inode);
    }
}
开发者ID:bahulkar,项目名称:cs140_p4,代码行数:38,代码来源:filesys.c

示例2: 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

示例3: file_open

/* Opens a file for the given INODE, of which it takes ownership,
   and returns the new file.  Returns a null pointer if an
   allocation fails or if INODE is null. */
struct file *
file_open (struct inode *inode) 
{
  struct file *file = calloc (1, sizeof *file);

  if (inode != NULL && file != NULL)
    {
      /* Open the directory if possible. */
      if (inode->data.is_dir)
        {
          struct dir *opened_dir = dir_open (inode);
          ASSERT (opened_dir != NULL);
          file->opened_dir = opened_dir;
        }
      else
        {
          file->opened_dir = NULL;
        }

      file->inode = inode;
      file->pos = 0;
      file->deny_write = false;
      return file;
    }
  else
    {
      inode_close (inode);
      free (file);
      return NULL; 
    }
}
开发者ID:jackykschou,项目名称:pintos,代码行数:34,代码来源:file.c

示例4: chdir

void chdir (struct intr_frame *f) {
	
	const char * dirname = *(char **)value_stack(f->esp,4);

	//if empty or root return
	if(strlen(dirname) ==  0 || strcmp( dirname, "/")) f->eax = 0;

	/* CLOSE FILE ? */
	struct file * file  = filesys_open(dirname);

	if ( file == NULL ) {
		f->eax = 0;
		return;
	}	
	struct inode * myinode = file_get_inode (file);

	enum file_type type = inode_type (myinode);

	//if the file is a dir open it and set pwd to it
	if(type == FILE_DIR) {
	 	f->eax = 1;
		dir_close(thread_current()->pwd);
		thread_current()->pwd = dir_open(inode_reopen(myinode));
		
	}
	else f->eax = 0;

	file_close(file);

}
开发者ID:c22dunbar,项目名称:sven-pintos-code,代码行数:30,代码来源:syscall.c

示例5: dir_open

DLLEXPORT DIR *opendir(const char *name)
{
	DIR	*dir;
	ke_handle dir_handle;

	dir_handle = dir_open(name);
	if (KE_INVALID_HANDLE== dir_handle)
		goto err;	

	/* ´´½¨DIR */
	dir = (DIR *)crt_zalloc(sizeof(*dir));
	if (NULL == dir)
		goto err1;
	dir->dir_handle	= dir_handle;
	dir->dir_buffer = dir_buff_malloc();
	if (NULL == dir->dir_buffer)
		goto err2;
	dir->total_size = DIR_BUFF_LEN;
	return dir;

err2:
	crt_free(dir);
err1:
	sys_close(dir_handle);
err:
	return NULL;
}
开发者ID:LastRitter,项目名称:GridOS,代码行数:27,代码来源:opendir.c

示例6: 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

示例7: 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

示例8: sys_open

/* Open system call. */
static int
sys_open (const char *ufile) 
{
  char *kfile = copy_in_string (ufile);
  struct file_descriptor *fd;
  int handle = -1;
 
  fd = calloc (1, sizeof *fd);
  if (fd != NULL)
    {
      struct inode *inode = filesys_open (kfile);
      if (inode != NULL)
        {
          if (inode_get_type (inode) == FILE_INODE)
            fd->file = file_open (inode);
          else
            fd->dir = dir_open (inode);
          if (fd->file != NULL || fd->dir != NULL)
            {
              struct thread *cur = thread_current ();
              handle = fd->handle = cur->next_handle++;
              list_push_front (&cur->fds, &fd->elem);
            }
          else 
            {
              free (fd);
              inode_close (inode);
            }
        }
    }
  
  palloc_free_page (kfile);
  return handle;
}
开发者ID:johnmiked15,项目名称:PintOS2,代码行数:35,代码来源:syscall.c

示例9: _findMetaXMLfiles

static void _findMetaXMLfiles(META_ROOT *meta, const char *device_path)
{
    BD_DIR_H *dir;
    BD_DIRENT ent;
    char *path = NULL;
    path = str_printf("%s" DIR_SEP "BDMV" DIR_SEP "META" DIR_SEP "DL", device_path);
    dir = dir_open(path);
    if (dir == NULL) {
        BD_DEBUG(DBG_DIR, "Failed to open meta dir %s\n", path);
        X_FREE(path);
        return;
    }
    int res;
    for (res = dir_read(dir, &ent); !res; res = dir_read(dir, &ent)) {
        if (ent.d_name[0] == '.')
            continue;
        else if (ent.d_name != NULL && strncasecmp(ent.d_name, "bdmt_", 5) == 0) {
            uint8_t i = meta->dl_count;
            meta->dl_count++;
            meta->dl_entries = realloc(meta->dl_entries, (meta->dl_count*sizeof(META_DL)));
            meta->dl_entries[i].filename = str_dup(ent.d_name);
            strncpy(meta->dl_entries[i].language_code, ent.d_name+5,3);
            meta->dl_entries[i].language_code[3] = '\0';
            str_tolower(meta->dl_entries[i].language_code);
        }
    }
    dir_close(dir);
    X_FREE(path);
}
开发者ID:hongxchen,项目名称:RTPServer,代码行数:29,代码来源:meta_parse.c

示例10: 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

示例11: 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

示例12: handle_info

static void handle_info(struct pfiled *pfiled, struct io *io)
{
	struct xseg_request *req = io->req;
	struct stat stat;
	int fd, r;
	uint64_t size;
	char *target = xseg_get_target(pfiled->xseg, req);
	char *data = xseg_get_data(pfiled->xseg, req);
	struct xseg_reply_info *xinfo  = (struct xseg_reply_info *)data;

	fd = dir_open(pfiled, io, target, req->targetlen, 0);
	if (fd < 0) {
		fail(pfiled, io);
		return;
	}

	r = fstat(fd, &stat);
	if (r < 0) {
		perror("fstat");
		fail(pfiled, io);
		return;
	}

	size = (uint64_t)stat.st_size;
	xinfo->size = size;

	complete(pfiled, io);
}
开发者ID:cnanakos,项目名称:archipelago,代码行数:28,代码来源:pfiled.c

示例13: handle_delete

static void handle_delete(struct pfiled *pfiled, struct io *io)
{
	struct xseg_request *req = io->req;
	char *buf = malloc(255);
	int fd;
	char *target = xseg_get_target(pfiled->xseg, req);

	fd = dir_open(pfiled, io, target, req->targetlen, 0);
	if (fd < 0) {
		fprintf(stderr, "fail in dir_open\n");
		fail(pfiled, io);
		return;
	}

	/* 'invalidate' cache entry */
	if (io->fdcacheidx >= 0) {
		pfiled->fdcache[io->fdcacheidx].fd = -1;
	}

	close(fd);

	if (create_path(buf, pfiled->vpath, target, req->targetlen, 0) < 0) {
		fail(pfiled, io);
		return;
	}
	unlink(buf);

	complete(pfiled, io);

	return;
}
开发者ID:cnanakos,项目名称:archipelago,代码行数:31,代码来源:pfiled.c

示例14: sys_readdir

/* read directory */
bool sys_readdir(int fd, char *name)
{
	bool result = false;
	struct file *pfile = process_get_file(fd);
	struct inode *inode = file_get_inode(pfile);
	struct dir *dir;
	int offset = 0;
	char entry[100];
	if(pfile != NULL)
	{
		/* if file is not directory, return false */
		if(inode_is_dir(inode) == false )
			return result;
		dir = dir_open(inode);
		/* read directory and store to name */
		while(dir_readdir(dir, entry) == true)
		{
			/* read directory except . and .. */
			if( strcmp(entry,".") == 0 || strcmp(entry,"..") == 0 )
				continue;
			/* copy entry to name */
			strlcpy(&name[offset], entry, strlen(entry)+1);
			offset = strlen(entry) + 1;
		}
		result = true;
	}
	return true;
}
开发者ID:GunjuKo,项目名称:Pintos,代码行数:29,代码来源:syscall.c

示例15: moddir_glob

static int moddir_glob( INSTANCE * my, int * params )
{
    const char * path = string_get( params[ 0 ] );
    static __DIR_ST * dh = NULL;
    int result;

    if ( dh && strcmp( dh->path, path ) )
    {
        dir_close( dh );
        dh = NULL;
    }

    if ( !dh ) dh = dir_open( path );

    string_discard( params[ 0 ] );

    if ( !dh )
    {
        result = string_new( "" );
        string_use( result );
        return ( result );
    }

    return ( __moddir_read( dh ) ) ;
}
开发者ID:GarethNelson,项目名称:BennuGD,代码行数:25,代码来源:mod_dir.c


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