diff options
Diffstat (limited to 'src/fs/file.cc')
| -rw-r--r-- | src/fs/file.cc | 40 |
1 files changed, 40 insertions, 0 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 |
