A Total Overhaul on the Lunaix's Virtual Memory Model (#26)
[lunaix-os.git] / lunaix-os / kernel / block / block.c
index a2242adb39c43b898bba75f562ca67243f9b760a..8ca511783e958138ff4d7d3dc5a5dca94f70df6c 100644 (file)
@@ -9,7 +9,7 @@
 #include <lunaix/block.h>
 #include <lunaix/fs/twifs.h>
 #include <lunaix/mm/cake.h>
-#include <lunaix/mm/page.h>
+#include <lunaix/mm/pagetable.h>
 #include <lunaix/mm/valloc.h>
 #include <lunaix/spike.h>
 #include <lunaix/syslog.h>
@@ -26,7 +26,7 @@ LOG_MODULE("BLOCK")
 static struct cake_pile* lbd_pile;
 static struct block_dev** dev_registry;
 static struct twifs_node* blk_sysroot;
-static struct device* blk_parent_dev;
+static struct device_cat* blk_parent_dev;
 
 int free_slot = 0;
 
@@ -156,7 +156,7 @@ __block_read_page(struct device* dev, void* buf, size_t offset)
     struct block_dev* bdev = (struct block_dev*)dev->underlay;
 
     u32_t lba = offset / bdev->blk_size + bdev->start_lba;
-    u32_t rd_lba = MIN(lba + PG_SIZE / bdev->blk_size, bdev->end_lba);
+    u32_t rd_lba = MIN(lba + PAGE_SIZE / bdev->blk_size, bdev->end_lba);
 
     if (rd_lba <= lba) {
         return 0;
@@ -183,7 +183,7 @@ __block_write_page(struct device* dev, void* buf, size_t offset)
     struct block_dev* bdev = (struct block_dev*)dev->underlay;
 
     u32_t lba = offset / bdev->blk_size + bdev->start_lba;
-    u32_t wr_lba = MIN(lba + PG_SIZE / bdev->blk_size, bdev->end_lba);
+    u32_t wr_lba = MIN(lba + PAGE_SIZE / bdev->blk_size, bdev->end_lba);
 
     if (wr_lba <= lba) {
         return 0;
@@ -299,7 +299,7 @@ __block_register(struct block_dev* bdev)
         return 0;
     }
 
-    struct device* dev = device_allocvol(blk_parent_dev, bdev);
+    struct device* dev = device_allocvol(dev_meta(blk_parent_dev), bdev);
     dev->ops.write = __block_write;
     dev->ops.write_page = __block_write_page;
     dev->ops.read = __block_read;
@@ -307,7 +307,7 @@ __block_register(struct block_dev* bdev)
 
     bdev->dev = dev;
 
-    device_register(dev, bdev->class, "sd%c", 'a' + free_slot);
+    register_device(dev, bdev->class, "sd%c", 'a' + free_slot);
     dev_registry[free_slot++] = bdev;
 
     strcpy(bdev->bdev_id, dev->name_val);
@@ -342,7 +342,7 @@ blk_mount_part(struct block_dev* bdev,
 
     llist_append(&bdev->parts, &pbdev->parts);
 
-    device_register(dev, pbdev->class, "%sp%d", bdev->bdev_id, index + 1);
+    register_device(dev, pbdev->class, "%sp%d", bdev->bdev_id, index + 1);
 
     return pbdev;
 }
\ No newline at end of file