Skip to content

copy_file_range

Intro

copy_file_range - copies data between two file descriptors

Description

The copy_file_range() function copies up to len bytes from the file referenced by fd_in to the file referenced by fd_out at the given offset of off_in and off_out respectively. The flags argument specifies the behavior if the range specified straddles a file boundary. copy_file_range() allows to copy data the same way that splice() does, but the data is copied from one file descriptor to another one instead of to/from a pipe.

This function does not work on a file opened with O_DIRECT. An ESYSNOTSUPP error is expected in that case.

Arguments

  • fd_in:int[K] - file descriptor of the input file.
  • off_in:off_t *[K] - starting offset of the input file.
  • fd_out:int[K] - file descriptor of the output file.
  • off_out:off_t *[K] - starting offset of the output file.
  • len:size_t[K] - the length of data that needs to be copied.
  • flags:unsigned int[K] - Possible values are COPY_FILE_RANGE_WAIT_BEFORE, COPY_FILE_RANGE_WAIT_AFTER, and COPY_FILE_RANGE_NONBLOCK.

Available Tags

  • K - Originated from kernel-space.

Hooks

sys_copy_file_range

Type

kprobe + kretprobe

Purpose

To trace data that is being copied between files.

sys_copy_file_range2

Type

kprobe

Purpose

To trace data that is being copied between files.

Example Use Case

An example use case of copy_file_range() is using it to compare two files and detect differences between them.

Issues

copy_file_range() does not work on files opened with O_DIRECT flags and an ESYSNOTSUPP error is expected in such cases.

This document was automatically generated by OpenAI and needs review. It might not be accurate and might contain errors. The authors of Tracee recommend that the user reads the "events.go" source file to understand the events and their arguments better.