summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authoralfred <alfred@FreeBSD.org>2001-05-17 19:47:09 +0000
committeralfred <alfred@FreeBSD.org>2001-05-17 19:47:09 +0000
commit91f8c63e8d3023bef3cab74b22bda09ae1d3e4ac (patch)
tree614407fb8fe15fef373b2e7a4f34ac0594539b83 /sys
parent6059e1a104e44d3a8a0724eeebb44bed8efd77f8 (diff)
downloadFreeBSD-src-91f8c63e8d3023bef3cab74b22bda09ae1d3e4ac.zip
FreeBSD-src-91f8c63e8d3023bef3cab74b22bda09ae1d3e4ac.tar.gz
Cleanup
Remove comment about setting error for reads on EOF, read returns 0 on EOF so the code should be ok. Remove non-effective priority boost, PRIO+1 doesn't do anything (according to McKusick), if a real priority boost is needed it should have been +4. Style fixes: .) return foo -> return (foo) .) FLAG1|FlAG2 -> FLAG1 | FlAG2 .) wrap long lines .) unwrap short lines .) for(i=0;i=foo;i++) -> for (i = 0; i=foo; i++) .) remove braces for some conditionals with a single statement .) fix continuation lines. md5 couldn't verify the binary because some code had to be shuffled around to address the style issues.
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/sys_pipe.c104
1 files changed, 50 insertions, 54 deletions
diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c
index 24b3464..0c32402 100644
--- a/sys/kern/sys_pipe.c
+++ b/sys/kern/sys_pipe.c
@@ -177,7 +177,7 @@ pipe(p, uap)
int fd, error;
if (pipe_zone == NULL)
- pipe_zone = zinit("PIPE", sizeof (struct pipe), 0, 0, 4);
+ pipe_zone = zinit("PIPE", sizeof(struct pipe), 0, 0, 4);
rpipe = wpipe = NULL;
if (pipe_create(&rpipe) || pipe_create(&wpipe)) {
@@ -324,9 +324,8 @@ pipe_create(cpipep)
#endif
error = pipespace(cpipe, PIPE_SIZE);
- if (error) {
+ if (error)
return (error);
- }
vfs_timestamp(&cpipe->pipe_ctime);
cpipe->pipe_atime = cpipe->pipe_ctime;
@@ -348,13 +347,13 @@ pipelock(cpipe, catch)
while (cpipe->pipe_state & PIPE_LOCK) {
cpipe->pipe_state |= PIPE_LWANT;
- if ((error = tsleep( cpipe,
- catch?(PRIBIO|PCATCH):PRIBIO, "pipelk", 0)) != 0) {
- return error;
- }
+ error = tsleep(cpipe, catch ? (PRIBIO | PCATCH) : PRIBIO,
+ "pipelk", 0);
+ if (error != 0)
+ return (error);
}
cpipe->pipe_state |= PIPE_LOCK;
- return 0;
+ return (0);
}
/*
@@ -418,9 +417,9 @@ pipe_read(fp, uio, cred, flags, p)
error = uiomove(&rpipe->pipe_buffer.buffer[rpipe->pipe_buffer.out],
size, uio);
- if (error) {
+ if (error)
break;
- }
+
rpipe->pipe_buffer.out += size;
if (rpipe->pipe_buffer.out >= rpipe->pipe_buffer.size)
rpipe->pipe_buffer.out = 0;
@@ -447,7 +446,8 @@ pipe_read(fp, uio, cred, flags, p)
if (size > (u_int) uio->uio_resid)
size = (u_int) uio->uio_resid;
- va = (caddr_t) rpipe->pipe_map.kva + rpipe->pipe_map.pos;
+ va = (caddr_t) rpipe->pipe_map.kva +
+ rpipe->pipe_map.pos;
error = uiomove(va, size, uio);
if (error)
break;
@@ -462,11 +462,10 @@ pipe_read(fp, uio, cred, flags, p)
} else {
/*
* detect EOF condition
+ * read returns 0 on EOF, no need to set error
*/
- if (rpipe->pipe_state & PIPE_EOF) {
- /* XXX error = ? */
+ if (rpipe->pipe_state & PIPE_EOF)
break;
- }
/*
* If the "write-side" has been blocked, wake it up now.
@@ -493,9 +492,9 @@ pipe_read(fp, uio, cred, flags, p)
* Handle non-blocking mode operation or
* wait for more data.
*/
- if (fp->f_flag & FNONBLOCK)
+ if (fp->f_flag & FNONBLOCK) {
error = EAGAIN;
- else {
+ } else {
rpipe->pipe_state |= PIPE_WANTR;
if ((error = tsleep(rpipe, PRIBIO|PCATCH, "piperd", 0)) == 0)
error = pipelock(rpipe, 1);
@@ -530,7 +529,7 @@ unlocked_error:
if ((rpipe->pipe_buffer.size - rpipe->pipe_buffer.cnt) >= PIPE_BUF)
pipeselwakeup(rpipe);
- return error;
+ return (error);
}
#ifndef PIPE_NODIRECT
@@ -552,18 +551,17 @@ pipe_build_write_buffer(wpipe, uio)
size = wpipe->pipe_buffer.size;
endaddr = round_page((vm_offset_t)uio->uio_iov->iov_base + size);
- for(i = 0, addr = trunc_page((vm_offset_t)uio->uio_iov->iov_base);
- addr < endaddr;
- addr += PAGE_SIZE, i+=1) {
-
+ addr = trunc_page((vm_offset_t)uio->uio_iov->iov_base);
+ for (i = 0; addr < endaddr; addr += PAGE_SIZE, i++) {
vm_page_t m;
if (vm_fault_quick((caddr_t)addr, VM_PROT_READ) < 0 ||
(paddr = pmap_kextract(addr)) == 0) {
int j;
- for(j=0;j<i;j++)
+
+ for (j = 0; j < i; j++)
vm_page_unwire(wpipe->pipe_map.ms[j], 1);
- return EFAULT;
+ return (EFAULT);
}
m = PHYS_TO_VM_PAGE(paddr);
@@ -575,7 +573,8 @@ pipe_build_write_buffer(wpipe, uio)
* set up the control block
*/
wpipe->pipe_map.npages = i;
- wpipe->pipe_map.pos = ((vm_offset_t) uio->uio_iov->iov_base) & PAGE_MASK;
+ wpipe->pipe_map.pos =
+ ((vm_offset_t) uio->uio_iov->iov_base) & PAGE_MASK;
wpipe->pipe_map.cnt = size;
/*
@@ -603,7 +602,7 @@ pipe_build_write_buffer(wpipe, uio)
uio->uio_iov++;
uio->uio_resid -= size;
uio->uio_offset += size;
- return 0;
+ return (0);
}
/*
@@ -611,7 +610,7 @@ pipe_build_write_buffer(wpipe, uio)
*/
static void
pipe_destroy_write_buffer(wpipe)
-struct pipe *wpipe;
+ struct pipe *wpipe;
{
int i;
@@ -626,7 +625,7 @@ struct pipe *wpipe;
amountpipekva -= wpipe->pipe_buffer.size + PAGE_SIZE;
}
}
- for (i=0;i<wpipe->pipe_map.npages;i++)
+ for (i = 0; i < wpipe->pipe_map.npages; i++)
vm_page_unwire(wpipe->pipe_map.ms[i], 1);
}
@@ -644,9 +643,8 @@ pipe_clone_write_buffer(wpipe)
size = wpipe->pipe_map.cnt;
pos = wpipe->pipe_map.pos;
- bcopy((caddr_t) wpipe->pipe_map.kva+pos,
- (caddr_t) wpipe->pipe_buffer.buffer,
- size);
+ bcopy((caddr_t) wpipe->pipe_map.kva + pos,
+ (caddr_t) wpipe->pipe_buffer.buffer, size);
wpipe->pipe_buffer.in = size;
wpipe->pipe_buffer.out = 0;
@@ -672,13 +670,12 @@ pipe_direct_write(wpipe, uio)
retry:
while (wpipe->pipe_state & PIPE_DIRECTW) {
- if ( wpipe->pipe_state & PIPE_WANTR) {
+ if (wpipe->pipe_state & PIPE_WANTR) {
wpipe->pipe_state &= ~PIPE_WANTR;
wakeup(wpipe);
}
wpipe->pipe_state |= PIPE_WANTW;
- error = tsleep(wpipe,
- PRIBIO|PCATCH, "pipdww", 0);
+ error = tsleep(wpipe, PRIBIO | PCATCH, "pipdww", 0);
if (error)
goto error1;
if (wpipe->pipe_state & PIPE_EOF) {
@@ -688,14 +685,13 @@ retry:
}
wpipe->pipe_map.cnt = 0; /* transfer not ready yet */
if (wpipe->pipe_buffer.cnt > 0) {
- if ( wpipe->pipe_state & PIPE_WANTR) {
+ if (wpipe->pipe_state & PIPE_WANTR) {
wpipe->pipe_state &= ~PIPE_WANTR;
wakeup(wpipe);
}
wpipe->pipe_state |= PIPE_WANTW;
- error = tsleep(wpipe,
- PRIBIO|PCATCH, "pipdwc", 0);
+ error = tsleep(wpipe, PRIBIO | PCATCH, "pipdwc", 0);
if (error)
goto error1;
if (wpipe->pipe_state & PIPE_EOF) {
@@ -728,7 +724,7 @@ retry:
wakeup(wpipe);
}
pipeselwakeup(wpipe);
- error = tsleep(wpipe, PRIBIO|PCATCH, "pipdwt", 0);
+ error = tsleep(wpipe, PRIBIO | PCATCH, "pipdwt", 0);
}
pipelock(wpipe,0);
@@ -742,11 +738,11 @@ retry:
pipe_destroy_write_buffer(wpipe);
}
pipeunlock(wpipe);
- return error;
+ return (error);
error1:
wakeup(wpipe);
- return error;
+ return (error);
}
#endif
@@ -769,7 +765,7 @@ pipe_write(fp, uio, cred, flags, p)
* detect loss of pipe read side, issue SIGPIPE if lost.
*/
if ((wpipe == NULL) || (wpipe->pipe_state & PIPE_EOF)) {
- return EPIPE;
+ return (EPIPE);
}
/*
@@ -787,7 +783,7 @@ pipe_write(fp, uio, cred, flags, p)
nbigpipe++;
pipeunlock(wpipe);
} else {
- return error;
+ return (error);
}
}
@@ -797,6 +793,7 @@ pipe_write(fp, uio, cred, flags, p)
orig_resid = uio->uio_resid;
while (uio->uio_resid) {
int space;
+
#ifndef PIPE_NODIRECT
/*
* If the transfer is large, we can gain performance if
@@ -812,9 +809,8 @@ pipe_write(fp, uio, cred, flags, p)
(wpipe->pipe_map.kva || (amountpipekva < LIMITPIPEKVA)) &&
(uio->uio_iov->iov_len >= PIPE_MINDIRECT)) {
error = pipe_direct_write( wpipe, uio);
- if (error) {
+ if (error)
break;
- }
continue;
}
#endif
@@ -832,7 +828,7 @@ pipe_write(fp, uio, cred, flags, p)
wpipe->pipe_state &= ~PIPE_WANTR;
wakeup(wpipe);
}
- error = tsleep(wpipe, PRIBIO|PCATCH, "pipbww", 0);
+ error = tsleep(wpipe, PRIBIO | PCATCH, "pipbww", 0);
if (wpipe->pipe_state & PIPE_EOF)
break;
if (error)
@@ -853,6 +849,7 @@ pipe_write(fp, uio, cred, flags, p)
if ((error = pipelock(wpipe,1)) == 0) {
int size; /* Transfer size */
int segsize; /* first segment to transfer */
+
/*
* It is possible for a direct write to
* slip in on us... handle it here...
@@ -955,9 +952,9 @@ pipe_write(fp, uio, cred, flags, p)
pipeselwakeup(wpipe);
wpipe->pipe_state |= PIPE_WANTW;
- if ((error = tsleep(wpipe, (PRIBIO+1)|PCATCH, "pipewr", 0)) != 0) {
+ error = tsleep(wpipe, PRIBIO | PCATCH, "pipewr", 0);
+ if (error != 0)
break;
- }
/*
* If read side wants to go away, we just issue a signal
* to ourselves.
@@ -970,9 +967,8 @@ pipe_write(fp, uio, cred, flags, p)
}
--wpipe->pipe_busy;
- if ((wpipe->pipe_busy == 0) &&
- (wpipe->pipe_state & PIPE_WANT)) {
- wpipe->pipe_state &= ~(PIPE_WANT|PIPE_WANTR);
+ if ((wpipe->pipe_busy == 0) && (wpipe->pipe_state & PIPE_WANT)) {
+ wpipe->pipe_state &= ~(PIPE_WANT | PIPE_WANTR);
wakeup(wpipe);
} else if (wpipe->pipe_buffer.cnt > 0) {
/*
@@ -1003,7 +999,7 @@ pipe_write(fp, uio, cred, flags, p)
if (wpipe->pipe_buffer.cnt)
pipeselwakeup(wpipe);
- return error;
+ return (error);
}
/*
@@ -1110,7 +1106,7 @@ pipe_stat(fp, ub, p)
{
struct pipe *pipe = (struct pipe *)fp->f_data;
- bzero((caddr_t)ub, sizeof (*ub));
+ bzero((caddr_t)ub, sizeof(*ub));
ub->st_mode = S_IFIFO;
ub->st_blksize = pipe->pipe_buffer.size;
ub->st_size = pipe->pipe_buffer.cnt;
@@ -1124,7 +1120,7 @@ pipe_stat(fp, ub, p)
* Left as 0: st_dev, st_ino, st_nlink, st_rdev, st_flags, st_gen.
* XXX (st_dev, st_ino) should be unique.
*/
- return 0;
+ return (0);
}
/* ARGSUSED */
@@ -1139,7 +1135,7 @@ pipe_close(fp, p)
fp->f_data = NULL;
funsetown(cpipe->pipe_sigio);
pipeclose(cpipe);
- return 0;
+ return (0);
}
static void
@@ -1189,7 +1185,7 @@ pipeclose(cpipe)
*/
while (cpipe->pipe_busy) {
wakeup(cpipe);
- cpipe->pipe_state |= PIPE_WANT|PIPE_EOF;
+ cpipe->pipe_state |= PIPE_WANT | PIPE_EOF;
tsleep(cpipe, PRIBIO, "pipecl", 0);
}
OpenPOWER on IntegriCloud