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 <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  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)->page_count)
 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 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 bool(* disk_page_load_t )(struct BattFsSuper *d, pgcnt_t page)
 Type interface for disk page load function.
typedef size_t(* disk_buffer_write_t )(struct BattFsSuper *d, pgaddr_t addr, const void *buf, size_t)
 Type interface for disk pagebuffer write function.
typedef size_t(* disk_buffer_read_t )(struct BattFsSuper *d, pgaddr_t addr, void *buf, size_t)
 Type interface for disk pagebuffer read function.
typedef bool(* disk_page_save_t )(struct BattFsSuper *d, pgcnt_t page)
 Type interface for disk page save 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 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 driver.
#define BATTFS_DISK_LOADPAGE_ERR   BV(2)
 Error loading a disk page in the buffer.
#define BATTFS_DISK_BUFFERWR_ERR   BV(3)
 Error writing in the disk page buffer.
#define BATTFS_DISK_GETNEWPAGE_ERR   BV(4)
 Error getting a free page.
#define BATTFS_DISK_BUFFERRD_ERR   BV(6)
 Error reading from the disk page buffer.
#define BATTFS_DISK_SPACEOVER_ERR   BV(7)
 No more disk space available.
#define BATTFS_DISK_FLUSHBUF_ERR   BV(8)
 Error flushing (writing) the current page to disk.
#define BATTFS_FILE_NOT_FOUND_ERR   BV(9)
 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 *d)
 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.

Detailed Description

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

Version:
Id
battfs.h 2653 2009-04-23 17:01:24Z duplo

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 233 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 243 of file battfs.h.


Typedef Documentation

typedef size_t(* disk_buffer_read_t)(struct BattFsSuper *d, pgaddr_t addr, void *buf, size_t)

Type interface for disk pagebuffer read function.

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

Returns:
the number of bytes read.

Definition at line 150 of file battfs.h.

typedef size_t(* disk_buffer_write_t)(struct BattFsSuper *d, pgaddr_t addr, const void *buf, size_t)

Type interface for disk pagebuffer write function.

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

Returns:
the number of bytes written.

Definition at line 142 of file battfs.h.

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 172 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 166 of file battfs.h.

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

Type interface for disk page load function.

The disk should supply a buffer used for loading/saving pages. This has to be done by the disk driver because it knows memory details (e.g. some memories can have the buffer inside the memory itself). page is the page to be loaded from the disk in the buffer.

Returns:
true if ok, false on errors.

Definition at line 134 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 123 of file battfs.h.

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

Type interface for disk page save function.

The disk should supply a buffer used for loading/saving pages. For details

See also:
disk_page_load_t. page is the page where the buffer will be written.
Returns:
true if ok, false on errors.

Definition at line 159 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 278 of file battfs.h.

bool battfs_fileExists ( BattFsSuper disk,
inode_t  inode 
)

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

Definition at line 894 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 940 of file battfs.c.

bool battfs_fsck ( struct BattFsSuper disk  ) 

Check the filesystem.

Returns:
true if ok, false on errors.

Definition at line 510 of file battfs.c.

bool battfs_mount ( struct BattFsSuper disk  ) 

Initialize and mount disk described by disk.

Returns:
false on errors, true otherwise.

Definition at line 442 of file battfs.c.