clang-format
This commit is contained in:
200
kern/lib/uio.c
200
kern/lib/uio.c
@@ -38,127 +38,117 @@
|
||||
* See uio.h for a description.
|
||||
*/
|
||||
|
||||
int
|
||||
uiomove(void *ptr, size_t n, struct uio *uio)
|
||||
{
|
||||
struct iovec *iov;
|
||||
size_t size;
|
||||
int result;
|
||||
int uiomove(void *ptr, size_t n, struct uio *uio) {
|
||||
struct iovec *iov;
|
||||
size_t size;
|
||||
int result;
|
||||
|
||||
if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE) {
|
||||
panic("uiomove: Invalid uio_rw %d\n", (int) uio->uio_rw);
|
||||
}
|
||||
if (uio->uio_segflg==UIO_SYSSPACE) {
|
||||
KASSERT(uio->uio_space == NULL);
|
||||
}
|
||||
else {
|
||||
KASSERT(uio->uio_space == proc_getas());
|
||||
}
|
||||
if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE) {
|
||||
panic("uiomove: Invalid uio_rw %d\n", (int)uio->uio_rw);
|
||||
}
|
||||
if (uio->uio_segflg == UIO_SYSSPACE) {
|
||||
KASSERT(uio->uio_space == NULL);
|
||||
} else {
|
||||
KASSERT(uio->uio_space == proc_getas());
|
||||
}
|
||||
|
||||
while (n > 0 && uio->uio_resid > 0) {
|
||||
/* get the first iovec */
|
||||
iov = uio->uio_iov;
|
||||
size = iov->iov_len;
|
||||
while (n > 0 && uio->uio_resid > 0) {
|
||||
/* get the first iovec */
|
||||
iov = uio->uio_iov;
|
||||
size = iov->iov_len;
|
||||
|
||||
if (size > n) {
|
||||
size = n;
|
||||
}
|
||||
if (size > n) {
|
||||
size = n;
|
||||
}
|
||||
|
||||
if (size == 0) {
|
||||
/* move to the next iovec and try again */
|
||||
uio->uio_iov++;
|
||||
uio->uio_iovcnt--;
|
||||
if (uio->uio_iovcnt == 0) {
|
||||
/*
|
||||
* This should only happen if you set
|
||||
* uio_resid incorrectly (to more than
|
||||
* the total length of buffers the uio
|
||||
* points to).
|
||||
*/
|
||||
panic("uiomove: ran out of buffers\n");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (size == 0) {
|
||||
/* move to the next iovec and try again */
|
||||
uio->uio_iov++;
|
||||
uio->uio_iovcnt--;
|
||||
if (uio->uio_iovcnt == 0) {
|
||||
/*
|
||||
* This should only happen if you set
|
||||
* uio_resid incorrectly (to more than
|
||||
* the total length of buffers the uio
|
||||
* points to).
|
||||
*/
|
||||
panic("uiomove: ran out of buffers\n");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (uio->uio_segflg) {
|
||||
case UIO_SYSSPACE:
|
||||
if (uio->uio_rw == UIO_READ) {
|
||||
memmove(iov->iov_kbase, ptr, size);
|
||||
}
|
||||
else {
|
||||
memmove(ptr, iov->iov_kbase, size);
|
||||
}
|
||||
iov->iov_kbase = ((char *)iov->iov_kbase+size);
|
||||
break;
|
||||
case UIO_USERSPACE:
|
||||
case UIO_USERISPACE:
|
||||
if (uio->uio_rw == UIO_READ) {
|
||||
result = copyout(ptr, iov->iov_ubase,size);
|
||||
}
|
||||
else {
|
||||
result = copyin(iov->iov_ubase, ptr, size);
|
||||
}
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
iov->iov_ubase += size;
|
||||
break;
|
||||
default:
|
||||
panic("uiomove: Invalid uio_segflg %d\n",
|
||||
(int)uio->uio_segflg);
|
||||
}
|
||||
switch (uio->uio_segflg) {
|
||||
case UIO_SYSSPACE:
|
||||
if (uio->uio_rw == UIO_READ) {
|
||||
memmove(iov->iov_kbase, ptr, size);
|
||||
} else {
|
||||
memmove(ptr, iov->iov_kbase, size);
|
||||
}
|
||||
iov->iov_kbase = ((char *)iov->iov_kbase + size);
|
||||
break;
|
||||
case UIO_USERSPACE:
|
||||
case UIO_USERISPACE:
|
||||
if (uio->uio_rw == UIO_READ) {
|
||||
result = copyout(ptr, iov->iov_ubase, size);
|
||||
} else {
|
||||
result = copyin(iov->iov_ubase, ptr, size);
|
||||
}
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
iov->iov_ubase += size;
|
||||
break;
|
||||
default:
|
||||
panic("uiomove: Invalid uio_segflg %d\n", (int)uio->uio_segflg);
|
||||
}
|
||||
|
||||
iov->iov_len -= size;
|
||||
uio->uio_resid -= size;
|
||||
uio->uio_offset += size;
|
||||
ptr = ((char *)ptr + size);
|
||||
n -= size;
|
||||
}
|
||||
iov->iov_len -= size;
|
||||
uio->uio_resid -= size;
|
||||
uio->uio_offset += size;
|
||||
ptr = ((char *)ptr + size);
|
||||
n -= size;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
uiomovezeros(size_t n, struct uio *uio)
|
||||
{
|
||||
/* static, so initialized as zero */
|
||||
static char zeros[16];
|
||||
size_t amt;
|
||||
int result;
|
||||
int uiomovezeros(size_t n, struct uio *uio) {
|
||||
/* static, so initialized as zero */
|
||||
static char zeros[16];
|
||||
size_t amt;
|
||||
int result;
|
||||
|
||||
/* This only makes sense when reading */
|
||||
KASSERT(uio->uio_rw == UIO_READ);
|
||||
/* This only makes sense when reading */
|
||||
KASSERT(uio->uio_rw == UIO_READ);
|
||||
|
||||
while (n > 0) {
|
||||
amt = sizeof(zeros);
|
||||
if (amt > n) {
|
||||
amt = n;
|
||||
}
|
||||
result = uiomove(zeros, amt, uio);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
n -= amt;
|
||||
}
|
||||
while (n > 0) {
|
||||
amt = sizeof(zeros);
|
||||
if (amt > n) {
|
||||
amt = n;
|
||||
}
|
||||
result = uiomove(zeros, amt, uio);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
n -= amt;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convenience function to initialize an iovec and uio for kernel I/O.
|
||||
*/
|
||||
|
||||
void
|
||||
uio_kinit(struct iovec *iov, struct uio *u,
|
||||
void *kbuf, size_t len, off_t pos, enum uio_rw rw)
|
||||
{
|
||||
iov->iov_kbase = kbuf;
|
||||
iov->iov_len = len;
|
||||
u->uio_iov = iov;
|
||||
u->uio_iovcnt = 1;
|
||||
u->uio_offset = pos;
|
||||
u->uio_resid = len;
|
||||
u->uio_segflg = UIO_SYSSPACE;
|
||||
u->uio_rw = rw;
|
||||
u->uio_space = NULL;
|
||||
void uio_kinit(struct iovec *iov, struct uio *u, void *kbuf, size_t len,
|
||||
off_t pos, enum uio_rw rw) {
|
||||
iov->iov_kbase = kbuf;
|
||||
iov->iov_len = len;
|
||||
u->uio_iov = iov;
|
||||
u->uio_iovcnt = 1;
|
||||
u->uio_offset = pos;
|
||||
u->uio_resid = len;
|
||||
u->uio_segflg = UIO_SYSSPACE;
|
||||
u->uio_rw = rw;
|
||||
u->uio_space = NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user