diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-01-02 10:09:37 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-01-02 10:09:37 +0800 |
| commit | 1c8e37f63d413a559825020289178d442537449e (patch) | |
| tree | 9779a712b5eec91035272e7646eb6811979d7eab /src/fs/file.cc | |
| parent | d8eaa13f2efc1eeca4e5f230d5a2d535aaf27338 (diff) | |
| download | lume-1c8e37f63d413a559825020289178d442537449e.tar.gz lume-1c8e37f63d413a559825020289178d442537449e.tar.xz | |
dev(sell): add simple libc and implement shell
please see the log for detail.
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 |
