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 path names 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
|
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 path name 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 path name of the new directory. This field has the length that is specified in Pathname_length.
Path names can begin with or without a slash:- A path name that begins with a slash is an absolute path name. The slash refers to the current root directory, and the search for the file starts at the current root directory.
- A path name that does not begin with a slash is a relative path name. 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
- Upon completion of the chroot, the specified directory is now the logical root of the file system for the process. All searches for path name beginning with slash (/) start from this directory, and all attempts to use dot dot (..) over the root remain in the new root.
- A new child process inherits a parent's changed root directory.
- 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
- chdir (BPX1CHD, BPX4CHD) — Change the working directory
- closedir (BPX1CLD, BPX4CLD) — Close a directory
- getcwd (BPX1GCW, BPX4GCW) — Get the path name of the working directory
- mkdir (BPX1MKD, BPX4MKD) — Make a directory
- opendir (BPX1OPD, BPX4OPD) — Open a directory
- readdir (BPX1RDD, BPX4RDD) — Read an entry from a directory
- rmdir (BPX1RMD, BPX4RMD) — Remove a directory
- unlink (BPX1UNL, BPX4UNL) — Remove a directory entry
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.