typedef fill_t pgaddr_t; ///< Type for addressing space inside a page
typedef uint16_t pgcnt_t; ///< Type for counting pages on disk
typedef pgcnt_t pgoff_t; ///< Type for counting pages inside a file
-typedef uint32_t mark_t; ///< Type for marking pages as free
typedef uint8_t inode_t; ///< Type for file inodes
typedef uint8_t seq_t; ///< Type for page seq number
typedef rotating_t fcs_t; ///< Type for header FCS.
* Size required for free block allocation is at least 1 bit more
* than page addressing.
*/
-STATIC_ASSERT(sizeof(mark_t) > sizeof(pgcnt_t));
+STATIC_ASSERT(sizeof(seq_t) > sizeof(pgcnt_t));
/**
* BattFS page header, used to represent a page
typedef struct BattFsPageHeader
{
inode_t inode; ///< File inode (file identifier).
- seq_t seq; ///< Page sequence number.
fill_t fill; ///< Filled bytes in page.
pgoff_t pgoff; ///< Page offset inside file.
- mark_t mark; ///< Marker used to keep trace of free/used pages.
-
- /**
- * FCS (Frame Check Sequence) of the page header once the page
- * as been marked as free.
- */
- fcs_t fcs_free;
+ seq_t seq; ///< Page sequence number.
/**
* FCS (Frame Check Sequence) of the page header.
* \see battfs_to_disk
* \see disk_to_battfs
*/
-#define BATTFS_HEADER_LEN 12
+#define BATTFS_HEADER_LEN 10
/**
- * Marks for valid pages.
- * Simply set to 1 all field bits.
- * \{
+ * Half-size of page sequence numer.
*/
-#define MARK_PAGE_VALID ((1 << (CPU_BITS_PER_CHAR * sizeof(pgcnt_t) + 1)) - 1)
-#define FCS_FREE_VALID ((1 << (CPU_BITS_PER_CHAR * sizeof(fcs_t))) - 1)
-/* \} */
-
+#define HALF_SEQ (1 << (CPU_BITS_PER_CHAR * sizeof(pgcnt_t)))
/**
- * Half-size of free page marker.
- * Used to keep trace of free marker wrap-arounds.
+ * Max sequence number.
*/
-#define MARK_HALF_SIZE (1 << (CPU_BITS_PER_CHAR * sizeof(pgcnt_t) + 1))
+#define MAX_SEQ ((1 << (CPU_BITS_PER_CHAR * sizeof(pgcnt_t) + 1)) - 1)
+
/**
* Maximum page address.
*/
#define PAGE_UNSET_SENTINEL ((1 << (CPU_BITS_PER_CHAR * sizeof(pgcnt_t))) - 1)
+/** Also used as an error marker sometimes */
+#define PAGE_ERROR PAGE_UNSET_SENTINEL
+
/**
* Type interface for disk init function.
* \return true if all is ok, false otherwise.
*/
pgcnt_t *page_array;
- /**
- * Lowest free page counter.
- * This is the counter of the first availble free page.
- */
- mark_t free_start;
-
- /**
- * Highest free page counter.
- * This value is the next to be used to mark a block as free.
+ /**
+ * Lowest address, in page array, for free pages.
+ * Pages above this element are free for use.
*/
- mark_t free_next;
+ pgcnt_t free_page_start;
disk_size_t disk_size; ///< Size of the disk, in bytes (page_count * page_size).
disk_size_t free_bytes; ///< Free space on the disk.
/**
* Describe a BattFs file usign a KFile.
*/
-typedef struct BattFS
+typedef struct BattFs
{
KFile fd; ///< KFile context
Node link; ///< Link for inserting in opened file list
BattFsSuper *disk; ///< Disk context
filemode_t mode; ///< File open mode
pgcnt_t *start; ///< Pointer to page_array file start position.
-} BattFS;
+} BattFs;
/**
* Id for battfs file descriptors.
* Macro used to cast a KFile to a BattFS.
* Also perform dynamic type check.
*/
-INLINE BattFS * BATTFSKFILE(KFile *fd)
+INLINE BattFs * BATTFS_CAST(KFile *fd)
{
ASSERT(fd->_type == KFT_BATTFS);
- return (BattFS *)fd;
+ return (BattFs *)fd;
}
bool battfs_init(struct BattFsSuper *d);
bool battfs_close(struct BattFsSuper *disk);
bool battfs_fileExists(BattFsSuper *disk, inode_t inode);
-bool battfs_fileopen(BattFsSuper *disk, BattFS *fd, inode_t inode, filemode_t mode);
-
-bool battfs_writeTestBlock(struct BattFsSuper *disk, pgcnt_t page, inode_t inode, seq_t seq, fill_t fill, pgoff_t pgoff, mark_t mark);
+bool battfs_fileopen(BattFsSuper *disk, BattFs *fd, inode_t inode, filemode_t mode);
+bool battfs_writeTestBlock(struct BattFsSuper *disk, pgcnt_t page, inode_t inode, seq_t seq, fill_t fill, pgoff_t pgoff, seq_t seq);
#endif /* FS_BATTFS_H */