summaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/file.cc40
-rw-r--r--src/fs/fs.cc4
2 files changed, 43 insertions, 1 deletions
diff --git a/src/fs/file.cc b/src/fs/file.cc
index 48af49e..99bb65d 100644
--- a/src/fs/file.cc
+++ b/src/fs/file.cc
@@ -5,6 +5,9 @@
#include "kernel/proc.h"
#define NFILE 100
+#define SEEK_SET 0
+#define SEEK_CUR 1
+#define SEEK_END 2
namespace FileTable
{
@@ -137,4 +140,41 @@ namespace FileTable
}
return -1;
}
+
+ int lseek(struct file *f, int offset, int whence)
+ {
+ if (f->type != FD_INODE)
+ return -1;
+
+ VFS::ilock(f->ip);
+
+ int new_off = f->off;
+ int size = f->ip->size;
+
+ switch (whence)
+ {
+ case SEEK_SET:
+ new_off = offset;
+ break;
+ case SEEK_CUR:
+ new_off += offset;
+ break;
+ case SEEK_END:
+ new_off = size + offset;
+ break;
+ default:
+ VFS::iunlock(f->ip);
+ return -1;
+ }
+
+ if (new_off < 0)
+ {
+ VFS::iunlock(f->ip);
+ return -1;
+ }
+
+ f->off = new_off;
+ VFS::iunlock(f->ip);
+ return new_off;
+ }
} // namespace FileTable
diff --git a/src/fs/fs.cc b/src/fs/fs.cc
index b2b91c2..c5a34ee 100644
--- a/src/fs/fs.cc
+++ b/src/fs/fs.cc
@@ -111,8 +111,10 @@ namespace VFS
ip->lock.release();
}
- static void iunlockput(Inode *ip)
+ void iunlockput(Inode *ip)
{
+ if (!ip)
+ return;
iunlock(ip);
iput(ip);
}