2006-06-18 00:41:10 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004, Swedish Institute of Computer Science.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This file is part of the Contiki operating system.
|
|
|
|
*
|
|
|
|
* Author: Adam Dunkels <adam@sics.se>
|
|
|
|
*
|
|
|
|
*/
|
2014-11-08 01:15:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* CFS header file.
|
|
|
|
* \author
|
|
|
|
* Adam Dunkels <adam@sics.se>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \addtogroup sys
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \defgroup cfs 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.
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2013-11-24 16:57:08 +01:00
|
|
|
#ifndef CFS_H_
|
|
|
|
#define CFS_H_
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2007-05-19 23:05:48 +02:00
|
|
|
#include "contiki.h"
|
|
|
|
|
2009-03-01 13:00:00 +01:00
|
|
|
#ifndef CFS_CONF_OFFSET_TYPE
|
2009-03-01 13:28:39 +01:00
|
|
|
typedef int cfs_offset_t;
|
2009-02-27 15:50:35 +01:00
|
|
|
#else
|
2009-03-01 13:00:00 +01:00
|
|
|
typedef CFS_CONF_OFFSET_TYPE cfs_offset_t;
|
2009-02-27 15:50:35 +01:00
|
|
|
#endif
|
|
|
|
|
2007-05-19 23:05:48 +02:00
|
|
|
struct cfs_dir {
|
2007-11-17 22:01:31 +01:00
|
|
|
char dummy_space[32];
|
2007-05-19 23:05:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cfs_dirent {
|
2007-11-17 22:01:31 +01:00
|
|
|
char name[32];
|
2009-02-27 15:50:35 +01:00
|
|
|
cfs_offset_t size;
|
2007-05-19 23:05:48 +02:00
|
|
|
};
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* \sa cfs_open()
|
|
|
|
*/
|
2007-12-23 16:22:33 +01:00
|
|
|
#ifndef CFS_READ
|
2007-03-23 00:55:32 +01:00
|
|
|
#define CFS_READ 1
|
2007-12-23 16:22:33 +01:00
|
|
|
#endif
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* \sa cfs_open()
|
|
|
|
*/
|
2007-12-23 16:22:33 +01:00
|
|
|
#ifndef CFS_WRITE
|
2007-03-23 00:55:32 +01:00
|
|
|
#define CFS_WRITE 2
|
2007-12-23 16:22:33 +01:00
|
|
|
#endif
|
2007-03-23 00:55:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* \sa cfs_open()
|
|
|
|
*/
|
2007-12-23 16:22:33 +01:00
|
|
|
#ifndef CFS_APPEND
|
2007-03-23 00:55:32 +01:00
|
|
|
#define CFS_APPEND 4
|
2007-12-23 16:22:33 +01:00
|
|
|
#endif
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2009-02-28 12:39:02 +01:00
|
|
|
/**
|
|
|
|
* Specify that cfs_seek() should compute the offset from the beginning of the file.
|
|
|
|
*
|
|
|
|
* \sa cfs_seek()
|
|
|
|
*/
|
|
|
|
#ifndef CFS_SEEK_SET
|
|
|
|
#define CFS_SEEK_SET 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specify that cfs_seek() should compute the offset from the current position of the file pointer.
|
|
|
|
*
|
|
|
|
* \sa cfs_seek()
|
|
|
|
*/
|
|
|
|
#ifndef CFS_SEEK_CUR
|
|
|
|
#define CFS_SEEK_CUR 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specify that cfs_seek() should compute the offset from the end of the file.
|
|
|
|
*
|
|
|
|
* \sa cfs_seek()
|
|
|
|
*/
|
|
|
|
#ifndef CFS_SEEK_END
|
|
|
|
#define CFS_SEEK_END 2
|
|
|
|
#endif
|
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
/**
|
|
|
|
* \brief Open a file.
|
|
|
|
* \param name The name of the file.
|
2008-01-08 15:27:06 +01:00
|
|
|
* \param flags CFS_READ, or CFS_WRITE/CFS_APPEND, or both.
|
2006-06-18 00:41:10 +02:00
|
|
|
* \return 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().
|
|
|
|
*
|
|
|
|
* \sa CFS_READ
|
|
|
|
* \sa CFS_WRITE
|
|
|
|
* \sa cfs_close()
|
|
|
|
*/
|
2007-12-23 16:22:33 +01:00
|
|
|
#ifndef cfs_open
|
2007-05-19 23:05:48 +02:00
|
|
|
CCIF int cfs_open(const char *name, int flags);
|
2007-12-23 16:22:33 +01:00
|
|
|
#endif
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Close an open file.
|
|
|
|
* \param fd The file descriptor of the open file.
|
|
|
|
*
|
|
|
|
* This function closes a file that has previously been
|
|
|
|
* opened with cfs_open().
|
|
|
|
*/
|
2007-12-23 16:22:33 +01:00
|
|
|
#ifndef cfs_close
|
2007-05-19 23:05:48 +02:00
|
|
|
CCIF void cfs_close(int fd);
|
2007-12-23 16:22:33 +01:00
|
|
|
#endif
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Read data from an open file.
|
|
|
|
* \param fd The file descriptor of the open file.
|
|
|
|
* \param buf The buffer in which data should be read from the file.
|
|
|
|
* \param len The number of bytes that should be read.
|
|
|
|
* \return 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.
|
|
|
|
*/
|
2007-12-23 16:22:33 +01:00
|
|
|
#ifndef cfs_read
|
2007-11-17 19:01:00 +01:00
|
|
|
CCIF int cfs_read(int fd, void *buf, unsigned int len);
|
2007-12-23 16:22:33 +01:00
|
|
|
#endif
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Write data to an open file.
|
|
|
|
* \param fd The file descriptor of the open file.
|
|
|
|
* \param buf The buffer from which data should be written to the file.
|
|
|
|
* \param len The number of bytes that should be written.
|
|
|
|
* \return 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.
|
|
|
|
*/
|
2007-12-23 16:22:33 +01:00
|
|
|
#ifndef cfs_write
|
2008-01-24 14:08:35 +01:00
|
|
|
CCIF int cfs_write(int fd, const void *buf, unsigned int len);
|
2007-12-23 16:22:33 +01:00
|
|
|
#endif
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Seek to a specified position in an open file.
|
|
|
|
* \param fd The file descriptor of the open file.
|
2009-02-27 15:25:37 +01:00
|
|
|
* \param offset A position, either relative or absolute, in the file.
|
|
|
|
* \param whence Determines how to interpret the offset parameter.
|
|
|
|
* \return The new position in the file, or (cfs_offset_t)-1 if the seek failed.
|
2006-06-18 00:41:10 +02:00
|
|
|
*
|
|
|
|
* This function moves the file position to the specified
|
|
|
|
* position in the file. The next byte that is read from
|
2009-02-27 15:25:37 +01:00
|
|
|
* or written to the file will be at the position given
|
|
|
|
* determined by the combination of the offset parameter
|
|
|
|
* and the whence parameter.
|
|
|
|
*
|
2009-02-28 14:40:25 +01:00
|
|
|
* \sa CFS_SEEK_CUR
|
|
|
|
* \sa CFS_SEEK_END
|
|
|
|
* \sa CFS_SEEK_SET
|
2006-06-18 00:41:10 +02:00
|
|
|
*/
|
2007-12-23 16:22:33 +01:00
|
|
|
#ifndef cfs_seek
|
2009-02-27 15:25:37 +01:00
|
|
|
CCIF cfs_offset_t cfs_seek(int fd, cfs_offset_t offset, int whence);
|
2007-12-23 16:22:33 +01:00
|
|
|
#endif
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2008-11-24 11:56:55 +01:00
|
|
|
/**
|
|
|
|
* \brief Remove a file.
|
|
|
|
* \param name The name of the file.
|
|
|
|
* \retval 0 If the file was removed.
|
|
|
|
* \return -1 If the file could not be removed or if it doesn't exist.
|
|
|
|
*/
|
|
|
|
#ifndef cfs_remove
|
|
|
|
CCIF int cfs_remove(const char *name);
|
|
|
|
#endif
|
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
/**
|
|
|
|
* \brief Open a directory for reading directory entries.
|
|
|
|
* \param dirp A pointer to a struct cfs_dir that is filled in by the function.
|
|
|
|
* \param name The name of the directory.
|
|
|
|
* \return 0 or -1 if the directory could not be opened.
|
|
|
|
*
|
|
|
|
* \sa cfs_readdir()
|
|
|
|
* \sa cfs_closedir()
|
|
|
|
*/
|
2007-12-23 16:22:33 +01:00
|
|
|
#ifndef cfs_opendir
|
2007-05-19 23:05:48 +02:00
|
|
|
CCIF int cfs_opendir(struct cfs_dir *dirp, const char *name);
|
2007-12-23 16:22:33 +01:00
|
|
|
#endif
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Read a directory entry
|
|
|
|
* \param dirp A pointer to a struct cfs_dir that has been opened with cfs_opendir().
|
|
|
|
* \param dirent A pointer to a struct cfs_dirent that is filled in by cfs_readdir()
|
|
|
|
* \retval 0 If a directory entry was read.
|
2007-11-22 12:27:08 +01:00
|
|
|
* \retval -1 If no more directory entries can be read.
|
2006-06-18 00:41:10 +02:00
|
|
|
*
|
|
|
|
* \sa cfs_opendir()
|
|
|
|
* \sa cfs_closedir()
|
|
|
|
*/
|
2007-12-23 16:22:33 +01:00
|
|
|
#ifndef cfs_readdir
|
2007-05-19 23:05:48 +02:00
|
|
|
CCIF int cfs_readdir(struct cfs_dir *dirp, struct cfs_dirent *dirent);
|
2007-12-23 16:22:33 +01:00
|
|
|
#endif
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Close a directory opened with cfs_opendir().
|
|
|
|
* \param dirp A pointer to a struct cfs_dir that has been opened with cfs_opendir().
|
|
|
|
*
|
|
|
|
* \sa cfs_opendir()
|
|
|
|
* \sa cfs_readdir()
|
|
|
|
*/
|
2007-12-23 16:22:33 +01:00
|
|
|
#ifndef cfs_closedir
|
2007-11-22 12:27:08 +01:00
|
|
|
CCIF void cfs_closedir(struct cfs_dir *dirp);
|
2007-12-23 16:22:33 +01:00
|
|
|
#endif
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2013-11-24 16:57:08 +01:00
|
|
|
#endif /* CFS_H_ */
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
/** @} */
|
|
|
|
/** @} */
|