battfs.c File Reference
BattFS: a filesystem for embedded platforms (implementation). More...
#include "battfs.h"#include <cfg/compiler.h>#include <cpu/types.h>#include <algo/rotating_hash.h>#include <struct/list.h>#include <kern/kfile.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 size_t | diskRead (struct BattFsSuper *disk, pgcnt_t page, pgaddr_t addr, void *buf, size_t size) |
| Read from disk. | |
| static bool | readHdr (struct BattFsSuper *disk, pgcnt_t page, struct BattFsPageHeader *hdr) |
| Read header of page in hdr. | |
| static bool | setBufferHdr (struct BattFsSuper *disk, struct BattFsPageHeader *hdr) |
| Set header on current disk page buffer. | |
| 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. | |
| static bool | flushBuffer (struct BattFsSuper *disk) |
| Flush the current disk buffer. | |
| static bool | loadPage (struct BattFsSuper *disk, pgcnt_t new_page, BattFsPageHeader *new_hdr) |
| Load new_page from disk in disk page buffer. | |
| bool | battfs_mount (struct BattFsSuper *disk) |
| 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).
- Version:
- Id
- battfs.c 2886 2009-09-07 13:39:46Z batt
Definition in file battfs.c.
Function Documentation
| static int battfs_fileclose | ( | struct KFile * | fd | ) | [static] |
| bool battfs_fileExists | ( | BattFsSuper * | disk, | |
| inode_t | inode | |||
| ) |
| bool battfs_fileopen | ( | BattFsSuper * | disk, | |
| BattFs * | fd, | |||
| inode_t | inode, | |||
| filemode_t | mode | |||
| ) |
| static int battfs_flush | ( | struct KFile * | fd | ) | [static] |
| bool battfs_fsck | ( | struct BattFsSuper * | disk | ) |
| bool battfs_mount | ( | struct BattFsSuper * | disk | ) |
| static size_t battfs_read | ( | struct KFile * | fd, | |
| void * | _buf, | |||
| size_t | size | |||
| ) | [static] |
| void battfs_to_disk | ( | struct BattFsPageHeader * | hdr, | |
| uint8_t * | buf | |||
| ) | [inline] |
| static size_t battfs_write | ( | struct KFile * | fd, | |
| const void * | _buf, | |||
| size_t | size | |||
| ) | [static] |
| 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.
| static file_size_t countFileSize | ( | BattFsSuper * | disk, | |
| pgcnt_t * | start, | |||
| inode_t | inode | |||
| ) | [static] |
| void disk_to_battfs | ( | uint8_t * | buf, | |
| struct BattFsPageHeader * | hdr | |||
| ) | [inline] |
| static size_t diskRead | ( | struct BattFsSuper * | disk, | |
| pgcnt_t | page, | |||
| pgaddr_t | addr, | |||
| void * | buf, | |||
| size_t | size | |||
| ) | [static] |
| 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.
| 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.
| static bool flushBuffer | ( | struct BattFsSuper * | disk | ) | [static] |
| static bool loadPage | ( | struct BattFsSuper * | disk, | |
| pgcnt_t | new_page, | |||
| BattFsPageHeader * | new_hdr | |||
| ) | [static] |
| 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).
| static bool readHdr | ( | struct BattFsSuper * | disk, | |
| pgcnt_t | page, | |||
| struct BattFsPageHeader * | hdr | |||
| ) | [static] |
| static bool setBufferHdr | ( | struct BattFsSuper * | disk, | |
| struct BattFsPageHeader * | hdr | |||
| ) | [static] |
