Fix the logic for block allocations and check for errors in fiotest.
This commit is contained in:
parent
3e24705537
commit
5fc993d847
@ -25,6 +25,7 @@ int *__error();
|
||||
#define ETIMEDOUT 0x1BAD0010
|
||||
#define EACCES 0x1BAD0011
|
||||
#define EPERM 0x1BAD0012
|
||||
#define ENOSPC 0x1BAD0013
|
||||
|
||||
#define EAFNOSUPPORT 0x1BAD0020
|
||||
#define ENOPROTOOPT 0x1BAD0021
|
||||
|
@ -269,8 +269,8 @@ void Superblock(ObjID *objid)
|
||||
sb.versionMinor = O2FS_VERSION_MINOR;
|
||||
sb.blockCount = diskSize / blockSize;
|
||||
sb.blockSize = blockSize;
|
||||
sb.bitmapSize = sb.blockCount;
|
||||
sb.bitmapOffset = 1;
|
||||
sb.bitmapSize = bitmapSize;
|
||||
sb.bitmapOffset = blockSize;
|
||||
|
||||
if (objid)
|
||||
memcpy(&sb.root, objid, sizeof(ObjID));
|
||||
|
@ -72,11 +72,11 @@ O2FS_Mount(Disk *disk)
|
||||
}
|
||||
|
||||
// Read bitmap
|
||||
for (int i = 0; i < (sb->bitmapSize / sb->blockSize); i++) {
|
||||
for (int i = 0; i < sb->bitmapSize; i++) {
|
||||
ASSERT(i < 16);
|
||||
|
||||
BufCacheEntry *bentry;
|
||||
uint64_t offset = (sb->bitmapOffset + i) * sb->blockSize;
|
||||
uint64_t offset = sb->bitmapOffset + i * sb->blockSize;
|
||||
|
||||
if (BufCache_Read(disk, offset, &bentry) < 0) {
|
||||
Alert(o2fs, "Bitmap read failed\n");
|
||||
@ -94,7 +94,7 @@ O2FS_Mount(Disk *disk)
|
||||
|
||||
fs->fsptr = entry;
|
||||
fs->fsval = sb->root.offset;
|
||||
fs->blksize = sb->bitmapSize;
|
||||
fs->blksize = sb->blockSize;
|
||||
|
||||
// Setup VFS structure
|
||||
fs->op = &O2FSOperations;
|
||||
@ -143,7 +143,7 @@ O2FSBAlloc(VFS *fs)
|
||||
// XXX: Check for end of disk
|
||||
for (int b = 0; b < fs->blksize; b++) {
|
||||
for (int bi = 0; bi < 8; bi++) {
|
||||
if ((bitmap[b] >> bi) & 0x1) {
|
||||
if (((bitmap[b] >> bi) & 0x1) == 0) {
|
||||
/* Set bit */
|
||||
bitmap[b] |= (1 << bi);
|
||||
|
||||
@ -156,12 +156,15 @@ O2FSBAlloc(VFS *fs)
|
||||
* 8 blocks per bitmap byte
|
||||
* bit #
|
||||
*/
|
||||
return fs->blksize*8*i + 8*b + bi;
|
||||
uint64_t blk = fs->blksize*8*i + 8*b + bi;
|
||||
DLOG(o2fs, "BAlloc %lu\n", blk);
|
||||
return blk;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Alert(o2fs, "Out of space!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -180,6 +183,8 @@ O2FSBFree(VFS *fs, uint64_t block)
|
||||
uint64_t bytoff = (block >> 8) % fs->blksize;
|
||||
uint64_t bufoff = block / (fs->blksize*8);
|
||||
|
||||
DLOG(o2fs, "BFree %lu\n", block);
|
||||
|
||||
BufCacheEntry *bentry = fs->bitmap[bufoff];
|
||||
ASSERT(bentry != NULL);
|
||||
|
||||
@ -264,10 +269,17 @@ O2FSGrowVNode(VNode *vn, uint64_t filesz)
|
||||
return -EINVAL;
|
||||
|
||||
for (int i = 0; i < ((filesz + vfs->blksize - 1) / vfs->blksize); i++) {
|
||||
if (bn->direct[i].offset == 0)
|
||||
bn->direct[i].offset = O2FSBAlloc(vfs) * vfs->blksize;
|
||||
if (bn->direct[i].offset == 0) {
|
||||
uint64_t blkno = O2FSBAlloc(vfs);
|
||||
if (blkno == 0) {
|
||||
return -ENOSPC;
|
||||
}
|
||||
|
||||
bn->direct[i].offset = blkno * vfs->blksize;
|
||||
}
|
||||
}
|
||||
|
||||
DLOG(o2fs, "Growing: %d\n", filesz);
|
||||
bn->size = filesz;
|
||||
|
||||
BufCache_Write(vnEntry);
|
||||
@ -554,10 +566,6 @@ O2FS_Write(VNode *fn, void *buf, uint64_t off, uint64_t len)
|
||||
|
||||
DLOG(o2fs, "Write %lld %d\n", fileBN->size, blocks);
|
||||
|
||||
if (off > fileBN->size) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// XXX: Check permissions
|
||||
|
||||
if (fileBN->size < (off+len)) {
|
||||
@ -582,7 +590,7 @@ O2FS_Write(VNode *fn, void *buf, uint64_t off, uint64_t len)
|
||||
if (status < 0)
|
||||
return status;
|
||||
|
||||
DLOG(o2fs, "READ %lx %lx %lld\n", buf, entry->buffer, bLen);
|
||||
DLOG(o2fs, "WRITE %lx %lx %lld\n", buf, entry->buffer, bLen);
|
||||
memcpy(entry->buffer + bOff, buf, bLen);
|
||||
BufCache_Write(entry);
|
||||
BufCache_Release(entry);
|
||||
|
@ -14,7 +14,11 @@ main(int argc, const char *argv[])
|
||||
uint64_t fd = OSOpen("/LICENSE", 0);
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
OSWrite(fd, "123456789\n", i*10, 10);
|
||||
int status = OSWrite(fd, "123456789\n", i*10, 10);
|
||||
if (status < 0) {
|
||||
printf("Error: %x\n", -status);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Success!\n");
|
||||
|
Loading…
Reference in New Issue
Block a user