1 |
Am Thu, 07 Sep 2017 17:46:27 +0200 |
2 |
schrieb Helmut Jarausch <jarausch@××××××.be>: |
3 |
|
4 |
> Hi, |
5 |
> |
6 |
> sorry, this question is not Gentoo specific - but I know there are |
7 |
> many very knowledgeable people on this list. |
8 |
> |
9 |
> I'd like to "hard-link" a file X to Y - i.e. there is no additional |
10 |
> space on disk for Y. |
11 |
> |
12 |
> But, contrary to the "standard" hard-link (ln), file Y should be |
13 |
> stored in a different place (inode) IF it gets modified. |
14 |
> With the standard hard-link, file X is the same as Y, so any changes |
15 |
> to Y are seen in X by definition. |
16 |
> |
17 |
> Is this possible |
18 |
> - with an ext4 FS |
19 |
> - or only with a different (which) FS |
20 |
|
21 |
You can do this with "cp --reflink=always" if the filesystem supports |
22 |
it. |
23 |
|
24 |
To my current knowledge, only btrfs (since a long time) and xfs (in |
25 |
newer kernel versions) support it. Not sure if ext4 supports it or |
26 |
plans support for it. |
27 |
|
28 |
It is different to hard linking as the new file is linked by a new |
29 |
inode, thus it has it's own time stamp and permissions unlike hard |
30 |
links. Just contents are initially shared until you modify them. Also |
31 |
keep in mind that this increases fragmentation especially when there |
32 |
are a lot of small modifications. |
33 |
|
34 |
At least in btrfs there's also a caveat that the original extents may |
35 |
not actually be split and the split extents share parts of the |
36 |
original extent. That means, if you delete the original later, the copy |
37 |
will occupy more space than expected until you defragment the file: |
38 |
|
39 |
File A extent map: [1111][22 2 2][3333] |
40 |
File B extent map: [1111][22 2 2][3333] |
41 |
Modify b: [1111][22][4][2][3333] <- one block modified |
42 |
|
43 |
Delete file a: [----][22 2 2][----] <- extent 2 still mapped |
44 |
File b extent map: [1111][22][4][2][3333] |
45 |
|
46 |
So extent 2 is still on disk in its original state [2222]. |
47 |
|
48 |
Defragment file b: [1111][2242][3333] |
49 |
File a: [----][----][----] <- completely gone now |
50 |
|
51 |
|
52 |
|
53 |
-- |
54 |
Regards, |
55 |
Kai |
56 |
|
57 |
Replies to list-only preferred. |