---
name: "pmem2_source_size"
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_source_size"
---

# pmem2\_source\_size(3)

returns the size of the data source

## NAME

**pmem2\_source\_size**() - returns the size of the data source

## SYNOPSIS

-

  ```
  #include <libpmem2.h>
  struct pmem2_source;
  int pmem2_source_size(const struct pmem2_source *source, size_t *size);
  ```

## DESCRIPTION

The **pmem2\_source\_size**() function retrieves the size of the file in bytes pointed by file descriptor or handle stored in the *source* and puts it in *\*size*.

This function is a portable replacement for OS-specific APIs. On Linux, it hides the quirkiness of Device DAX size detection.

## RETURN VALUE

The **pmem2\_source\_size**() function returns 0 on success. If the function fails, the *\*size* variable is left unmodified and a negative error code is returned.

## ERRORS

The **pmem2\_source\_size**() can fail with the following errors:

On all systems:

- •

  **PMEM2\_E\_INVALID\_FILE\_HANDLE** - source contains an invalid file handle.

On Windows:

- •

  **PMEM2\_E\_INVALID\_FILE\_TYPE** - handle points to a resource that is not a regular file.

On Linux:

- •

  **PMEM2\_E\_INVALID\_FILE\_TYPE** - file descriptor points to a directory, block device, pipe, or socket.

- •

  **PMEM2\_E\_INVALID\_FILE\_TYPE** - file descriptor points to a character device other than Device DAX.

- •

  **PMEM2\_E\_INVALID\_SIZE\_FORMAT** - kernel query for Device DAX size returned data in invalid format.

- •

  \-**errno** set by failing [**fstat**(2)](/fstat/2.md), while trying to validate the file descriptor.

- •

  \-**errno** set by failing [**realpath**(3)](/realpath/3.md), while trying to determine whether fd points to a Device DAX.

- •

  \-**errno** set by failing [**open**(2)](/open/2.md), while trying to determine Device DAX’s size.

- •

  \-**errno** set by failing [**read**(2)](/read/2.md), while trying to determine Device DAX’s size.

- •

  \-**errno** set by failing [**strtoull**(3)](/strtoull/3.md), while trying to determine Device DAX’s size.

On FreeBSD:

- •

  **PMEM2\_E\_INVALID\_FILE\_TYPE** - file descriptor points to a directory, block device, pipe, socket, or character device.

- •

  \-**errno** set by failing [**fstat**(2)](/fstat/2.md), while trying to validate the file descriptor.

## SEE ALSO

[**errno**(3)](/errno/3.md), [**fstat**(2)](/fstat/2.md), [**realpath**(3)](/realpath/3.md), [**open**(2)](/open/2.md), [**read**(2)](/read/2.md), [**strtoull**(3)](/strtoull/3.md), [**pmem2\_config\_new**(3)](/pmem2_config_new/3.md), [**libpmem2**(7)](/libpmem2/7.md) and **\<https://pmem.io\>**
