Contiki 2.6
|
00001 /** 00002 * \addtogroup cfs 00003 * @{ 00004 */ 00005 00006 /* 00007 * Copyright (c) 2008, Swedish Institute of Computer Science 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without 00011 * modification, are permitted provided that the following conditions 00012 * are met: 00013 * 1. Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in the 00017 * documentation and/or other materials provided with the distribution. 00018 * 3. Neither the name of the Institute nor the names of its contributors 00019 * may be used to endorse or promote products derived from this software 00020 * without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00023 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00025 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00028 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00029 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00031 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00032 * SUCH DAMAGE. 00033 * 00034 * This file is part of the Contiki operating system. 00035 * 00036 */ 00037 00038 #ifndef CFS_COFFEE_H 00039 #define CFS_COFFEE_H 00040 00041 #include "cfs.h" 00042 00043 /** 00044 * Instruct Coffee that the access pattern to this file is adapted to 00045 * flash I/O semantics by design, and Coffee should therefore not 00046 * invoke its own micro logs when file modifications occur. 00047 * 00048 * This semantical I/O setting is useful when implementing flash storage 00049 * algorithms on top of Coffee. 00050 * 00051 * \sa cfs_coffee_set_io_semantics() 00052 */ 00053 #define CFS_COFFEE_IO_FLASH_AWARE 0x1 00054 00055 /** 00056 * Instruct Coffee not to attempt to extend the file when there is 00057 * an attempt to write past the reserved file size. 00058 * 00059 * A case when this is necessary is when the file has a firm size limit, 00060 * and a safeguard is needed to protect against writes beyond this limit. 00061 * 00062 * \sa cfs_coffee_set_io_semantics() 00063 */ 00064 #define CFS_COFFEE_IO_FIRM_SIZE 0x2 00065 00066 /** 00067 * \file 00068 * Header for the Coffee file system. 00069 * \author 00070 * Nicolas Tsiftes <nvt@sics.se> 00071 * 00072 * \name Functions called from application programs 00073 * @{ 00074 */ 00075 00076 /** 00077 * \brief Reserve space for a file. 00078 * \param name The filename. 00079 * \param size The size of the file. 00080 * \return 0 on success, -1 on failure. 00081 * 00082 * Coffee uses sequential page structures for files. The sequential 00083 * structure can be reserved with a certain size. If a file has not 00084 * been reserved when it is opened for the first time, it will be 00085 * allocated with a default size. 00086 */ 00087 int cfs_coffee_reserve(const char *name, cfs_offset_t size); 00088 00089 /** 00090 * \brief Configure the on-demand log file. 00091 * \param file The filename. 00092 * \param log_size The total log size. 00093 * \param log_entry_size The log entry size. 00094 * \return 0 on success, -1 on failure. 00095 * 00096 * When file data is first modified, Coffee creates a micro log for the 00097 * file. The micro log stores a table of modifications whose 00098 * parameters--the log size and the log entry size--can be modified 00099 * through the cfs_coffee_configure_log function. 00100 */ 00101 int cfs_coffee_configure_log(const char *file, unsigned log_size, 00102 unsigned log_entry_size); 00103 00104 /** 00105 * \brief Set the I/O semantics for accessing a file. 00106 * 00107 * \param fd The file descriptor through which the file is accessed. 00108 * \param flags A bit vector of flags. 00109 * 00110 * Coffee is used on a wide range of storage types, and the default 00111 * I/O file semantics may not be optimal for the access pattern 00112 * of a certain file. Hence, this functions allows programmers to 00113 * switch the /O semantics on a file that is accessed through a 00114 * particular file descriptor. 00115 * 00116 */ 00117 int cfs_coffee_set_io_semantics(int fd, unsigned flags); 00118 00119 /** 00120 * \brief Format the storage area assigned to Coffee. 00121 * \return 0 on success, -1 on failure. 00122 * 00123 * Coffee formats the underlying storage by setting all bits to zero. 00124 * Formatting must be done before using Coffee for the first time in 00125 * a mote. 00126 */ 00127 int cfs_coffee_format(void); 00128 00129 /** 00130 * \brief Points out a memory region that may not be altered during 00131 * checkpointing operations that use the file system. 00132 * \param size 00133 * \return A pointer to the protected memory. 00134 * 00135 * This function returns the protected memory pointer and writes its size 00136 * to the given parameter. Mainly used by sensornet checkpointing to protect 00137 * the coffee state during CFS-based checkpointing operations. 00138 */ 00139 void *cfs_coffee_get_protected_mem(unsigned *size); 00140 00141 /** @} */ 00142 /** @} */ 00143 00144 #endif /* !COFFEE_H */