Initial commit of block device interface and emulated block device

This commit is contained in:
Christopher Haster
2017-02-25 14:31:14 -06:00
parent b113bba3ae
commit 02156cb47d
7 changed files with 471 additions and 43 deletions

56
lfs_bd.h Normal file
View File

@@ -0,0 +1,56 @@
/*
* Block device interface
*
* Copyright (c) 2017 Christopher Haster
* Distributed under the MIT license
*/
#ifndef LFS_BD_H
#define LFS_BD_H
#include "lfs_config.h"
// Description of block devices
struct lfs_bd_info {
lfs_size_t read_size; // Size of readable block
lfs_size_t write_size; // Size of programmable block
lfs_size_t erase_size; // Size of erase block
lfs_lsize_t total_size; // Total size of the device
};
// Block device operations
//
// The little file system takes in a pointer to an opaque type
// and this struct, all operations are passed the opaque pointer
// which can be used to reference any state associated with the
// block device
struct lfs_bd_ops {
// Read a block
lfs_error_t (*read)(void *bd, uint8_t *buffer,
lfs_ino_t ino, lfs_off_t off, lfs_size_t size);
// Program a block
//
// The block must have previously been erased.
lfs_error_t (*write)(void *bd, const uint8_t *buffer,
lfs_ino_t ino, lfs_off_t off, lfs_size_t size);
// Erase a block
//
// A block must be erased before being programmed. The
// state of an erased block is undefined.
lfs_error_t (*erase)(void *bd,
lfs_ino_t ino, lfs_off_t off, lfs_size_t size);
// Sync the block device
lfs_error_t (*sync)(void *bd);
// Get a description of the block device
//
// Any unknown information may be left as zero
lfs_error_t (*info)(void *bd, struct lfs_bd_info *info);
};
#endif