* Append the scatter/gather list elements in 'second' to the * scatter/gather list 'first'. If there is not enough space in * 'first', EFBIG is returned. */
| 829 | * 'first', EFBIG is returned. |
| 830 | */ |
| 831 | int |
| 832 | sglist_join(struct sglist *first, struct sglist *second) |
| 833 | { |
| 834 | struct sglist_seg *flast, *sfirst; |
| 835 | int append; |
| 836 | |
| 837 | /* If 'second' is empty, there is nothing to do. */ |
| 838 | if (second->sg_nseg == 0) |
| 839 | return (0); |
| 840 | |
| 841 | /* |
| 842 | * If the first entry in 'second' can be appended to the last entry |
| 843 | * in 'first' then set append to '1'. |
| 844 | */ |
| 845 | append = 0; |
| 846 | flast = &first->sg_segs[first->sg_nseg - 1]; |
| 847 | sfirst = &second->sg_segs[0]; |
| 848 | if (first->sg_nseg != 0 && |
| 849 | flast->ss_paddr + flast->ss_len == sfirst->ss_paddr) |
| 850 | append = 1; |
| 851 | |
| 852 | /* Make sure 'first' has enough room. */ |
| 853 | if (first->sg_nseg + second->sg_nseg - append > first->sg_maxseg) |
| 854 | return (EFBIG); |
| 855 | |
| 856 | /* Merge last in 'first' and first in 'second' if needed. */ |
| 857 | if (append) |
| 858 | flast->ss_len += sfirst->ss_len; |
| 859 | |
| 860 | /* Append new segments from 'second' to 'first'. */ |
| 861 | bcopy(first->sg_segs + first->sg_nseg, second->sg_segs + append, |
| 862 | (second->sg_nseg - append) * sizeof(struct sglist_seg)); |
| 863 | first->sg_nseg += second->sg_nseg - append; |
| 864 | sglist_reset(second); |
| 865 | return (0); |
| 866 | } |
| 867 | |
| 868 | /* |
| 869 | * Generate a new scatter/gather list from a range of an existing |
nothing calls this directly
no test coverage detected