Implemented emulating write_pages() using the write() hook.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21658 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2007-07-19 13:35:53 +00:00
parent 6a2dfcbd88
commit 9c31fe7e21
1 changed files with 33 additions and 3 deletions

View File

@ -1937,7 +1937,8 @@ devfs_write_pages(fs_volume _fs, fs_vnode _vnode, fs_cookie _cookie, off_t pos,
//TRACE(("devfs_write_pages: vnode %p, vecs %p, count = %lu, pos = %Ld, size = %lu\n", vnode, vecs, count, pos, *_numBytes)); //TRACE(("devfs_write_pages: vnode %p, vecs %p, count = %lu, pos = %Ld, size = %lu\n", vnode, vecs, count, pos, *_numBytes));
if (!S_ISCHR(vnode->stream.type) if (!S_ISCHR(vnode->stream.type)
|| vnode->stream.u.dev.info->write_pages == NULL || (vnode->stream.u.dev.info->write_pages == NULL
&& vnode->stream.u.dev.info->write == NULL)
|| cookie == NULL) || cookie == NULL)
return B_NOT_ALLOWED; return B_NOT_ALLOWED;
@ -1946,10 +1947,39 @@ devfs_write_pages(fs_volume _fs, fs_vnode _vnode, fs_cookie _cookie, off_t pos,
*_numBytes); *_numBytes);
} }
if (vnode->stream.u.dev.info->write_pages) {
return vnode->stream.u.dev.info->write_pages(cookie->device_cookie, pos, return vnode->stream.u.dev.info->write_pages(cookie->device_cookie, pos,
vecs, count, _numBytes); vecs, count, _numBytes);
} }
// emulate write_pages() using write()
status_t error = B_OK;
size_t bytesTransferred = 0;
size_t remainingBytes = *_numBytes;
for (size_t i = 0; i < count && remainingBytes > 0; i++) {
size_t toWrite = min_c(vecs[i].iov_len, remainingBytes);
size_t length = toWrite;
error = vnode->stream.u.dev.info->write(cookie->device_cookie, pos,
vecs[i].iov_base, &length);
if (error != B_OK)
break;
pos += length;
bytesTransferred += length;
remainingBytes -= length;
if (length < toWrite)
break;
}
*_numBytes = bytesTransferred;
return (bytesTransferred > 0 ? B_OK : error);
}
static status_t static status_t
devfs_read_stat(fs_volume _fs, fs_vnode _vnode, struct stat *stat) devfs_read_stat(fs_volume _fs, fs_vnode _vnode, struct stat *stat)