Exemple #1
0
// read file
int
file_read(int fd, void *base, size_t len, size_t *copied_store) {
    cprintf("file_read begin\n");
    int ret;
    struct file *file;
    *copied_store = 0;
    if ((ret = fd2file(fd, &file)) != 0) {
        return ret;
    }
    if (!file->readable) {
        return -E_INVAL;
    }
    fd_array_acquire(file);
    cprintf("file_read file acquired\n");

    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;
    fd_array_release(file);
    cprintf("file_read file released\n");
    cprintf("file_read end\n");
    return ret;
}
Exemple #2
0
int filestruct_read(struct file *file, void *base, size_t len)
{
	struct iobuf __iob, *iob = iobuf_init(&__iob, base, len, file->pos);
	vop_read(file->node, iob);
	size_t copied = iobuf_used(iob);
	file->pos += copied;
	return copied;
}
Exemple #3
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);

    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;
}
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;
}
Exemple #5
0
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;
}