RTEMS: Journalling Flash File System Version 2 (JFFS2) Support

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions
Journalling Flash File System Version 2 (JFFS2) Support
IO Library » File System Types and Mount

Mount options for the Journalling Flash File System, Version 2 (JFFS2). More...

## Data Structures
struct | rtems_jffs2_flash_control
| JFFS2 flash device control. More...
struct | rtems_jffs2_compressor_control
| JFFS2 compressor control. More...
struct | rtems_jffs2_compressor_zlib_control
| ZLIB compressor control structure. More...
struct | rtems_jffs2_mount_data
| JFFS2 mount options. More...
struct | rtems_jffs2_info
| JFFS2 filesystem instance information. More...

## Macros
#define | RTEMS_JFFS2_GET_INFO _IOR('F', 1, rtems_jffs2_info)
| IO control to get the JFFS2 filesystem instance information.
#define | RTEMS_JFFS2_ON_DEMAND_GARBAGE_COLLECTION _IO('F', 2)
| IO control to perform an on demand garbage collection in a JFFS2 filesystem instance.
#define | RTEMS_JFFS2_FORCE_GARBAGE_COLLECTION _IO('F', 3)
| IO control to force a garbage collection in a JFFS2 filesystem instance.

## Typedefs
typedef int(* | rtems_jffs2_flash_read) (rtems_jffs2_flash_control *self, uint32_t offset, unsigned char *buffer, size_t size_of_buffer)
| Read from flash operation.
typedef int(* | rtems_jffs2_flash_write) (rtems_jffs2_flash_control *self, uint32_t offset, const unsigned char *buffer, size_t size_of_buffer)
| Write to flash operation.
typedef int(* | rtems_jffs2_flash_erase) (rtems_jffs2_flash_control *self, uint32_t offset)
| Flash erase operation.
typedef void(* | rtems_jffs2_flash_destroy) (rtems_jffs2_flash_control *self)
| Flash destroy operation.
typedef void(* | rtems_jffs2_trigger_garbage_collection) (rtems_jffs2_flash_control *self)
| Trigger garbage collection operation.
typedef struct rtems_jffs2_compressor_control | rtems_jffs2_compressor_control
typedef uint16_t(* | rtems_jffs2_compressor_compress) (rtems_jffs2_compressor_control *self, unsigned char *data_in, unsigned char *cdata_out, uint32_t *datalen, uint32_t *cdatalen)
| Compress operation.
typedef int(* | rtems_jffs2_compressor_decompress) (rtems_jffs2_compressor_control *self, uint16_t comprtype, unsigned char *cdata_in, unsigned char *data_out, uint32_t cdatalen, uint32_t datalen)
| Decompress operation.
typedef void(* | rtems_jffs2_compressor_destroy) (rtems_jffs2_compressor_control *self)
| Compressor destroy operation.

## Functions
uint16_t | rtems_jffs2_compressor_rtime_compress (rtems_jffs2_compressor_control *self, unsigned char *data_in, unsigned char *cdata_out, uint32_t *datalen, uint32_t *cdatalen)
| RTIME compressor compress operation.
int | rtems_jffs2_compressor_rtime_decompress (rtems_jffs2_compressor_control *self, uint16_t comprtype, unsigned char *cdata_in, unsigned char *data_out, uint32_t cdatalen, uint32_t datalen)
| RTIME compressor decompress operation.
uint16_t | rtems_jffs2_compressor_zlib_compress (rtems_jffs2_compressor_control *self, unsigned char *data_in, unsigned char *cdata_out, uint32_t *datalen, uint32_t *cdatalen)
| ZLIB compressor compress operation.
int | rtems_jffs2_compressor_zlib_decompress (rtems_jffs2_compressor_control *self, uint16_t comprtype, unsigned char *cdata_in, unsigned char *data_out, uint32_t cdatalen, uint32_t datalen)
| ZLIB compressor decompress operation.
int | rtems_jffs2_initialize (rtems_filesystem_mount_table_entry_t *mt_entry, const void *data)
| Initialization handler of the JFFS2 file system.

## Detailed Description

Mount options for the Journalling Flash File System, Version 2 (JFFS2).

The application must provide flash device geometry information and flash device operations in the flash control structure rtems_jffs2_flash_control.

The application can optionally provide a compressor control structure to enable data compression using the selected compression algorithm.

The application must enable JFFS2 support with rtems_filesystem_register() or CONFIGURE_FILESYSTEM_JFFS2 via <rtems/confdefs.h>.

An example mount with a simple memory based flash device simulation follows. The zlib is used for as the compressor.

#include <string.h>
#include <rtems/jffs2.h>
#include <rtems/libio.h>
#define BLOCK_SIZE (32UL * 1024UL)
#define FLASH_SIZE (32UL * BLOCK_SIZE)
typedef struct {
rtems_jffs2_flash_control super;
unsigned char area[FLASH_SIZE];
} flash_control;
static flash_control *get_flash_control(rtems_jffs2_flash_control *super)
{
return (flash_control *) super;
}
static int flash_read(
rtems_jffs2_flash_control *super,
uint32_t offset,
unsigned char *buffer,
size_t size_of_buffer
)
{
flash_control *self = get_flash_control(super);
unsigned char *chunk = &self->area[offset];
memcpy(buffer, chunk, size_of_buffer);
return 0;
}
static int flash_write(
rtems_jffs2_flash_control *super,
uint32_t offset,
const unsigned char *buffer,
size_t size_of_buffer
)
{
flash_control *self = get_flash_control(super);
unsigned char *chunk = &self->area[offset];
size_t i;
for (i = 0; i < size_of_buffer; ++i) {
chunk[i] &= buffer[i];
}
return 0;
}
static int flash_erase(
rtems_jffs2_flash_control *super,
uint32_t offset
)
{
flash_control *self = get_flash_control(super);
unsigned char *chunk = &self->area[offset];
memset(chunk, 0xff, BLOCK_SIZE);
return 0;
}
static flash_control flash_instance = {
.super = {
.block_size = BLOCK_SIZE,
.flash_size = FLASH_SIZE,
.read = flash_read,
.write = flash_write,
.erase = flash_erase,
.device_identifier = 0xc01dc0fe
}
};
static rtems_jffs2_compressor_zlib_control compressor_instance = {
.super = {
.compress = rtems_jffs2_compressor_zlib_compress,
.decompress = rtems_jffs2_compressor_zlib_decompress
}
};
static const rtems_jffs2_mount_data mount_data = {
.flash_control = &flash_instance.super,
.compressor_control = &compressor_instance.super
};
static void erase_all(void)
{
memset(&flash_instance.area[0], 0xff, FLASH_SIZE);
}
void example_jffs2_mount(const char *mount_dir)
{
int rv;
erase_all();
rv = mount_and_make_target_path(
NULL,
mount_dir,
RTEMS_FILESYSTEM_TYPE_JFFS2,
RTEMS_FILESYSTEM_READ_WRITE,
&mount_data
);
assert(rv == 0);
}
NULL
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77
mount_and_make_target_path
int mount_and_make_target_path(const char *source, const char *target, const char *filesystemtype, rtems_filesystem_options_t options, const void *data)
Mounts a file system and makes the target path.
Definition: mount-mktgt.c:30
rtems_jffs2_compressor_zlib_compress
uint16_t rtems_jffs2_compressor_zlib_compress(rtems_jffs2_compressor_control *self, unsigned char *data_in, unsigned char *cdata_out, uint32_t *datalen, uint32_t *cdatalen)
ZLIB compressor compress operation.
Definition: compr_zlib.c:46
rtems_jffs2_compressor_zlib_decompress
int rtems_jffs2_compressor_zlib_decompress(rtems_jffs2_compressor_control *self, uint16_t comprtype, unsigned char *cdata_in, unsigned char *data_out, uint32_t cdatalen, uint32_t datalen)
ZLIB compressor decompress operation.
Definition: compr_zlib.c:121
libio.h
Basic IO API.
rtems_jffs2_compressor_control::compress
rtems_jffs2_compressor_compress compress
Compress operation.
Definition: jffs2.h:371
rtems_jffs2_compressor_zlib_control
ZLIB compressor control structure.
Definition: jffs2.h:417
rtems_jffs2_flash_control
JFFS2 flash device control.
Definition: jffs2.h:249
rtems_jffs2_mount_data
JFFS2 mount options.
Definition: jffs2.h:450
rtems_jffs2_mount_data::flash_control
rtems_jffs2_flash_control * flash_control
Flash control.
Definition: jffs2.h:454

## Macro Definition Documentation

## ◆ RTEMS_JFFS2_FORCE_GARBAGE_COLLECTION

#define RTEMS_JFFS2_FORCE_GARBAGE_COLLECTION _IO('F', 3)

IO control to force a garbage collection in a JFFS2 filesystem instance.

Use this operation with care since it may wear out your flash.

## ◆ RTEMS_JFFS2_GET_INFO

#define RTEMS_JFFS2_GET_INFO _IOR('F', 1, rtems_jffs2_info)

IO control to get the JFFS2 filesystem instance information.

See also
  rtems_jffs2_info.

## ◆ RTEMS_JFFS2_ON_DEMAND_GARBAGE_COLLECTION

#define RTEMS_JFFS2_ON_DEMAND_GARBAGE_COLLECTION _IO('F', 2)

IO control to perform an on demand garbage collection in a JFFS2 filesystem instance.

This operation is intended to be used by an optional garbage collection thread. See rtems_jffs2_flash_control::trigger_garbage_collection.

## Typedef Documentation

## ◆ rtems_jffs2_compressor_compress

typedef uint16_t(* rtems_jffs2_compressor_compress) (rtems_jffs2_compressor_control *self, unsigned char *data_in, unsigned char *cdata_out, uint32_t *datalen, uint32_t *cdatalen)

Compress operation.

Parameters

  [in,out] | self | The compressor control.
  [in] | data_in | The uncompressed data.
  [out] | cdata_out | Pointer to buffer with the compressed data.
  [in,out] | datalen | On entry, the size in bytes of the uncompressed data. On exit, the size in bytes of uncompressed data which was actually compressed.
  [in,out] | cdatalen | On entry, the size in bytes available for compressed data. On exit, the size in bytes of the actually compressed data.

Returns
  The compressor type.

## ◆ rtems_jffs2_compressor_decompress

typedef int(* rtems_jffs2_compressor_decompress) (rtems_jffs2_compressor_control *self, uint16_t comprtype, unsigned char *cdata_in, unsigned char *data_out, uint32_t cdatalen, uint32_t datalen)

Decompress operation.

Parameters

  [in,out] | self | The compressor control.
  [in] | comprtype | The compressor type.
  [in] | cdata_in | The compressed data.
  [out] | data_out | The uncompressed data.
  [in] | cdatalen | The size in bytes of the compressed data.
  [in] | datalen | The size in bytes of the uncompressed data.

Return values

  0 | Successful operation.
  -EIO | An error occurred. Please note that the value is negative.
  other | All other values are reserved and must not be used.

## ◆ rtems_jffs2_compressor_destroy

typedef void(* rtems_jffs2_compressor_destroy) (rtems_jffs2_compressor_control *self)

Compressor destroy operation.

The compressor destroy operation is called during unmount of the file system instance. It can be used to free the resources associated with the now unused compressor operations.

Parameters

  [in,out] | self | The compressor control.

## ◆ rtems_jffs2_flash_destroy

typedef void(* rtems_jffs2_flash_destroy) (rtems_jffs2_flash_control *self)

Flash destroy operation.

The flash destroy operation is called during unmount of the file system instance. It can be used to free the resources associated with the now unused flash control

Parameters

  [in,out] | self | The flash control.

## ◆ rtems_jffs2_flash_erase

typedef int(* rtems_jffs2_flash_erase) (rtems_jffs2_flash_control *self, uint32_t offset)

Flash erase operation.

This operation must erase one block specified by the offset.

Parameters

  [in,out] | self | The flash control.
  [in] | offset | The offset to erase from the flash begin in bytes.

Return values

  0 | Successful operation.
  -EIO | An error occurred. Please note that the value is negative.
  other | All other values are reserved and must not be used.

## ◆ rtems_jffs2_flash_read

typedef int(* rtems_jffs2_flash_read) (rtems_jffs2_flash_control *self, uint32_t offset, unsigned char *buffer, size_t size_of_buffer)

Read from flash operation.

Parameters

  [in,out] | self | The flash control.
  [in] | offset | The offset to read from the flash begin in bytes.
  [out] | buffer | The buffer receiving the data.
  [in] | size_of_buffer | The size of the buffer in bytes.

Return values

  0 | Successful operation.
  -EIO | An error occurred. Please note that the value is negative.
  other | All other values are reserved and must not be used.

## ◆ rtems_jffs2_flash_write

typedef int(* rtems_jffs2_flash_write) (rtems_jffs2_flash_control *self, uint32_t offset, const unsigned char *buffer, size_t size_of_buffer)

Write to flash operation.

Parameters

  [in,out] | self | The flash control.
  [in] | offset | The offset to write from the flash begin in bytes.
  [in] | buffer | The buffer containing the data to write.
  [in] | size_of_buffer | The size of the buffer in bytes.

Return values

  0 | Successful operation.
  -EIO | An error occurred. Please note that the value is negative.
  other | All other values are reserved and must not be used.

## ◆ rtems_jffs2_trigger_garbage_collection

typedef void(* rtems_jffs2_trigger_garbage_collection) (rtems_jffs2_flash_control *self)

Trigger garbage collection operation.

An optional garbage collection thread may perform now a garbage collection using the RTEMS_JFFS2_ON_DEMAND_GARBAGE_COLLECTION IO control.

The garbage collection must not run in the executing context.

Parameters

  [in] | self | The flash control.

## Function Documentation

## ◆ rtems_jffs2_initialize()

int rtems_jffs2_initialize | ( | rtems_filesystem_mount_table_entry_t * | mt_entry,
|  | const void * | data
| ) |  |

Initialization handler of the JFFS2 file system.

Parameters

  [in,out] | mt_entry | The mount table entry.
  [in] | data | The mount options are mandatory for JFFS2 and data must point to a valid rtems_jffs2_mount_data structure used for this file system instance.

Return values

  0 | Successful operation.
  -1 | An error occurred. The `errno` indicates the error.

See also
  mount().