From 675060882480c21915629750a5a504d9da445ba3 Mon Sep 17 00:00:00 2001
From: Frans Kaashoek <kaashoek@mit.edu>
Date: Thu, 24 Sep 2020 13:18:54 -0400
Subject: When either_copyin/out fails, return an error from write/read

Add a test to check that read/write return an error
---
 kernel/fs.c | 2 ++
 1 file changed, 2 insertions(+)

(limited to 'kernel')

diff --git a/kernel/fs.c b/kernel/fs.c
index ec68cd7..848b2c9 100644
--- a/kernel/fs.c
+++ b/kernel/fs.c
@@ -468,6 +468,7 @@ readi(struct inode *ip, int user_dst, uint64 dst, uint off, uint n)
     m = min(n - tot, BSIZE - off%BSIZE);
     if(either_copyout(user_dst, dst, bp->data + (off % BSIZE), m) == -1) {
       brelse(bp);
+      tot = -1;
       break;
     }
     brelse(bp);
@@ -495,6 +496,7 @@ writei(struct inode *ip, int user_src, uint64 src, uint off, uint n)
     m = min(n - tot, BSIZE - off%BSIZE);
     if(either_copyin(bp->data + (off % BSIZE), user_src, src, m) == -1) {
       brelse(bp);
+      n = -1;
       break;
     }
     log_write(bp);
-- 
cgit v1.2.3