summaryrefslogtreecommitdiff
path: root/kernel/fs.c
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2020-07-16 11:38:08 -0400
committerFrans Kaashoek <[email protected]>2020-08-10 11:19:10 -0400
commitaf9eb9114c2f8700d4315eaa1e2d637c2aaaf210 (patch)
tree9e2e5cc663d2a3d56358121761755a4d3e878d6b /kernel/fs.c
parent672217ae2a3d68b73b2229ab368979ef7790e28a (diff)
downloadxv6-labs-af9eb9114c2f8700d4315eaa1e2d637c2aaaf210.tar.gz
xv6-labs-af9eb9114c2f8700d4315eaa1e2d637c2aaaf210.tar.bz2
xv6-labs-af9eb9114c2f8700d4315eaa1e2d637c2aaaf210.zip
make "echo hello > x" truncate file x.
Diffstat (limited to 'kernel/fs.c')
-rw-r--r--kernel/fs.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/kernel/fs.c b/kernel/fs.c
index 53586d5..e33ec30 100644
--- a/kernel/fs.c
+++ b/kernel/fs.c
@@ -22,7 +22,6 @@
#include "file.h"
#define min(a, b) ((a) < (b) ? (a) : (b))
-static void itrunc(struct inode*);
// there should be one superblock per disk device, but we run with
// only one device
struct superblock sb;
@@ -406,11 +405,8 @@ bmap(struct inode *ip, uint bn)
}
// Truncate inode (discard contents).
-// Only called when the inode has no links
-// to it (no directory entries referring to it)
-// and has no in-memory reference to it (is
-// not an open file or current directory).
-static void
+// Caller must hold ip->lock.
+void
itrunc(struct inode *ip)
{
int i, j;
@@ -463,7 +459,7 @@ readi(struct inode *ip, int user_dst, uint64 dst, uint off, uint n)
struct buf *bp;
if(off > ip->size || off + n < off)
- return -1;
+ return 0;
if(off + n > ip->size)
n = ip->size - off;