}
-static int blk_free(struct vm_device * dev) {
- return -1;
+static int blk_free(struct blk_state * blk) {
+ V3_FreePages((void *)blk->blk_base_addr, blk->capacity / 4096);
+
+ V3_Free(blk);
+ return 0;
}
static struct v3_device_ops dev_ops = {
- .free = blk_free,
+ .free = (int (*)(void *))blk_free,
};
blk = (struct blk_state *)V3_Malloc(sizeof(struct blk_state));
+ if (!blk) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
blk->capacity = capacity;
blk->blk_base_addr = (addr_t)V3_AllocPages(blk->capacity / 4096);
+
+ if (!blk->blk_base_addr) {
+ PrintError("Cannot allocate block space\n");
+ V3_Free(blk);
+ return -1;
+ }
+
blk->blk_space = (uint8_t *)V3_VAddr((void *)(blk->blk_base_addr));
memset(blk->blk_space, 0, capacity);