CopyOnWrite 0.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package CopyOnWrite --version 0.1.2
NuGet\Install-Package CopyOnWrite -Version 0.1.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CopyOnWrite" Version="0.1.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CopyOnWrite --version 0.1.2
#r "nuget: CopyOnWrite, 0.1.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CopyOnWrite as a Cake Addin
#addin nuget:?package=CopyOnWrite&version=0.1.2

// Install CopyOnWrite as a Cake Tool
#tool nuget:?package=CopyOnWrite&version=0.1.2

This library provides a .NET layer on top of OS-specific logic that provides copy-on-write linking for files (a.k.a. CoW, file cloning, or reflinking). CoW linking provides the ability to copy a file without actually copying the original file's bytes from one disk location to another. The filesystem is in charge of ensuring that if the original file is modified or deleted, the CoW linked files remain unmodified by lazily copying the original file's bytes into each link. Unlike symlinks or hardlinks, writes to CoW links do not write through to the original file, as the filesystem breaks the link and copies in a lazy fashion. This enables scenarios like file caches where a single copy of a file held in a content-addressable or other store is safely linked to many locations in a filesystem with low I/O overhead.

This library allows a .NET developer to:

  • Discover whether CoW links are allowed between two filesystem paths,
  • Discover whether CoW links are allowed for a directory tree based at a specific root directory,
  • Create CoW links.
  • Find filesystem CoW link limits.

Discovery is important, as different operating systems and different filesystems available for those operating systems provide varying levels of CoW link support:

  • Windows: The default NTFS filesystem does NOT support CoW, but the ReFS filesystem does.
  • Linux: Btrfs, Xfs, Zfs support CoW while ext4 does not.
  • Mac: AppleFS supports CoW by default.

When using this library you may need to create a wrapper that copies the file if CoW is not available.

Example

using Microsoft.CopyOnWrite;

ICopyOnWriteFilesystem cow = CopyOnWriteFilesystemFactory.GetInstance();
bool canCloneInCurrentDirectory = cow.CopyOnWriteLinkSupportedInDirectoryTree(Environment.CurrentDirectory);
if (canCloneInCurrentDirectory)
{
    cow.CloneFile(existingFile, cowLinkFilePath);
}

Release History

  • 0.1.2 October 2021: Performance fixes for Windows. Mac and Linux throw NotSupportedException.
  • 0.1.1 October 2021: Bug fixes for Windows. Mac and Linux throw NotSupportedException.
  • 0.1.0 July 2021: Windows ReFS support. Mac and Linux throw NotSupportedException.

Performance Comparisons

Windows

Generally, CoW links on ReFS save time over file copies except at file size zero. The savings is proportional to the file size, with 16MB files at about 35X performance, 1MB at 3.2X, and small sizes at about 1.3X.

Detailed numbers for a VHD formatted empty with ReFS for each iteration, comparing System.IO.File.Copy() with CloneFile(), 25 copies/clones of a single source file per measurement. See CoWComparisons.cs. Machine was an 8/16-core M.2 SSD, Win10 21H1 Enterprise.

Method FileSize Mean Error StdDev Median Ratio RatioSD
File.Copy 0 4.933 ms 0.3274 ms 0.9551 ms 4.799 ms 1.00 0.00
CoW 0 5.002 ms 0.2447 ms 0.7100 ms 4.885 ms 1.04 0.21
File.Copy 1 8.841 ms 0.4976 ms 1.4197 ms 8.515 ms 1.00 0.00
CoW 1 6.499 ms 0.3647 ms 1.0579 ms 6.169 ms 0.75 0.13
File.Copy 1024 8.614 ms 0.4982 ms 1.4374 ms 8.471 ms 1.00 0.00
CoW 1024 6.678 ms 0.3776 ms 1.0834 ms 6.269 ms 0.79 0.14
File.Copy 16384 8.950 ms 0.5148 ms 1.4770 ms 8.454 ms 1.00 0.00
CoW 16384 6.774 ms 0.3240 ms 0.9137 ms 6.622 ms 0.77 0.12
File.Copy 262144 12.700 ms 0.6236 ms 1.7993 ms 12.140 ms 1.00 0.00
CoW 262144 7.036 ms 0.3911 ms 1.1470 ms 6.882 ms 0.56 0.10
File.Copy 1048576 21.920 ms 0.4359 ms 1.1785 ms 21.690 ms 1.00 0.00
CoW 1048576 6.940 ms 0.3652 ms 1.0711 ms 6.743 ms 0.32 0.05
File.Copy 16777216 252.637 ms 2.9167 ms 2.5855 ms 251.895 ms 1.00 0.00
CoW 16777216 7.272 ms 0.2882 ms 0.7987 ms 7.136 ms 0.03 0.00
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on CopyOnWrite:

Repository Stars
microsoft/MSBuildSdks
MSBuild project SDKs
Version Downloads Last updated
0.3.8 3,162 3/25/2024
0.3.7 8,020 9/11/2023
0.3.6 7,806 7/17/2023
0.3.5 162 7/13/2023
0.3.4 172 7/12/2023
0.3.3 165 7/11/2023
0.3.2 8,957 2/9/2023
0.3.1 299 2/8/2023
0.3.0 1,054 1/30/2023
0.2.2 365 1/27/2023
0.2.1 5,870 9/27/2022
0.2.0 445 9/15/2022
0.1.13 434 9/15/2022
0.1.12 447 9/15/2022
0.1.11 445 9/6/2022
0.1.10 403 9/3/2022
0.1.9 380 9/3/2022
0.1.8 487 4/19/2022
0.1.7 466 4/19/2022
0.1.6 417 4/19/2022
0.1.5 350 10/15/2021
0.1.4 337 10/14/2021
0.1.3 329 10/13/2021
0.1.2 319 10/13/2021
0.1.1 363 10/11/2021
0.1.0 378 7/10/2021