ftruncate (BPX1FTR, BPX4FTR) — Change the size of a file

Function

The ftruncate service changes the size of a file. The file is identified by its file descriptor.

Requirements

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

AMODE 64 callers use BPX4FTR with the same parameters.

Parameters

File_descriptor
Supplied parameter
Type:
Integer
Length:
Fullword

The name of a fullword that contains the file descriptor of the file whose size is to be changed.

File_length
Supplied parameter
Type:
Integer
Length:
Doubleword

The name of a doubleword that contains the number of bytes the file is to contain after its size has been changed.

This field is a doubleword to accommodate large files. For normal processing with a singleword value, propagate the sign bit through the second word, so that the final doubleword value has a valid sign. The ftruncate service accepts only positive values.

Return_value
Returned parameter
Type:
Integer
Length:
Fullword

The name of a fullword in which the ftruncate 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 ftruncate service stores the return code. The ftruncate service returns Return_code only if Return_value is -1. For a complete list of possible return code values, see z/OS UNIX System Services Messages and Codes. The ftruncate service can return one of the following values in the Return_code parameter:
Return_code Explanation
EBADF The File_descriptor parameter does not specify a valid, open file.
EINVAL The file is not a regular file; it is opened Read Only; or the File_length specified is negative. The following reason codes can accompany the return code: JRTrNegOffset, JRTrNotRegFile, and JRTrOpenedRO.
EROFS The specified file is on a read-only file system. The following reason code can accompany the return code: JRTrMountedRO.
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.
Reason_code
Returned parameter
Type:
Integer
Length:
Fullword

The name of a fullword in which the ftruncate service stores the reason code. The ftruncate 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 ftruncate 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. The file offset is not affected by an ftruncate request.

Related services

Characteristics and restrictions

The file specified must be a regular file, open for writing.

Examples

For an example using this callable service, see BPX1FTR (ftruncate) example.