chroot (BPX1CRT, BPX4CRT) — Change the root directory

Function

The chroot service changes the root directory from the current one to a new one. The root directory is the starting point for path searches of pathnames beginning with a slash. The working directory of the process is unaffected by chroot().

Requirements

Operation Environment
Authorization: Supervisor state or problem state, any PSW key
Dispatchable unit mode: Task
Cross memory mode: PASN = HASN
AMODE (BPX1CRT): 31-bit
AMODE (BPX4CRT): 64-bit
ASC mode: Primary mode
Interrupt status: Enabled for interrupts
Locks: Unlocked
Control parameters: All parameters must be addressable by the caller and in the primary address space.

Format

CALL BPX1CRT,(Pathname_length,
              Pathname,
              Return_value,
              Return_code,
              Reason_code)

AMODE 64 callers use BPX4CRT with the same parameters.

Parameters

Pathname_length
Supplied parameter
Type:
Integer
Length:
Fullword

The name of a fullword that contains the length of the pathname of the directory that is to become your root directory.

Pathname
Supplied parameter
Type:
Character string
Character set:
No restriction
Length:
Specified by the Pathname_length parameter

The name of a field that contains the pathname of the new directory. This field has the length that is specified in Pathname_length.

Pathnames can begin with or without a slash:
  • A pathname that begins with a slash is an absolute pathname. The slash refers to the current root directory, and the search for the file starts at the current root directory.
  • A pathname that does not begin with a slash is a relative pathname. The search for the file starts at the working directory.
Return_value
Returned parameter
Type:
Integer
Length:
Fullword

The name of a fullword in which the chroot service returns 0 if the request is successful, or -1 if it is not successful.

Return_code
Returned parameter
Type:
Integer
Length:
Fullword
The name of a fullword in which the chroot service stores the return code. The chroot service returns Return_code only if Return_value is -1. See z/OS UNIX System Services Messages and Codes for a complete list of possible return code values. The chroot service can return one of the following values in the Return_code parameter:
Return_code Explanation
EACCES The calling process does not have permission to search one of the components of Pathname.
EINVAL The Pathname parameter is not valid; it contains nulls.
ELOOP A loop exists in symbolic links that were encountered during resolution of the Pathname argument. This error is issued if more than 24 symbolic links are detected in the resolution of Pathname.
ENAMETOOLONG Pathname is longer than 1023 characters, or a component of Pathname is longer than 255 characters. Name truncation is not supported.
ENOENT No directory named Pathname was found, or no Pathname was specified. The following reason codes can accompany the return code: JRChdNoEnt and JRQuiescing.
ENOTDIR Some component of Pathname is not a directory. The following reason code can accompany the return code: JRChdNotDir.
EPERM The calling process is not a superuser. The following reason code can accompany the return code: JRUserNotPrivileged.
Reason_code
Returned parameter
Type:
Integer
Length:
Fullword

The name of a fullword in which the chroot service stores the reason code. The chroot service returns a Reason_code only if Return_value is -1. Reason_code further qualifies the Return_code value. See z/OS UNIX System Services Messages and Codes for the reason codes.

Usage notes

  1. Upon completion of the chroot, the specified directory is now the logical root of the file system for the process. All searches for pathname beginning with slash (/) start from this directory, and all attempts to use dot dot (..) over the root remain in the new root.
  2. A new child process inherits a parent's changed root directory.
  3. If the current working directory is above the new root, chroot(.) can be used to reset the root directory to equal the current working directory. However, when the current working directory is above the root directory, getcwd() fails with ENOENT return code.

Related services

Characteristics and restrictions

To change the root directory, the caller must have appropriate privileges (see Authorization).

Examples

See BPX1CRT (chroot) example for an example using this callable service.