diff options
author | Ian Moffett <ian@osmora.org> | 2025-08-16 20:23:15 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-08-16 20:35:13 -0400 |
commit | 7b0701707857a3205cbd4fc69c08429a193c5bff (patch) | |
tree | 9e12a704d9b59ddff115d0cfafee77c4ed2b938b /sys/kern | |
parent | 4386cfb6490025c4d0f464e31cf4a8d90f065a1b (diff) |
kernel: disk: Introduce virtual blocksmain
This commit implements the concept of virtual blocks which may be bigger
than the hardware block size (e.g., 512 bytes). The virtual block size
must be a multiple of the hardware blocksize. The system will panic if
this condition is not met.
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_disk.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/sys/kern/kern_disk.c b/sys/kern/kern_disk.c index b956c02..af2aa13 100644 --- a/sys/kern/kern_disk.c +++ b/sys/kern/kern_disk.c @@ -171,6 +171,10 @@ __disk_get_id(diskid_t id) * @buf: Buffer to read data into * @len: Number of bytes to read * @write: If true, do a write + * + * XXX: The size in which blocks are read at is in + * virtual blocks which is defined by V_BSIZE + * in sys/disk.h */ static ssize_t disk_rw(diskid_t id, blkoff_t blk, void *buf, size_t len, bool write) @@ -180,6 +184,8 @@ disk_rw(diskid_t id, blkoff_t blk, void *buf, size_t len, bool write) struct disk *dp; int error; + len = ALIGN_UP(len, V_BSIZE); + /* Attempt to grab the disk object */ error = disk_get_id(id, &dp); if (error < 0) { @@ -268,6 +274,10 @@ disk_add(const char *name, dev_t dev, const struct bdevsw *bdev, int flags) dp->id = disk_count++; dp->bsize = DEFAULT_BSIZE; + if ((V_BSIZE & (dp->bsize - 1)) != 0) { + panic("virtual block size not hw bsize aligned\n"); + } + /* Now we can add it to the queue */ spinlock_acquire(&diskq_lock); TAILQ_INSERT_TAIL(&diskq, dp, link); @@ -343,9 +353,9 @@ disk_buf_alloc(diskid_t id, size_t len) /* * Here we will align the buffer size by the - * disk's block size to ensure it is big enough. + * virtual block size to ensure it is big enough. */ - len = ALIGN_UP(len, dp->bsize); + len = ALIGN_UP(len, V_BSIZE); buf = dynalloc(len); return buf; } |