BeRTOS
Functions
battfs.c File Reference

BattFS: a filesystem for embedded platforms (implementation). More...

#include "battfs.h"
#include "cfg/cfg_battfs.h"
#include <cfg/debug.h>
#include <cfg/macros.h>
#include <cfg/test.h>
#include <cpu/byteorder.h>
#include <cfg/log.h>
#include <string.h>

Go to the source code of this file.

Functions

void battfs_to_disk (struct BattFsPageHeader *hdr, uint8_t *buf)
 Convert from memory representation to disk structure.
void disk_to_battfs (uint8_t *buf, struct BattFsPageHeader *hdr)
 Convert from disk structure to memory representation.
static fcs_t computeFcs (struct BattFsPageHeader *hdr)
 Compute the fcs of the header.
static bool readHdr (struct BattFsSuper *disk, pgcnt_t page, struct BattFsPageHeader *hdr)
 Read header of page in hdr.
static pgcnt_t countPages (pgoff_t *filelen_table, inode_t inode)
 Count the number of pages from inode 0 to inode in filelen_table.
static void movePages (struct BattFsSuper *disk, pgcnt_t src, int offset)
 Move all pages in page allocation array from src to src + offset.
static bool countDiskFilePages (struct BattFsSuper *disk, pgoff_t *filelen_table)
 Count number of pages per file on disk.
static bool fillPageArray (struct BattFsSuper *disk, pgoff_t *filelen_table)
 Fill page allocation array of disk using file lenghts in filelen_table.
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.
static int battfs_flush (struct KFile *fd)
 Flush file fd.
static int battfs_fileclose (struct KFile *fd)
 Close file fd.
static size_t battfs_write (struct KFile *fd, const void *_buf, size_t size)
 Write to file fd size bytes from buf.
static size_t battfs_read (struct KFile *fd, void *_buf, size_t size)
 Read from file fd size bytes in buf.
static bool findFile (BattFsSuper *disk, inode_t inode, pgcnt_t *last)
 Search file inode in disk using a binary search.
bool battfs_fileExists (BattFsSuper *disk, inode_t inode)
static file_size_t countFileSize (BattFsSuper *disk, pgcnt_t *start, inode_t inode)
 Count size of file inode on disk, starting at pointer start in disk->page_array.
bool battfs_fileopen (BattFsSuper *disk, BattFs *fd, inode_t inode, filemode_t mode)
 Open file inode from disk in mode.
bool battfs_umount (struct BattFsSuper *disk)
 Umount disk.

Detailed Description

BattFS: a filesystem for embedded platforms (implementation).

Author:
Francesco Sacchi <batt@develer.com>

Definition in file battfs.c.


Function Documentation

static int battfs_fileclose ( struct KFile fd) [static]

Close file fd.

Returns:
0 if ok, EOF on errors.

Definition at line 500 of file battfs.c.

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.

static int battfs_flush ( struct KFile fd) [static]

Flush file fd.

Returns:
0 if ok, EOF on errors.

Definition at line 483 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.

static size_t battfs_read ( struct KFile fd,
void *  _buf,
size_t  size 
) [static]

Read from file fd size bytes in buf.

Returns:
The number of bytes read.

Definition at line 771 of file battfs.c.

void battfs_to_disk ( struct BattFsPageHeader hdr,
uint8_t *  buf 
) [inline]

Convert from memory representation to disk structure.

Note:
filesystem is in little-endian format.

Definition at line 71 of file battfs.c.

static size_t battfs_write ( struct KFile fd,
const void *  _buf,
size_t  size 
) [static]

Write to file fd size bytes from buf.

Returns:
The number of bytes written.

Definition at line 565 of file battfs.c.

static bool countDiskFilePages ( struct BattFsSuper disk,
pgoff_t filelen_table 
) [static]

Count number of pages per file on disk.

This information is registered in filelen_table. Array index represent file inode, while value contained is the number of pages used by that file.

Returns:
true if ok, false on disk read errors.
Note:
The whole disk is scanned once.

Definition at line 221 of file battfs.c.

static file_size_t countFileSize ( BattFsSuper disk,
pgcnt_t start,
inode_t  inode 
) [static]

Count size of file inode on disk, starting at pointer start in disk->page_array.

Size is written in size.

Returns:
true if all s ok, false on disk read errors.

Definition at line 871 of file battfs.c.

void disk_to_battfs ( uint8_t *  buf,
struct BattFsPageHeader hdr 
) [inline]

Convert from disk structure to memory representation.

Note:
filesystem is in little-endian format.

Definition at line 105 of file battfs.c.

static bool fillPageArray ( struct BattFsSuper disk,
pgoff_t filelen_table 
) [static]

Fill page allocation array of disk using file lenghts in filelen_table.

The page allocation array is an array containings all file infos. Is ordered by file, and within each file is ordered by page offset inside file. e.g. : at page array[0] you will find page address of the first page of the first file (if present). Free blocks are allocated after the last file.

Returns:
true if ok, false on disk read errors.
Note:
The whole disk is scanned at max twice.

Definition at line 267 of file battfs.c.

static bool findFile ( BattFsSuper disk,
inode_t  inode,
pgcnt_t last 
) [static]

Search file inode in disk using a binary search.

last is filled with array offset of file start in disk->page_array if file is found, otherwise last is filled with the correct insert position for creating a file with the given inode.

Returns:
true if file is found, false otherwisr.

Definition at line 827 of file battfs.c.

static void movePages ( struct BattFsSuper disk,
pgcnt_t  src,
int  offset 
) [static]

Move all pages in page allocation array from src to src + offset.

The number of pages moved is page_count - MAX(dst, src).

Definition at line 198 of file battfs.c.

static bool readHdr ( struct BattFsSuper disk,
pgcnt_t  page,
struct BattFsPageHeader hdr 
) [static]

Read header of page in hdr.

Returns:
true on success, false otherwise.

Definition at line 134 of file battfs.c.