SdFat
Public Member Functions | Static Public Attributes | List of all members
FsCache Class Reference

Sector cache. More...

#include <FsCache.h>

Public Member Functions

uint8_t * cacheBuffer ()
 
bool cacheSafeRead (uint32_t sector, uint8_t *dst)
 
bool cacheSafeRead (uint32_t sector, uint8_t *dst, size_t count)
 
bool cacheSafeWrite (uint32_t sector, const uint8_t *src)
 
bool cacheSafeWrite (uint32_t sector, const uint8_t *src, size_t count)
 
uint8_t * clear ()
 
void dirty ()
 
uint8_t * get (uint32_t sector, uint8_t option)
 
void init (BlockDevice *blockDev)
 
void invalidate ()
 
bool isCached (uint32_t sector) const
 
bool isCached (uint32_t sector, size_t count)
 
bool isDirty ()
 
uint32_t sector ()
 
void setMirrorOffset (uint32_t offset)
 
bool sync ()
 

Static Public Attributes

static const uint8_t CACHE_FOR_READ = 0
 
static const uint8_t CACHE_FOR_WRITE = CACHE_STATUS_DIRTY
 
static const uint8_t CACHE_OPTION_NO_READ = 4
 
static const uint8_t CACHE_RESERVE_FOR_WRITE
 
static const uint8_t CACHE_STATUS_DIRTY = 1
 
static const uint8_t CACHE_STATUS_MASK
 
static const uint8_t CACHE_STATUS_MIRROR_FAT = 2
 

Detailed Description

Sector cache.

Member Function Documentation

◆ cacheBuffer()

uint8_t* FsCache::cacheBuffer ( )
inline
Returns
Cache buffer address.

◆ cacheSafeRead() [1/2]

bool FsCache::cacheSafeRead ( uint32_t  sector,
uint8_t *  dst 
)
inline

Cache safe read of a sector.

Parameters
[in]sectorLogical sector to be read.
[out]dstPointer to the location that will receive the data.
Returns
true for success or false for failure.

◆ cacheSafeRead() [2/2]

bool FsCache::cacheSafeRead ( uint32_t  sector,
uint8_t *  dst,
size_t  count 
)
inline

Cache safe read of multiple sectors.

Parameters
[in]sectorLogical sector to be read.
[in]countNumber of sectors to be read.
[out]dstPointer to the location that will receive the data.
Returns
true for success or false for failure.

◆ cacheSafeWrite() [1/2]

bool FsCache::cacheSafeWrite ( uint32_t  sector,
const uint8_t *  src 
)
inline

Cache safe write of a sectors.

Parameters
[in]sectorLogical sector to be written.
[in]srcPointer to the location of the data to be written.
Returns
true for success or false for failure.

◆ cacheSafeWrite() [2/2]

bool FsCache::cacheSafeWrite ( uint32_t  sector,
const uint8_t *  src,
size_t  count 
)
inline

Cache safe write of multiple sectors.

Parameters
[in]sectorLogical sector to be written.
[in]srcPointer to the location of the data to be written.
[in]countNumber of sectors to be written.
Returns
true for success or false for failure.

◆ clear()

uint8_t* FsCache::clear ( )
inline
Returns
Clear the cache and returns a pointer to the cache.

◆ dirty()

void FsCache::dirty ( )
inline

Set current sector dirty.

◆ get()

uint8_t * FsCache::get ( uint32_t  sector,
uint8_t  option 
)

Fill cache with sector data.

Parameters
[in]sectorSector to read.
[in]optionmode for cached sector.
Returns
Address of cached sector.

Copyright (c) 2011-2020 Bill Greiman This file is part of the SdFat library for SD memory cards.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

◆ init()

void FsCache::init ( BlockDevice blockDev)
inline

Initialize the cache.

Parameters
[in]blockDevBlock device for this cache.

◆ invalidate()

void FsCache::invalidate ( )
inline

Invalidate current cache sector.

◆ isCached() [1/2]

bool FsCache::isCached ( uint32_t  sector) const
inline

Check if a sector is in the cache.

Parameters
[in]sectorSector to checked.
Returns
true if the sector is cached.

◆ isCached() [2/2]

bool FsCache::isCached ( uint32_t  sector,
size_t  count 
)
inline

Check if the cache contains a sector from a range.

Parameters
[in]sectorStart sector of the range.
[in]countNumber of sectors in the range.
Returns
true if a sector in the range is cached.

◆ isDirty()

bool FsCache::isDirty ( )
inline
Returns
dirty status

◆ sector()

uint32_t FsCache::sector ( )
inline
Returns
Logical sector number for cached sector.

◆ setMirrorOffset()

void FsCache::setMirrorOffset ( uint32_t  offset)
inline

Set the offset to the second FAT for mirroring.

Parameters
[in]offsetSector offset to second FAT.

◆ sync()

bool FsCache::sync ( )

Write current sector if dirty.

Returns
true for success or false for failure.

Member Data Documentation

◆ CACHE_FOR_READ

const uint8_t FsCache::CACHE_FOR_READ = 0
static

Cache sector for read.

◆ CACHE_FOR_WRITE

const uint8_t FsCache::CACHE_FOR_WRITE = CACHE_STATUS_DIRTY
static

Cache sector for write.

◆ CACHE_OPTION_NO_READ

const uint8_t FsCache::CACHE_OPTION_NO_READ = 4
static

Sync existing sector but do not read new sector.

◆ CACHE_RESERVE_FOR_WRITE

const uint8_t FsCache::CACHE_RESERVE_FOR_WRITE
static
Initial value:

Reserve cache sector for write - do not read from sector device.

◆ CACHE_STATUS_DIRTY

const uint8_t FsCache::CACHE_STATUS_DIRTY = 1
static

Cached sector is dirty

◆ CACHE_STATUS_MASK

const uint8_t FsCache::CACHE_STATUS_MASK
static
Initial value:

Cache sector status bits

◆ CACHE_STATUS_MIRROR_FAT

const uint8_t FsCache::CACHE_STATUS_MIRROR_FAT = 2
static

Cashed sector is FAT entry and must be mirrored in second FAT.


The documentation for this class was generated from the following files:
FsCache::CACHE_STATUS_MIRROR_FAT
static const uint8_t CACHE_STATUS_MIRROR_FAT
Definition: FsCache.h:43
FsCache::CACHE_OPTION_NO_READ
static const uint8_t CACHE_OPTION_NO_READ
Definition: FsCache.h:48
FsCache::CACHE_STATUS_DIRTY
static const uint8_t CACHE_STATUS_DIRTY
Definition: FsCache.h:41