Skip to content

Commit 8886c64

Browse files
committed
Lecture 111 - Implementing FSEEK in user land
1 parent 981c934 commit 8886c64

15 files changed

Lines changed: 46 additions & 3 deletions

File tree

184 Bytes
Binary file not shown.
192 Bytes
Binary file not shown.
400 Bytes
Binary file not shown.
48 Bytes
Binary file not shown.

PeachOS64Bit/programs/stdlib/src/file.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ void fclose(int fd)
1616
int fread(void* buffer, size_t size, size_t count, long fd)
1717
{
1818
return peachos_fread(buffer, size, count, fd);
19+
}
20+
21+
int fseek(int fd, int offset, int whence)
22+
{
23+
return (int) peachos_fseek(fd, offset, whence);
1924
}

PeachOS64Bit/programs/stdlib/src/file.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
int fopen(const char* filename, const char* mode);
88
void fclose(int fd);
99
int fread(void* buffer, size_t size, size_t count, long fd);
10-
10+
int fseek(int fd, int offset, int whence);
1111
#endif

PeachOS64Bit/programs/stdlib/src/peachos.asm

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ global peachos_exit:function
1414
global peachos_fopen:function
1515
global peachos_fclose:function
1616
global peachos_fread:function
17+
global peachos_fseek:function
1718

1819
; void print(const char* filename)
1920
print:
@@ -110,4 +111,14 @@ peachos_fread:
110111
push qword rdi ; buffer
111112
int 0x80 ; invoke kernel
112113
add rsp, 32 ; restore the stack
113-
ret
114+
ret
115+
116+
; long peachos_fseek(long fd, long offset, long whence);
117+
peachos_fseek:
118+
mov rax, 13 ; Command 13 fseek
119+
push qword rdx ; whence
120+
push qword rsi ; offset
121+
push qword rdi ; fd
122+
int 0x80 ; invokes the kernel
123+
add rsp, 24 ; restores the stack
124+
ret ; return

PeachOS64Bit/programs/stdlib/src/peachos.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ void peachos_exit();
3535
int peachos_fopen(const char* filename, const char* mode);
3636
void peachos_fclose(size_t fd);
3737
long peachos_fread(void* buffer, size_t size, size_t count, long fd);
38-
38+
long peachos_fseek(long fd, long offset, long whence);
3939
#endif
416 Bytes
Binary file not shown.

PeachOS64Bit/src/isr80h/file.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
#include "idt/idt.h"
55
#include <stddef.h>
66
#include <stdint.h>
7+
void* isr80h_command13_fseek(struct interrupt_frame* frame)
8+
{
9+
long fd = (long) task_get_stack_item(task_current(), 0);
10+
long offset = (long) task_get_stack_item(task_current(), 1);
11+
long whence = (long) task_get_stack_item(task_current(), 2);
12+
13+
return (void*) (long) process_fseek(task_current()->process, fd, offset, whence);
14+
}
715

816
void* isr80h_command12_fread(struct interrupt_frame* frame)
917
{

0 commit comments

Comments
 (0)