From 9f1ffbdc20193b22141857affc2a61bb3519bd67 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Mon, 25 Jul 2016 17:34:38 +0100 Subject: [PATCH] block io: rationalise blkdev and swap blk_op variables want thinning out but that can be done later --- Kernel/dev/blkdev.c | 20 ++++++++------------ Kernel/swap.c | 25 ++++++++++++++----------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/Kernel/dev/blkdev.c b/Kernel/dev/blkdev.c index 8791ecf0..d0b6460d 100644 --- a/Kernel/dev/blkdev.c +++ b/Kernel/dev/blkdev.c @@ -84,29 +84,25 @@ static int blkdev_transfer(uint8_t minor, uint8_t rawflag) switch(rawflag){ case 0: /* read single 512-byte sector to buffer in kernel memory */ - blk_op.nblock = 1; - blk_op.lba = udata.u_buf->bf_blk; - blk_op.addr = udata.u_buf->bf_data; break; case 1: /* read some number of 512-byte sectors directly to user memory */ - blk_op.nblock = (udata.u_count >> BLKSHIFT); - if((udata.u_count | (uint16_t)udata.u_offset) & BLKMASK) - panic("blkdev: not integral"); - blk_op.lba = (udata.u_offset >> BLKSHIFT); - blk_op.addr = udata.u_base; + if (d_blkoff(BLKSHIFT)) + return -1; break; #ifdef SWAPDEV case 2: - blk_op.nblock = swapcnt >> BLKSHIFT; - blk_op.lba = swapblk; - blk_op.addr = swapbase; blk_op.swap_page = swappage; break; #endif default: goto xferfail; } + /* FIXME: these should go away now but we need to make u_block some + kind of raw blkno_t that can be 32bit optionally */ + blk_op.nblock = udata.u_nblock; + blk_op.lba = udata.u_block; + blk_op.addr = udata.u_dptr; if(partition == 0){ /* partition 0 is the whole disk and requires no translation */ @@ -130,7 +126,7 @@ static int blkdev_transfer(uint8_t minor, uint8_t rawflag) blk_op.lba += n; } - return count; /* 10/10, would transfer sectors again */ + return count << BLKSHIFT; /* 10/10, would transfer sectors again */ xferfail: udata.u_error = EIO; return -1; diff --git a/Kernel/swap.c b/Kernel/swap.c index 1ae7b4d9..9ff1ea95 100644 --- a/Kernel/swap.c +++ b/Kernel/swap.c @@ -12,9 +12,6 @@ #ifdef SWAPDEV -uint8_t *swapbase; -unsigned int swapcnt; -blkno_t swapblk; uint16_t swappage; /* Target page */ /* Table of available maps */ @@ -36,15 +33,18 @@ int swapmap_alloc(void) return 0; } -/* FIXME: clean this up by having a common i/o structure to avoid - all the mode 1 and mode 2 confusion and conversions */ +/* We can re-use udata.u_block and friends as we can never be swapped while + we are in the middle of an I/O (at least for now). If we rework the kernel + for sleepable I/O this will change */ int swapread(uint16_t dev, blkno_t blkno, unsigned int nbytes, uint16_t buf, uint16_t page) { - swapbase = swap_map(buf); - swapcnt = nbytes; - swapblk = blkno; + udata.u_dptr = swap_map(buf); + udata.u_block = blkno; + if (nbytes & BLKMASK) + panic("swprd"); + udata.u_nblock = nbytes >> BLKSHIFT; swappage = page; return ((*dev_tab[major(dev)].dev_read) (minor(dev), 2, 0)); } @@ -53,9 +53,12 @@ int swapread(uint16_t dev, blkno_t blkno, unsigned int nbytes, int swapwrite(uint16_t dev, blkno_t blkno, unsigned int nbytes, uint16_t buf, uint16_t page) { - swapbase = swap_map(buf); - swapcnt = nbytes; - swapblk = blkno; + /* FIXME: duplication here */ + udata.u_dptr = swap_map(buf); + udata.u_block = blkno; + if (nbytes & BLKMASK) + panic("swpwr"); + udata.u_nblock = nbytes >> BLKSHIFT; swappage = page; return ((*dev_tab[major(dev)].dev_write) (minor(dev), 2, 0)); } -- 2.34.1