ARGSUSED */
| 688 | |
| 689 | /* ARGSUSED */ |
| 690 | static int |
| 691 | pipe_read(struct file *fp, struct uio *uio, struct ucred *active_cred, |
| 692 | int flags, struct thread *td) |
| 693 | { |
| 694 | struct pipe *rpipe; |
| 695 | int error; |
| 696 | int nread = 0; |
| 697 | int size; |
| 698 | |
| 699 | rpipe = fp->f_data; |
| 700 | PIPE_LOCK(rpipe); |
| 701 | ++rpipe->pipe_busy; |
| 702 | error = pipelock(rpipe, 1); |
| 703 | if (error) |
| 704 | goto unlocked_error; |
| 705 | |
| 706 | #ifdef MAC |
| 707 | error = mac_pipe_check_read(active_cred, rpipe->pipe_pair); |
| 708 | if (error) |
| 709 | goto locked_error; |
| 710 | #endif |
| 711 | if (amountpipekva > (3 * maxpipekva) / 4) { |
| 712 | if ((rpipe->pipe_state & PIPE_DIRECTW) == 0 && |
| 713 | rpipe->pipe_buffer.size > SMALL_PIPE_SIZE && |
| 714 | rpipe->pipe_buffer.cnt <= SMALL_PIPE_SIZE && |
| 715 | piperesizeallowed == 1) { |
| 716 | PIPE_UNLOCK(rpipe); |
| 717 | pipespace(rpipe, SMALL_PIPE_SIZE); |
| 718 | PIPE_LOCK(rpipe); |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | while (uio->uio_resid) { |
| 723 | /* |
| 724 | * normal pipe buffer receive |
| 725 | */ |
| 726 | if (rpipe->pipe_buffer.cnt > 0) { |
| 727 | size = rpipe->pipe_buffer.size - rpipe->pipe_buffer.out; |
| 728 | if (size > rpipe->pipe_buffer.cnt) |
| 729 | size = rpipe->pipe_buffer.cnt; |
| 730 | if (size > uio->uio_resid) |
| 731 | size = uio->uio_resid; |
| 732 | |
| 733 | PIPE_UNLOCK(rpipe); |
| 734 | error = uiomove( |
| 735 | &rpipe->pipe_buffer.buffer[rpipe->pipe_buffer.out], |
| 736 | size, uio); |
| 737 | PIPE_LOCK(rpipe); |
| 738 | if (error) |
| 739 | break; |
| 740 | |
| 741 | rpipe->pipe_buffer.out += size; |
| 742 | if (rpipe->pipe_buffer.out >= rpipe->pipe_buffer.size) |
| 743 | rpipe->pipe_buffer.out = 0; |
| 744 | |
| 745 | rpipe->pipe_buffer.cnt -= size; |
| 746 | |
| 747 | /* |
nothing calls this directly
no test coverage detected