check for reflink capability and for shared data
Hi,
how can I do the following in a shell script:
- check whether my file system supports cp --reflink?
- check whether two files share the same data on disk, i.e. one has been created by cp --reflink of the other?
Thank you!
Thomas Koch
Quoted 5 lines · Thomas Koch
Hi,
how can I do the following in a shell script:
- check whether my file system supports cp --reflink?
touch foo; if cp --reflink=always foo bar; then ...; fi; rm -f foo bar
Quoted 2 lines
- check whether two files share the same data on disk, i.e. one has been created by cp --reflink of the other?
You can't, using simple userspace tools. I think the only way would
be to use the tree search ioctl to inspect the extents for each file, and see whether any of them overlap. Why do you need to know this?
Hugo.
Signature · 3 lines
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
PGP key: 65E74AC0 from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
--- Someone's been throwing dead sheep down my Fun Well --- Quoted 7 lines · Hugo Mills
Quoted 5 lines · Thomas Koch
Hi,
how can I do the following in a shell script:
- check whether my file system supports cp --reflink?
Quoted 8 lines
touch foo; if cp --reflink=always foo bar; then ...; fi; rm -f foo bar
Quoted 2 lines
- check whether two files share the same data on disk, i.e. one has been created by cp --reflink of the other?
You can't, using simple userspace tools. I think the only way would
be to use the tree search ioctl to inspect the extents for each file, and see whether any of them overlap. Why do you need to know this?
It should work with fiemap to a file in question and btrfs inspect logical to what ever extents fiemap reported as "physical".
-Jan
Quoted 7 lines · Thomas Koch
Hi,
how can I do the following in a shell script:
- check whether my file system supports cp --reflink?
- check whether two files share the same data on disk, i.e. one has been created by cp --reflink of the other?
Someone has proposed to teach 'du(1)' to show this, ie. 'du --shared'[1].
It's written for ocfs2 originally, besides btrfs, ocfs2 also can share data between two files.
[1]: https://oss.oracle.com/pipermail/ocfs2-devel/2010-September/007287.html
-liubo
Quoted 2 lines · Thomas Koch
- check whether two files share the same data on disk, i.e. one has been created by cp --reflink of the other?
How about inspecting the output of filefrag -v $filename? For example, you could filter out with grep all lines except the ones that contain information about the extents.
Then you could hash the lines left and use that single hash to compare the two files.