Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _FLATFS_H_
- #define _FLATFS_H_
- #include <stdint.h>
- #include <stdbool.h>
- /**
- * A file entry in the flat file system.
- */
- struct ffsfile
- {
- /**
- * File size in blocks
- */
- uint32_t size;
- /**
- * The name of the file.
- */
- int8_t name[8];
- /**
- * The file extension
- */
- int8_t extension[2];
- /**
- * A set of generic flags that can be used for this file.
- */
- uint16_t flags;
- };
- /**
- * The definition of a flat file system. Contains all access methods
- * and meta-information to access files.
- */
- struct ffs
- {
- /**
- * The block size of this file system.
- */
- uint32_t blockSize;
- /**
- * A function that allows the ffs driver to read a block of memory.
- * @param ffs The file system structure that wants to access the read operation.
- * @param blockNum The block ffs wants to read.
- * @param buffer A pointer to target memory where the block should be stored. Must be at least @ref blockSize large.
- * @return true on success, otherwise false.
- */
- bool (*readBlock)(struct ffs * ffs, uint32_t blockNum, void * buffer);
- /**
- * A function that allows the ffs driver to write a block of memory.
- * @param ffs The file system structure that wants to access the writes operation.
- * @param blockNum The block ffs wants to write.
- * @param buffer A pointer to target memory where the block should read from. Must be at least @ref blockSize large.
- * @return true on success, otherwise false.
- */
- bool (*writeBlock)(struct ffs * ffs, uint32_t blockNum, void const * buffer);
- };
- /**
- * This function will return the n-th file in the file system, including empty
- * files.
- * @param ffs The file system that should be enumerated.
- * @param index The zero-based index of the file that should be enumerated.
- * @param result If the file was found, this pointer will received the file information.
- * @returns true on success, otherwise false.
- */
- bool ffs_enumerate(struct ffs * ffs, uint32_t index, struct ffsfile * result);
- /**
- * This function will search for a file with the given name and extension.
- * @param ffs The file system that should be searched.
- * @param name An either zero-terminated or at least 8 byte long string that will contain the file name.
- * @param ext An either zero-terminated or at least 2 byte long string that will contain the file extension.
- * @returns Zero-based index of the file or -1 of the file was not found.
- */
- int ffs_find(struct ffs * ffs, char const * name, char const * ext);
- /**
- * This function will store a file on the given storage.
- * @param ffs The file system that should store the file.
- * @param name An either zero-terminated or at least 8 byte long string that will contain the file name.
- * @param ext An either zero-terminated or at least 2 byte long string that will contain the file extension.
- * @param data A pointer to the file data that should be stored.
- * @param length The length of the file in bytes.
- * @returns true on success, otherwise false.
- */
- bool ffs_store(
- struct ffs * ffs,
- char const * name,
- char const * ext,
- void const * data,
- uint32_t length);
- /**
- * This function will load a file from the given storage.
- * @param ffs The file system that should load the file.
- * @param name An either zero-terminated or at least 8 byte long string that will contain the file name.
- * @param ext An either zero-terminated or at least 2 byte long string that will contain the file extension.
- * @param data A pointer to a buffer that will receive the loaded data. Should provide at least the file size of bytes.
- * @returns true on success, otherwise false.
- */
- bool ffs_load(
- struct ffs * ffs,
- char const * name,
- char const * ext,
- void * data);
- /**
- * This function will compact the file system and squish out all empty blocks at the begin of the file system.
- * @param ffs The file system that should be squished
- * @returns true on success, otherwise false.
- */
- bool ffs_compact(struct ffs * ffs);
- #endif
Advertisement
Add Comment
Please, Sign In to add comment