nvm_bbt - Bad-Block-Table

nvm_bbt

struct nvm_bbt

Representation of bad-block-table.

The bad-block-table describes block-state of a given LUN

See
nvm_bbt_get, nvm_bbt_set, nvm_bbt_mark, nvm_bbt_free, and nvm_bbt_pr

Public Members

struct nvm_dev* dev

Device on which the bbt resides.

struct nvm_addr addr

Address of the LUN described by the bbt.

uint64_t nblks

Total # of blocks in lun.

uint32_t nbad

of manufacturer marked bad blocks

uint32_t ngbad

of grown bad blocks

uint32_t ndmrk

of device reserved/marked blocks

uint32_t nhmrk

of of host reserved/marked blocks

uint8_t nvm_bbt::blks[]

Array of block status for each block in LUN.

nvm_bbt_state

enum nvm_bbt_state

Representation of valid values of bad-block-table states.

Values:

NVM_BBT_FREE = 0x0

Block is free AKA good.

NVM_BBT_BAD = 0x1

Block is bad.

NVM_BBT_GBAD = 0x1 << 1

Block marked as grown bad.

NVM_BBT_DMRK = 0x1 << 2

Block marked by device side.

NVM_BBT_HMRK = 0x1 << 3

Block marked by host side.

nvm_bbt_get

const struct nvm_bbt* nvm_bbt_get(struct nvm_dev * dev, struct nvm_addr addr, struct nvm_ret * ret)

Retrieves a bad block table from device.

Return
On success, a pointer to the bad-block-table is returned. On error, NULL is returned, errno set to indicate the error and ret filled with lower-level result codes
Parameters
  • dev: Device handle obtained with nvm_dev_open
  • addr: Address of the LUN to retrieve bad-block-table for
  • ret: Pointer to structure in which to store lower-level status and result

nvm_bbt_set

int nvm_bbt_set(struct nvm_dev * dev, const struct nvm_bbt * bbt, struct nvm_ret * ret)

Updates the bad-block-table on given device using the provided bbt.

Return
On success, 0 is returned. On error, -1 is returned, errno set to indicate the error and ret filled with lower-level result codes
Parameters
  • dev: Device handle obtained with nvm_dev_open
  • bbt: The bbt to write to device
  • ret: Pointer to structure in which to store lower-level status and result

nvm_bbt_mark

int nvm_bbt_mark(struct nvm_dev * dev, struct nvm_addr addrs[], int naddrs, uint16_t flags, struct nvm_ret * ret)

Mark addresses good, bad, or host-bad.

Note
The addresses given to this function are interpreted as block addresses, in contrast to nvm_addr_write, and nvm_addr_read which interpret addresses and sector addresses.
See
enum nvm_bbt_state
Return
On success, 0 is returned. On error, -1 is returned, errno set to indicate the error and ret filled with lower-level result codes
Parameters
  • dev: Device handle obtained with nvm_dev_open
  • addrs: Array of memory address
  • naddrs: Length of memory address array
  • flags: 0x0 = GOOD, 0x1 = BAD, 0x2 = GROWN_BAD, as well as access mode
  • ret: Pointer to structure in which to store lower-level status and result.

nvm_bbt_flush

int nvm_bbt_flush(struct nvm_dev * dev, struct nvm_addr addr, struct nvm_ret * ret)

Persist the bad-block-table at addr on device and deallocate managed memory for the given bad-block-table describing the LUN at addr.

Return
On success, 0 is returned. On error, -1 is returned, errno set to indicate the error and ret filled with lower-level result codes
Parameters
  • dev: Device handle obtained with nvm_dev_open
  • addr: Address of the LUN to flush bad-block-table for
  • ret: Pointer to structure in which to store lower-level status and result

nvm_bbt_flush_all

int nvm_bbt_flush_all(struct nvm_dev * dev, struct nvm_ret * ret)

Persist all bad-block-tables associated with the given dev

Return
On success, 0 is returned. On error, -1 is returned, errno set to indicate the error and ret filled with lower-level result codes
Parameters
  • dev: Device handle obtained with nvm_dev_open
  • ret: Pointer to structure in which to store lower-level status and result

nvm_bbt_alloc_cp

struct nvm_bbt* nvm_bbt_alloc_cp(const struct nvm_bbt * bbt)

Allocate a copy of the given bad-block-table.

Return
On success, a pointer to a write-able copy of the given bbt is returned. On error, NULL is returned and errno set to indicate the error
Parameters
  • bbt: Pointer to the bad-block-table to copy

nvm_bbt_free

void nvm_bbt_free(struct nvm_bbt * bbt)

Destroys a given bad-block-table.

Parameters
  • bbt: The bad-block-table to destroy

nvm_bbt_pr

void nvm_bbt_pr(const struct nvm_bbt * bbt)

Prints a humanly readable representation of the given bad-block-table.

Parameters
  • bbt: The bad-block-table to print

nvm_bbt_state_pr

void nvm_bbt_state_pr(int state)

Prints a humanly readable representation of the given bad-block-table state.