/*1* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 20092* The President and Fellows of Harvard College.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. Neither the name of the University nor the names of its contributors13* may be used to endorse or promote products derived from this software14* without specific prior written permission.15*16* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*/2829#ifndef _UNISTD_H_30#define _UNISTD_H_3132#include <sys/types.h>3334/*35* Get the various constants (flags, codes, etc.) for calls from36* kernel includes. This way user-level code doesn't need to know37* about the kern/ headers.38*/39#include <kern/fcntl.h>40#include <kern/ioctl.h>41#include <kern/reboot.h>42#include <kern/seek.h>43#include <kern/time.h>44#include <kern/unistd.h>45#include <kern/wait.h>464748/*49* Prototypes for OS/161 system calls.50*51* Note that the following system calls are prototyped in other52* header files, as follows:53*54* stat: sys/stat.h55* fstat: sys/stat.h56* lstat: sys/stat.h57* mkdir: sys/stat.h58*59* If this were standard Unix, more prototypes would go in other60* header files as well, as follows:61*62* waitpid: sys/wait.h63* open: fcntl.h or sys/fcntl.h64* reboot: sys/reboot.h65* ioctl: sys/ioctl.h66* remove: stdio.h67* rename: stdio.h68* time: time.h69*70* Also note that the prototypes for open() and mkdir() contain, for71* compatibility with Unix, an extra argument that is not meaningful72* in OS/161. This is the "mode" (file permissions) for a newly created73* object. (With open, if no file is created, this is ignored, and the74* call prototype is gimmicked so it doesn't have to be passed either.)75*76* You should ignore these arguments in the OS/161 kernel unless you're77* implementing security and file permissions.78*79* If you are implementing security and file permissions and using a80* model different from Unix so that you need different arguments to81* these calls, you may make appropriate changes, or define new syscalls82* with different names and take the old ones out, or whatever.83*84* As a general rule of thumb, however, while you can make as many new85* syscalls of your own as you like, you shouldn't change the86* definitions of the ones that are already here. They've been written87* to be pretty much compatible with Unix, and the teaching staff has88* test code that expects them to behave in particular ways.89*90* Of course, if you want to redesign the user/kernel API and make a91* lot of work for yourself, feel free, just contact the teaching92* staff beforehand. :-)93*94* The categories (required/recommended/optional) are guesses - check95* the text of the various assignments for an authoritative list.96*/979899/*100* NOTE NOTE NOTE NOTE NOTE101*102* This file is *not* shared with the kernel, even though in a sense103* the kernel needs to know about these prototypes. This is because,104* due to error handling concerns, the in-kernel versions of these105* functions will usually have slightly different signatures.106*/107108109#ifdef __GNUC__110/* GCC gets into a snit if _exit isn't declared to not return */111#define __DEAD __attribute__((__noreturn__))112#else113#define __DEAD114#endif115116/* Required. */117__DEAD void _exit(int code);118int execv(const char *prog, char *const *args);119pid_t fork(void);120int waitpid(pid_t pid, int *returncode, int flags);121/*122* Open actually takes either two or three args: the optional third123* arg is the file mode used for creation. Unless you're implementing124* security and permissions, you can ignore it.125*/126int open(const char *filename, int flags, ...);127int read(int filehandle, void *buf, size_t size);128int write(int filehandle, const void *buf, size_t size);129int close(int filehandle);130int reboot(int code);131int sync(void);132/* mkdir - see sys/stat.h */133int rmdir(const char *dirname);134135/* Recommended. */136int getpid(void);137int ioctl(int filehandle, int code, void *buf);138off_t lseek(int filehandle, off_t pos, int code);139int fsync(int filehandle);140int ftruncate(int filehandle, off_t size);141int remove(const char *filename);142int rename(const char *oldfile, const char *newfile);143int link(const char *oldfile, const char *newfile);144/* fstat - see sys/stat.h */145int chdir(const char *path);146147/* Optional. */148void *sbrk(int change);149int getdirentry(int filehandle, char *buf, size_t buflen);150int symlink(const char *target, const char *linkname);151int readlink(const char *path, char *buf, size_t buflen);152int dup2(int filehandle, int newhandle);153int pipe(int filehandles[2]);154time_t __time(time_t *seconds, unsigned long *nanoseconds);155int __getcwd(char *buf, size_t buflen);156/* stat - see sys/stat.h */157/* lstat - see sys/stat.h */158159/*160* These are not themselves system calls, but wrapper routines in libc.161*/162163char *getcwd(char *buf, size_t buflen); /* calls __getcwd */164time_t time(time_t *seconds); /* calls __time */165166#endif /* _UNISTD_H_ */167168169