4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
35 * \author Francesco Sacchi <batt@develer.com>
37 * \brief BattFS: a filesystem for embedded platforms (interface).
38 * TODO: Add detailed filesystem description.
44 #include <cfg/compiler.h> // uintXX_t; STATIC_ASSERT
45 #include <cpu/types.h> // CPU_BITS_PER_CHAR
47 typedef uint16_t fill_t;
48 typedef fill_t pgaddr_t;
49 typedef uint16_t pgoff_t;
50 typedef pgoff_t mark_t;
51 typedef uint8_t inode_t;
52 typedef uint8_t seq_t;
53 typedef uint16_t fcs_t;
57 * \note fields order is chosen to comply
60 typedef struct BattFsPageHeader
62 inode_t inode; ///< File inode (file identifier).
63 seq_t seq; ///< Page sequence number.
64 mark_t mark; ///< Marker used to keep trace of free/used pages.
65 pgoff_t pgoff; ///< Page offset inside file.
66 fill_t fill; ///< Filled bytes in page.
67 uint16_t rfu; ///< Reserved for future use, 0xFFFF for now.
68 fcs_t fcs; ///< FCS (Frame Check Sequence) of the page header.
71 /* Ensure structure has no padding added */
72 STATIC_ASSERT(sizeof(BattFsPageHeader) == 12);
78 * Type for disk page addressing.
80 typedef uint16_t pgcnt_t;
83 * Type interface for disk init function.
84 * \return true if all is ok, false otherwise.
86 typedef bool (*disk_open_t) (struct BattFsSuper *d);
89 * Type interface for disk page read function.
90 * \a page is the page address, \a addr the address inside the page,
91 * \a size the lenght to be read.
92 * \return the number of bytes read.
94 typedef size_t (*disk_page_read_t) (struct BattFsSuper *d, pgcnt_t page, pgaddr_t addr, void *buf, size_t);
97 * Type interface for disk page write function.
98 * \a page is the page address, \a addr the address inside the page,
99 * \a size the lenght to be written.
100 * \return the number of bytes written.
102 typedef size_t (*disk_page_write_t) (struct BattFsSuper *d, pgcnt_t page, pgaddr_t addr, void *buf, size_t);
105 * Type interface for disk page erase function.
106 * \a page is the page address.
107 * \return true if all is ok, false otherwise.
109 typedef bool (*disk_page_erase_t) (struct BattFsSuper *d, pgcnt_t page);
112 * Type interface for disk deinit function.
113 * \return true if all is ok, false otherwise.
115 typedef bool (*disk_close_t) (struct BattFsSuper *d);
118 typedef uint32_t disk_size_t; ///< Type for disk sizes.
121 * Context used to describe a disk.
122 * This context structure will be used to access disk.
123 * Must be initialized by hw memory driver.
125 typedef struct BattFsSuper
127 disk_open_t open; ///< Disk init.
128 disk_page_read_t read; ///< Page read.
129 disk_page_write_t write; ///< Page write.
130 disk_page_erase_t erase; ///< Page erase.
131 disk_close_t close; ///< Disk deinit.
133 pgaddr_t page_size; ///< Size of a disk page, in bytes.
134 pgcnt_t page_count; ///< Number of pages on disk.
137 * Page allocation array.
138 * This array must be allocated somewhere and
139 * must have enough space for page_count elements.
140 * Is used by the filesystem to represent
141 * the entire disk in memory.
145 disk_size_t disk_size; ///< Size of the disk, in bytes (page_count * page_size).
146 disk_size_t free_bytes; ///< Free space on the disk.
148 /* TODO add other fields. */
152 * Initialize and mount disk described by
154 * \return false on errors, true otherwise.
156 bool battfs_init(struct BattFsSuper *d);
158 #endif /* FS_BATTFS_H */