os161-1.99
 All Data Structures
unistd.h
00001 /*
00002  * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
00003  *      The President and Fellows of Harvard College.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  */
00029 
00030 #ifndef _UNISTD_H_
00031 #define _UNISTD_H_
00032 
00033 #include <sys/types.h>
00034 
00035 /*
00036  * Get the various constants (flags, codes, etc.) for calls from
00037  * kernel includes. This way user-level code doesn't need to know
00038  * about the kern/ headers.
00039  */
00040 #include <kern/fcntl.h>
00041 #include <kern/ioctl.h>
00042 #include <kern/reboot.h>
00043 #include <kern/seek.h>
00044 #include <kern/time.h>
00045 #include <kern/unistd.h>
00046 #include <kern/wait.h>
00047 
00048 
00049 /*
00050  * Prototypes for OS/161 system calls.
00051  *
00052  * Note that the following system calls are prototyped in other
00053  * header files, as follows:
00054  *
00055  *     stat:     sys/stat.h
00056  *     fstat:    sys/stat.h
00057  *     lstat:    sys/stat.h
00058  *     mkdir:    sys/stat.h
00059  *
00060  * If this were standard Unix, more prototypes would go in other
00061  * header files as well, as follows:
00062  * 
00063  *     waitpid:  sys/wait.h
00064  *     open:     fcntl.h or sys/fcntl.h
00065  *     reboot:   sys/reboot.h
00066  *     ioctl:    sys/ioctl.h
00067  *     remove:   stdio.h
00068  *     rename:   stdio.h
00069  *     time:     time.h
00070  *
00071  * Also note that the prototypes for open() and mkdir() contain, for
00072  * compatibility with Unix, an extra argument that is not meaningful
00073  * in OS/161. This is the "mode" (file permissions) for a newly created
00074  * object. (With open, if no file is created, this is ignored, and the
00075  * call prototype is gimmicked so it doesn't have to be passed either.)
00076  * 
00077  * You should ignore these arguments in the OS/161 kernel unless you're
00078  * implementing security and file permissions. 
00079  *
00080  * If you are implementing security and file permissions and using a 
00081  * model different from Unix so that you need different arguments to
00082  * these calls, you may make appropriate changes, or define new syscalls
00083  * with different names and take the old ones out, or whatever. 
00084  *
00085  * As a general rule of thumb, however, while you can make as many new
00086  * syscalls of your own as you like, you shouldn't change the
00087  * definitions of the ones that are already here. They've been written
00088  * to be pretty much compatible with Unix, and the teaching staff has
00089  * test code that expects them to behave in particular ways.
00090  *
00091  * Of course, if you want to redesign the user/kernel API and make a
00092  * lot of work for yourself, feel free, just contact the teaching
00093  * staff beforehand. :-)
00094  *
00095  * The categories (required/recommended/optional) are guesses - check
00096  * the text of the various assignments for an authoritative list.
00097  */
00098 
00099 
00100 /*
00101  * NOTE NOTE NOTE NOTE NOTE
00102  *
00103  * This file is *not* shared with the kernel, even though in a sense
00104  * the kernel needs to know about these prototypes. This is because,
00105  * due to error handling concerns, the in-kernel versions of these
00106  * functions will usually have slightly different signatures.
00107  */
00108 
00109 
00110 #ifdef __GNUC__
00111 /* GCC gets into a snit if _exit isn't declared to not return */
00112 #define __DEAD __attribute__((__noreturn__))
00113 #else
00114 #define __DEAD
00115 #endif
00116 
00117 /* Required. */
00118 __DEAD void _exit(int code);
00119 int execv(const char *prog, char *const *args);
00120 pid_t fork(void);
00121 int waitpid(pid_t pid, int *returncode, int flags);
00122 /* 
00123  * Open actually takes either two or three args: the optional third
00124  * arg is the file mode used for creation. Unless you're implementing
00125  * security and permissions, you can ignore it.
00126  */
00127 int open(const char *filename, int flags, ...);
00128 int read(int filehandle, void *buf, size_t size);
00129 int write(int filehandle, const void *buf, size_t size);
00130 int close(int filehandle);
00131 int reboot(int code);
00132 int sync(void);
00133 /* mkdir - see sys/stat.h */
00134 int rmdir(const char *dirname);
00135 
00136 /* Recommended. */
00137 int getpid(void);
00138 int ioctl(int filehandle, int code, void *buf);
00139 off_t lseek(int filehandle, off_t pos, int code);
00140 int fsync(int filehandle);
00141 int ftruncate(int filehandle, off_t size);
00142 int remove(const char *filename);
00143 int rename(const char *oldfile, const char *newfile);
00144 int link(const char *oldfile, const char *newfile);
00145 /* fstat - see sys/stat.h */
00146 int chdir(const char *path);
00147 
00148 /* Optional. */
00149 void *sbrk(int change);
00150 int getdirentry(int filehandle, char *buf, size_t buflen);
00151 int symlink(const char *target, const char *linkname);
00152 int readlink(const char *path, char *buf, size_t buflen);
00153 int dup2(int filehandle, int newhandle);
00154 int pipe(int filehandles[2]);
00155 time_t __time(time_t *seconds, unsigned long *nanoseconds);
00156 int __getcwd(char *buf, size_t buflen);
00157 /* stat - see sys/stat.h */
00158 /* lstat - see sys/stat.h */
00159 
00160 /*
00161  * These are not themselves system calls, but wrapper routines in libc.
00162  */
00163 
00164 char *getcwd(char *buf, size_t buflen);         /* calls __getcwd */
00165 time_t time(time_t *seconds);                   /* calls __time */
00166 
00167 #endif /* _UNISTD_H_ */
 All Data Structures