@@ -163,6 +163,46 @@ void test_read_write() {
163
163
TEST_ASSERT_EQUAL (0 , err);
164
164
}
165
165
166
+ void test_single_mbr () {
167
+ int err = bd.init ();
168
+ TEST_ASSERT_EQUAL (0 , err);
169
+
170
+ const bd_addr_t MBR_OFFSET = 0 ;
171
+ const bd_addr_t FAT1_OFFSET = 1 ;
172
+ const bd_addr_t FAT2_OFFSET = BLOCK_COUNT/2 ;
173
+
174
+ uint8_t *buffer = (uint8_t *)malloc (BLOCK_SIZE);
175
+ TEST_ASSERT (buffer);
176
+
177
+ // Check that all three header blocks have the 0x55aa signature
178
+ err = bd.read (buffer, MBR_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
179
+ TEST_ASSERT_EQUAL (0 , err);
180
+ TEST_ASSERT (memcmp (&buffer[BLOCK_SIZE-2 ], " \x55\xaa " , 2 ) == 0 );
181
+
182
+ err = bd.read (buffer, FAT1_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
183
+ TEST_ASSERT_EQUAL (0 , err);
184
+ TEST_ASSERT (memcmp (&buffer[BLOCK_SIZE-2 ], " \x55\xaa " , 2 ) == 0 );
185
+
186
+ err = bd.read (buffer, FAT2_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
187
+ TEST_ASSERT_EQUAL (0 , err);
188
+ TEST_ASSERT (memcmp (&buffer[BLOCK_SIZE-2 ], " \x55\xaa " , 2 ) == 0 );
189
+
190
+ // Check that the headers for both filesystems contain a jump code
191
+ // indicating they are actual FAT superblocks and not an extra MBR
192
+ err = bd.read (buffer, FAT1_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
193
+ TEST_ASSERT_EQUAL (0 , err);
194
+ TEST_ASSERT (buffer[0 ] == 0xe9 || buffer[0 ] == 0xeb || buffer[0 ] == 0xe8 );
195
+
196
+ err = bd.read (buffer, FAT2_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
197
+ TEST_ASSERT_EQUAL (0 , err);
198
+ TEST_ASSERT (buffer[0 ] == 0xe9 || buffer[0 ] == 0xeb || buffer[0 ] == 0xe8 );
199
+
200
+ free (buffer);
201
+
202
+ bd.deinit ();
203
+ TEST_ASSERT_EQUAL (0 , err);
204
+ }
205
+
166
206
167
207
// Test setup
168
208
utest::v1::status_t test_setup (const size_t number_of_cases) {
@@ -174,6 +214,7 @@ Case cases[] = {
174
214
Case (" Testing formating" , test_format),
175
215
Case (" Testing read write < block" , test_read_write<BLOCK_SIZE/2 >),
176
216
Case (" Testing read write > block" , test_read_write<2 *BLOCK_SIZE>),
217
+ Case (" Testing for no extra MBRs" , test_single_mbr),
177
218
};
178
219
179
220
Specification specification (test_setup, cases);
0 commit comments