From 8d0c3e9ea36396b7037449212526850054121c61 Mon Sep 17 00:00:00 2001 From: Will Sowerbutts Date: Wed, 11 Feb 2015 19:58:45 +0000 Subject: [PATCH] Kernel: readi() - when reading whole sectors, transfer them directly into user memory. --- Kernel/inode.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/Kernel/inode.c b/Kernel/inode.c index ce34f2d4..d0ae1a83 100644 --- a/Kernel/inode.c +++ b/Kernel/inode.c @@ -11,6 +11,8 @@ void readi(inoptr ino, uint8_t flag) unsigned char *bp; uint16_t dev; bool ispipe; + off_t uostash; + usize_t ucstash; dev = ino->c_dev; ispipe = false; @@ -51,19 +53,29 @@ void readi(inoptr ino, uint8_t flag) loop: while (toread) { - if ((pblk = - bmap(ino, udata.u_offset >> BLKSHIFT, - 1)) != NULLBLK) - bp = bread(dev, pblk, 0); - else - bp = zerobuf(); - - amount = - min(toread, BLKSIZE - (udata.u_offset&BLKMASK)); - - uputsys(bp + (udata.u_offset & BLKMASK), amount); - - brelse(bp); + amount = min(toread, BLKSIZE - (udata.u_offset&BLKMASK)); + pblk = bmap(ino, udata.u_offset >> BLKSHIFT, 1); + + if(!ispipe && amount == BLKSIZE && bfind(dev, pblk) == 0){ + /* we can transfer direct from disk to the userspace buffer */ + uostash = udata.u_offset; /* stash file offset */ + ucstash = udata.u_count; /* stash byte count */ + udata.u_count = amount; /* transfer one sector */ + udata.u_offset = ((off_t)pblk) << BLKSHIFT; /* replace with sector offset on device */ + ((*dev_tab[major(dev)].dev_read) (minor(dev), 1, 0)); /* read */ + udata.u_offset = uostash; /* restore file offset */ + udata.u_count = ucstash; /* restore byte count */ + }else{ + /* we transfer through the buffer pool */ + if (pblk == NULLBLK) + bp = zerobuf(); + else + bp = bread(dev, pblk, 0); + + uputsys(bp + (udata.u_offset & BLKMASK), amount); + + brelse(bp); + } udata.u_base += amount; udata.u_offset += amount; @@ -145,7 +157,7 @@ void writei(inoptr ino, uint8_t flag) loop: while (towrite) { - amount = min(towrite, 512 - (udata.u_offset&BLKMASK)); + amount = min(towrite, BLKSIZE - (udata.u_offset&BLKMASK)); if ((pblk = bmap(ino, udata.u_offset >> BLKSHIFT, -- 2.34.1