battfs.h File Reference

BattFS: a filesystem for embedded platforms (interface). TODO: Add detailed filesystem description. More...

#include <cfg/compiler.h>
#include <cpu/types.h>
#include <algo/rotating_hash.h>
#include <mware/list.h>
#include <kern/kfile.h>

Go to the source code of this file.


Data Structures

struct  BattFsPageHeader
 BattFS page header, used to represent a page header in memory. More...
struct  BattFsSuper
 Context used to describe a disk. More...
struct  KFileBattFs
 Describe a BattFs file usign a KFile. More...

Defines

#define BATTFS_HEADER_LEN   12
 Size of the header once saved on disk.
#define MARK_HALF_SIZE   (1 << (CPU_BITS_PER_CHAR * sizeof(pgcnt_t) + 1))
 Half-size of free page marker.
#define MAX_PAGE_ADDR   ((1 << (CPU_BITS_PER_CHAR * sizeof(pgcnt_t))) - 1)
 Maximum page address.
#define BATTFS_MAX_FILES   (1 << (CPU_BITS_PER_CHAR * sizeof(inode_t)))
 Max number of files.
#define PAGE_UNSET_SENTINEL   ((1 << (CPU_BITS_PER_CHAR * sizeof(pgcnt_t))) - 1)
 Sentinel used to keep trace of unset pages in disk->page_array.
#define MARK_PAGE_VALID   ((1 << (CPU_BITS_PER_CHAR * sizeof(pgcnt_t) + 1)) - 1)
 Marks for valid pages.

Typedefs

typedef uint16_t fill_t
 Type for keeping trace of space filled inside a page.
typedef fill_t pgaddr_t
 Type for addressing space inside a page.
typedef uint16_t pgcnt_t
 Type for counting pages on disk.
typedef pgcnt_t pgoff_t
 Type for counting pages inside a file.
typedef uint32_t mark_t
 Type for marking pages as free.
typedef uint8_t inode_t
 Type for file inodes.
typedef uint8_t seq_t
 Type for page seq number.
typedef rotating_t fcs_t
 Type for header FCS.
typedef bool(* disk_open_t )(struct BattFsSuper *d)
 Type interface for disk init function.
typedef size_t(* disk_page_read_t )(struct BattFsSuper *d, pgcnt_t page, pgaddr_t addr, void *buf, size_t)
 Type interface for disk page read function.
typedef size_t(* disk_page_write_t )(struct BattFsSuper *d, pgcnt_t page, pgaddr_t addr, const void *buf, size_t)
 Type interface for disk page write function.
typedef bool(* disk_page_erase_t )(struct BattFsSuper *d, pgcnt_t page)
 Type interface for disk page erase function.
typedef bool(* disk_close_t )(struct BattFsSuper *d)
 Type interface for disk deinit function.
typedef uint32_t disk_size_t
 Type for disk sizes.
typedef uint8_t filemode_t
 Type for file open modes.
typedef uint32_t file_size_t
 Type for file sizes.

Functions

 STATIC_ASSERT (sizeof(mark_t) > sizeof(pgcnt_t))
 Size required for free block allocation is at least 1 bit more than page addressing.
#define BATTFS_CREATE   BV(0)
 Modes for battfs_fileopen.
#define BATTFS_RD   BV(1)
 Open file for reading.
#define BATTFS_WR   BV(2)
 Open file fir writing.
#define KFT_BATTFS   MAKE_ID('B', 'T', 'F', 'S')
 Id for battfs file descriptors.
KFileBattFsKFILEBATTFS (KFile *fd)
 Macro used to cast a KFile to a KFileBattFs.
bool battfs_init (struct BattFsSuper *d)
 Initialize and mount disk described by disk.
bool battfs_close (struct BattFsSuper *disk)
 Close disk.
bool battfs_fileExists (BattFsSuper *disk, inode_t inode)
bool battfs_fileopen (BattFsSuper *disk, KFileBattFs *fd, inode_t inode, filemode_t mode)
 Open file inode from disk in mode.

Detailed Description

BattFS: a filesystem for embedded platforms (interface). TODO: Add detailed filesystem description.

Version:
$Id$
Author:
Francesco Sacchi <batt@develer.com>

Definition in file battfs.h.


Define Documentation

#define BATTFS_CREATE   BV(0)

Modes for battfs_fileopen.

Create file if does not exist

Definition at line 222 of file battfs.h.

#define BATTFS_HEADER_LEN   12

Size of the header once saved on disk.

See also:
battfs_to_disk

disk_to_battfs

Definition at line 97 of file battfs.h.

#define MARK_HALF_SIZE   (1 << (CPU_BITS_PER_CHAR * sizeof(pgcnt_t) + 1))

Half-size of free page marker.

Used to keep trace of free marker wrap-arounds.

Definition at line 113 of file battfs.h.

#define MARK_PAGE_VALID   ((1 << (CPU_BITS_PER_CHAR * sizeof(pgcnt_t) + 1)) - 1)

Marks for valid pages.

Simply set to 1 all field bits.

Definition at line 104 of file battfs.h.


Typedef Documentation

typedef bool(* disk_close_t)(struct BattFsSuper *d)

Type interface for disk deinit function.

Returns:
true if all is ok, false otherwise.

Definition at line 166 of file battfs.h.

typedef bool(* disk_open_t)(struct BattFsSuper *d)

Type interface for disk init function.

Returns:
true if all is ok, false otherwise.

Definition at line 137 of file battfs.h.

typedef bool(* disk_page_erase_t)(struct BattFsSuper *d, pgcnt_t page)

Type interface for disk page erase function.

page is the page address.

Returns:
true if all is ok, false otherwise.

Definition at line 160 of file battfs.h.

typedef size_t(* disk_page_read_t)(struct BattFsSuper *d, pgcnt_t page, pgaddr_t addr, void *buf, size_t)

Type interface for disk page read function.

page is the page address, addr the address inside the page, size the lenght to be read.

Returns:
the number of bytes read.

Definition at line 145 of file battfs.h.

typedef size_t(* disk_page_write_t)(struct BattFsSuper *d, pgcnt_t page, pgaddr_t addr, const void *buf, size_t)

Type interface for disk page write function.

page is the page address, addr the address inside the page, size the lenght to be written.

Returns:
the number of bytes written.

Definition at line 153 of file battfs.h.


Function Documentation

bool battfs_fileExists ( BattFsSuper disk,
inode_t  inode 
)

Returns:
true if file inode exists on disk, false otherwise.

Definition at line 687 of file battfs.c.

bool battfs_fileopen ( BattFsSuper disk,
KFileBattFs fd,
inode_t  inode,
filemode_t  mode 
)

Open file inode from disk in mode.

File context is stored in fd.

Returns:
true if ok, false otherwise.

Definition at line 718 of file battfs.c.

bool battfs_init ( struct BattFsSuper disk  ) 

Initialize and mount disk described by disk.

Returns:
false on errors, true otherwise.

Definition at line 539 of file battfs.c.

KFileBattFs* KFILEBATTFS ( KFile fd  )  [inline]

Macro used to cast a KFile to a KFileBattFs.

Also perform dynamic type check.

Definition at line 250 of file battfs.h.