moss.drivers
Class MRamdisk

java.lang.Object
  extended by moss.drivers.MRamdisk
All Implemented Interfaces:
MFileOps

public class MRamdisk
extends java.lang.Object
implements MFileOps

this implements a "ramdisk" block device


Field Summary
 
Fields inherited from interface moss.fs.MFileOps
F_GETFL, F_OK, F_SETFL, LSEEK_BEG, LSEEK_CUR, LSEEK_END, O_CLOEXEC, O_NONBLOCK, OPEN_CREAT, OPEN_READ, OPEN_TRUNC, OPEN_WRITE, R_OK, W_OK, X_OK
 
Constructor Summary
MRamdisk()
          constructor -- initialises the ramdisk
 
Method Summary
 int close(MFile handle)
          called when closing the ramdisk (it remains intact, however, unless garbage-collected)
 int fcntl(MFile handle, int op, int arg)
          file-handle control
 int lseek(MFile handle, int offset, int whence)
          seeks to a specific block in the ramdisk.
 int open(MFile handle, int flags)
          called when opening the ramdisk; stores reference to self in the file-handle
 int read(MFile handle, byte[] buffer, int count)
          called to read a block from the ramdisk (at the current offset)
 int write(MFile handle, byte[] buffer, int count)
          called to write data to the ramdisk (at the current offset)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MRamdisk

public MRamdisk()
constructor -- initialises the ramdisk

Method Detail

open

public int open(MFile handle,
                int flags)
called when opening the ramdisk; stores reference to self in the file-handle

Specified by:
open in interface MFileOps
Parameters:
handle - file-handle
flags - open flags (ignored)
Returns:
0 on success or < 0 on error

close

public int close(MFile handle)
called when closing the ramdisk (it remains intact, however, unless garbage-collected)

Specified by:
close in interface MFileOps
Parameters:
handle - file-handle
Returns:
0 on success or < 0 on error

lseek

public int lseek(MFile handle,
                 int offset,
                 int whence)
seeks to a specific block in the ramdisk. Seeking to the "end-of-file" is allowed (not much use, though)

Specified by:
lseek in interface MFileOps
Parameters:
handle - file-handle
offset - block offset
whence - where to seek from (LSEEK_{BEG,CUR,END})
Returns:
new absolute block offset, or < 0 indicating error

read

public int read(MFile handle,
                byte[] buffer,
                int count)
called to read a block from the ramdisk (at the current offset)

Specified by:
read in interface MFileOps
Parameters:
handle - file-handle
buffer - buffer where data will be stored
count - maximum number of bytes to read
Returns:
number of bytes read, 0 on end-of-file, or < 0 on error

write

public int write(MFile handle,
                 byte[] buffer,
                 int count)
called to write data to the ramdisk (at the current offset)

Specified by:
write in interface MFileOps
Parameters:
handle - file handle
buffer - data to write
count - number of bytes to write
Returns:
number of bytes written or < 0 on error

fcntl

public int fcntl(MFile handle,
                 int op,
                 int arg)
Description copied from interface: MFileOps
file-handle control

Specified by:
fcntl in interface MFileOps
Parameters:
handle - file-handle
op - operation to perform
arg - argument to operation (if applicable)
Returns:
>= 0 on success, or < 0 indicating failure