---
name: "g_write_data"
section: "9"
platform: "linux"
package: "freebsd-manpages"
version: "6.0-5"
release: "Debian 4.0 (Etch)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/g_write_data"
---

# g\_write\_data(9)

read/write data from/to GEOM consumer

## NAME

**g\_read\_data**, **g\_write\_data** – read/write data from/to GEOM consumer

## SYNOPSIS

**#include \<geom/geom.h\>**

*void \**\

**g\_read\_data**(*struct g\_consumer \*cp*, *off\_t offset*, *off\_t length*, *int \*error*);

*int*\

**g\_write\_data**(*struct g\_consumer \*cp*, *off\_t offset*, *void \*ptr*, *off\_t length*);

## DESCRIPTION

The **g\_read\_data**() function reads *length* bytes of data from the provider attached to consumer *cp*, starting at offset *offset*. The buffer returned from **g\_read\_data**() is allocated with **g\_malloc**(), so it should be freed by the caller with **g\_free**() after use. If the operation fails, an error value will be stored in the *error* argument if it is not NULL.

The **g\_write\_data**() function writes *length* bytes of data from the buffer pointed to by *ptr* to the provider attached to consumer *cp*, starting at offset *offset*.

## RESTRICTIONS/CONDITIONS

The *length* argument should be a multiple of the provider's sectorsize and less than or equal to DFLTPHYS (DFLTPHYS is defined in ⟨sys/param.h⟩).

The topology lock must not be held.

## RETURN VALUES

The **g\_read\_data**() function returns a pointer to a data buffer or NULL if an error occurred. In that case an error value is stored in the *error* argument unless it is NULL.

The **g\_write\_data**() function returns 0 if successful; otherwise an error code is returned.

## ERRORS

Possible errors:

- \[EIO\]

  An I/O error occurred while reading from or writing to the consumer.

## SEE ALSO

[geom(4)](/geom/4.md), [DECLARE\_GEOM\_CLASS(9)](/DECLARE_GEOM_CLASS/9.md), [g\_access(9)](/g_access/9.md), [g\_attach(9)](/g_attach/9.md), [g\_bio(9)](/g_bio/9.md), [g\_consumer(9)](/g_consumer/9.md), [g\_event(9)](/g_event/9.md), [g\_geom(9)](/g_geom/9.md), [g\_provider(9)](/g_provider/9.md), [g\_provider\_by\_name(9)](/g_provider_by_name/9.md), [g\_wither\_geom(9)](/g_wither_geom/9.md)

## AUTHORS

This manual page was written by Pawel Jakub Dawidek ⟨pjd@FreeBSD.org⟩.
