Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
script3r
GitHub Repository: script3r/os161
Path: blob/master/user/include/unistd.h
734 views
1
/*
2
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
3
* The President and Fellows of Harvard College.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
7
* are met:
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* 3. Neither the name of the University nor the names of its contributors
14
* may be used to endorse or promote products derived from this software
15
* without specific prior written permission.
16
*
17
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
18
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
21
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
* SUCH DAMAGE.
28
*/
29
30
#ifndef _UNISTD_H_
31
#define _UNISTD_H_
32
33
#include <sys/types.h>
34
35
/*
36
* Get the various constants (flags, codes, etc.) for calls from
37
* kernel includes. This way user-level code doesn't need to know
38
* about the kern/ headers.
39
*/
40
#include <kern/fcntl.h>
41
#include <kern/ioctl.h>
42
#include <kern/reboot.h>
43
#include <kern/seek.h>
44
#include <kern/time.h>
45
#include <kern/unistd.h>
46
#include <kern/wait.h>
47
48
49
/*
50
* Prototypes for OS/161 system calls.
51
*
52
* Note that the following system calls are prototyped in other
53
* header files, as follows:
54
*
55
* stat: sys/stat.h
56
* fstat: sys/stat.h
57
* lstat: sys/stat.h
58
* mkdir: sys/stat.h
59
*
60
* If this were standard Unix, more prototypes would go in other
61
* header files as well, as follows:
62
*
63
* waitpid: sys/wait.h
64
* open: fcntl.h or sys/fcntl.h
65
* reboot: sys/reboot.h
66
* ioctl: sys/ioctl.h
67
* remove: stdio.h
68
* rename: stdio.h
69
* time: time.h
70
*
71
* Also note that the prototypes for open() and mkdir() contain, for
72
* compatibility with Unix, an extra argument that is not meaningful
73
* in OS/161. This is the "mode" (file permissions) for a newly created
74
* object. (With open, if no file is created, this is ignored, and the
75
* call prototype is gimmicked so it doesn't have to be passed either.)
76
*
77
* You should ignore these arguments in the OS/161 kernel unless you're
78
* implementing security and file permissions.
79
*
80
* If you are implementing security and file permissions and using a
81
* model different from Unix so that you need different arguments to
82
* these calls, you may make appropriate changes, or define new syscalls
83
* with different names and take the old ones out, or whatever.
84
*
85
* As a general rule of thumb, however, while you can make as many new
86
* syscalls of your own as you like, you shouldn't change the
87
* definitions of the ones that are already here. They've been written
88
* to be pretty much compatible with Unix, and the teaching staff has
89
* test code that expects them to behave in particular ways.
90
*
91
* Of course, if you want to redesign the user/kernel API and make a
92
* lot of work for yourself, feel free, just contact the teaching
93
* staff beforehand. :-)
94
*
95
* The categories (required/recommended/optional) are guesses - check
96
* the text of the various assignments for an authoritative list.
97
*/
98
99
100
/*
101
* NOTE NOTE NOTE NOTE NOTE
102
*
103
* This file is *not* shared with the kernel, even though in a sense
104
* the kernel needs to know about these prototypes. This is because,
105
* due to error handling concerns, the in-kernel versions of these
106
* functions will usually have slightly different signatures.
107
*/
108
109
110
#ifdef __GNUC__
111
/* GCC gets into a snit if _exit isn't declared to not return */
112
#define __DEAD __attribute__((__noreturn__))
113
#else
114
#define __DEAD
115
#endif
116
117
/* Required. */
118
__DEAD void _exit(int code);
119
int execv(const char *prog, char *const *args);
120
pid_t fork(void);
121
int waitpid(pid_t pid, int *returncode, int flags);
122
/*
123
* Open actually takes either two or three args: the optional third
124
* arg is the file mode used for creation. Unless you're implementing
125
* security and permissions, you can ignore it.
126
*/
127
int open(const char *filename, int flags, ...);
128
int read(int filehandle, void *buf, size_t size);
129
int write(int filehandle, const void *buf, size_t size);
130
int close(int filehandle);
131
int reboot(int code);
132
int sync(void);
133
/* mkdir - see sys/stat.h */
134
int rmdir(const char *dirname);
135
136
/* Recommended. */
137
int getpid(void);
138
int ioctl(int filehandle, int code, void *buf);
139
off_t lseek(int filehandle, off_t pos, int code);
140
int fsync(int filehandle);
141
int ftruncate(int filehandle, off_t size);
142
int remove(const char *filename);
143
int rename(const char *oldfile, const char *newfile);
144
int link(const char *oldfile, const char *newfile);
145
/* fstat - see sys/stat.h */
146
int chdir(const char *path);
147
148
/* Optional. */
149
void *sbrk(int change);
150
int getdirentry(int filehandle, char *buf, size_t buflen);
151
int symlink(const char *target, const char *linkname);
152
int readlink(const char *path, char *buf, size_t buflen);
153
int dup2(int filehandle, int newhandle);
154
int pipe(int filehandles[2]);
155
time_t __time(time_t *seconds, unsigned long *nanoseconds);
156
int __getcwd(char *buf, size_t buflen);
157
/* stat - see sys/stat.h */
158
/* lstat - see sys/stat.h */
159
160
/*
161
* These are not themselves system calls, but wrapper routines in libc.
162
*/
163
164
char *getcwd(char *buf, size_t buflen); /* calls __getcwd */
165
time_t time(time_t *seconds); /* calls __time */
166
167
#endif /* _UNISTD_H_ */
168
169