test72: fix mock bdev functions
The minixfs library only ever submits vector elements (and reads) of the system page size. The test implementation was expecting vector elements (and reads) of the file system block size. The resulting mismatch caused I/O to fail in various ways, even though this did not have an effect on the actual test. Change-Id: I02f4a3efcd4a32916435d82c7d5798e6b78f0a27
This commit is contained in:
parent
f018897664
commit
35118b0a91
1 changed files with 34 additions and 53 deletions
|
@ -116,35 +116,27 @@ static void allocate(int b)
|
||||||
ssize_t
|
ssize_t
|
||||||
bdev_gather(dev_t dev, u64_t pos, iovec_t *vec, int count, int flags)
|
bdev_gather(dev_t dev, u64_t pos, iovec_t *vec, int count, int flags)
|
||||||
{
|
{
|
||||||
int i;
|
int i, block;
|
||||||
|
size_t size, block_off;
|
||||||
ssize_t tot = 0;
|
ssize_t tot = 0;
|
||||||
assert(dev == MYDEV);
|
assert(dev == MYDEV);
|
||||||
assert(curblocksize > 0);
|
assert(curblocksize > 0);
|
||||||
assert(!(pos % curblocksize));
|
assert(!(pos % curblocksize));
|
||||||
for(i = 0; i < count; i++) {
|
for(i = 0; i < count; i++) {
|
||||||
int subpages, block, block_off;
|
|
||||||
char *data = (char *) vec[i].iov_addr;
|
char *data = (char *) vec[i].iov_addr;
|
||||||
assert(!(pos % curblocksize));
|
|
||||||
block = pos / curblocksize;
|
block = pos / curblocksize;
|
||||||
block_off = pos % curblocksize;
|
block_off = (size_t)(pos % curblocksize);
|
||||||
assert(!(vec[i].iov_size % PAGE_SIZE));
|
size = vec[i].iov_size;
|
||||||
subpages = vec[i].iov_size / PAGE_SIZE;
|
assert(size == PAGE_SIZE);
|
||||||
while(subpages > 0) {
|
|
||||||
assert(block >= 0);
|
assert(block >= 0);
|
||||||
assert(block < MAXBLOCKS);
|
assert(block < MAXBLOCKS);
|
||||||
assert(block_off >= 0);
|
assert(block_off + size <= curblocksize);
|
||||||
assert(block_off < curblocksize);
|
|
||||||
if(!writtenblocks[block]) {
|
if(!writtenblocks[block]) {
|
||||||
allocate(block);
|
allocate(block);
|
||||||
}
|
}
|
||||||
memcpy(data, writtenblocks[block] + block_off,
|
memcpy(data, writtenblocks[block] + block_off, size);
|
||||||
PAGE_SIZE);
|
pos += size;
|
||||||
block++;
|
tot += size;
|
||||||
subpages--;
|
|
||||||
data += PAGE_SIZE;
|
|
||||||
tot += PAGE_SIZE;
|
|
||||||
block_off += PAGE_SIZE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return tot;
|
return tot;
|
||||||
|
@ -154,29 +146,26 @@ ssize_t
|
||||||
bdev_scatter(dev_t dev, u64_t pos, iovec_t *vec, int count, int flags)
|
bdev_scatter(dev_t dev, u64_t pos, iovec_t *vec, int count, int flags)
|
||||||
{
|
{
|
||||||
int i, block;
|
int i, block;
|
||||||
|
size_t size, block_off;
|
||||||
ssize_t tot = 0;
|
ssize_t tot = 0;
|
||||||
assert(dev == MYDEV);
|
assert(dev == MYDEV);
|
||||||
assert(curblocksize > 0);
|
assert(curblocksize > 0);
|
||||||
assert(!(pos % curblocksize));
|
assert(!(pos % curblocksize));
|
||||||
block = pos / curblocksize;
|
|
||||||
for(i = 0; i < count; i++) {
|
for(i = 0; i < count; i++) {
|
||||||
int subblocks;
|
|
||||||
char *data = (char *) vec[i].iov_addr;
|
char *data = (char *) vec[i].iov_addr;
|
||||||
assert(vec[i].iov_size > 0);
|
block = pos / curblocksize;
|
||||||
assert(!(vec[i].iov_size % PAGE_SIZE));
|
block_off = (size_t)(pos % curblocksize);
|
||||||
subblocks = vec[i].iov_size / curblocksize;
|
size = vec[i].iov_size;
|
||||||
while(subblocks > 0) {
|
assert(size == PAGE_SIZE);
|
||||||
assert(block >= 0);
|
assert(block >= 0);
|
||||||
assert(block < MAXBLOCKS);
|
assert(block < MAXBLOCKS);
|
||||||
|
assert(block_off + size <= curblocksize);
|
||||||
if(!writtenblocks[block]) {
|
if(!writtenblocks[block]) {
|
||||||
allocate(block);
|
allocate(block);
|
||||||
}
|
}
|
||||||
memcpy(writtenblocks[block], data, curblocksize);
|
memcpy(writtenblocks[block] + block_off, data, size);
|
||||||
block++;
|
pos += size;
|
||||||
subblocks--;
|
tot += size;
|
||||||
data += curblocksize;
|
|
||||||
tot += curblocksize;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return tot;
|
return tot;
|
||||||
|
@ -186,31 +175,23 @@ ssize_t
|
||||||
bdev_read(dev_t dev, u64_t pos, char *data, size_t count, int flags)
|
bdev_read(dev_t dev, u64_t pos, char *data, size_t count, int flags)
|
||||||
{
|
{
|
||||||
int block;
|
int block;
|
||||||
ssize_t tot = 0;
|
|
||||||
int subblocks;
|
|
||||||
|
|
||||||
assert(dev == MYDEV);
|
assert(dev == MYDEV);
|
||||||
assert(curblocksize > 0);
|
assert(curblocksize > 0);
|
||||||
assert(!(pos % curblocksize));
|
assert(!(pos % curblocksize));
|
||||||
assert(count > 0);
|
assert(count > 0);
|
||||||
assert(!(count % curblocksize));
|
assert(!(count % curblocksize));
|
||||||
|
assert(count == PAGE_SIZE);
|
||||||
|
assert(curblocksize == PAGE_SIZE);
|
||||||
|
|
||||||
block = pos / curblocksize;
|
block = pos / curblocksize;
|
||||||
subblocks = count / curblocksize;
|
|
||||||
while(subblocks > 0) {
|
|
||||||
assert(block >= 0);
|
assert(block >= 0);
|
||||||
assert(block < MAXBLOCKS);
|
assert(block < MAXBLOCKS);
|
||||||
if(!writtenblocks[block]) {
|
if(!writtenblocks[block]) {
|
||||||
allocate(block);
|
allocate(block);
|
||||||
}
|
}
|
||||||
memcpy(data, writtenblocks[block], curblocksize);
|
memcpy(data, writtenblocks[block], curblocksize);
|
||||||
block++;
|
return count;
|
||||||
subblocks--;
|
|
||||||
data += curblocksize;
|
|
||||||
tot += curblocksize;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tot;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fake some libsys functions */
|
/* Fake some libsys functions */
|
||||||
|
|
Loading…
Reference in a new issue