Exemplo n.º 1
0
int _cp(char *src, char *dest)
{
  int fd, gd, ino, p_ino, dev = running->cwd->dev, temp;
  char src_path[INODE_NAME], dest_path[INODE_NAME], parent_path[INODE_NAME*2];
  MINODE *pip;

  strcpy(src_path, src);
  strcpy(dest_path, dest);
  strcpy(parent_path, dirname(dest));

  if (dest[0] == '/')
  {
    dev = root->dev;
  }
  temp = dev;

  ino = get_inode(dest_path, &temp, TRUE);
  if (ino < 0)                                    // Must first create the destination file
  {
    p_ino = get_inode(parent_path, &dev, FALSE);
    if (p_ino < 0)
    {
      return p_ino;
    }
    pip = iget(dev, p_ino);
    __creat(pip, basename(dest_path), REG_FILE);
    iput(pip);
  }

  fd = __open(src_path, 0); // open the source file for read
  if (fd < 0)
  {
    return fd;
  }
  gd = __open(dest_path, 1); // open the dest file for write
  if (gd < 0)
  {
    return gd;
  }

  int n = 0, counter = 0;
  char cp_buf[BLKSIZE];
  bzero(cp_buf, BLKSIZE);

  while ( (n = __read(fd, cp_buf, BLKSIZE)) > 0 ) // Read from the source file
  {
    if (n < 0)
      break;

    __write(gd, cp_buf, n);                       // Write to the destination file

    bzero(cp_buf, BLKSIZE);
    counter++;
  }

  __close(fd);
  __close(gd);

  return 0;
}
Exemplo n.º 2
0
/*
 * Cancellation behavior:
 *   If thread is canceled, file is not created.
 */
int
___creat(const char *path, mode_t mode)
{
	struct pthread *curthread = _get_curthread();
	int ret;

	_thr_cancel_enter(curthread);
	ret = __creat(path, mode);
	_thr_cancel_leave(curthread, ret == -1);
	
	return ret;
}
Exemplo n.º 3
0
int
___creat(const char *path, mode_t mode)
{
	struct pthread *curthread = _get_curthread();
	int ret;

	_thr_cancel_enter(curthread);
	ret = __creat(path, mode);
	/*
	 * To avoid possible file handle leak, 
	 * only check cancellation point if it is failure
	 */
	_thr_cancel_leave(curthread, (ret == -1));
	
	return ret;
}
Exemplo n.º 4
0
int creat64(const char *filename, mode_t mode)
{
	int e;
	funcptr __creat;

	DPRINT(("creat64: filename=%s \n", filename));
	check_file_open(filename, O_RDWR | O_CREAT);
	__creat = load_library_symbol("creat64");
	if (__creat == NULL) {
		errno = ENOENT;
		return -1;
	}
	DPRINT(("creat64 = %p\n", __creat));
	e = __creat(filename, mode);
	DPRINT(("creat64: filename=%s e=%d\n", filename, e));
	return e;
}