コード例 #1
0
ファイル: file.c プロジェクト: cty12/ucore_plus
int linux_devfile_write(int fd, void *base, size_t len, size_t * copied_store)
{
	int ret = -E_INVAL;
	struct file *file;
	/* use 8byte int, in case of 64bit off_t
	 * config in linux kernel */
	int64_t offset;
	if ((ret = fd2file(fd, &file)) != 0) {
		return 0;
	}

	if (!file->writable) {
		return -E_INVAL;
	}
	filemap_acquire(file);
	offset = file->pos;
	struct device *dev = vop_info(file->node, device);
	assert(dev);
	ret = dev->d_linux_write(dev, base, len, (size_t *) & offset);
	if (ret >= 0) {
		*copied_store = (size_t) ret;
		file->pos += ret;
		ret = 0;
	}
	filemap_release(file);
	return ret;
}
コード例 #2
0
ファイル: file.c プロジェクト: cty12/ucore_plus
int file_seek(int fd, off_t pos, int whence)
{
	struct stat __stat, *stat = &__stat;
	int ret;
	struct file *file;
	if ((ret = fd2file(fd, &file)) != 0) {
		return ret;
	}
	filemap_acquire(file);

	switch (whence) {
	case LSEEK_SET:
		break;
	case LSEEK_CUR:
		pos += file->pos;
		break;
	case LSEEK_END:
		if ((ret = vop_fstat(file->node, stat)) == 0) {
			pos += stat->st_size;
		}
		break;
	default:
		ret = -E_INVAL;
	}

	if (ret == 0) {
		if ((ret = vop_tryseek(file->node, pos)) == 0) {
			file->pos = pos;
		}
	}
	filemap_release(file);
	return ret;
}
コード例 #3
0
ファイル: vmm.c プロジェクト: piyifan/ucore_plus-next
static void vma_unmapfile(struct vma_struct *vma)
{
	/*
	   kprintf("un_mapfile:0x%08x\n", vma->mfile.file);
	 */

	if (vma->mfile.file != NULL) {
		filemap_release(vma->mfile.file);
	}
	vma->mfile.file = NULL;
}
コード例 #4
0
ファイル: file.c プロジェクト: cty12/ucore_plus
int file_fsync(int fd)
{
	int ret;
	struct file *file;
	if ((ret = fd2file(fd, &file)) != 0) {
		return ret;
	}
	filemap_acquire(file);
	ret = vop_fsync(file->node);
	filemap_release(file);
	return ret;
}
コード例 #5
0
ファイル: file.c プロジェクト: cty12/ucore_plus
int file_fstat(int fd, struct stat *stat)
{
	int ret;
	struct file *file;
	if ((ret = fd2file(fd, &file)) != 0) {
		return ret;
	}
	filemap_acquire(file);
	ret = vop_fstat(file->node, stat);
	filemap_release(file);
	return ret;
}
コード例 #6
0
ファイル: file.c プロジェクト: cty12/ucore_plus
int linux_devfile_ioctl(int fd, unsigned int cmd, unsigned long arg)
{
	int ret = -E_INVAL;
	struct file *file;
	if ((ret = fd2file(fd, &file)) != 0) {
		return 0;
	}
	filemap_acquire(file);
	struct device *dev = vop_info(file->node, device);
	assert(dev);
	ret = dev->d_linux_ioctl(dev, cmd, arg);
	filemap_release(file);
	return ret;
}
コード例 #7
0
ファイル: file.c プロジェクト: chyyuu/ucore-arch-arm
void *linux_devfile_mmap2(void *addr, size_t len, int prot, int flags, int fd, size_t pgoff)
{
  int ret = -E_INVAL;
  struct file *file;
  if ((ret = fd2file(fd, &file)) != 0) {
    return NULL;
  }
  filemap_acquire(file);
  struct device *dev = vop_info(file->node, device);
  assert(dev);
  void* r = dev->d_linux_mmap(dev, addr, len, prot, flags, pgoff);
  filemap_release(file);
  return r;
}
コード例 #8
0
ファイル: file.c プロジェクト: chyyuu/ucore-arch-arm
int
file_getdirentry(int fd, struct dirent *direntp) {
    int ret;
    struct file *file;
    if ((ret = fd2file(fd, &file)) != 0) {
        return ret;
    }
    filemap_acquire(file);

    struct iobuf __iob, *iob = iobuf_init(&__iob, direntp->d_name, sizeof(direntp->d_name), direntp->d_off);
    if ((ret = vop_getdirentry(file->node, iob)) == 0) {
        direntp->d_off += iobuf_used(iob);
    }
    filemap_release(file);
    return ret;
}
コード例 #9
0
int
file_getdirentry(int fd, struct dirent *direntp) {
    int ret;
    struct file *file;
    if ((ret = fd2file(fd, &file)) != 0) {
        return ret;
    }
    filemap_acquire(file);
    // kprintf("%s %s %d\n", __FILE__, __func__, __LINE__);
    struct iobuf __iob, *iob = iobuf_init(&__iob, direntp->name, sizeof(direntp->name), direntp->offset);
    if ((ret = vop_getdirentry(file->node, iob)) == 0) {
        direntp->offset += iobuf_used(iob);
    }
    filemap_release(file);
    return ret;
}
コード例 #10
0
ファイル: file.c プロジェクト: tansinan/ucore_plus
int file_write(int fd, void *base, size_t len, size_t * copied_store)
{
	int ret;
	struct file *file;
	*copied_store = 0;
	if ((ret = fd2file(fd, &file)) != 0) {
		return ret;
	}
	if (!file->writable) {
		return -E_INVAL;
	}
	filemap_acquire(file);

	struct iobuf __iob, *iob = iobuf_init(&__iob, base, len, file->pos);
	ret = vop_write(file->node, iob, file->io_flags);

	size_t copied = iobuf_used(iob);
	file->pos += copied;
	*copied_store = copied;
	filemap_release(file);
	return ret;
}
コード例 #11
0
ファイル: file.c プロジェクト: cty12/ucore_plus
/*
 * file_read - read file
 * */
int file_read(int fd, void *base, size_t len, size_t * copied_store)
{
	int ret;
	struct file *file;
	*copied_store = 0;
	if ((ret = fd2file(fd, &file)) != 0) {
		return ret;
	}
	if (!file->readable) {
		return -E_INVAL;
	}
	filemap_acquire(file);

	struct iobuf __iob, *iob = iobuf_init(&__iob, base, len, file->pos);
	ret = vop_read(file->node, iob);

	size_t copied = iobuf_used(iob);
	if (file->status == FD_OPENED) {
		file->pos += copied;
	}
	*copied_store = copied;
	filemap_release(file);
	return ret;
}