Skip to content

Use fs.copyFile with UV_FS_COPYFILE_FICLONE flag when ready #5456

@langpavel

Description

@langpavel

Do you want to request a feature or report a bug?

Feature

Prerequisites

Summary

There is new awesome upcoming feature which can dramatically improve copying files on Copy on Write file systems: UV_FS_COPYFILE_FICLONE
File copied (cloned) this way will not occupy additional disk space until first modification, but it also have all the properties that standalone file has.

Cloning from Btrfs at Wikipedia.org (+)

Btrfs provides a clone operation that atomically creates a copy-on-write snapshot of a file. Such cloned files are sometimes referred to as reflinks, in light of the associated Linux kernel system calls.

By cloning, the file system does not create a new link pointing to an existing inode; instead, it creates a new inode that initially shares the same disk blocks with the original file. As a result, cloning works only within the boundaries of the same Btrfs file system, but since version 3.6 of the Linux kernel it may cross the boundaries of subvolumes under certain circumstances. The actual data blocks are not duplicated; at the same time, due to the copy-on-write (CoW) nature of Btrfs, modifications to any of the cloned files are not visible in the original file and vice versa.

Cloning should not be confused with hard links, which are directory entries that associate multiple file names with actual files on a file system. While hard links can be taken as different names for the same file, cloning in Btrfs provides independent files that share their disk blocks.

Support for this Btrfs feature was added in version 7.5 of the GNU coreutils, via the --reflink option to the cp command.


Relevant paragraph from libuv docs (+)

.. c:function:: int uv_fs_copyfile(uv_loop_t* loop, uv_fs_t* req, const char* path, const char* new_path, int flags, uv_fs_cb cb)
Copies a file from path to new_path. Supported flags are described below.
—————————————————————————————
- UV_FS_COPYFILE_FICLONE: If present, uv_fs_copyfile() will attempt to
create a copy-on-write reflink. If the underlying platform does not
support copy-on-write, then a fallback copy mechanism is used.
—————————————————————————————
.. versionchanged:: 1.20.0 UV_FS_COPYFILE_FICLONE is supported.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions