#include <cfg/macros.h> /* MIN, MAX */
#include <cpu/byteorder.h> /* cpu_to_xx */
-#define LOG_LEVEL LOG_LVL_INFO
+#define LOG_LEVEL LOG_LVL_WARN
#define LOG_FORMAT LOG_FMT_VERBOSE
#include <cfg/log.h>
#include <string.h> /* memset, memmove */
+#ifdef _DEBUG
+static void dumpPageArray(struct BattFsSuper *disk)
+{
+ kprintf("Page array dump:");
+ for (pgcnt_t i = 0; i < disk->page_count; i++)
+ {
+ if (!(i % 16))
+ kputchar('\n');
+ kprintf("%04d ", disk->page_array[i]);
+ }
+ kputchar('\n');
+}
+#endif
/**
* Convert from memory representation to disk structure.
static void movePages(struct BattFsSuper *disk, pgcnt_t src, int offset)
{
pgcnt_t dst = src + offset;
- LOG_INFO("src %d, offset %d, size %d\n", src, offset, (disk->page_count - MAX(dst, src)) * sizeof(pgcnt_t));
+ LOG_INFO("src %d, offset %d, size %ld\n", src, offset, (disk->page_count - MAX(dst, src)) * sizeof(pgcnt_t));
memmove(&disk->page_array[dst], &disk->page_array[src], (disk->page_count - MAX(dst, src)) * sizeof(pgcnt_t));
if (offset < 0)
fdb->disk->free_bytes -= fill_delta;
fdb->disk->curr_hdr.fill += fill_delta;
fd->size += fill_delta;
- LOG_INFO("free_bytes %ld, seek_pos %ld, size %ld, curr_hdr.fill %ld\n", fdb->disk->free_bytes, fd->seek_pos, fd->size, fdb->disk->curr_hdr.fill);
+ LOG_INFO("free_bytes %d, seek_pos %d, size %d, curr_hdr.fill %d\n", fdb->disk->free_bytes, fd->seek_pos, fd->size, fdb->disk->curr_hdr.fill);
}
return total_write;
}
/**
* Search file \a inode in \a disk using a binary search.
* \a last is filled with array offset of file start
- * in disk->page_array if filse is found, otherwise
+ * in disk->page_array if file is found, otherwise
* \a last is filled with the correct insert position
* for creating a file with the given \a inode.
* \return true if file is found, false otherwisr.
while (first < *last)
{
page = (first + *last) / 2;
-
+ LOG_INFO("first %d, last %d, page %d\n", first, *last, page);
if (!readHdr(disk, disk->page_array[page], &hdr))
return false;
file_size_t size = 0;
BattFsPageHeader hdr;
- for (;;)
+ while (start < &disk->page_array[disk->free_page_start])
{
if (!readHdr(disk, *start++, &hdr))
return EOF;
if (hdr.fcs == computeFcs(&hdr) && hdr.inode == inode)
size += hdr.fill;
else
- return size;
+ break;
}
+ return size;
}
/**
pgcnt_t start_pos;
if (!findFile(disk, inode, &start_pos))
{
+ LOG_INFO("file %d not found\n", inode);
if (!(mode & BATTFS_CREATE))
return false;
/* Create the file */
return false;
}
fd->start = &disk->page_array[start_pos];
+ LOG_INFO("Start pos %d\n", start_pos);
/* Fill file size */
if ((fd->fd.size = countFileSize(disk, fd->start, inode)) == EOF)
}
#if UNIT_TEST
+
bool battfs_writeTestBlock(struct BattFsSuper *disk, pgcnt_t page, inode_t inode, seq_t seq, fill_t fill, pgoff_t pgoff)
{
BattFsPageHeader hdr;