X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=fs%2Fbattfs.c;h=93a8868e868b66e5b3950dddaf78f5382b996436;hb=HEAD;hp=d4ee72335d9a5d75968060a84333f66775d97641;hpb=c63526c6ea2ccec3e2fd259ca39e807a7238d9fb;p=bertos.git diff --git a/fs/battfs.c b/fs/battfs.c deleted file mode 100644 index d4ee7233..00000000 --- a/fs/battfs.c +++ /dev/null @@ -1,156 +0,0 @@ -/** - * \file - * - * - * \version $Id:$ - * - * \author Francesco Sacchi - * - * \brief BattFS: a filesystem for embedded platforms (implementation). - */ - -#include "battfs.h" - -#include /* cpu_to_xx */ - -#include /* memset */ - -/** - * Convert from cpu endianess to filesystem endianness. - * \note filesystem is in little-endian format. - */ -INLINE void cpu_to_battfs(struct BattFsPageHeader *hdr) -{ - STATIC_ASSERT(sizeof(hdr->inode) == 1); - STATIC_ASSERT(sizeof(hdr->seq) == 1); - - STATIC_ASSERT(sizeof(hdr->mark) == 2); - hdr->mark = cpu_to_le16(hdr->mark); - - STATIC_ASSERT(sizeof(hdr->fill) == 2); - hdr->fill = cpu_to_le16(hdr->fill); - - STATIC_ASSERT(sizeof(hdr->pgoff) == 2); - hdr->pgoff = cpu_to_le16(hdr->pgoff); - - STATIC_ASSERT(sizeof(hdr->fcs) == 2); - hdr->fcs = cpu_to_le16(hdr->fcs); - - STATIC_ASSERT(sizeof(hdr->rfu) == 2); - hdr->rfu = cpu_to_le16(hdr->rfu); -} - - -/** - * Convert from filesystem endianness to cpu endianess. - * \note filesystem is in little-endian format. - */ -INLINE void battfs_to_cpu(struct BattFsPageHeader *hdr) -{ - STATIC_ASSERT(sizeof(hdr->inode) == 1); - STATIC_ASSERT(sizeof(hdr->seq) == 1); - - STATIC_ASSERT(sizeof(hdr->mark) == 2); - hdr->mark = le16_to_cpu(hdr->mark); - - STATIC_ASSERT(sizeof(hdr->fill) == 2); - hdr->fill = le16_to_cpu(hdr->fill); - - STATIC_ASSERT(sizeof(hdr->pgoff) == 2); - hdr->pgoff = le16_to_cpu(hdr->pgoff); - - STATIC_ASSERT(sizeof(hdr->fcs) == 2); - hdr->fcs = le16_to_cpu(hdr->fcs); - - STATIC_ASSERT(sizeof(hdr->rfu) == 2); - hdr->rfu = le16_to_cpu(hdr->rfu); -} - - -/** - * Read header of page \a page. - * \return true on success, false otherwise. - * \note \a hdr is dirtyed even on errors. - */ -static bool battfs_readHeader(struct BattFsSuper *disk, pgcnt_t page, struct BattFsPageHeader *hdr) -{ - /* - * Read header from disk. - * header is actually a footer, and so - * resides at page end. - */ - if (disk->read(disk, page, disk->page_size - sizeof(BattFsPageHeader), hdr, sizeof(BattFsPageHeader)) - != sizeof(BattFsPageHeader)) - return false; - - /* Fix endianess */ - battfs_to_cpu(hdr); - return true; -} - -/** - * Initialize and mount disk described by - * \a d. - * \return false on errors, true otherwise. - */ -bool battfs_init(struct BattFsSuper *disk) -{ - BattFsPageHeader hdr; - rotating_t cks; - pgoff_t filelen_table[BATTFS_MAX_FILES]; - - /* Init disk device */ - if (!disk->open(disk)) - return false; - - memset(filelen_table, 0, BATTFS_MAX_FILES * sizeof(pgoff_t)); - - for (pgcnt_t page = 0; page < disk->page_count; page++) - { - if (!battfs_readHeader(disk, page, &hdr)) - return false; - - /* Check header FCS */ - rotating_init(&cks); - rotating_update(&hdr, sizeof(BattFsPageHeader) - sizeof(rotating_t), &cks); - if (cks == hdr.fcs) - filelen_table[page]++; - else - { - #warning Finish me! - } - } - - - return true; -} - -