add: if (size > fileVecs[0].length) size = fileVecs[0].length;  ASSERT(size <= fileVecs[0].length);
context: readwrite_pages(file_cache_ref *ref, off_t offset, const iovec *vecs, size_t count,	size_t *_numBytes, bool doWrite){	TRACE(("read_pages: ref = %p, offset = %Ld, size = %lu\n", ref, offset, *_numBytes));	// translate the iovecs into direct device accesses	file_io_vec fileVecs[16];	size_t fileVecCount = 16;	size_t numBytes = *_numBytes;	status_t status = vfs_get_file_map(ref->vnode, offset, numBytes, fileVecs, &fileVecCount);	if (status < B_OK)		return status;	// ToDo: handle array overflow gracefully!#ifdef TRACE_FILE_CACHE	dprintf("got %lu file vecs:\n", fileVecCount);	for (size_t i = 0; i < fileVecCount; i++)		dprintf("[%lu] offset = %Ld, size = %Ld\n", i, fileVecs[i].offset, fileVecs[i].length);#endif	// now directly read the data from the device	// the first file_io_vec can be read directly	size_t size = fileVecs[0].length;	if (size > numBytes)		size = numBytes;	if (doWrite)		status = vfs_write_pages(ref->device, ref->cookie, fileVecs[0].offset, vecs, count, &size);	else		status = vfs_read_pages(ref->device, ref->cookie, fileVecs[0].offset, vecs, count, &size);	if (status < B_OK)		return status;	// If the file portion was contiguous, we're already done now	if (size == numBytes)		return B_OK;	// if we reached the end of the file, we can return as well	if (size != fileVecs[0].length) {		*_numBytes = size;		return B_OK;	}	// Too bad, let's process the rest of the file_io_vecs	size_t totalSize = size;	// first, find out where we have to continue in our iovecs	uint32 i = 0;	for (; i < count; i++) {		if (size <= vecs[i].iov_len)			break;		size -= vecs[i].iov_len;	}	size_t vecOffset = size;	for (uint32 fileVecIndex = 1; fileVecIndex < fileVecCount; fileVecIndex++) {		file_io_vec &fileVec = fileVecs[fileVecIndex];		iovec tempVecs[8];		uint32 tempCount = 1;		tempVecs[0].iov_base = (void *)((addr_t)vecs[i].iov_base + vecOffset);		size = min_c(vecs[i].iov_len - vecOffset, fileVec.length);		tempVecs[0].iov_len = size;		vecOffset = 0;		while (size < fileVec.length && ++i < count) {			tempVecs[tempCount].iov_base = vecs[i].iov_base;			tempCount++;						// is this iovec larger than the file_io_vec?			if (vecs[i].iov_len + size > fileVec.length) {				size += tempVecs[tempCount].iov_len = vecOffset = fileVec.length - size;				break;			}			size += tempVecs[tempCount].iov_len = vecs[i].iov_len;		}		size_t bytes = size;		if (doWrite)			status = vfs_read_pages(ref->device, ref->cookie, fileVec.offset, tempVecs, tempCount, &bytes);		else			status = vfs_read_pages(ref->device, ref->cookie, fileVec.offset, tempVecs, tempCount, &bytes);		if (status < B_OK)			return status;		if (size != bytes) {			// there are no more bytes, let's bail out			*_numBytes = size + totalSize;			return B_OK;		}		totalSize += size;	}	return B_OK;}