Giter VIP home page Giter VIP logo

sdfat-spin's Introduction

sdfat-spin


This is a P8X32A/Propeller, P2X8C4M64P/Propeller 2 implementation of the FAT filesystem on SD.

IMPORTANT: This software is meant to be used with the spin-standard-library (P8X32A) or p2-spin-standard-library (P2X8C4M64P). Please install the applicable library first before attempting to use this code, otherwise you will be missing several files required to build the project.

Salient Features

  • FAT32 on SDHC/SDXC
  • Open file by name or dirent number
  • Read currently opened file's attributes: file name and extension, is directory, is the volume name, size, date, time
  • Read, write a block of data (writes are currently always synchronous)
  • File management: rename, delete, create, find by filename
  • Cluster management: Find free cluster, allocate an arbitrary cluster, allocate block of clusters, allocate additional cluster for currently open file, count clusters allocated to file
  • POSIX-ish familiarities: (some) method names and params, file open modes

File open modes supported

Symbol Description Seek behavior allowed
O_RDONLY Read random
O_WRITE Write random
O_RDWR Read/Write random
O_CREAT Create file n/a
O_APPEND Writes append to file always points to EOF
O_TRUNC Truncate file to 0 bytes after opening n/a

(modes are bitfields that can be OR'd together)

Requirements

P1/SPIN1:

P2/SPIN2:

  • p2-spin-standard-library

Compiler Compatibility

Processor Language Compiler Backend Status
P1 SPIN1 FlexSpin (6.8.1) Bytecode OK
P1 SPIN1 FlexSpin (6.8.1) Native/PASM Some demos FTBFS
P2 SPIN2 FlexSpin (6.8.1) NuCode Not yet implemented
P2 SPIN2 FlexSpin (6.8.1) Native/PASM2 Not yet implemented

(other versions or toolchains not listed are not supported, and may or may not work)

Limitations

  • Very early in development - may malfunction, or outright fail to build
  • FAT16, FAT12 not yet supported
  • Pre-SDHC cards unsupported (unplanned)
  • No (sub)directory support yet
  • No long filename support yet
  • Slow
  • API should be considered unstable

sdfat-spin's People

Contributors

avsa242 avatar

Watchers

 avatar  avatar

sdfat-spin's Issues

Defer writes until a full sector is buffered

Right now even very small writes to a sector write the sector in full to the card, which blocks for a long time. Add logic to wait until the sector buffer is full, or is explicitly flushed by the user.

  • add a separate metadata buffer
  • find a way to eliminate the need to read in the FAT every time fseek() is called, to reduce unnecessary SD access; maybe set a flag indicating what kind of data is currently in the metadata buffer, and if it's the correct FAT sector, then do nothing
  • add a method to 'queue' data
  • add a mechanism for explicitly flushing the write buffer
  • rewrite fwrite() to wait until sector buffer is full

fread() should only read a block from SD if it needs to

Currently, it reads a block (even re-reading the current one) every time it's called, as long as the seek pointer is before the EOF.
Example: fread() is called to read 10 bytes. A full 512 byte sector is read in. If the next call only reads another 10 bytes, it should simply copy the data from the sector buffer instead of re-reading the sector.

Add support for deleting files

Find out exactly how this is implemented in other systems - the dirent is marked deleted, but what is done with the cluster chain - is it simply overwritten with zeroes?
Alternative implementation is a permanent - clear out the dirent entirely and zero out cluster chain as well as the actual file data.

Verify FWrite() with some example code

Some code exists for this that hasn't yet been committed to the repo
Make sure it can:

  • seek to any arbitrary position
  • write a block of data to the current position
  • enlarge a file (confined to the current sector)
  • enlarge a file (confined to the current cluster)
  • enlarge a file (allocating cluster(s) as needed)

fcount_clust() blindly advances to next numerical sector

when following the cluster chain, the loop just advances to the next fat sector, if it needs to. Shouldn't this actually go to a specific sector based on the next link in the chain, which might not necessarily be the very next sector?

fseek(): sect_offs unused

Well it is technically: it just increments by 4 in the cluster chain-following loop, but the resulting value isn't used. Probably a vestige of older code. Make sure something that used it wasn't erroneously ripped out.

Add support for (sub)directories

Currently only a vague awareness of the root directory exists. Add the ability to create, remove, rename, chdir to subdirectories.

Add support for reading 'system' date, time

Set this up so it can be read via pointer - that way a user can independently run e.g., an RTC driver and trigger an update of the current time, and then do some file I/O that can use the current date/time.

Add support for O_TRUNC

Needed for overwrite when opening, and truncating a file to 0 bytes.

  • change dirent size to 0
  • clear cluster chain

add SYNC_IO file mode

Optional mode for fopen(), to indicate to fwrite() that writes should be committed immediately, not deferred until the sector buffer is full.

fdelete(): operate directly on directory entries

Currently, the file is fopen()'d to read/use its metadata to mark it for deletion. Rewrite it so it operates directly on the directory entries. This will also mean a check has to be added to make sure the file being deleted isn't the currently open file.

Verify FRead() with some example code

Some code not committed to the repo exists - make sure it:

  • handles common errors (e.g., file not found, I/O error)
  • can seek to any arbitrary position
  • can read any part of the file, reliably
  • can't access beyond the end (or beginning) of the file

Move FClose2() code to fatfs-spin

This shouldn't really need anything specific to the block I/O layer, so move the code to fatfs FClose(), and define the VARs there instead.
If something at this layer is needed later, maybe it can be called FCloseEnt()?

Conditionally build with debug statements

The serial object and debug output statements are all always built into the project, making it appear much larger than it is, and also slowing things down. See if it's practical to use the debug functionality in FlexSpin, or only build with debug if a certain preprocessor symbol is defined.

Add directory listing code

Some code exists for this that hasn't yet been committed to the repo
Make sure it:

  • can show the volume label
  • list files with their name, size, attributes, date/timestamps
  • show total number of files as well as total size
  • list subdirectories

fwrite(): length isn't verified

It shouldn't waste time doing anything if it was called with write length 0 (without having reviewed the code in detail - maybe doing so could even cause problems).

Relax interpretation of filenames

Right now in e.g., FOpen(), the filename param must be in a certain format in order to successfully find it. Rewrite this to be more lax. Space-pad the filename if less than 8 chars was given, assume the extension is just three spaces if no extension is given, etc.....

  • pad short filenames to 8.3 format
  • convert full filename to uppercase

fseek(): doesn't follow chain to other FAT sectors

A file's cluster chain could continue from one FAT sector to another, but the loop that follows the chain doesn't advance to other sectors. It's actually written pretty naiively, just repeating a number of times equal to the number of clusters the file uses. This could just walk right off the end of the metadata buffer.

Add chattr() or similar

When calling fopen(), the write protect bit is now honored if trying to open the file for writing. Before, to change a file's attributes, it could be opened, then the fatfs layer's fset_attrs() called to modify the directory entry cached in RAM's attributes, then written back to disk, but this won't be possible now.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.