Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Examples

The Contiki file system interface
[Contiki system]


Detailed Description

The Contiki file system interface (CFS) defines an abstract API for reading directories and for reading and writing files.

The CFS API is intentionally simple. The CFS API is modeled after the POSIX file API, and slightly simplified.


Files

file  cfs.h
 CFS header file.

Defines

#define CFS_READ   0
 Specify that cfs_open() should open a file for reading.
#define CFS_WRITE   1
 Specify that cfs_open() should open a file for writing.
#define cfs_open(name, flags)   (cfs_find_service()->open(name, flags))
#define cfs_close(fd)   (cfs_find_service()->close(fd))
#define cfs_read(fd, buf, len)   (cfs_find_service()->read(fd, buf, len))
#define cfs_write(fd, buf, len)   (cfs_find_service()->write(fd, buf, len))
#define cfs_seek(fd, off)   (cfs_find_service()->seek(fd, off))
#define cfs_opendir(dirp, name)   (cfs_find_service()->opendir(dirp, name))
#define cfs_readdir(dirp, ent)   (cfs_find_service()->readdir(dirp, ent))
#define cfs_closedir(dirp)   (cfs_find_service()->closedir(dirp))

Functions

int cfs_open (const char *name, int flags)
 Open a file.
void cfs_close (int fd)
 Close an open file.
int cfs_read (int fd, char *buf, unsigned int len)
 Read data from an open file.
int cfs_write (int fd, char *buf, unsigned int len)
 Write data to an open file.
int cfs_seek (int fd, unsigned int offset)
 Seek to a specified position in an open file.
int cfs_opendir (struct cfs_dir *dirp, const char *name)
 Open a directory for reading directory entries.
int cfs_readdir (struct cfs_dir *dirp, struct cfs_dirent *dirent)
 Read a directory entry.
int cfs_closedir (struct cfs_dir *dirp)
 Close a directory opened with cfs_opendir().


Define Documentation

#define CFS_READ   0
 

Specify that cfs_open() should open a file for reading.

This constant indicates to cfs_open() that a file should be opened for reading. CFS_WRITE should be used if the file is opened for writing, and CFS_READ + CFS_WRITE indicates that the file is opened for both reading and writing.

See also:
cfs_open()

Definition at line 74 of file cfs.h.

#define CFS_WRITE   1
 

Specify that cfs_open() should open a file for writing.

This constant indicates to cfs_open() that a file should be opened for writing. CFS_READ should be used if the file is opened for reading, and CFS_READ + CFS_WRITE indicates that the file is opened for both reading and writing.

See also:
cfs_open()

Definition at line 86 of file cfs.h.


Function Documentation

void cfs_close int  fd  ) 
 

Close an open file.

Parameters:
fd The file descriptor of the open file.
This function closes a file that has previously been opened with cfs_open().

int cfs_closedir struct cfs_dir *  dirp  ) 
 

Close a directory opened with cfs_opendir().

Parameters:
dirp A pointer to a struct cfs_dir that has been opened with cfs_opendir().
See also:
cfs_opendir()

cfs_readdir()

int cfs_open const char *  name,
int  flags
 

Open a file.

Parameters:
name The name of the file.
flags CFS_READ, or CFS_WRITE, or both.
Returns:
A file descriptor, if the file could be opened, or -1 if the file could not be opened.
This function opens a file and returns a file descriptor for the opened file. If the file could not be opened, the function returns -1. The function can open a file for reading or writing, or both.

An opened file must be closed with cfs_close().

See also:
CFS_READ

CFS_WRITE

cfs_close()

int cfs_opendir struct cfs_dir *  dirp,
const char *  name
 

Open a directory for reading directory entries.

Parameters:
dirp A pointer to a struct cfs_dir that is filled in by the function.
name The name of the directory.
Returns:
0 or -1 if the directory could not be opened.
See also:
cfs_readdir()

cfs_closedir()

int cfs_read int  fd,
char *  buf,
unsigned int  len
 

Read data from an open file.

Parameters:
fd The file descriptor of the open file.
buf The buffer in which data should be read from the file.
len The number of bytes that should be read.
Returns:
The number of bytes that was actually read from the file.
This function reads data from an open file into a buffer. The file must have first been opened with cfs_open() and the CFS_READ flag.

int cfs_readdir struct cfs_dir *  dirp,
struct cfs_dirent *  dirent
 

Read a directory entry.

Parameters:
dirp A pointer to a struct cfs_dir that has been opened with cfs_opendir().
dirent A pointer to a struct cfs_dirent that is filled in by cfs_readdir()
Return values:
0 If a directory entry was read.
0 If no more directory entries can be read.
See also:
cfs_opendir()

cfs_closedir()

int cfs_seek int  fd,
unsigned int  offset
 

Seek to a specified position in an open file.

Parameters:
fd The file descriptor of the open file.
offset The position in the file.
Returns:
The new position in the file.
This function moves the file position to the specified position in the file. The next byte that is read from or written to the file will be at the position given by the offset parameter.

int cfs_write int  fd,
char *  buf,
unsigned int  len
 

Write data to an open file.

Parameters:
fd The file descriptor of the open file.
buf The buffer from which data should be written to the file.
len The number of bytes that should be written.
Returns:
The number of bytes that was actually written to the file.
This function reads writes data from a memory buffer to an open file. The file must have been opened with cfs_open() and the CFS_WRITE flag.


Generated on Thu Jun 22 17:45:43 2006 for Contiki 2.x by  doxygen 1.4.4