tac0S
Template Affectional Command Operating System
sysdep.h
Go to the documentation of this file.
1 
13 #ifndef SYSDEP_H
14 #define SYSDEP_H
15 
16 #include "copyright.h"
17 
18 // Check file to see if there are any characters to be read.
19 // If no characters in the file, return without waiting.
20 extern bool PollFile(int fd);
21 
22 // File operations: open/read/write/lseek/close, and check for error
23 // For simulating the disk and the console devices.
24 extern int OpenForWrite(const char *name);
25 extern int OpenForReadWrite(const char *name, bool crashOnError);
26 extern void Read(int fd, char *buffer, int nBytes);
27 extern int ReadPartial(int fd, char *buffer, int nBytes);
28 extern void WriteFile(int fd, const char *buffer, int nBytes);
29 extern void Lseek(int fd, int offset, int whence);
30 extern int Tell(int fd);
31 extern void Close(int fd);
32 extern bool Unlink(const char *name);
33 
34 // Interprocess communication operations, for simulating the network
35 extern int OpenSocket();
36 extern void CloseSocket(int sockID);
37 extern void AssignNameToSocket(const char *socketName, int sockID);
38 extern void DeAssignNameToSocket(const char *socketName);
39 extern bool PollSocket(int sockID);
40 extern void ReadFromSocket(int sockID, char *buffer, int packetSize);
41 extern void SendToSocket(int sockID, const char *buffer, int packetSize, const char *toName);
42 
44 extern void Abort();
45 extern void Exit(int exitCode);
46 extern void Delay(int seconds);
47 
49 extern void CallOnUserAbort(VoidNoArgFunctionPtr cleanUp);
50 
52 extern void RandomInit(unsigned seed);
53 extern int Random();
54 
57 extern char *AllocBoundedArray(int size);
58 extern void DeallocBoundedArray(char *p, int size);
59 
62 #include <stdlib.h> // for atoi, atof, abs
63 #include <stdio.h> // for printf, fprintf
64 #include <string.h> // for DEBUG, etc.
65 
66 #endif // SYSDEP_H
void Read(int fd, char *buffer, int nBytes)
Read Read characters from an open file. Abort if read fails.
Definition: coff2flat.c:37
void AssignNameToSocket(const char *socketName, int sockID)
AssignNameToSocket Give a UNIX file name to the IPC port, so other instances of Nachos can locate the...
Definition: sysdep.cc:312
void CallOnUserAbort(VoidNoArgFunctionPtr cleanUp)
Initialize system so that cleanUp routine is called when user hits ctl-C.
Definition: sysdep.cc:404
bool Unlink(const char *name)
Unlink Delete a file.
Definition: sysdep.cc:259
void Abort()
Process control: abort, exit, and sleep.
Definition: sysdep.cc:428
void ReadFromSocket(int sockID, char *buffer, int packetSize)
ReadFromSocket Read a fixed size packet off the IPC port. Abort on error.
Definition: sysdep.cc:351
int OpenForWrite(const char *name)
OpenForWrite Open a file for writing. Create it if it doesn&#39;t exist; truncate it if it does already e...
Definition: sysdep.cc:151
int OpenForReadWrite(const char *name, bool crashOnError)
OpenForReadWrite Open a file for reading or writing.
Definition: sysdep.cc:168
void Lseek(int fd, int offset, int whence)
Lseek Change the location within an open file. Abort on error.
Definition: sysdep.cc:219
void DeAssignNameToSocket(const char *socketName)
DeAssignNameToSocket Delete the UNIX file name we assigned to our IPC port, on cleanup.
Definition: sysdep.cc:330
void Close(int fd)
Close Close a file. Abort on error.
Definition: sysdep.cc:247
int Tell(int fd)
Tell Report the current location within an open file.
Definition: sysdep.cc:231
void RandomInit(unsigned seed)
Initialize the pseudo random number generator.
Definition: sysdep.cc:451
void SendToSocket(int sockID, const char *buffer, int packetSize, const char *toName)
SendToSocket Transmit a fixed size packet to another Nachos&#39; IPC port. Abort on error.
Definition: sysdep.cc:385
bool PollSocket(int sockID)
PollSocket.
Definition: sysdep.cc:341
void WriteFile(int fd, const char *buffer, int nBytes)
WriteFile Write characters to an open file. Abort if write fails.
Definition: sysdep.cc:207
void DeallocBoundedArray(char *p, int size)
DeallocBoundedArray Deallocate an array of integers, unprotecting its two boundary pages...
Definition: sysdep.cc:499
int ReadPartial(int fd, char *buffer, int nBytes)
ReadPartial Read characters from an open file, returning as many as are available.
Definition: sysdep.cc:195
void Exit(int exitCode)
Exit Quit without dropping core.
Definition: sysdep.cc:439
void CloseSocket(int sockID)
CloseSocket Close the IPC connection.
Definition: sysdep.cc:288
int Random()
Random.
Definition: sysdep.cc:462
void Delay(int seconds)
Sleep Put the UNIX process running Nachos to sleep for x seconds, to give the user time to start up a...
Definition: sysdep.cc:417
char * AllocBoundedArray(int size)
Allocate, de-allocate an array, such that de-referencing just beyond either end of the array will cau...
Definition: sysdep.cc:480
int OpenSocket()
OpenSocket Open an interprocess communication (IPC) connection. For now, just open a datagram port wh...
Definition: sysdep.cc:272
bool PollFile(int fd)
PollFile Check open file or open socket to see if there are any characters that can be read immediate...
Definition: sysdep.cc:117