Class Library

Object
  extended byLibrary

public class Library
extends Object

Convenience calls for using the Kernel. Each function in this class makes a system call. Sometimes, the arguments are manipulated to make their user representation more convenient. Note that this class contains only static methods. All methods return integers. Negative return values are error codes. Some methods return positive values; others simply return 0 to mean "ok".

See Also:
Kernel

Field Summary
static String[] errorMessage
          A table of error messages corresponding to Kernel error return codes.
 
Constructor Summary
private Library()
          This private constructor ensures that no instances of Library are ever created.
 
Method Summary
static int create(String fname)
          Creates a new empty file (size 0).
static int exec(String command, String[] args)
          Performs SYSCALL_EXEC.
static int format(int dsize, int isize)
          Formats the disk.
static int input(StringBuffer result)
          Performs SYSCALL_INPUT.
static int join(int pid)
          Performs SYSCALL_JOIN.
static int link(String oldFname, String newFname)
          Adds an additional name to an existing file.
static int list()
          Reports information about the file system to System.out.
static int output(String s)
          Performs SYSCALL_OUTPUT.
static int read(String fname, int offset, byte[] buffer)
          Reads from a file.
static int sync()
          Flushes all cached information to disk.
static int unlink(String fname)
          Removes a name from a file.
static int write(String fname, int offset, byte[] buffer)
          Writes to a file.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

errorMessage

public static final String[] errorMessage
A table of error messages corresponding to Kernel error return codes. This table should be indexed by the negative of rc, where
          rc = Kernel.interrupt(Kernel.INTERRUPT_USER, ... )
 
and rc is less than 0.

Constructor Detail

Library

private Library()
This private constructor ensures that no instances of Library are ever created.

Method Detail

output

public static int output(String s)
Performs SYSCALL_OUTPUT. Displays text on the console.

Parameters:
s - a String to display
Returns:
zero

input

public static int input(StringBuffer result)
Performs SYSCALL_INPUT. Waits for the user to type some text and hit [return]. The input line is returned in the supplied StringBuffer

Parameters:
result - a place to put the result
Returns:
zero on success, or one of the error codes Kernel.END_OF_FILE or Kernel.ERROR_IO.

exec

public static int exec(String command,
                       String[] args)
Performs SYSCALL_EXEC. Launches the named program, and lets it run in parallel to the current program.

Parameters:
command - The name of a Java class to execute.
args - The arguments to give the new program
Returns:
a non-negative process id, or ERROR_BAD_COMMAND.

join

public static int join(int pid)
Performs SYSCALL_JOIN. Waits for a process to terminate

Parameters:
pid - a process id returned by a previous call to exec.
Returns:
zero or ERROR_NO_SUCH_PROCESS

format

public static int format(int dsize,
                         int isize)
Formats the disk. If the disk is already formatted, this system call will destroy all data on it.

Parameters:
dsize - space allocated to the directory, in blocks.
isize - space allocated for inodes, in blocks.
Returns:
0 on success and -1 on failure.

create

public static int create(String fname)
Creates a new empty file (size 0).

Parameters:
fname - the name of the new file being created.
Returns:
0 on success and -1 on failure.

read

public static int read(String fname,
                       int offset,
                       byte[] buffer)
Reads from a file.

Parameters:
fname - the name of the file to read from.
offset - the starting position in the file (0 is start).
buffer - the destination for the data.
Returns:
0 on success and -1 on failure.

write

public static int write(String fname,
                        int offset,
                        byte[] buffer)
Writes to a file.

Parameters:
fname - the name of the file to write to.
offset - the starting position in the file (0 is start).
buffer - the source of the data.
Returns:
0 on success and -1 on failure.

link

public static int link(String oldFname,
                       String newFname)
Adds an additional name to an existing file.

Parameters:
oldFname - the name of an existing file.
newFname - a new name for the file.
Returns:
0 on success and -1 on failure.

unlink

public static int unlink(String fname)
Removes a name from a file.

Parameters:
fname - the name of an existing file. If no other names exist for the file, it is deleted.
Returns:
0 on success and -1 on failure.

list

public static int list()
Reports information about the file system to System.out.

Returns:
0 on success and -1 on failure.

sync

public static int sync()
Flushes all cached information to disk.

Returns:
0 on success and -1 on failure.