truncate (BPX1TRU, BPX4TRU) — Change the size of a file

Function

The truncate service changes the size of a file. The file is identified by a path name.

Requirements

Operation Environment
Authorization: Supervisor state or problem state, any PSW key
Dispatchable unit mode: Task
Cross memory mode: PASN = HASN
AMODE (BPX1TRU): 31-bit
AMODE (BPX4TRU): 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 BPX1TRU,(Pathname_length,
              Pathname,
              File_length,
              Return_value,
              Return_code,
              Reason_code)

AMODE 64 callers use BPX4TRU 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 file whose size is to be changed.

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 file. 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 root directory, and the search for the file starts at the 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.
File_length
Supplied parameter
Type:
Integer
Length:
Doubleword

The name of a doubleword that contains the number of bytes that are to be contained in the file after the size is changed.

This field is a doubleword to accommodate large files. For normal processing with a singleword value, the second word should be zero. The truncate service accepts only positive values.

Return_value
Returned parameter
Type:
Integer
Length:
Fullword

The name of a fullword in which the truncate 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 truncate service stores the return code. The truncate 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 truncate 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 some component of the Pathname prefix; or write permission is denied on the file.
EBUSY The file is open by a remote NFS client with a share reservation that conflicts with the requested operation.
EFBIG The File_length parameter is greater than the maximum file size limit for the process. The following reason code can accompany the return code: JRWriteBeyondLimit.
EINVAL The file is not a regular file; or the File_length that is specified is either negative or greater than the maximum file size. The following reason codes can accompany the return code: JRTrNegOffset, JRTrNotRegFile.
EISDIR The file is a directory.
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 the pathname is longer than 255 characters.
ENOENT No file named Pathname was found, or no pathname was specified. The following reason code can accompany the return code: JRFileNotThere.
ENOTDIR Some component of the Pathname prefix is not a directory.
EROFS The specified file is on a read-only file system. The following reason code can accompany the return code: JRTrMountedRO.
Reason_code
Returned parameter
Type:
Integer
Length:
Fullword

The name of a fullword in which the truncate service stores the reason code. The truncate 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

  1. The truncate service changes the file size to File_length bytes, beginning from the first byte of the file. If the file was originally larger than File_length bytes, the data from File_length to the original end of the file is removed. If the file was originally shorter than File_length, bytes between the old and new lengths are read as zeros.
  2. If File_length is greater than the soft file size limit for the process, the request fails with EFBIG, and the SIGXFSZ signal is generated for the process.
  3. Full blocks are returned to the file system, so that they can be used again.
  4. A file may not be truncated if it is currently open by a remote NFS client with a share reservation that prevents the file from being opened for writing. Refer to open (BPX1OPN, BPX4OPN) — Open a file for details about the NFS share reservations.

Related services

Characteristics and restrictions

The file that is specified must be a regular file to which the calling process has write access.

Examples

For an example using this callable service, see BPX1TRU (truncate) example.