Bad-Block-TableΒΆ

The state of the underlying media is exposed to the user through the bad-block-interface (BBT). A bad-block table exists for each LUN, retrieving the BBT for LUN 3 on channel 2 is done by executing:

nvm_bbt get /dev/nvme0n1 2 3 | grep -vi free

The command outputs the entire table so we filter out the less interesting free entries, thus yielding:

# nvm_bbt_get
bbt:
  addr: 0x0203000000000000: {ch: 02, lun: 03, pl: 0, blk: 0000, pg: 000, sec: 0}
  nblks: 2040
  npl_blks: 1020
  pl_blks:
    0041: [  BAD(1),  BAD(1) ]
    0042: [ GBAD(2), GBAD(2) ]
  nbad: 1
  gbad: 1
  ndmrk: 0
  nhmrk: 0

A given block can be in one of the following states: FREE, BAD, GROWN BAD, DEVICE MARKED/RESERVED, and HOST MARKED/RESERVED. State can be changed by e.g. marking block 42 as GROWN BAD:

sudo nvm_bbt mark_g /dev/nvme0n1 0x020300000000002a

Yielding:

# nvm_bbt_mark
0x020300000000002a: {ch: 02, lun: 03, pl: 0, blk: 0042, pg: 000, sec: 0}

Note

SYSADMIN priviliges are required for modifying the BBT

Retrieving the BBT after the state change:

nvm_bbt get /dev/nvme0n1 2 3 | grep -vi free

Yields:

# nvm_bbt_get
bbt:
  addr: 0x0203000000000000: {ch: 02, lun: 03, pl: 0, blk: 0000, pg: 000, sec: 0}
  nblks: 2040
  npl_blks: 1020
  pl_blks:
    0041: [  BAD(1),  BAD(1) ]
    0042: [ GBAD(2), GBAD(2) ]
  nbad: 1
  gbad: 1
  ndmrk: 0
  nhmrk: 0

Note

C API for retrieving and modifying the BBT is done using nvm_bbt_get which return a const struct nvm_bbt*. To modify it, make a copy with nvm_bbt_alloc_cp, and persist it with nvm_bbt_set.