예제 #1
0
파일: filesys.c 프로젝트: kcm1700/ChoPintOS
/* 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 *path, off_t initial_size)
{
  block_sector_t inode_sector = 0;
  struct dir *dir = NULL;
  bool success = false;
  char *name = malloc (NAME_MAX + 1);
  if (name == NULL)
    goto done;
  if (!dir_follow_path (thread_current ()->cwd, path, &dir, name))
    goto done;

  success = (dir != NULL
             && free_map_allocate (1, &inode_sector)
             && inode_create (inode_sector, initial_size)
             && dir_add (dir, name, inode_sector));
  if (!success && inode_sector != 0)
  {
    cache_remove (fs_cache, inode_sector, 1);
    free_map_release (inode_sector, 1);
  }
done:
  dir_close (dir);
  free (name);
  return success;
}
예제 #2
0
int
fs_mknod(const char *path, mode_t mode, dev_t rdev)
{
	struct inode *ino;
	time_t curtime;
	struct fuse_context *ctxt;
	int r;

	if ((r = inode_create(path, &ino)) < 0)
		return r;
	ino->i_size = 0;
	ino->i_mode = mode;
	ino->i_nlink = 1;
	ino->i_rdev = rdev;

	curtime = time(NULL);
	ino->i_atime = curtime;
	ino->i_ctime = curtime;
	ino->i_mtime = curtime;

	ctxt = fuse_get_context();
	ino->i_owner = ctxt->uid;
	ino->i_group = ctxt->gid;
	flush_block(ino);

	return 0;
}
예제 #3
0
/* 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) 
{

  block_sector_t inode_sector = 0;
  struct dir *dir;
  char parsed_name[NAME_MAX + 1];
  
  if (*name == NULL || (strlen (name) > NAME_MAX))
    {
      return false;
    }
  bool success = parse_path (name, &dir, parsed_name);
  if (!success)
    {
      return success;
    }

  struct inode *inode;

  success = (dir != NULL
                  && free_map_allocate (1, &inode_sector)
                  && inode_create (inode_sector, initial_size, false)
                  && dir_add (dir, parsed_name, inode_sector)
                  && dir_lookup (dir, ".", &inode));
  if (!success && inode_sector != 0) 
    free_map_release (inode_sector, 1);
  dir_close (dir);


  return success;
}
예제 #4
0
/* 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;
}
예제 #5
0
파일: fs.c 프로젝트: steinwaywhw/Random
int fs_mk (fs_t *fs, char *pathname, char *type) {
	// assert (fs != NULL);
	// assert (pathname != NULL);

	super_block_t *sb = fs->super_block;

	// can't make
	if (sb->free_inodes == 0)
		return -1;
	if (sb->free_blocks == 0)
		return -1;
	if (strlen (pathname) > MAX_FILE_FULL)
		return -1;

	// parent not exists
	int parent = inode_lookup_parent (fs->super_block, pathname);
	if (parent < 0)
		return -1;

	// child already exists
	int child = inode_lookup_full (fs->super_block, pathname);
	if (child >= 0)
		return -1;

	int status = inode_create (fs->super_block, pathname, type);

	if (status < 0)
		return -1;

	return 0;
}
예제 #6
0
/* 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, bool isdir)
{
  block_sector_t inode_sector = 0;
  // Get directory
  struct dir *dir = get_containing_dir(name);

  char *file_name = get_filename(name);

  // Get file name
  char* file_name = get_filename(name);

  bool success = false;
  if (strcmp(file_name, ".") != 0 && strcmp(file_name, "..") != 0)
  {
    success = (dir != NULL
               && free_map_allocate (1, &inode_sector)
               && inode_create (inode_sector, initial_size, isdir)
               && dir_add (dir, file_name, inode_sector));
  }
  if (!success && inode_sector != 0)
    free_map_release (inode_sector, 1);
  dir_close (dir);
  free(file_name);

  return success;
}
예제 #7
0
int
fs_mkdir(const char *path, mode_t mode)
{
	struct inode *dir;
	time_t curtime;
	struct fuse_context *ctxt;
	int r;

	if ((r = inode_create(path, &dir)) < 0)
		return r;
	dir->i_size = 0;
	dir->i_mode = S_IFDIR | (mode & 0777);
	dir->i_nlink = 1;

	curtime = time(NULL);
	dir->i_atime = curtime;
	dir->i_ctime = curtime;
	dir->i_mtime = curtime;

	ctxt = fuse_get_context();
	dir->i_owner = ctxt->uid;
	dir->i_group = ctxt->gid;
	flush_block(dir);

	return 0;
}
예제 #8
0
/* returns id */
int fs_addINode(char* name, int fileStart, int fileSize, int processes, int* processStart, int* processSize) {
    int i;
    INode* node;

    if (FS_DEBUG) {
        lightLine();
        printf("fs_addINode(\"%s\", %d, %d, ..., ...)\n", name, fileStart, fileSize);

        if (FS_VERBOSE) {
            printf("processStart: [");
            for (i = 0; i < processes; i++)
                printf("%d ", processStart[i]);
            printf("]\nprocessSize: [");
            for (i = 0; i < processes; i++)
                printf("%d ", processSize[i]);
            printf("]\n");
        }
        lightLine();
    }

    /* outside of bounds */
    if (fileStart < 0) {
        printf("start position is outside of bounds\n");
        return -1;
    }

    node = inode_create(++fs_idCounter, name, fileStart, fileSize, processes, processStart, processSize);
    list_addLast(iNodes, node);

    return fs_idCounter;
}
예제 #9
0
/* 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,bool is_dir) 
{
//  printf("create start: %s\n",name);
//  printf("%s size: %d\n",name,initial_size);
  disk_sector_t inode_sector = 0;
  char *file_name = get_file_name(name);
  bool success=true;
  if( strcmp(file_name,"")==0 )
  {
    return false;
  }
//  if( is_dir)
//    printf("mkdir!\n");
//  printf("file name : %s\n",file_name);
  struct dir *dir = get_directory(name);
//  printf("sector of dir :  %d\n", inode_get_inumber(dir_get_inode(dir)));
//  if( inode_get_parent(dir_get_inode(dir)) ==0 )
//    {
//    printf("its on root directory!\n");
//    }
/*  if(dir == NULL)
  {
    printf("no directory\n");
    success=false;
  }
  if(!free_map_allocate(1,&inode_sector))
  {
    printf("no free map\n");
    success=false;
  }
  if(!inode_create(inode_sector,initial_size,is_dir))
  {
    printf("inode create fail\n");
    success=false;
  }
  if(!dir_add(dir,file_name,inode_sector))
  {
    printf("dir add fail\n");
    success=false;
  }*/
//  printf("file name:%s\n",file_name);
  success = (dir != NULL
                  && free_map_allocate (1, &inode_sector)
                  && inode_create (inode_sector, initial_size, is_dir)
                  && dir_add (dir, file_name, inode_sector));
  
  if (!success && inode_sector != 0)
  {
//    printf("haha\n");
    free_map_release (inode_sector, 1);
  }
  dir_close (dir);
//  printf("create end sector num : %d\n",inode_sector);
  free(file_name);
  return success;
}
예제 #10
0
파일: fs.c 프로젝트: srimugunthan/simplefs
int create_root_inode()
{
	struct inode *root_inode;
//	create_inode();
	printf("sizeof inode = %d\n", sizeof(struct inode));
	root_inode = inode_create();
	if(root_inode != NULL)
		superblk->root_inode = root_inode;
			
}
예제 #11
0
파일: directory.c 프로젝트: mjy0503/pintos
/* Creates a directory with space for ENTRY_CNT entries in the
   given SECTOR.  Returns true if successful, false on failure. */
bool
dir_create (disk_sector_t sector, size_t entry_cnt, disk_sector_t parent_sector)
{
  if(!inode_create (sector, entry_cnt * sizeof (struct dir_entry), INODE_MAX_LEVEL, true))
    return false;
  struct inode *inode = inode_open(sector);
  inode_set_parent(inode, parent_sector);
  inode_close(inode);
  return true;
}
예제 #12
0
/*! 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) {
    block_sector_t inode_sector = 0;
    struct dir *dir = dir_open_root();
    bool success = (dir != NULL &&
                    free_map_allocate(1, &inode_sector) &&
                    inode_create(inode_sector, initial_size) &&
                    dir_add(dir, name, inode_sector));
    if (!success && inode_sector != 0) 
        free_map_release(inode_sector, 1);
    dir_close(dir);

    return success;
}
예제 #13
0
/* Creates a new free map file on disk and writes the free map to
   it. */
void
free_map_create (void)
{
    /* Create inode. */
    if (!inode_create (FREE_MAP_SECTOR, bitmap_file_size (free_map),0,1))
        PANIC ("free map creation failed");

    /* Write bitmap to file. */
    free_map_file = file_open (inode_open (FREE_MAP_SECTOR));
    if (free_map_file == NULL)
        PANIC ("can't open free map");
    if (!bitmap_write (free_map, free_map_file))
        PANIC ("can't write free map");
}
예제 #14
0
/* Creates a new free map file on disk and writes the free map to
   it. */
void
free_map_create (void) 
{
  /* Create inode. */
  printf("free_map_create(): free_map_file_size: %d\n", bitmap_file_size (free_map));
  if (!inode_create (FREE_MAP_SECTOR, bitmap_file_size (free_map)))
    PANIC ("free map creation failed");
  struct inode_disk* buff = (struct inode_disk*)malloc(BLOCK_SECTOR_SIZE);
  block_read(fs_device, FREE_MAP_SECTOR, buff);
  ASSERT (buff->direct[0] != 0);
  /* Write bitmap to file. */
  free_map_file = file_open (inode_open (FREE_MAP_SECTOR));
  if (free_map_file == NULL)
    PANIC ("can't open free map");
  if (!bitmap_write (free_map, free_map_file))
    PANIC ("can't write free map");
}
예제 #15
0
파일: filesys.c 프로젝트: gypintos/np4
/* Creates a file named NAME with the given INITIAL_SIZE.*/
bool
filesys_create (const char *name, off_t initial_size, bool isdir) 
{
  if (strlen(name) == 0) return false;
  block_sector_t inode_sector = 0;

  struct dir *dir_ = filesys_get_dir(name);
  char *name_ = filesys_get_name(name);
  bool success = false;

  if (strcmp (name_, "") == 0) goto done;
  success = (dir_ && free_map_allocate (1, &inode_sector)
    && inode_create (inode_sector, initial_size) 
    && dir_add (dir_, name_, inode_sector, isdir));

  struct inode *ninode = NULL;
  struct dir *ndir = NULL;
  bool success1 = true;
  if (success && isdir){
    success1 = ((ninode = inode_open (inode_sector))
      && (ndir = dir_open (ninode))
      && dir_add (ndir, ".", inode_sector, true)
      && dir_add (ndir, "..",inode_get_inumber (dir_get_inode (dir_)), true));
  }

  if (inode_sector != 0 && !success) 
    free_map_release (inode_sector, 1);

  if (success && !success1) {
    success = false;
    printf("Failure: create dir: %s\n", name);
    dir_remove (dir_, name_);
  }

  done:
    dir_close (dir_);

  free(name_);
  if (!ndir && ninode){
    inode_close(ninode);
  } else if (ndir) {
    dir_close(ndir);
  }

  return success;
}
예제 #16
0
파일: tmpfs.c 프로젝트: jrwilson/Lily
static inode_t*
directory_find_or_create (inode_t* parent,
			  const char* name_begin,
			  const char* name_end)
{
  /* Iterate over the parent's children looking for the name. */
  inode_t** ptr;
  for (ptr = &parent->first_child; *ptr != 0; ptr = &(*ptr)->next_sibling) {
    if (pstrcmp ((*ptr)->name_begin, (*ptr)->name_end, name_begin, name_end) == 0) {
      return *ptr;
    }
  }

  /* Create a node. */
  *ptr = inode_create (DIRECTORY, name_begin, name_end, -1, 0, parent);

  return *ptr;
}
예제 #17
0
파일: filesys.c 프로젝트: anoopjs/pintos
/* 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 *path, off_t initial_size) 
{
  char *name = get_filename (path);
  block_sector_t inode_sector = 0;

  struct dir *dir = dir_get (path);
  bool success = (dir != NULL
                  && free_map_allocate (1, &inode_sector)
                  && inode_create (inode_sector, initial_size, false)
                  && dir_add (dir, name, inode_sector));

  if (!success && inode_sector != 0) 
    free_map_release (inode_sector, 1);

  dir_close (dir);
  free (name);
  return success;
}
예제 #18
0
파일: tmpfs.c 프로젝트: jrwilson/Lily
static inode_t*
file_find_or_create (inode_t* parent,
		     const char* name_begin,
		     const char* name_end,
		     bd_t bd,
		     size_t size)
{
  /* Iterate over the parent's children looking for the name. */
  inode_t** ptr;
  for (ptr = &parent->first_child; *ptr != 0; ptr = &(*ptr)->next_sibling) {
    if (pstrcmp ((*ptr)->name_begin, (*ptr)->name_end, name_begin, name_end) == 0) {
      return *ptr;
    }
  }

  /* Create a node. */
  *ptr = inode_create (FILE, name_begin, name_end, bd, size, parent);

  return *ptr;
}
/* 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) 
{
  block_sector_t inode_sector = 0;
  struct thread *cur = thread_current();
  struct dir *dir;
  if(cur->current_directory == NULL)
    dir = dir_open_root ();
  else
    dir = dir_open_current();
  bool success = (dir != NULL
                  && free_map_allocate (1, &inode_sector)
                  && inode_create (inode_sector, initial_size, false)
                  && dir_add (dir, name, inode_sector));
  if (!success && inode_sector != 0) 
    free_map_release (inode_sector, 1);
  dir_close (dir);

  return success;
}
예제 #20
0
파일: filesys.c 프로젝트: GunjuKo/Pintos
/* 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) 
{
  char *cp_name   = malloc( sizeof(char) * (strlen(name) + 1) );
  char *file_name = malloc( sizeof(char) * (strlen(name) + 1) ); 
  if( cp_name == NULL || file_name == NULL)
	  return false;
  strlcpy(cp_name, name, strlen(name)+1);
  block_sector_t inode_sector = 0;
  struct dir *dir = parse_path (cp_name, file_name);
  bool success = (dir != NULL
                  && free_map_allocate (1, &inode_sector)
                  && inode_create (inode_sector, initial_size, IS_FILE)
                  && dir_add (dir, file_name, inode_sector));
  if (!success && inode_sector != 0) 
    free_map_release (inode_sector, 1);
  dir_close (dir);
  free(cp_name);
  free(file_name);
  return success;
}
예제 #21
0
/* Creates a directory in the given SECTOR.  Returns true if successful, false
   on failure. */
bool
dir_create (block_sector_t sector, block_sector_t parent)
{
  bool status;
  struct dir *dir;

  /* Create sector with enough room for two entries */
  status = inode_create (sector, 2 * sizeof (struct dir_entry), true);
	
  if (!status) return status;

  /* Add entries for '.' and '..' */
  struct inode *i = inode_open (sector);
  dir = dir_open (i);
  if (dir == NULL) return false;

  dir_add (dir, ".", sector);
  dir_add (dir, "..", parent);
  dir_close (dir);

  return true;
}
예제 #22
0
/* 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, bool is_dir) 
{
  block_sector_t inode_sector = 0;
  /* Start of Project 4 */
  bool success = false;
  struct dir *dir = dir_from_path (name);
  char* file_name = retrieve_file_name (name);
  if (strcmp(file_name, ".") != 0 && strcmp(file_name, "..") != 0)
  {
    success = (dir != NULL
               && free_map_allocate (1, &inode_sector)
  	       && inode_create (inode_sector, initial_size, is_dir)
	       && dir_add (dir, file_name, inode_sector));
  }
  free(file_name);
  /* End of Project 4 */
  if (!success && inode_sector != 0) 
    free_map_release (inode_sector, 1);
  dir_close (dir);

  return success;
}
예제 #23
0
int
fs_symlink(const char *dstpath, const char *srcpath)
{
	struct inode *ino;
	struct fuse_context *ctxt;
	time_t curtime;
	size_t dstlen;
	char *blk;
	int r;

	if ((dstlen = strlen(dstpath)) >= PATH_MAX)
		return -ENAMETOOLONG;
	if ((r = inode_create(srcpath, &ino)) < 0) {
		return r;
	}
	ino->i_size = dstlen;
	ino->i_mode = S_IFLNK | 0777;
	ino->i_nlink = 1;

	curtime = time(NULL);
	ino->i_atime = curtime;
	ino->i_ctime = curtime;
	ino->i_mtime = curtime;

	ctxt = fuse_get_context();
	ino->i_owner = ctxt->uid;
	ino->i_group = ctxt->gid;

	if ((r = inode_get_block(ino, 0, &blk)) < 0) {
		inode_unlink(srcpath);
		return r;
	}
	memcpy(blk, dstpath, dstlen);
	inode_flush(ino);

	return 0;
}
예제 #24
0
파일: filesys.c 프로젝트: bahulkar/cs140_p4
/* 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)
{
    char name_copy[MAX_FULL_PATH];
    char *file_name = NULL;
    char *token, *save_ptr;
    block_sector_t inode_sector = 0;

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

    /* Open parent directory. */
    struct dir *dir = recursive_dir_open (name);
    if (!dir)
    {
        return false;
    }
    /* extract only file name from entire path. */
    strlcpy (name_copy, name, strlen (name) + 1);
    for (token = strtok_r (name_copy, "/", &save_ptr); token != NULL;
            token = strtok_r (NULL, "/", &save_ptr))
    {
        file_name = token;
    }
    if (file_name[0] == '\0')
    {
        dir_close (dir);
        return false;
    }
    if (strlen (file_name) > NAME_MAX)
    {
        dir_close (dir);
        return false;
    }

    /* Check for and prevent simultaneous accesses. */
    struct list_elem *e;
    block_sector_t parent_dir_sector = inode_get_inumber (dir_get_inode (dir));
    lock_acquire (&cur_name_list_lock);
    for (e = list_begin (&cur_name_list);
            e != list_end (&cur_name_list);
            e = list_next (e))
    {
        struct cur_name_list_entry *cur_name_list_entry = NULL;
        cur_name_list_entry = list_entry (e, struct cur_name_list_entry, elem);
        if ((cur_name_list_entry->parent_dir_sector == parent_dir_sector)
                && (!strcmp (file_name, cur_name_list_entry->file_name)))
        {
            dir_close (dir);
            return false;
        }
    }
    struct cur_name_list_entry *name_entry = NULL;
    name_entry = malloc (sizeof (struct cur_name_list_entry));
    if (name_entry == NULL)
    {
        dir_close (dir);
        lock_release (&cur_name_list_lock);
        return false;
    }
    strlcpy (name_entry->file_name, file_name, strlen (file_name) + 1);
    name_entry->parent_dir_sector = parent_dir_sector;
    list_push_back (&cur_name_list, &name_entry->elem);
    lock_release (&cur_name_list_lock);

    /* Create file. and add directory entry. */
    bool success = (dir != NULL
                    && free_map_allocate (1, &inode_sector)
                    && inode_create (inode_sector, initial_size)
                    && dir_add (dir, file_name, inode_sector, true));
    if (!success && inode_sector != 0)
        free_map_release (inode_sector, 1);
    dir_close (dir);

    lock_acquire (&cur_name_list_lock);
    list_remove (&name_entry->elem);
    lock_release (&cur_name_list_lock);
    free (name_entry);
    return success;
}
예제 #25
0
/* 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, uint32_t is_dir) 
{
  block_sector_t inode_sector = (block_sector_t) -1;
  struct inode *inode = NULL;
  struct dir *search_dir = get_cwd(name);

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

  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 || get_next_part(part, &name) != 0) {
    if (inode != NULL && !inode_is_dir(inode)) {
      inode_close(inode);
    }
    dir_close(search_dir);
    free(part);
    return false;
  }

  
  bool success = false;
  if (is_dir) {
    block_sector_t parent_sector = inode_get_inumber(dir_get_inode(search_dir));
    success = (search_dir != NULL
               && free_map_allocate (1, &inode_sector)
               && dir_create (inode_sector, initial_size, parent_sector)
               && dir_add (search_dir, part, inode_sector));
  } else {
    success = (search_dir != NULL
               && free_map_allocate (1, &inode_sector)
               && inode_create (inode_sector, initial_size, is_dir)
               && dir_add (search_dir, part, inode_sector));
  }
  
  if (!success) 
    free_map_release (inode_sector, 1);
  dir_close (search_dir);
  free(part);
  return success;
}
예제 #26
0
/* 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. */
static bool
_filesys_create (const char *full_path, off_t initial_size,
                 bool is_dir)
{
    block_sector_t cwd = thread_current ()->cwd_sector;
    bool found = true;
    if (cwd != (block_sector_t) ROOT_DIR_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);
        found = false;
        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)
            {
                found = true;
                break;
            }
        }
    }
    if (!found)
        return false;

    char leaf_name[NAME_MAX + 1];
    if (!dir_get_leaf_name (full_path, leaf_name))
        return false;

    struct dir *parent_dir = dir_get_parent_dir (full_path);

    if (parent_dir == NULL)
        return false;

    block_sector_t inode_sector = 0;
    if (!free_map_allocate_one (&inode_sector))
    {
        dir_close (parent_dir);
        return false;
    }
    bool success = is_dir? dir_create (inode_sector, BLOCK_SECTOR_SIZE /
                                       sizeof (struct dir_entry)) :
                   inode_create (inode_sector, initial_size);
    if (!success)
    {
        free_map_release (inode_sector, 1);
        dir_close (parent_dir);
        return false;
    }
    if (!dir_add (parent_dir, leaf_name, inode_sector))
    {
        inode_remove (inode_open (inode_sector));
        free_map_release (inode_sector, 1);
        dir_close (parent_dir);
        return false;
    }
    dir_close (parent_dir);
    return true;
}
예제 #27
0
/* Create a directory */
bool dir_create (size_t entry_cnt, block_sector_t sector)
{
  return inode_create (sector, entry_cnt * sizeof(struct dir_entry), true);
}
예제 #28
0
파일: file.c 프로젝트: gilsho/os2-4
bool file_create(block_sector_t inode_sector, off_t initial_size){
  inode_create (inode_sector, initial_size, false);
}
예제 #29
0
/* Creates a directory with space for ENTRY_CNT entries in the
   given SECTOR.  Returns true if successful, false on failure. */
bool
dir_create (block_sector_t sector, size_t entry_cnt)
{
  return inode_create (sector, entry_cnt * sizeof (struct dir_entry));
}
예제 #30
0
파일: directory.c 프로젝트: jwanglof/TDIU16
/* Creates a directory with space for ENTRY_CNT entries in the
   given SECTOR.  Returns true if successful, false on failure. */
bool
dir_create (disk_sector_t sector, size_t entry_cnt)
{
//  lock_init(&directory_lock);
  return inode_create (sector, entry_cnt * sizeof (struct dir_entry));
}