Contiki-NG
Loading...
Searching...
No Matches
cfs-coffee.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008, Swedish Institute of Computer Science
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This file is part of the Contiki operating system.
30 *
31 */
32
33/**
34 * \addtogroup cfs
35 * @{
36 */
37
38#ifndef CFS_COFFEE_H
39#define CFS_COFFEE_H
40
41#include "cfs.h"
42
43/**
44 * Instruct Coffee that the access pattern to this file is adapted to
45 * flash I/O semantics by design, and Coffee should therefore not
46 * invoke its own micro logs when file modifications occur.
47 *
48 * This semantical I/O setting is useful when implementing flash storage
49 * algorithms such as database indices on top of Coffee.
50 *
51 * \sa cfs_coffee_set_io_semantics()
52 */
53#define CFS_COFFEE_IO_FLASH_AWARE 0x1
54
55/**
56 * Instruct Coffee not to attempt to extend the file upon a request
57 * to write past the reserved file size.
58 *
59 * A case when this is necessary is when the file has a firm size limit,
60 * and a safeguard is needed to protect against writes beyond this limit.
61 *
62 * \sa cfs_coffee_set_io_semantics()
63 */
64#define CFS_COFFEE_IO_FIRM_SIZE 0x2
65
66/**
67 * Instruct Coffee to set unused bytes in the destination buffer to zero.
68 * Trailing zeros may cause a wrong file size, this option ensures that
69 * the corresponding bytes get set, so Coffee does not read unexpected data.
70 *
71 * \sa cfs_coffee_set_io_semantics()
72 */
73#define CFS_COFFEE_IO_ENSURE_READ_LENGTH 0x4
74
75/**
76 * \file
77 * Header for the Coffee file system.
78 * \author
79 * Nicolas Tsiftes <nvt@sics.se>
80 *
81 * \name Functions called from application programs
82 * @{
83 */
84
85/**
86 * \brief Reserve space for a file.
87 * \param name The file name.
88 * \param size The initial size to be reserved for the file.
89 * \return 0 on success, -1 on failure.
90 *
91 * Coffee uses sequential page structures for files. The sequential
92 * structure can be reserved with a certain size. If a file has not
93 * been reserved when it is opened for the first time, it will be
94 * allocated with a default size.
95 */
96int cfs_coffee_reserve(const char *name, cfs_offset_t size);
97
98/**
99 * \brief Configure the on-demand log file.
100 * \param file The file name.
101 * \param log_size The total log file size.
102 * \param log_entry_size The log entry size.
103 * \return 0 on success, -1 on failure.
104 *
105 * When file data is first modified, Coffee creates a micro log for the
106 * file. The micro log stores a table of modifications whose parameters --
107 * the log size and the log entry size -- can be modified through the
108 * cfs_coffee_configure_log function.
109 */
110int cfs_coffee_configure_log(const char *file, unsigned log_size,
111 unsigned log_entry_size);
112
113/**
114 * \brief Set the I/O semantics for accessing a file.
115 *
116 * \param fd The file descriptor through which the file is accessed.
117 * \param flags A bit vector of flags.
118 *
119 * Coffee is used on a wide range of storage types, and the default
120 * I/O file semantics may not be optimal for the access pattern
121 * of a certain file. Hence, this function allows programmers to
122 * switch the I/O semantics on a file that is accessed through a
123 * particular file descriptor.
124 *
125 */
126int cfs_coffee_set_io_semantics(int fd, unsigned flags);
127
128/**
129 * \brief Format the storage area assigned to Coffee.
130 * \return 0 on success, -1 on failure.
131 *
132 * Coffee formats the underlying storage by setting all bits to zero.
133 * Formatting must be done before using Coffee for the first time in
134 * a mote.
135 *
136 * Notice that the erased bits may be set to 1 on the physical storage
137 * when using flash memory. In this case, Coffee requires that the
138 * COFFEE_READ and COFFEE_WRITE functions used to access the flash memory
139 * invert all bits.
140 */
141int cfs_coffee_format(void);
142
143/** @} */
144/** @} */
145
146#endif /* !COFFEE_H */
CFS header file.
int cfs_coffee_configure_log(const char *file, unsigned log_size, unsigned log_entry_size)
Configure the on-demand log file.
int cfs_coffee_format(void)
Format the storage area assigned to Coffee.
int cfs_coffee_reserve(const char *name, cfs_offset_t size)
Reserve space for a file.
int cfs_coffee_set_io_semantics(int fd, unsigned flags)
Set the I/O semantics for accessing a file.
int cfs_offset_t
CFS directory entry name length.
Definition cfs.h:65