stat (BPX1STA, BPX4STA) — Get status information about a file by pathname
Function
The stat callable service obtains status information about a specified file. You specify the file by its pathname.
If the pathname that is specified refers to a symbolic link, the symbolic link name is resolved to a file, and the status information for that file is returned. To obtain status information about a symbolic link, rather than a file it refers to, use lstat (BPX1LST, BPX4LST) — Get status information about a file or symbolic link by path name.
For the corresponding service using a file descriptor, see fstat (BPX1FST, BPX4FST) — Get status information about a file by descriptor.
Requirements
Operation | Environment |
---|---|
Authorization: | Supervisor state or problem state, any PSW key |
Dispatchable unit mode: | Task |
Cross memory mode: | PASN = HASN |
AMODE (BPX1STA): | 31-bit |
AMODE (BPX4STA): | 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 BPX4STA with the same parameters.
Parameters
- Pathname_length
- Supplied parameter
- Type:
- Integer
- Length:
- Fullword
The name of a fullword that contains the length of Pathname.
- Pathname
- Supplied parameter
- Type:
- Character string
- Character set:
- No restriction
- Length:
- Specified by the Pathname_length parameter
The name of an area, of length Pathname_length, that contains the pathname of the file for which you want to obtain status. The Pathname can be a pathname to a file, a link named by a pathname to a file (as created by link (BPX1LNK, BPX4LNK) — Create a link to a file), or a symbolic link named by a pathname to a file (as created by symlink (BPX1SYM, BPX4SYM) — Create a symbolic link to a path name).
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 root directory, and the search for the file starts at the 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.
- Status_area_length
- Supplied parameter
- Type:
- Integer
- Length:
- Fullword
The name of a fullword that contains the length of the area to which the service returns Status_area. To determine the value of Status_area_length, use the BPXYSTAT macro (see BPXYSTAT — Map the response structure for stat).
- Status_area
- Parameter supplied and returned
- Type:
- Structure
- Length:
- Specified by the Status_area_length parameter
The name of an area, of length Status_area_length, to which the service returns the status information for the file. The Status_area is mapped by the BPXYSTAT macro (see BPXYSTAT — Map the response structure for stat).
- Return_value
- Returned parameter
- Type:
- Integer
- Length:
- Fullword
The name of a fullword in which the stat 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 stat service stores the return code. The stat 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 stat service can return one of the following values in the Return_code parameter:Return_code Explanation EACCES The process does not have permission to search some component of the Pathname prefix. EINVAL Parameter error—for example, a zero-length buffer. The following reason code can accompany the return code: JRBuffTooSmall. 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 some component of the pathname is longer than 255 characters. This could be as a result of encountering a symbolic link during resolution of Pathname, if the substituted string is longer than 1023 characters. ENOENT No file named Pathname was found, or Pathname was not specified. The following reason code can accompany the return code: JRFileNotThere. ENOTDIR A component of the Pathname prefix is not a directory. - Reason_code
- Returned parameter
- Type:
- Integer
- Length:
- Fullword
The name of a fullword in which the stat service stores the reason code. The stat service returns Reason_code only if Return_value is -1. Reason_code further qualifies the Return_code value. For the reason codes, see z/OS UNIX System Services Messages and Codes.
Usage notes
- All time fields in the Status_area are in POSIX format.
- The File Mode field in the Status_area is mapped by the BPXYMODE macro (see BPXYMODE — Map the mode constants of the file services). For information on the values for file type, see BPXYFTYP — File type definitions.
- If no security label (SECLABEL) exists for the file, the security label field in the Status_area contains binary zeros.
Related services
- chmod (BPX1CHM, BPX4CHM) — Change the mode of a file or directory
- exec (BPX1EXC, BPX4EXC) — Run a program
- fpathconf (BPX1FPC, BPX4FPC) — Determine configurable path name variables using a descriptor
- fstat (BPX1FST, BPX4FST) — Get status information about a file by descriptor
- link (BPX1LNK, BPX4LNK) — Create a link to a file
- mkdir (BPX1MKD, BPX4MKD) — Make a directory
- open (BPX1OPN, BPX4OPN) — Open a file
- pipe (BPX1PIP, BPX4PIP) — Create an unnamed pipe
- read (BPX1RED, BPX4RED) — Read from a file or socket
- symlink (BPX1SYM, BPX4SYM) — Create a symbolic link to a path name
- unlink (BPX1UNL, BPX4UNL) — Remove a directory entry
- utime (BPX1UTI, BPX4UTI) — Set file access and modification times
- write (BPX1WRT, BPX4WRT) — Write to a file or a socket
Characteristics and restrictions
To obtain information about a file, you need not have permissions for the file itself; however, you must have search permission for all the directory components of Pathname.
Examples
For an example using this callable service, see BPX1STA (stat) example.