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 */
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;
#ifdef SWAPDEV
-uint8_t *swapbase;
-unsigned int swapcnt;
-blkno_t swapblk;
uint16_t swappage; /* Target page */
/* Table of available maps */
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));
}
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));
}