Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
The Contiki file system interface

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.

Data Structures

struct  cfs_dir
 
struct  cfs_dirent
 

Files

file  cfs.h
 
    CFS header file.

 

Macros

#define CFS_APPEND   4
 Specify that cfs_open() should append written data to the file rather than overwriting it. More...
 
#define CFS_READ   1
 Specify that cfs_open() should open a file for reading. More...
 
#define CFS_SEEK_CUR   1
 Specify that cfs_seek() should compute the offset from the current position of the file pointer. More...
 
#define CFS_SEEK_END   2
 Specify that cfs_seek() should compute the offset from the end of the file. More...
 
#define CFS_SEEK_SET   0
 Specify that cfs_seek() should compute the offset from the beginning of the file. More...
 
#define CFS_WRITE   2
 Specify that cfs_open() should open a file for writing. More...
 

Typedefs

typedef int cfs_offset_t
 

Functions

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

#define CFS_APPEND   4

Specify that cfs_open() should append written data to the file rather than overwriting it.

This constant indicates to cfs_open() that a file that should be opened for writing gets written data appended to the end of the file. The default behaviour (without CFS_APPEND) is that the file is overwritten with the new data.

See Also
cfs_open()
#define CFS_READ   1

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()
#define CFS_SEEK_CUR   1

Specify that cfs_seek() should compute the offset from the current position of the file pointer.

See Also
cfs_seek()
#define CFS_SEEK_END   2

Specify that cfs_seek() should compute the offset from the end of the file.

See Also
cfs_seek()
#define CFS_SEEK_SET   0

Specify that cfs_seek() should compute the offset from the beginning of the file.

See Also
cfs_seek()
#define CFS_WRITE   2

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()

typedef int cfs_offset_t

CCIF void cfs_close ( int  fd)

Close an open file.

Parameters
fdThe file descriptor of the open file.
        This function closes a file that has previously been
        opened with cfs_open().
CCIF void cfs_closedir ( struct cfs_dir dirp)

Close a directory opened with cfs_opendir().

Parameters
dirpA pointer to a struct cfs_dir that has been opened with cfs_opendir().
See Also
cfs_opendir()
cfs_readdir()
CCIF int cfs_open ( const char *  name,
int  flags 
)

Open a file.

Parameters
nameThe name of the file.
flagsCFS_READ, or CFS_WRITE/CFS_APPEND, 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()
CCIF int cfs_opendir ( struct cfs_dir dirp,
const char *  name 
)

Open a directory for reading directory entries.

Parameters
dirpA pointer to a struct cfs_dir that is filled in by the function.
nameThe name of the directory.
Returns
0 or -1 if the directory could not be opened.
See Also
cfs_readdir()
cfs_closedir()
CCIF int cfs_read ( int  fd,
void *  buf,
unsigned int  len 
)

Read data from an open file.

Parameters
fdThe file descriptor of the open file.
bufThe buffer in which data should be read from the file.
lenThe 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.
CCIF int cfs_readdir ( struct cfs_dir dirp,
struct cfs_dirent dirent 
)

Read a directory entry.

Parameters
dirpA pointer to a struct cfs_dir that has been opened with cfs_opendir().
direntA pointer to a struct cfs_dirent that is filled in by cfs_readdir()
Return values
0If a directory entry was read.
-1If no more directory entries can be read.
See Also
cfs_opendir()
cfs_closedir()
CCIF int cfs_remove ( const char *  name)

Remove a file.

Parameters
nameThe name of the file.
Return values
0If the file was removed.
Returns
-1 If the file could not be removed or if it doesn't exist.
CCIF cfs_offset_t cfs_seek ( int  fd,
cfs_offset_t  offset,
int  whence 
)

Seek to a specified position in an open file.

Parameters
fdThe file descriptor of the open file.
offsetA position, either relative or absolute, in the file.
whenceDetermines how to interpret the offset parameter.
Returns
The new position in the file, or (cfs_offset_t)-1 if the seek failed.
        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 
        determined by the combination of the offset parameter 
        and the whence parameter.
See Also
CFS_SEEK_CUR
CFS_SEEK_END
CFS_SEEK_SET
CCIF int cfs_write ( int  fd,
const void *  buf,
unsigned int  len 
)

Write data to an open file.

Parameters
fdThe file descriptor of the open file.
bufThe buffer from which data should be written to the file.
lenThe 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.