---
name: "pmem2_map_from_existing"
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_map_from_existing"
---

# pmem2\_map\_from\_existing(3)

creates a pmem2\_map object from an existing mapping

## NAME

**pmem2\_map\_from\_existing**() - creates a pmem2\_map object from an existing mapping

## SYNOPSIS

-

  ```
  #include <libpmem2.h>
  int pmem2_map_from_existing(struct pmem2_map **map, const struct pmem2_source *src,
      void *addr, size_t len, enum pmem2_granularity gran);
  ```

## DESCRIPTION

The **pmem2\_map\_from\_existing**() returns a new \*struct pmem2\_map **for mapping provided by the user. This function allows** **usage of** libpmem2**(7) API without** pmem2\_map\_new**(3)** **for mapping file. Mapping is defined by** ***addr*** **and** ***len*****. You have to specify underlying file as a** ***src*****,** **and define granularity of this mapping. See** pmem2\_config\_set\_required\_store\_granularity**(3) and** libpmem2\*\*(7) for more details.

For the *pmem2\_map* object created by the [**pmem2\_map\_from\_existing**(3)](/pmem2_map_from_existing/3.md) function, the [**pmem2\_map\_delete**(3)](/pmem2_map_delete/3.md) will only destroy the object, but it won’t unmap the mapping this object describes.

## RETURN VALUE

The **pmem2\_map\_from\_existing**() function returns 0 when it succeeds or a negative error code on failure.

## ERRORS

The **pmem2\_map\_from\_existing**() can fail with the following errors:

**PMEM2\_E\_MAPPING\_EXISTS** - when contiguous region (*addr*, *addr* + *len*) is already registered by *libpmem2*

It can also return **-ENOMEM** from the underlying **malloc**(2) function.

## SEE ALSO

**malloc(2)**, [**pmem2\_map\_delete**(3)](/pmem2_map_delete/3.md), [**pmem2\_map\_new**(3)](/pmem2_map_new/3.md), [**pmem2\_source\_from\_fd**(3)](/pmem2_source_from_fd/3.md), [**libpmem2**(7)](/libpmem2/7.md) and **\<https://pmem.io\>**
