MentOS  0.8.0
The Mentoring Operating System
syscall.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include "system/syscall_types.h"
9 #include "fs/vfs_types.h"
10 #include "kernel.h"
11 #include "sys/dirent.h"
12 #include "sys/types.h"
13 
15 void syscall_init(void);
16 
19 void syscall_handler(pt_regs *f);
20 
24 
27 void sys_exit(int exit_code);
28 
34 ssize_t sys_read(int fd, void *buf, size_t nbytes);
35 
41 ssize_t sys_write(int fd, const void *buf, size_t nbytes);
42 
51 off_t sys_lseek(int fd, off_t offset, int whence);
52 
63 int sys_open(const char *pathname, int flags, mode_t mode);
64 
68 int sys_close(int fd);
69 
73 int sys_unlink(const char *path);
74 
82 pid_t sys_waitpid(pid_t pid, int *status, int options);
83 
87 int sys_execve(pt_regs *f);
88 
92 int sys_chdir(char const *path);
93 
97 int sys_fchdir(int fd);
98 
101 pid_t sys_getpid(void);
102 
109 pid_t sys_getsid(pid_t pid);
110 
119 pid_t sys_setsid(void);
120 
125 pid_t sys_getpgid(pid_t pid);
126 
132 int sys_setpgid(pid_t pid, pid_t pgid);
133 
136 gid_t sys_getgid(void);
137 
142 int sys_setgid(gid_t gid);
143 
146 gid_t sys_getegid(void);
147 
153 int sys_setregid(gid_t rgid, gid_t egid);
154 
157 pid_t sys_getppid(void);
158 
161 uid_t sys_getuid(void);
162 
167 int sys_setuid(uid_t uid);
168 
171 uid_t sys_geteuid(void);
172 
178 int sys_setreuid(uid_t ruid, uid_t euid);
179 
183 int sys_nice(int increment);
184 
194 int sys_reboot(int magic1, int magic2, unsigned int cmd, void *arg);
195 
201 char *sys_getcwd(char *buf, size_t size);
202 
210 
215 int sys_stat(const char *path, stat_t *buf);
216 
221 int sys_fstat(int fd, stat_t *buf);
222 
227 int sys_mkdir(const char *path, mode_t mode);
228 
232 int sys_rmdir(const char *path);
233 
240 int sys_creat(const char *path, mode_t mode);
241 
247 int sys_readlink(const char *path, char *buffer, size_t bufsize);
248 
253 int sys_symlink(const char *linkname, const char *path);
254 
263 ssize_t sys_getdents(int fd, dirent_t *dirp, unsigned int count);
264 
Functions used to manage directories.
Kernel generic data structure and functions.
signed int pid_t
The type of process id.
Definition: types.h:9
int gid_t
The type of group-id.
Definition: stddef.h:43
long ssize_t
Define the generic signed size type.
Definition: stddef.h:31
long int off_t
The type of offset.
Definition: stddef.h:46
unsigned int mode_t
The type of mode.
Definition: stddef.h:49
int uid_t
The type of user-id.
Definition: stddef.h:40
Directory entry.
Definition: dirent.h:44
Interrupt stack frame.
Definition: kernel.h:24
Data structure which contains information about a file.
Definition: stat.h:16
gid_t sys_getgid(void)
returns the real group ID of the calling process.
Definition: scheduler.c:393
int sys_open(const char *pathname, int flags, mode_t mode)
Given a pathname for a file, open() returns a file descriptor, a small, nonnegative integer for use i...
Definition: open.c:18
int sys_stat(const char *path, stat_t *buf)
Stat the file at the given path.
Definition: stat.c:14
pid_t sys_getppid(void)
Returns the parent process ID (PPID) of the calling process.
Definition: scheduler.c:491
int sys_setuid(uid_t uid)
Tries to set the User ID (UID) of the calling process.
Definition: scheduler.c:433
int sys_fstat(int fd, stat_t *buf)
Retrieves information about the file at the given location.
Definition: stat.c:19
pid_t sys_setsid(void)
creates a new session if the calling process is not a process group leader. The calling process is th...
Definition: scheduler.c:331
int sys_setgid(gid_t gid)
sets the group ID of the calling process.
Definition: scheduler.c:441
int sys_fchdir(int fd)
Changes the working directory.
Definition: process.c:462
int sys_readlink(const char *path, char *buffer, size_t bufsize)
Read the symbolic link, if present.
Definition: namei.c:79
ssize_t sys_getdents(int fd, dirent_t *dirp, unsigned int count)
Definition: readdir.c:16
pid_t sys_getpgid(pid_t pid)
returns the Process Group ID (PGID) of the process specified by pid. If pid is zero,...
Definition: scheduler.c:348
gid_t sys_getegid(void)
returns the effective group ID of the calling process.
Definition: scheduler.c:397
off_t sys_lseek(int fd, off_t offset, int whence)
Repositions the file offset inside a file.
Definition: read_write.c:82
pid_t sys_getpid(void)
Returns the process ID (PID) of the calling process.
Definition: scheduler.c:293
pt_regs * get_current_interrupt_stack_frame(void)
Returns the current interrupt stack frame.
Definition: syscall.c:252
void syscall_init(void)
Initialize the system calls.
Definition: syscall.c:57
int sys_setregid(gid_t rgid, gid_t egid)
sets the real and effective group ID of the calling process.
Definition: scheduler.c:470
void sys_exit(int exit_code)
Definition: scheduler.c:654
int sys_nice(int increment)
Adds the increment to the priority value of the task.
Definition: scheduler.c:500
int sys_symlink(const char *linkname, const char *path)
Creates a symbolic link.
Definition: namei.c:74
int sys_chdir(char const *path)
Changes the working directory.
Definition: process.c:439
int sys_close(int fd)
Definition: open.c:55
int sys_rmdir(const char *path)
Removes the given directory.
Definition: namei.c:45
pid_t sys_waitpid(pid_t pid, int *status, int options)
Suspends execution of the calling thread until a child specified by pid argument has changed state.
Definition: scheduler.c:534
int sys_mkdir(const char *path, mode_t mode)
Creates a new directory at the given path.
Definition: namei.c:40
int sys_creat(const char *path, mode_t mode)
Creates a new file or rewrite an existing one.
Definition: namei.c:50
int sys_unlink(const char *path)
Delete a name and possibly the file it refers to.
Definition: namei.c:35
int sys_setpgid(pid_t pid, pid_t pgid)
Sets the Process Group ID (PGID) of the process specified by pid. If pid is zero, the process ID of t...
Definition: scheduler.c:362
uid_t sys_getuid(void)
Returns the real User ID (UID) of the calling process.
Definition: scheduler.c:384
pid_t sys_fork(pt_regs *f)
Clone the calling process, but without copying the whole address space. The calling process is suspen...
Definition: process.c:489
char * sys_getcwd(char *buf, size_t size)
Get current working directory.
Definition: process.c:429
int sys_setreuid(uid_t ruid, uid_t euid)
Set the real and effective User ID (UID) of the calling process.
Definition: scheduler.c:449
ssize_t sys_write(int fd, const void *buf, size_t nbytes)
Write data into a file descriptor.
Definition: read_write.c:49
int sys_reboot(int magic1, int magic2, unsigned int cmd, void *arg)
Reboots the system, or enables/disables the reboot keystroke.
Definition: sys.c:35
int sys_execve(pt_regs *f)
Replaces the current process image with a new process image.
Definition: process.c:527
void syscall_handler(pt_regs *f)
Handler for the system calls.
Definition: syscall.c:257
ssize_t sys_read(int fd, void *buf, size_t nbytes)
Read data from a file descriptor.
Definition: read_write.c:14
time_t sys_time(time_t *time)
Returns the current time.
Definition: time.c:24
uid_t sys_geteuid(void)
Returns the effective User ID (UID) of the calling process.
Definition: scheduler.c:388
pid_t sys_getsid(pid_t pid)
Return session id of the given process. If pid == 0 return the SID of the calling process If pid !...
Definition: scheduler.c:304
System Call numbers.
unsigned int time_t
Used to store time values.
Definition: time.h:22
time_t time(time_t *t)
Returns the current time.
Virtual filesystem data types.