moss.fs
Interface MFileOps

All Known Implementing Classes:
MJavaConsole, MPipe, MRamdisk

public interface MFileOps

This interface defines kernel "file-operations". Besides its obvious use for "real" file-handling, it is used to interface any stream in general, including pipes, character devices and block devices. Character devices treat read/write in the way that would be expected, lseek() is probably meaningless though. Block devices treat read/write/lseek a bit differently: read() must be called with the correct sized block of data (ie, the device block-size) write() must be used in similar manner lseek() offsets are block offsets, not byte-offsets. BEG/CUR/END are still valid, however How a block-device handles its own internal management of the "offset" is up to it.. i'd suggest all operations sharing a common offset, that is the block offset, which read() and write() increment.


Field Summary
static int F_GETFL
          get file-descriptor flags
static int F_OK
          file exists
static int F_SETFL
          set file-descriptor flags
static int LSEEK_BEG
          seek from beginning of file
static int LSEEK_CUR
          seek from current offset
static int LSEEK_END
          seek from end of file
static int O_CLOEXEC
          close on exec flag
static int O_NONBLOCK
          non-blocking flag
static int OPEN_CREAT
          create file if it doesn't exist
static int OPEN_READ
          open file for reading
static int OPEN_TRUNC
          truncate the file (empty it) if it exists
static int OPEN_WRITE
          open file for writing
static int R_OK
          file is readable
static int W_OK
          file is writable
static int X_OK
          file is executable
 
Method Summary
 int close(MFile handle)
          used to close the file.
 int fcntl(MFile handle, int op, int arg)
          file-handle control
 int lseek(MFile handle, int offset, int whence)
          seek to a specific offset
 int open(MFile handle, int flags)
          used to open the file.
 int read(MFile handle, byte[] buffer, int count)
          read bytes from file
 int write(MFile handle, byte[] buffer, int count)
          write bytes to file
 

Field Detail

F_GETFL

static final int F_GETFL
get file-descriptor flags

See Also:
Constant Field Values

F_SETFL

static final int F_SETFL
set file-descriptor flags

See Also:
Constant Field Values

O_NONBLOCK

static final int O_NONBLOCK
non-blocking flag

See Also:
Constant Field Values

O_CLOEXEC

static final int O_CLOEXEC
close on exec flag

See Also:
Constant Field Values

OPEN_READ

static final int OPEN_READ
open file for reading

See Also:
Constant Field Values

OPEN_WRITE

static final int OPEN_WRITE
open file for writing

See Also:
Constant Field Values

OPEN_CREAT

static final int OPEN_CREAT
create file if it doesn't exist

See Also:
Constant Field Values

OPEN_TRUNC

static final int OPEN_TRUNC
truncate the file (empty it) if it exists

See Also:
Constant Field Values

LSEEK_BEG

static final int LSEEK_BEG
seek from beginning of file

See Also:
Constant Field Values

LSEEK_CUR

static final int LSEEK_CUR
seek from current offset

See Also:
Constant Field Values

LSEEK_END

static final int LSEEK_END
seek from end of file

See Also:
Constant Field Values

F_OK

static final int F_OK
file exists

See Also:
Constant Field Values

R_OK

static final int R_OK
file is readable

See Also:
Constant Field Values

W_OK

static final int W_OK
file is writable

See Also:
Constant Field Values

X_OK

static final int X_OK
file is executable

See Also:
Constant Field Values
Method Detail

open

int open(MFile handle,
         int flags)
used to open the file. This is only ever called once for each file-handle when the file is opened for the first time.

Parameters:
handle - file-handle of file being opened
flags - open flags (for devices, minor number is (flags >> 16))
Returns:
0 on success or < 0 indicating error

close

int close(MFile handle)
used to close the file. This is only ever called once for each file-handle.

Parameters:
handle - file-handle of file being closed
Returns:
0 on success or < 0 indicating error

lseek

int lseek(MFile handle,
          int offset,
          int whence)
seek to a specific offset

Parameters:
handle - file-handle
offset - byte-offset relative to "whence" (block offset for block devices)
whence - constant indicating position seek should occur from
Returns:
new absolute offset or < 0 indicating error

read

int read(MFile handle,
         byte[] buffer,
         int count)
read bytes from file

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 indicating error

write

int write(MFile handle,
          byte[] buffer,
          int count)
write bytes to file

Parameters:
handle - file-handle
buffer - data to write
count - maximum number of bytes to write
Returns:
number of bytes written or < 0 indicating error

fcntl

int fcntl(MFile handle,
          int op,
          int arg)
file-handle control

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