• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ dir_open函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: devfs_open_dir

static int devfs_open_dir(void * opaque, const char * path){
    if( strlen(path) == 0 ){
        // TODO : Add function
        return dir_open(NULL,NULL,NULL); 
    }else{
        return OPENDIR_NOTFOUND;
    }
}
开发者ID:CobooGuo,项目名称:freertos-basic,代码行数:8,代码来源:fio.c


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


示例18: dir_lookup_rec

//returns the inode of the last dir in name before the last /
//the user has to check for existing file after the /
struct dir *
dir_lookup_rec (const char *name) {

	//printf("lookup path is %s\n",name);

	//if the string starts with / it is an absolut path
	//root dir
	if ( strcmp( name, "/") == 0 ) return dir_open_root();

	//for the return value
	int success = 0;
	char *token ,*save_ptr;
	char * temp = (char *)malloc(strlen(name) + 1 );
	strlcpy (temp, name, strlen(name) + 1); 

	//open root and start 
	struct dir * current;

	//if it is relative make it absolute 
	if ( name[0] != '/' ) {
		current = dir_reopen(thread_current()->pwd);
	} else {
		current = dir_open_root();
	}
	
	struct inode * nextdir = dir_get_inode(current);

	//go through and check that the previous direcrtories exist
	for (token = strtok_r (temp, "/", &save_ptr); token != NULL; token = strtok_r (NULL, "/", &save_ptr)) {

		//somethings wrong if this hapens	
		if (current == NULL ) break;
		//last round has to be not existing
		if (strlen(save_ptr) == 0) {
			success = 1;
			break;
				
		}

		//goto next if token is empty in case of //a/
		if(strlen(token) !=  0) {
			//check if this directory exists true if exists
			if ( dir_lookup (current, token,&nextdir) ) {
				//check if it is a directory and then open it
				enum file_type type =  inode_type (nextdir);
				//is it a dir
				if(type == FILE_DIR) {
					dir_close(current);
					current = dir_open(nextdir);
				}
				else break;
			}
			else break;
		}
	}

  if( success == 1) return current; else return NULL;
}
开发者ID:c22dunbar,项目名称:sven-pintos-code,代码行数:60,代码来源:directory.c


示例19: filesys_chdir

bool filesys_chdir(const char *name)
{
  bool success=false;
  struct inode *inode = NULL;
  struct thread *t = thread_current();
  char *file_name = get_file_name(name);
  struct dir *dir = get_directory(name);
//  printf("lookup start\n");
  if (dir != NULL)
  {
    if( strcmp(file_name,".")==0)
    {
      t->curr_dir = dir_reopen(dir);
      free(file_name);
      return true;
    }
    else if(strcmp(file_name,"..")==0)
    {
      if( inode_get_inumber(dir_get_inode(dir))==1 )
      {
        t->curr_dir = dir_open(inode_open(1));
        free(file_name);
        dir_close(dir);
        return true;
      }
      else
      {
        t->curr_dir = dir_open( inode_open(inode_get_parent(dir_get_inode(dir))));
        free(file_name);
        dir_close(dir);
        return true;
      }
    }
    success=dir_lookup (dir, file_name, &inode);
  }
  dir_close (dir);
  if(success)
  {
    t->curr_dir = dir_open(inode);
  }
  free(file_name);
/*  printf("changed dir sector: %d\n",inode_get_inumber(dir_get_inode(t->curr_dir)));
  printf("value %d\n",inode_get_data(dir_get_inode(t->curr_dir),0));*/
  return success;
}
开发者ID:goodahn,项目名称:cs330_OperatingSystem,代码行数:45,代码来源:filesys.c


示例20: _db_new

struct db *db_new_mock()
{
	struct db *db = _db_new(".");
	db->index_dir = dir_open(db, ".");
	assert(db->index_dir);

	db->log_fd = dup(2); /* stderr */
	return db;
}
开发者ID:deniskin82,项目名称:ydb,代码行数:9,代码来源:ydb_db.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ direction函数代码示例发布时间:2022-05-30
下一篇:
C++ dir_list_free函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap