---
name: "preroot"
section: "3"
platform: "macos"
package: "ksh"
version: "42"
release: "macOS 26.5"
platforms: ["macos"]
url: "https://new.carta.tech/preroot"
---

# preroot(3)

preroot support

## NAME

preroot - preroot support

## SYNOPSIS

```
#include <preroot.h>
char*    getpreroot(char* path, char* cmd);
int      ispreroot(char* dir);
int      realopen(char* path, int mode, int perm);
void     setpreroot(char** argv, char* dir);
```

## DESCRIPTION

*The* *preroot* *routines manipulate the process preroot.* *preroot* *is a kernel supported per-process two level viewpath.* *All pathnames rooted at* $1$2//////// are first searched for in the process preroot directory and then in the system root directory. Setting the process preroot is a priveleged operation controlled by the */etc/preroot*(1) command.

$1$2\<preroot.h\>\<preroot.h\>\<preroot.h\>\<preroot.h\>\<preroot.h\>\<preroot.h\>\<preroot.h\>\<preroot.h\> defines the symbol **FS\_PREROOT** for those systems that support preroot. The following routines are valid only when **FS\_PREROOT** is defined:

- $1$2getprerootgetprerootgetprerootgetprerootgetprerootgetprerootgetprerootgetpreroot

  returns a pointer to the absolute pathname of the preroot directory for the executable *cmd*. The result is placed in *path*. If *path* is **0** then [*malloc*(3)](/malloc/3.md) is used to allocate the pathname space. **0** is returned if *cmd* has no preroot or if an error was encountered. In this case *errno* is set to indicate the error.

- $1$2isprerootisprerootisprerootisprerootisprerootisprerootisprerootispreroot

  Non-zero is returned if  *dir* is the current process preroot. If  *dir* is **0** then non-zero is returned if the current process has a preroot.

- $1$2realopenrealopenrealopenrealopenrealopenrealopenrealopenrealopen

  temporarily disables the process preroot and does an *open*(3) relative to the system root directory. The return value from *open* is returned. If there is no preroot then *realopen* is equivalent to *open*.

- $1$2setprerootsetprerootsetprerootsetprerootsetprerootsetprerootsetprerootsetpreroot

  calls [*execvp*(3)](/execvp/3.md) as $1$2execvp(a*rgv*\[0\],*argv*)execvp(a*rgv*\[0\],*argv*)execvp(a*rgv*\[0\],*argv*)execvp(a*rgv*\[0\],*argv*)execvp(a*rgv*\[0\],*argv*)execvp(a*rgv*\[0\],*argv*)execvp(a*rgv*\[0\],*argv*)execvp(a*rgv*\[0\],*argv*) with the process preroot set to *dir*. *argv* must be a **0**-terminated argument array. If  *argv* is **0** then the value of *opt\_argv* from [*optget*(3)](/optget/3.md) is used. $1$2setprerootsetprerootsetprerootsetprerootsetprerootsetprerootsetprerootsetpreroot returns immediately if *dir* is already the process preroot.

## SEE ALSO

/etc/preroot(1)

## BUGS

Preroot semantics should be preserved when reading directories. The *ast* [*directory*(3)](/directory/3.md) routines do this. *3d*(1) viewpathing does  *preroot* the right way.
