summaryrefslogtreecommitdiff
path: root/src/kernel/arch/amd64/driver/util.c
blob: f02c4e2773708d7566e688ed75de904957a7d73a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <camellia/fsutil.h>
#include <kernel/arch/amd64/driver/util.h>
#include <kernel/panic.h>
#include <kernel/proc.h>
#include <kernel/vfs/request.h>

int req_readcopy(VfsReq *req, const void *buf, size_t len) {
	if (!req->caller) return -1;
	assert(req->type == VFSOP_READ);
	fs_normslice(&req->offset, &req->output.len, len, false);
	/* read errors are ignored. TODO write a spec */
	pcpy_to(req->caller, req->output.buf, buf + req->offset, req->output.len);
	return req->output.len;
}

size_t ring_to_virt(ring_t *r, Proc *proc, void __user *ubuf, size_t max) {
	char tmp[32];
	if (max > sizeof tmp) max = sizeof tmp;
	max = ring_get(r, tmp, max);
	return pcpy_to(proc, ubuf, tmp, max);
}