source: rtems/cpukit/libfs/src/jffs2/include/rtems/jffs2.h @ 73bf499

4.115
Last change on this file since 73bf499 was 73bf499, checked in by Sebastian Huber <sebastian.huber@…>, on 06/10/14 at 08:56:55

JFFS2: Add device identifier for the flash device

It is used in combination with the inode number to uniquely identify a
file system node in the system.

  • Property mode set to 100644
File size: 11.3 KB
Line 
1/*
2 * Copyright (c) 2013 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifndef RTEMS_JFFS2_H
16#define RTEMS_JFFS2_H
17
18#include <rtems/fs.h>
19#include <sys/param.h>
20#include <zlib.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif /* __cplusplus */
25
26typedef struct rtems_jffs2_flash_control rtems_jffs2_flash_control;
27
28/**
29 * @defgroup JFFS2 Journalling Flash File System Version 2 (JFFS2) Support
30 *
31 * @ingroup FileSystemTypesAndMount
32 *
33 * @brief Mount options for the Journalling Flash File System, Version 2
34 * (JFFS2).
35 *
36 * The application must provide flash device geometry information and flash
37 * device operations in the flash control structure
38 * @ref rtems_jffs2_flash_control.
39 *
40 * The application can optionally provide a compressor control structure to
41 * enable data compression using the selected compression algorithm.
42 *
43 * The application must enable JFFS2 support with rtems_filesystem_register()
44 * or CONFIGURE_FILESYSTEM_JFFS2 via <rtems/confdefs.h>.
45 *
46 * An example mount with a simple memory based flash device simulation follows.
47 * The zlib is used for as the compressor.
48 *
49 * @code
50 * #include <string.h>
51 *
52 * #include <rtems/jffs2.h>
53 * #include <rtems/libio.h>
54 *
55 * #define BLOCK_SIZE (32UL * 1024UL)
56 *
57 * #define FLASH_SIZE (32UL * BLOCK_SIZE)
58 *
59 * typedef struct {
60 *   rtems_jffs2_flash_control super;
61 *   unsigned char area[FLASH_SIZE];
62 * } flash_control;
63 *
64 * static flash_control *get_flash_control(rtems_jffs2_flash_control *super)
65 * {
66 *   return (flash_control *) super;
67 * }
68 *
69 * static int flash_read(
70 *   rtems_jffs2_flash_control *super,
71 *   uint32_t offset,
72 *   unsigned char *buffer,
73 *   size_t size_of_buffer
74 * )
75 * {
76 *   flash_control *self = get_flash_control(super);
77 *   unsigned char *chunk = &self->area[offset];
78 *
79 *   memcpy(buffer, chunk, size_of_buffer);
80 *
81 *   return 0;
82 * }
83 *
84 * static int flash_write(
85 *   rtems_jffs2_flash_control *super,
86 *   uint32_t offset,
87 *   const unsigned char *buffer,
88 *   size_t size_of_buffer
89 * )
90 * {
91 *   flash_control *self = get_flash_control(super);
92 *   unsigned char *chunk = &self->area[offset];
93 *   size_t i;
94 *
95 *   for (i = 0; i < size_of_buffer; ++i) {
96 *     chunk[i] &= buffer[i];
97 *   }
98 *
99 *   return 0;
100 * }
101 *
102 * static int flash_erase(
103 *   rtems_jffs2_flash_control *super,
104 *   uint32_t offset
105 * )
106 * {
107 *   flash_control *self = get_flash_control(super);
108 *   unsigned char *chunk = &self->area[offset];
109 *
110 *   memset(chunk, 0xff, BLOCK_SIZE);
111 *
112 *   return 0;
113 * }
114 *
115 * static flash_control flash_instance = {
116 *   .super = {
117 *     .block_size = BLOCK_SIZE,
118 *     .flash_size = FLASH_SIZE,
119 *     .read = flash_read,
120 *     .write = flash_write,
121 *     .erase = flash_erase,
122 *     .device_identifier = 0xc01dc0fe
123 *   }
124 * };
125 *
126 * static rtems_jffs2_compressor_zlib_control compressor_instance = {
127 *   .super = {
128 *     .compress = rtems_jffs2_compressor_zlib_compress,
129 *     .decompress = rtems_jffs2_compressor_zlib_decompress
130 *   }
131 * };
132 *
133 * static const rtems_jffs2_mount_data mount_data = {
134 *   .flash_control = &flash_instance.super,
135 *   .compressor_control = &compressor_instance.super
136 * };
137 *
138 * static void erase_all(void)
139 * {
140 *   memset(&flash_instance.area[0], 0xff, FLASH_SIZE);
141 * }
142 *
143 * void example_jffs2_mount(const char *mount_dir)
144 * {
145 *   int rv;
146 *
147 *   erase_all();
148 *
149 *   rv = mount_and_make_target_path(
150 *     NULL,
151 *     mount_dir,
152 *     RTEMS_FILESYSTEM_TYPE_JFFS2,
153 *     RTEMS_FILESYSTEM_READ_WRITE,
154 *     &mount_data
155 *   );
156 *   assert(rv == 0);
157 * }
158 * @endcode
159 *
160 * @{
161 */
162
163/**
164 * @brief Read from flash operation.
165 *
166 * @param[in, out] self The flash control.
167 * @param[in] offset The offset to read from the flash begin in bytes.
168 * @param[out] buffer The buffer receiving the data.
169 * @param[in] size_of_buffer The size of the buffer in bytes.
170 *
171 * @retval 0 Successful operation.
172 * @retval -EIO An error occurred.  Please note that the value is negative.
173 * @retval other All other values are reserved and must not be used.
174 */
175typedef int (*rtems_jffs2_flash_read)(
176  rtems_jffs2_flash_control *self,
177  uint32_t offset,
178  unsigned char *buffer,
179  size_t size_of_buffer
180);
181
182/**
183 * @brief Write to flash operation.
184 *
185 * @param[in, out] self The flash control.
186 * @param[in] offset The offset to write from the flash begin in bytes.
187 * @param[in] buffer The buffer containing the data to write.
188 * @param[in] size_of_buffer The size of the buffer in bytes.
189 *
190 * @retval 0 Successful operation.
191 * @retval -EIO An error occurred.  Please note that the value is negative.
192 * @retval other All other values are reserved and must not be used.
193 */
194typedef int (*rtems_jffs2_flash_write)(
195  rtems_jffs2_flash_control *self,
196  uint32_t offset,
197  const unsigned char *buffer,
198  size_t size_of_buffer
199);
200
201/**
202 * @brief Flash erase operation.
203 *
204 * This operation must erase one block specified by the offset.
205 *
206 * @param[in, out] self The flash control.
207 * @param[in] offset The offset to erase from the flash begin in bytes.
208 *
209 * @retval 0 Successful operation.
210 * @retval -EIO An error occurred.  Please note that the value is negative.
211 * @retval other All other values are reserved and must not be used.
212 */
213typedef int (*rtems_jffs2_flash_erase)(
214  rtems_jffs2_flash_control *self,
215  uint32_t offset
216);
217
218/**
219 * @brief Flash destroy operation.
220 *
221 * The flash destroy operation is called during unmount of the file system
222 * instance.  It can be used to free the resources associated with the now
223 * unused flash control
224 *
225 * @param[in, out] self The flash control.
226 */
227typedef void (*rtems_jffs2_flash_destroy)(
228  rtems_jffs2_flash_control *self
229);
230
231/**
232 * @brief JFFS2 flash device control.
233 */
234struct rtems_jffs2_flash_control {
235  /**
236   * @brief The size in bytes of the erasable unit of the flash device.
237   */
238  uint32_t block_size;
239
240  /**
241   * @brief The size in bytes of the flash device.
242   *
243   * It must be an integral multiple of the block size.  The flash device must
244   * have at least five blocks.
245   */
246  uint32_t flash_size;
247
248  /**
249   * @brief Read from flash operation.
250   */
251  rtems_jffs2_flash_read read;
252
253  /**
254   * @brief Write to flash operation.
255   */
256  rtems_jffs2_flash_write write;
257
258  /**
259   * @brief Flash erase operation.
260   */
261  rtems_jffs2_flash_erase erase;
262
263  /**
264   * @brief Flash destroy operation.
265   *
266   * This operation is optional and the pointer may be @c NULL.
267   */
268  rtems_jffs2_flash_destroy destroy;
269
270  /**
271   * @brief The device identifier of the flash device.
272   *
273   * It is used in combination with the inode number to uniquely identify a
274   * file system node in the system.
275   */
276  dev_t device_identifier;
277};
278
279typedef struct rtems_jffs2_compressor_control rtems_jffs2_compressor_control;
280
281/**
282 * @brief Compress operation.
283 *
284 * @param[in, out] self The compressor control.
285 * @param[in] data_in The uncompressed data.
286 * @param[out] cdata_out Pointer to buffer with the compressed data.
287 * @param[in, out] datalen On entry, the size in bytes of the uncompressed
288 * data.  On exit, the size in bytes of uncompressed data which was actually
289 * compressed.
290 * @param[in, out] cdatalen On entry, the size in bytes available for
291 * compressed data.  On exit, the size in bytes of the actually compressed
292 * data.
293 *
294 * @return The compressor type.
295 */
296typedef uint16_t (*rtems_jffs2_compressor_compress)(
297  rtems_jffs2_compressor_control *self,
298  unsigned char *data_in,
299  unsigned char *cdata_out,
300  uint32_t *datalen,
301  uint32_t *cdatalen
302);
303
304/**
305 * @brief Decompress operation.
306 *
307 * @param[in, out] self The compressor control.
308 * @param[in] comprtype The compressor type.
309 * @param[in] cdata_in The compressed data.
310 * @param[out] data_out The uncompressed data.
311 * @param[in] cdatalen The size in bytes of the compressed data.
312 * @param[in] datalen The size in bytes of the uncompressed data.
313 *
314 * @retval 0 Successful operation.
315 * @retval -EIO An error occurred.  Please note that the value is negative.
316 * @retval other All other values are reserved and must not be used.
317 */
318typedef int (*rtems_jffs2_compressor_decompress)(
319  rtems_jffs2_compressor_control *self,
320  uint16_t comprtype,
321  unsigned char *cdata_in,
322  unsigned char *data_out,
323  uint32_t cdatalen,
324  uint32_t datalen
325);
326
327/**
328 * @brief Compressor destroy operation.
329 *
330 * The compressor destroy operation is called during unmount of the file system
331 * instance.  It can be used to free the resources associated with the now
332 * unused compressor operations.
333 *
334 * @param[in, out] self The compressor control.
335 */
336typedef void (*rtems_jffs2_compressor_destroy)(
337  rtems_jffs2_compressor_control *self
338);
339
340/**
341 * @brief JFFS2 compressor control.
342 */
343struct rtems_jffs2_compressor_control {
344  /**
345   * @brief Compress operation.
346   */
347  rtems_jffs2_compressor_compress compress;
348
349  /**
350   * @brief Decompress operation.
351   */
352  rtems_jffs2_compressor_decompress decompress;
353
354  /**
355   * @brief Compressor destroy operation.
356   *
357   * This operation is optional and the pointer may be @c NULL.
358   */
359  rtems_jffs2_compressor_destroy destroy;
360
361  /**
362   * @brief Compression buffer.
363   */
364  unsigned char buffer[PAGE_SIZE];
365};
366
367/**
368 * @brief RTIME compressor compress operation.
369 */
370uint16_t rtems_jffs2_compressor_rtime_compress(
371  rtems_jffs2_compressor_control *self,
372  unsigned char *data_in,
373  unsigned char *cdata_out,
374  uint32_t *datalen,
375  uint32_t *cdatalen
376);
377
378/**
379 * @brief RTIME compressor decompress operation.
380 */
381int rtems_jffs2_compressor_rtime_decompress(
382  rtems_jffs2_compressor_control *self,
383  uint16_t comprtype,
384  unsigned char *cdata_in,
385  unsigned char *data_out,
386  uint32_t cdatalen,
387  uint32_t datalen
388);
389
390/**
391 * @brief ZLIB compressor control structure.
392 */
393typedef struct {
394  rtems_jffs2_compressor_control super;
395  z_stream stream;
396} rtems_jffs2_compressor_zlib_control;
397
398/**
399 * @brief ZLIB compressor compress operation.
400 */
401uint16_t rtems_jffs2_compressor_zlib_compress(
402  rtems_jffs2_compressor_control *self,
403  unsigned char *data_in,
404  unsigned char *cdata_out,
405  uint32_t *datalen,
406  uint32_t *cdatalen
407);
408
409/**
410 * @brief ZLIB compressor decompress operation.
411 */
412int rtems_jffs2_compressor_zlib_decompress(
413  rtems_jffs2_compressor_control *self,
414  uint16_t comprtype,
415  unsigned char *cdata_in,
416  unsigned char *data_out,
417  uint32_t cdatalen,
418  uint32_t datalen
419);
420
421/**
422 * @brief JFFS2 mount options.
423 *
424 * For JFFS2 the mount options are mandatory.
425 */
426typedef struct {
427  /**
428   * @brief Flash control.
429   */
430  rtems_jffs2_flash_control *flash_control;
431
432  /**
433   * @brief Compressor control.
434   *
435   * The compressor is optional and this pointer may be @c NULL.
436   */
437  rtems_jffs2_compressor_control *compressor_control;
438} rtems_jffs2_mount_data;
439
440/**
441 * @brief Initialization handler of the JFFS2 file system.
442 *
443 * @param[in, out] mt_entry The mount table entry.
444 * @param[in] data The mount options are mandatory for JFFS2 and data must
445 * point to a valid @ref rtems_jffs2_mount_data structure used for this file
446 * system instance.
447 *
448 * @retval 0 Successful operation.
449 * @retval -1 An error occurred.  The @c errno indicates the error.
450 *
451 * @see mount().
452 */
453int rtems_jffs2_initialize(
454  rtems_filesystem_mount_table_entry_t *mt_entry,
455  const void *data
456);
457
458/** @} */
459
460#ifdef __cplusplus
461}
462#endif /* __cplusplus */
463
464#endif /* RTEMS_JFFS2_H */
Note: See TracBrowser for help on using the repository browser.