Use new header locations everywhere
[bertos.git] / bertos / fs / battfs.c
index fd8fe1c6761b6cabdbb5c65a4eac8bba894c05b3..481674e1e0f73c931578546357f2ce37603826a6 100644 (file)
  *
  * -->
  *
+ * \brief BattFS: a filesystem for embedded platforms (implementation).
+ *
  * \version $Id:$
  *
  * \author Francesco Sacchi <batt@develer.com>
  *
- * \brief BattFS: a filesystem for embedded platforms (implementation).
  */
 
 #include "battfs.h"
 
+#warning TODO:Fix and complete this module.
+
+#if 0
 #include <cfg/debug.h>
 #include <cfg/macros.h> /* MIN, MAX */
-#include <mware/byteorder.h> /* cpu_to_xx */
+#include <cpu/byteorder.h> /* cpu_to_xx */
 
 
 #include <string.h> /* memset, memmove */
@@ -213,7 +217,7 @@ static void movePages(struct BattFsSuper *disk, pgcnt_t src, int offset)
 {
        pgcnt_t dst = src + offset;
        memmove(&disk->page_array[dst], &disk->page_array[src], (disk->page_count - MAX(dst, src)) * sizeof(pgcnt_t));
-       
+
        if (offset < 0)
        {
                /* Fill empty space in array with sentinel */
@@ -320,7 +324,7 @@ static void findFreeStartNext(struct BattFsSuper *disk, mark_t minl, mark_t maxl
                         * Upper interval is invalid.
                         * Use lower values.
                         */
-                       
+
                        disk->free_start = minl;
                        disk->free_next = maxl;
                }
@@ -396,7 +400,7 @@ static bool countDiskFilePages(struct BattFsSuper *disk, pgoff_t *filelen_table)
                {
                        /* Increase free space */
                        disk->free_bytes += disk->page_size - BATTFS_HEADER_LEN;
-                       
+
                        /* Check if page is marked free */
                        if (hdr.fcs_free == computeFcsFree(&hdr))
                        {
@@ -464,7 +468,7 @@ static bool fillPageArray(struct BattFsSuper *disk, pgoff_t *filelen_table)
                        else
                        {
                                BattFsPageHeader hdr_old;
-                               
+
                                if (!battfs_readHeader(disk, disk->page_array[array_pos], &hdr_old))
                                        return false;
 
@@ -507,7 +511,7 @@ static bool fillPageArray(struct BattFsSuper *disk, pgoff_t *filelen_table)
                                array_pos -= hdr.pgoff;
                                array_pos += filelen_table[hdr.inode];
                                movePages(disk, array_pos, -1);
-                               
+
                                /* Decrease file page count */
                                filelen_table[hdr.inode]--;
 
@@ -587,7 +591,7 @@ bool battfs_init(struct BattFsSuper *disk)
 
        /* Init list for opened files. */
        LIST_INIT(&disk->file_opened_list);
-       return true;    
+       return true;
 }
 
 /**
@@ -607,7 +611,7 @@ static int battfs_flush(struct KFile *fd)
  */
 static int battfs_fileclose(struct KFile *fd)
 {
-       KFileBattFs *fdb = KFILEBATTFS(fd);
+       BattFS *fdb = BATTFSKFILE(fd);
 
        battfs_flush(fd);
        REMOVE(&fdb->link);
@@ -620,7 +624,7 @@ static int battfs_fileclose(struct KFile *fd)
  */
 static size_t battfs_read(struct KFile *fd, void *_buf, size_t size)
 {
-       KFileBattFs *fdb = KFILEBATTFS(fd);
+       BattFS *fdb = BATTFSKFILE(fd);
        uint8_t *buf = (uint8_t *)_buf;
 
        size_t total_read = 0;
@@ -628,7 +632,7 @@ static size_t battfs_read(struct KFile *fd, void *_buf, size_t size)
        pgaddr_t addr_offset;
        pgaddr_t read_len;
 
-       size = MIN(size, fd->size - fd->seek_pos);
+       size = MIN((kfile_size_t)size, fd->size - fd->seek_pos);
 
        while (size)
        {
@@ -664,18 +668,18 @@ static pgcnt_t *findFile(BattFsSuper *disk, inode_t inode)
 
        while (first <= last)
        {
-                       page = (first + last) / 2;
+               page = (first + last) / 2;
 
                if (!battfs_readHeader(disk, disk->page_array[page], &hdr))
                        return NULL;
 
                fcs = computeFcs(&hdr);
                if (hdr.fcs == fcs && hdr.inode == inode)
-                       return (&disk->page_array[page]) - hdr.pgoff;
-                       else if (hdr.fcs == fcs && hdr.inode < inode)
-                       first = page + 1;
-                       else
-                       last = page - 1;
+                       return (&disk->page_array[page]) - hdr.pgoff;
+               else if (hdr.fcs == fcs && hdr.inode < inode)
+                       first = page + 1;
+               else
+                       last = page - 1;
        }
 
        return NULL;
@@ -715,7 +719,7 @@ static bool countFileSize(BattFsSuper *disk, pgcnt_t *start, inode_t inode, file
  * File context is stored in \a fd.
  * \return true if ok, false otherwise.
  */
-bool battfs_fileopen(BattFsSuper *disk, KFileBattFs *fd, inode_t inode, filemode_t mode)
+bool battfs_fileopen(BattFsSuper *disk, BattFS *fd, inode_t inode, filemode_t mode)
 {
        Node *n;
 
@@ -750,7 +754,7 @@ bool battfs_fileopen(BattFsSuper *disk, KFileBattFs *fd, inode_t inode, filemode
        /* Insert file handle in list, ordered by inode, ascending. */
        FOREACH_NODE(n, &disk->file_opened_list)
        {
-               KFileBattFs *file = containerof(n, KFileBattFs, link);
+               BattFS *file = containerof(n, BattFS, link);
                if (file->inode >= inode)
                        break;
        }
@@ -766,7 +770,7 @@ bool battfs_fileopen(BattFsSuper *disk, KFileBattFs *fd, inode_t inode, filemode
        fd->fd.read = battfs_read;
        fd->fd.reopen = kfile_genericReopen;
        fd->fd.seek = kfile_genericSeek;
-       
+
 #warning TODO battfs_write, battfs_error, battfs_clearerr
 #if 0
        fd->fd.write = battfs_write;
@@ -790,7 +794,7 @@ bool battfs_close(struct BattFsSuper *disk)
        /* Close all open files */
        FOREACH_NODE(n, &disk->file_opened_list)
        {
-               KFileBattFs *file = containerof(n, KFileBattFs, link);
+               BattFS *file = containerof(n, BattFS, link);
                res += battfs_fileclose(&file->fd);
        }
 
@@ -824,3 +828,5 @@ bool battfs_writeTestBlock(struct BattFsSuper *disk, pgcnt_t page, inode_t inode
 
        return true;
 }
+
+#endif