rem: if (pages[i]->state == PAGE_STATE_BUSY)
add: if (writeThrough)
context: write_chunk_to_cache(file_cache_ref *ref, off_t offset, size_t size,	int32 pageOffset, addr_t buffer, size_t bufferSize){	iovec vecs[MAX_IO_VECS];	int32 vecCount = 0;	vm_page *pages[MAX_IO_VECS];	int32 pageIndex = 0;	// allocate pages for the cache and mark them busy	for (size_t pos = 0; pos < size; pos += B_PAGE_SIZE) {		// ToDo: if space is becoming tight, and this cache is already grown		//	big - shouldn't we better steal the pages directly in that case?		//	(a working set like approach for the file cache)		vm_page *page = pages[pageIndex++] = vm_page_allocate_page(PAGE_STATE_FREE);		page->state = PAGE_STATE_BUSY;		vm_cache_insert_page(ref->cache, page, offset + pos);		addr_t virtualAddress;		vm_get_physical_page(page->ppn * B_PAGE_SIZE, &virtualAddress, PHYSICAL_PAGE_CAN_WAIT);		add_to_iovec(vecs, vecCount, MAX_IO_VECS, virtualAddress, B_PAGE_SIZE);		// ToDo: check if the array is large enough!		size_t bytes = min_c(bufferSize, size_t(B_PAGE_SIZE - pageOffset));		if (bytes != B_PAGE_SIZE) {			// This is only a partial write, so we have to read the rest of the page			// from the file to have consistent data in the cache			size_t bytesRead = B_PAGE_SIZE;			iovec readVec = { (void *)virtualAddress, B_PAGE_SIZE };			// ToDo: when calling pages_io(), unlocking the cache_ref would be			//	a great idea. But we can't do this in this loop, so the whole			//	thing should be changed so that pages_io() and the copy stuff			//	below can be called without holding the lock			pages_io(ref, offset + pos, &readVec, 1, &bytesRead, false);			// ToDo: handle errors!		}		// copy data from user buffer if necessary		if (bufferSize != 0) {			user_memcpy((void *)(virtualAddress + pageOffset), (void *)buffer, bytes);			buffer += bytes;			bufferSize -= bytes;			vm_page_set_state(page, PAGE_STATE_MODIFIED);		}		pageOffset = 0;	}	// ToDo: we only have to write the pages back immediately if write-back mode	//	is disabled, which is not possible right now#if 0	// write cached pages back to the file if we were asked to do that	status_t status = readwrite_pages(ref, offset, vecs, vecCount, &size, true);	if (status < B_OK) {		// ToDo: remove allocated pages...		panic("file_cache: remove allocated pages! write pages failed: %s\n", strerror(status));		return status;	}#endif	// unmap the pages again	for (int32 i = 0; i < vecCount; i++) {		addr_t base = (addr_t)vecs[i].iov_base;		size_t size = vecs[i].iov_len;		for (size_t pos = 0; pos < size; pos += B_PAGE_SIZE, base += B_PAGE_SIZE)			vm_put_physical_page(base);	}	// make the pages accessible in the cache	for (int32 i = pageIndex; i-- > 0;) {		if (pages[i]->state == PAGE_STATE_BUSY)			pages[i]->state = PAGE_STATE_ACTIVE;	}	return B_OK;}