nvm_dev - Device Management

nvm_dev

struct nvm_dev

Opaque handle for NVM devices.

nvm_dev_open

struct nvm_dev* nvm_dev_open(const char * dev_path)

Creates a handle to given device path.

Return
A handle to the device
Parameters
  • dev_path: Path of the device to open e.g. “/dev/nvme0n1”

nvm_dev_close

void nvm_dev_close(struct nvm_dev * dev)

Destroys device-handle.

Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_openf

struct nvm_dev* nvm_dev_openf(const char * dev_path, int flags)

Creates a handle to given device path.

Return
A handle to the device
Parameters
  • dev_path: Path of the device to open e.g. “/dev/nvme0n1”
  • flags: Flags for opening device in different modes

nvm_dev_attr_pr

void nvm_dev_attr_pr(const struct nvm_dev * dev)

Prints misc.

device attribute associated with the given handle

Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_pr

void nvm_dev_pr(const struct nvm_dev * dev)

Prints all information about the device associated with the given handle.

Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_bbts_cached

int nvm_dev_get_bbts_cached(const struct nvm_dev * dev)

Returns whether caching is enabled for bad-block-tables on the device.

Note
0 = cache disabled 1 = cache enabled
Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_be_id

int nvm_dev_get_be_id(const struct nvm_dev * dev)

Returns the backend identifier associated with the given device.

Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_erase_naddrs_max

int nvm_dev_get_erase_naddrs_max(const struct nvm_dev * dev)

Returns the maximum number of addresses to use when sending erases to device.

That is, when invoking nvm_addr_erase.

Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_fd

int nvm_dev_get_fd(const struct nvm_dev * dev)

Returns the file-descriptor associated with the given device.

Return
On success, file descriptor is returned
Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_geo

const struct nvm_geo* nvm_dev_get_geo(const struct nvm_dev * dev)

Returns the geometry of the given device.

Note
See struct nvm_geo for the specifics of the returned geometry
Return
The geometry (struct nvm_geo) of given device handle
Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_lbaf

const struct nvm_spec_lbaf* nvm_dev_get_lbaf(const struct nvm_dev * dev)

Returns the LBA format of the given device.

Return
On success, LBA format is returned
Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_mccap

uint32_t nvm_dev_get_mccap(const struct nvm_dev * dev)

Returns the media-controller capabilities mask of the given device.

Return
On success, capabilities mask is returned
Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_meta_mode

int nvm_dev_get_meta_mode(const struct nvm_dev * dev)

Returns the ‘meta-mode’ of the given device.

Return
On success, meta-mode is returned
Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_mw_cunits

int nvm_dev_get_mw_cunits(const struct nvm_dev * dev)

Returns the minimal write cache units for the given device.

Return
The spec. 2.0 defined minimal write cache units, in sectors.
Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_name

const char* nvm_dev_get_name(const struct nvm_dev * dev)

Returns the name associated with the given device.

Return
On success, string is returned. On error, NULL is returned.
Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_nsid

int nvm_dev_get_nsid(const struct nvm_dev * dev)

Returns the NVME namespace identifier of the given device.

Return
On success, NVME namespace identifier is returned.
Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_path

const char* nvm_dev_get_path(const struct nvm_dev * dev)

Returns the path associated with the given device.

Return
On success, string is returned. On error, NULL is returned.
Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_pmode

int nvm_dev_get_pmode(const struct nvm_dev * dev)

Returns the default plane_mode of the given device.

Return
On success, pmode flag is returned
Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_ppaf

const struct nvm_spec_ppaf_nand* nvm_dev_get_ppaf(const struct nvm_dev * dev)

Returns the ppa-format of the given device.

Return
On success, ppa-format is returned
Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_ppaf_mask

const struct nvm_spec_ppaf_nand_mask* nvm_dev_get_ppaf_mask(const struct nvm_dev * dev)

Returns the ppa-format mask of the given device.

Return
On success, ppa-format mask is returned
Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_quirks

int nvm_dev_get_quirks(const struct nvm_dev * dev)

Returns the mask of quirks for the given device.

Return
On success, quirk mask is returned
Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_read_naddrs_max

int nvm_dev_get_read_naddrs_max(const struct nvm_dev * dev)

Set the maximum number of addresses to use for reads, that is, when invoking nvm_addr_read.

Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_verid

int nvm_dev_get_verid(const struct nvm_dev * dev)

Returns the verid of the given device.

Return
On success, verid is returned
Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_write_naddrs_max

int nvm_dev_get_write_naddrs_max(const struct nvm_dev * dev)

Set the maximum number of addresses to use for writes, that is, when invoking nvm_addr_write.

Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_ws_min

int nvm_dev_get_ws_min(const struct nvm_dev * dev)

Returns the minimum write size, in number of sectors, for the given device.

Return
The spec. 2.0 defined minimum write size, in sectors. An equivalent value for spec. 1.2
Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_get_ws_opt

int nvm_dev_get_ws_opt(const struct nvm_dev * dev)

Returns the optimal write size, in number of sectors, for the given device.

Return
The spec. 2.0 defined optimal write size, in sectors, an equivalent value for spec. 1.2
Parameters
  • dev: Device handle obtained with nvm_dev_open

nvm_dev_set_bbts_cached

int nvm_dev_set_bbts_cached(struct nvm_dev * dev, int bbts_cached)

Sets whether retrieval and changes to bad-block-tables should be cached.

Return
0 on success, -1 on error and errno set to indicate the error.
Parameters
  • dev: Device handle obtained with nvm_dev_open
  • bbts_cached: 1 = cache enabled, 0 = cache disabled

nvm_dev_set_erase_naddrs_max

int nvm_dev_set_erase_naddrs_max(struct nvm_dev * dev, int naddrs)

Set the maximum number of addresses to use for erases, that is, when invoking nvm_addr_erase.

Return
0 on success, -1 on error and errno set to indicate the error.
Parameters
  • dev: Device handle obtained with nvm_dev_open
  • naddrs: The maximum

nvm_dev_set_meta_mode

int nvm_dev_set_meta_mode(struct nvm_dev * dev, int meta_mode)

Set the default ‘meta-mode’ of the given device.

The meta-mode is a setting used by the nvm_vblk interface to write pseudo-meta data to the out-of-bound area.

Return
On success, 0 is returned. On error, -1 is returned and errno set to indicate the error.
Parameters
  • dev: Device handle obtained with nvm_dev_open
  • meta_mode: One of: NVM_META_MODE_[NONE|ALPHA|CONST]

nvm_dev_set_pmode

int nvm_dev_set_pmode(struct nvm_dev * dev, int pmode)

Set the default plane-mode for the given device.

Return
0 on success, -1 on error and errno set to indicate the error.
Parameters
  • dev: Device handle obtained with nvm_dev_open
  • pmode: Default plane-mode

nvm_dev_set_quirks

int nvm_dev_set_quirks(struct nvm_dev * dev, int quirks)

Set the default plane-mode for the given device.

Return
0 on success, -1 on error and errno set to indicate the error.
Parameters
  • dev: Device handle obtained with nvm_dev_open
  • quirks: Mask of enum nvm_quirks

nvm_dev_set_read_naddrs_max

int nvm_dev_set_read_naddrs_max(struct nvm_dev * dev, int naddrs)

Set the maximum number of addresses to use for erases, that is, when invoking nvm_addr_erase.

Return
0 on success, -1 on error and errno set to indicate the error.
Parameters
  • dev: Device handle obtained with nvm_dev_open
  • naddrs: The maximum

nvm_dev_set_write_naddrs_max

int nvm_dev_set_write_naddrs_max(struct nvm_dev * dev, int naddrs)

Set the maximum number of addresses to use for erases, that is, when invoking nvm_addr_erase.

Return
0 on success, -1 on error and errno set to indicate the error.
Parameters
  • dev: Device handle obtained with nvm_dev_open
  • naddrs: The maximum