Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

SmartFS Internals

General Structure

As described in Using SmartFS, the code is divided into a SMART MTD layer and a filesystem layer. The MTD layer divides the flash or partition into equal sized logical sectors, allocates, deallocates and moves them around as needed to fulfill requests from the filesystem layer. The filesystem layer uses the logical sectors to store directory and file information, and to create chains of logical sector numbers to build larger files (and directories).

...

  • File 'a': Has data in 3 sectors, a0-a2, logical sectors 12-14
  • File 'b': Has data in 4 sectors, b0-b3, logical sectors 15-18
  • File 'c': Has data in a single sector, c0, logical sector 19

Device or partition ::UWCTOKENCOLSPANS:20::

EB ::UWCTOKENCOLSPANS:4::

EB ::UWCTOKENCOLSPANS:4::

EB ::UWCTOKENCOLSPANS:4::

EB ::UWCTOKENCOLSPANS:4::

... ::UWCTOKENCOLSPANS:4::

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

...

LS

LS

LS

LS

LS

LS

LS

LS

LS

LS

LS

LS

LS

LS

LS

LS

LS

LS

LS

...

FS

b0

RS

b1

a0

b2

a1

b3

a2

c0

...

0

15

 

 



3

16

 

 



12

17

 

 



13

18

 

 



14

19

 

 



EB = Erase Block
LS = Logical Sector
FS = Format Sector
RS = Root-directory Sector
— = Free Sector

...

The filesystem layer uses the recorded logical sector numbers in the directory sectors and header sector-chain information to perform logical sector allocate, read/write and sector release requests to carry out all typical file system operations. The SMART MTD layer then performs all the logical to physical mapping, wear-leveling, sector relocation and block erase operations, etc. When a sector needs to be physically relocated, it will retain it's logical sector number, preventing the need to update file sector-chain information, etc. The MTD layer will simply update the logical to physical map assignments.

When things change

Writing data to the filesystem and then reading it back is great. But at some point you might actually want to change or delete something. When this happens, the existing data on the flash has to be modified. As you probably already know, data on a flash can't simply be re-written, it must be erased in large chunks (erase blocks) that are typically 4K, 32K or 64K in size. When erasing this large a chunk of the flash, it is highly likely that there will be data in that erase block which should NOT be erased.

...

Logical Sector MTD Header

MTD Header (5 bytes)

FS Header

Logical Sector Number ::UWCTOKENCOLSPANS:2::

Seq #

CRC

Status ::UWCTOKENCOLSPANS:5::

5 Bytes

LSB

MSB

 

 



CB

RB

CE

SS~2-0~

FV~1-0~

 


CB: Commit Bit
RB: Release Bit
CE: CRC Enable Bit
SS: Sector Size Bits
FV: Format Version Bits