BeRTOS
Data Structures | Defines | Typedefs
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 <struct/list.h>
#include <io/kfile.h>
#include <io/kblock.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  BattFs
 Describe a BattFs file usign a KFile. More...

Defines

#define BATTFS_HEADER_LEN   12
 Size of the header once saved on disk.
#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   ((pgcnt_t)((1L << (CPU_BITS_PER_CHAR * sizeof(pgcnt_t))) - 1))
 Sentinel used to keep trace of unset pages in disk->page_array.
#define SPACE_OVER(disk)   ((disk)->free_page_start >= (disk)->dev->blk_cnt)
 True if space on disk is over.

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 uint8_t inode_t
 Type for file inodes.
typedef uint64_t seq_t
 Type for page seq number, at least 40bits wide.
typedef rotating_t fcs_t
 Type for header FCS.
typedef uint32_t disk_size_t
 Type for disk sizes.
typedef uint8_t filemode_t
 Type for file open modes.
typedef int32_t file_size_t
 Type for file sizes.
#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 BATTFS_NEGATIVE_SEEK_ERR   BV(0)
 File errors.
#define BATTFS_DISK_READ_ERR   BV(1)
 Error reading from disk device.
#define BATTFS_DISK_WRITE_ERR   BV(2)
 Error writing in the disk device.
#define BATTFS_DISK_SPACEOVER_ERR   BV(3)
 No more disk space available.
#define BATTFS_DISK_FLUSHBUF_ERR   BV(4)
 Error flushing (writing) the current page to disk.
#define BATTFS_FILE_NOT_FOUND_ERR   BV(5)
 File not found on disk.
#define KFT_BATTFS   MAKE_ID('B', 'T', 'F', 'S')
 Id for battfs file descriptors.
BattFsBATTFS_CAST (KFile *fd)
 Macro used to cast a KFile to a BattFS.
bool battfs_mount (struct BattFsSuper *disk, struct KBlock *dev, pgcnt_t *page_array, size_t array_size)
 Initialize and mount disk described by disk.
bool battfs_fsck (struct BattFsSuper *disk)
 Check the filesystem.
bool battfs_umount (struct BattFsSuper *disk)
 Umount disk.
bool battfs_fileExists (BattFsSuper *disk, inode_t inode)
bool battfs_fileopen (BattFsSuper *disk, BattFs *fd, inode_t inode, filemode_t mode)
 Open file inode from disk in mode.
void battfs_writeTestBlock (KBlock *dev, pgcnt_t page, inode_t inode, seq_t seq, fill_t fill, pgoff_t pgoff)
 Modes for battfs_fileopen.
void battfs_eraseBlock (KBlock *dev, pgcnt_t page)
 Modes for battfs_fileopen.

Detailed Description

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

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 160 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 BATTFS_NEGATIVE_SEEK_ERR   BV(0)

File errors.

Trying to read/write before file start.

Definition at line 170 of file battfs.h.


Function Documentation

BattFs* BATTFS_CAST ( KFile fd) [inline]

Macro used to cast a KFile to a BattFS.

Also perform dynamic type check.

Definition at line 202 of file battfs.h.

void battfs_eraseBlock ( KBlock dev,
pgcnt_t  page 
)

Modes for battfs_fileopen.

Create file if does not exist

bool battfs_fileExists ( BattFsSuper disk,
inode_t  inode 
)
Returns:
true if file inode exists on disk, false otherwise.

Definition at line 860 of file battfs.c.

bool battfs_fileopen ( BattFsSuper disk,
BattFs 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 906 of file battfs.c.

bool battfs_fsck ( struct BattFsSuper disk)

Check the filesystem.

Returns:
true if ok, false on errors.

Definition at line 425 of file battfs.c.

bool battfs_mount ( struct BattFsSuper disk,
struct KBlock dev,
pgcnt_t page_array,
size_t  array_size 
)

Initialize and mount disk described by disk.

Returns:
false on errors, true otherwise.

Definition at line 364 of file battfs.c.

void battfs_writeTestBlock ( KBlock dev,
pgcnt_t  page,
inode_t  inode,
seq_t  seq,
fill_t  fill,
pgoff_t  pgoff 
)

Modes for battfs_fileopen.

Create file if does not exist