> ## Content Index
> Fetch the complete content index at: https://www.ctrl.blog/llms.txt
> Use this file to discover other available public pages before exploring further.

# Which file systems support file cloning
- URL: https://www.ctrl.blog/entry/file-cloning/
- Published: 2020-09-21T13:51:00.000Z
- Updated: 2026-08-23T22:06:38.000Z
- Description: You can instantly clone files on many copy-on-write (CoW) file systems. But how do you do that in different operating and file systems?
- Author: Daniel Aleksandersen
- Tags: Storage

File cloning is a feature of copy-on-write (CoW) file systems. It’s an immediate way to make duplicate copies of files without requiring a second copy to be stored. Here’s a quick overview of cloning-capable file systems and the system calls and commands required to take advantage of them on Linux, MacOS, Windows, and other operating systems.

Most file systems developed in the last decade, proprietary and open-source alike, are CoW file systems. Simply put, CoW file systems always create a new copy when you modify a file instead of overwriting data in-place. This helps protect your data against a slew of different problems that can occur while writing files.

Copy-on-write file systems also enables use cases like data integrity checking, file system snapshots, and data deduplication. In this article, I’ll focus exclusively on the latter use case.

On traditional file systems, storing extra copies of your files takes up more space on your storage drives. File cloning enables you to make multiple copies of the same file without storing more than one copy of the actual data. If either the original file or one of its clones make changes to the data, the new data is written to another place on the drive. The other copies that shares data with it remains unchanged. The clones that shared data with it can still share some identical chunks of data with the modified file.

Cloning is a safer alternative to file system hard links. Hard links are supported in most file systems, and work more like a shortcut. The hard-linked shortcut points to the exact same location on your storage drive as the original file. Almost no programs are hard-link aware and won’t warn you that you’re about to modify more than one file.

Support for file cloning must be baked into the operating system kernel and the file system driver. Programs must also be made aware of file cloning capabilities before they can take advantage of it. The following table shows the system calls (syscall) and cloning-aware copy commands for popular operating and file systems.

| OS      | FS                       | Copy command                 | System call |
| ------- | ------------------------ | ---------------------------- | ----------- |
| Linux   | Bcachefs                 | cp --reflink=always          | ficlone     |
| Btrfs   |                          |                              |             |
| XFS     |                          |                              |             |
| OCFS2   |                          |                              |             |
| Ext4    | Unsupported.             |                              |             |
| OpenZFS |                          |                              |             |
| FreeBSD |                          |                              |             |
| ZFS     |                          |                              |             |
| Solaris | Oracle ZFS               | cp -z                        | reflink     |
| MacOS   | APFS                     | cp -c                        | clonefile   |
| HFS+    | Unsupported; non-CoW FS. |                              |             |
| Windows | NTFS                     |                              |             |
| ReFSv2  | Not included.            | DUPLICATE\_EXTENTS\_TO\_FILE |             |

As shown above, the `cp` (copy) command on some operating systems can make use of syscalls to instruct the kernel to clone a file instead of making a complete copy. The most notable example, after the copy command, is Finder on MacOS. It’ll clone files automatically when you copy them on an APFS volume. File Explorer on Windows and Nautilus and Dolphin on Linux will always make complete copies.

It’s unfortunate that the different operating systems have settled on different argument extensions to the POSIX `cp` command. It would have been better for developers if there could have been a little more cooperation between the implementors. I had trouble finding any examples of cross-platform implementations. [Syncthing stands out](https://www.ctrl.blog/entry/syncthing-deduplication-master/) with support for all but Solaris’ `reflink` syscall.

Each of the syscalls mentioned in the table clone entire files. Linux also supports partial cloning of files using the `ficlonerange` and `fideduperange` syscalls. These syscalls only allow you to address parts of a file that is aligned to the block size of the underlying storage media.

OpenZFS isn’t part of the Linux kernel because of licensing issues, and that is [unlikely to change](https://www.phoronix.com/news/Linus-Says-No-To-ZFS-Linux?ref=ctrl.blog). OpenZFS doesn’t support reflinks, nor any of the relevant Linux syscalls for cloning files or blocks. It supports file system-level cloning but not

Bcachefs isn’t in the kernel yet either, but it’s developed under a Linux-kernel compatible license with the ultimate goal of being merged into the kernel. It supports all the relevant Linux-specific syscalls for file cloning.

Over the last three years, Apple has switched all of its products to its new CoW-based Apple File System (APFS). Microsoft has decided to go in the opposite direction, and removed its copy-on-write file system, ReFS, from Windows 10 Professional in 2017. ReFS is now only available on Workstation and Server editions. [ReFS was not suitable](https://www.ctrl.blog/entry/adventures-in-refs/) for use on Windows desktops anyway. This does leave Windows as the only computer operating system without a CoW file system. 

I find file cloning fascinating, and I’ll explore several potential use cases for it in the coming weeks. Next up will be how you can [identify a cloned file](https://www.ctrl.blog/entry/distinguish-file-link-clone/). Something that is surprisingly difficult because the file system doesn’t keep track of it.

**Update** (2023-01-11): An earlier version of this article incorrectly stated that OpenZFS and ZFS supported `reflink` internally, but didn’t expose any syscalls for it. These file systems do not support reflinks. Thanks to Richard Yao of the OpenZFS project for the correction.

#### Sources

- [Snapshots in bcachefs](https://evilpiepirate.org/git/bcachefs-wiki.git/plain/Snapshots.mdwn?id=8db496a95bc5ba9c618a4c9c250d4433ecdf68f3&ref=ctrl.blog), commit 8db496a9, 2020-01-09, Kent Overstreet
- [Linus Torvalds Doesn’t Recommend Using ZFS On Linux](https://www.phoronix.com/news/Linus-Says-No-To-ZFS-Linux?ref=ctrl.blog), 2020-01-08, Michael Larabel, Phoronix
- [Copy files and directories](https://www.gnu.org/software/coreutils/manual/html%5Fnode/cp-invocation.html?ref=ctrl.blog), 2020, Documentation, GNU Coreutils, GNU Project
- [fideduperange man page](https://www.man7.org/linux/man-pages/man2/ioctl%5Ffideduperange.2.html?ref=ctrl.blog), 2019-10-10, Linux Programmer’s Manual, Linux man-pages project
- [FSCTL\_DUPLICATE\_EXTENTS\_TO\_FILE IOCTL](https://learn.microsoft.com/en-us/windows/win32/api/winioctl/ni-winioctl-fsctl%5Fduplicate%5Fextents%5Fto%5Ffile?ref=ctrl.blog), 2018-12-05, Win32 API, Windows Dev Center, Microsoft
- [Block cloning on ReFS](https://learn.microsoft.com/en-us/windows-server/storage/refs/block-cloning?ref=ctrl.blog), 2018-10-17, Windows Server documentation, Microsoft
- [reflink(3c) What is it? Why do I care? And how can I use it?](https://blogs.oracle.com/solaris/post/reflink3c-what-is-it-why-do-i-care-and-how-can-i-use-it?ref=ctrl.blog), 2018-01-30, Chris Beal, Oracle Solaris Blog, Oracle
- [ficlone man page](https://www.man7.org/linux/man-pages/man2/ioctl%5Fficlone.2.html?ref=ctrl.blog), 2017-09-15, Linux Programmer’s Manual, Linux man-pages project
- [ficlonerange man page](https://www.man7.org/linux/man-pages/man2/ioctl%5Fficlonerange.2.html?ref=ctrl.blog), 2017-09-15, Linux Programmer’s Manual, Linux man-pages project
- [Microsoft to remove full ReFS support from Windows 10 Pro, push Workstation SKU](https://arstechnica.com/gadgets/2017/08/microsoft-to-remove-full-refs-support-from-windows-10-pro-push-workstation-sku/?ref=ctrl.blog), 2017-08.21, Peter Bright, Ars Technica, Condé Nast
- [Under the hood: How does ReFS block cloning works](http://blog.dewin.me/2017/02/under-hood-how-does-refs-block-cloning.html?ref=ctrl.blog), 2017-02-22, Timothy Dewin, Blog
- [XFS, Reflinks and Deduplication](https://strugglers.net/~andy/blog/2017/01/10/xfs-reflinks-and-deduplication/?ref=ctrl.blog), 2017-01-10, Andy Smith, Blog
- [clonefile man page](https://opensource.apple.com/source/xnu/xnu-6153.81.5/bsd/man/man2/clonefile.2.auto.html?ref=ctrl.blog), 2015-12-04, xnu version 6153.81.5, Open Source Releases, Apple
- [The Btrfs filesystem: An introduction](https://lwn.net/Articles/576276/?ref=ctrl.blog), 2013-12-11, Jonathan Corbet, LWN, Eklektix