---
name: "pmem2_badblock_clear"
section: "3"
platform: "linux"
package: "libpmem2-dev"
version: "1.13.1-1.1+b1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/pmem2_badblock_clear"
---

# pmem2\_badblock\_clear(3)

clear the given bad block

## NAME

**pmem2\_badblock\_clear**() - clear the given bad block

## SYNOPSIS

-

  ```
  #include <libpmem2.h>
  struct pmem2_badblock;
  struct pmem2_badblock_context;
  int pmem2_badblock_clear(
          struct pmem2_badblock_context *bbctx,
          struct pmem2_badblock *bb);
  ```

## DESCRIPTION

The **pmem2\_badblock\_clear**() function clears the given *\*bb* bad block.

It means that the **pmem2\_badblock\_clear**() function unmaps bad blocks and maps new, healthy, blocks in place of the bad ones. The new blocks are zeroed. The content of the bad blocks is lost.

It is not supported on Windows.

## RETURN VALUE

The **pmem2\_badblock\_clear**() function clears the given *\*bb* bad block and returns 0 on success or a negative error code on failure.

## ERRORS

**pmem2\_badblock\_clear**() can fail with the following errors:

- •

  **PMEM2\_E\_OFFSET\_OUT\_OF\_RANGE** - bad block’s offset is greater than INT64\_MAX

- •

  **PMEM2\_E\_LENGTH\_OUT\_OF\_RANGE** - bad block’s length is greater than INT64\_MAX

- •

  **PMEM2\_E\_NOSUPP** - on Windows or when the OS does not support this functionality

- •

  **-errno** - set by failing [**fallocate**(2)](/fallocate/2.md), while deallocating bad blocks or allocating new blocks

- •

  **-errno** - set by failing ndctl functions: **ndctl\_bus\_cmd\_new\_ars\_cap**, **ndctl\_cmd\_submit**, **ndctl\_cmd\_ars\_cap\_get\_range** or **ndctl\_bus\_cmd\_new\_clear\_error** while trying to clear a bad block in a DAX device

- •

  **-ENXIO** - **ndctl\_bus\_cmd\_new\_clear\_error** did not manage to clear all bad blocks

## SEE ALSO

[**pmem2\_badblock\_context\_new**(3)](/pmem2_badblock_context_new/3.md), [**pmem2\_badblock\_next**(3)](/pmem2_badblock_next/3.md), [**libpmem2**(7)](/libpmem2/7.md) and **\<https://pmem.io\>**
