---
name: "gd_alter_protection"
section: "3"
platform: "linux"
package: "libgetdata-doc"
version: "0.11.0-15"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/gd_alter_protection"
---

# gd\_alter\_protection(3)

modify the protection level of a Dirfile fragment

## NAME

gd\_alter\_protection — modify the protection level of a Dirfile fragment

## SYNOPSIS

**#include \<getdata.h\>**

**int gd\_alter\_protection(DIRFILE \****dirfile***, int** *protection\_level***, int** *fragment\_index***);**

## DESCRIPTION

The **gd\_alter\_protection**() function sets the advisory protection level of the format specification fragment given by *fragment\_index* to *protection\_level* in the [dirfile(5)](/dirfile/5.md) database specified by *dirfile*.

The *protection\_level* argument should be one of the following:\
  .TP 8 **GD\_PROTECT\_NONE** Indicating that the fragment should not be protected at all.\
  .TP 8 **GD\_PROTECT\_FORMAT** Indicating that the fragment's metadata should be protected.\
  .TP 8 **GD\_PROTECT\_DATA** Indicating that the fragment's binary data should be protected.\
  .TP 8 **GD\_PROTECT\_ALL** Indicating that both the fragment's metadata and its binary data should be protected.  This symbol is equivalent to the bitwise or of **GD\_PROTECT\_FORMAT** and **GD\_PROTECT\_DATA**.

In addition to being simply a valid fragment index, *fragment\_index* may also be the special value **GD\_ALL\_FRAGMENTS**, which indicates that the protection level of all fragments in the database should be changed.

## RETURN VALUE

Upon successful completion, **gd\_alter\_protection**() returns zero.  On error, it returns a negative-valued error code.  Possible error codes are:\
  .TP 8 **GD\_E\_ACCMODE** The specified dirfile was opened read-only.\
  .TP 8 **GD\_E\_ARGUMENT** The supplied *protection\_level* was invalid.\
  .TP 8 **GD\_E\_BAD\_DIRFILE** The supplied dirfile was invalid.\
  .TP 8 **GD\_E\_BAD\_INDEX** The supplied index was out of range.\
  .TP 8 **GD\_E\_BAD\_PROTECTION** The supplied protection level was invalid.

The error code is also stored in the **DIRFILE** object and may be retrieved after this function returns by calling [**gd\_error**(3)](/gd_error/3.md). A descriptive error string for the error may be obtained by calling [**gd\_error\_string**(3)](/gd_error_string/3.md).

## NOTES

This is the only GetData function which ignores the (existing) protection level of a format specification fragment.

## HISTORY

The function **dirfile\_protect**() appeared in GetData-0.5.0.

In GetData-0.7.0, this function was renamed to **gd\_alter\_protection**().

In GetData-0.10.0, the error return from this function changed from -1 to a negative-valued error code.

## SEE ALSO

[**gd\_error**(3)](/gd_error/3.md), [**gd\_error\_string**(3)](/gd_error_string/3.md), [**gd\_protection**(3)](/gd_protection/3.md), [**gd\_open**(3)](/gd_open/3.md)
