Atomically write a file without changing inodes (preserve hard link)
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
The normal way to safely, atomically write a file X
on Unix is:
- Write the new file contents to a temporary file
Y
. rename(2)
Y
toX
It is protected against race conditions and unintentional data loss (where X
is destroyed but Y
is incomplete or destroyed).
The drawback (in this case) of this is that it doesn't write the inode referred to by X
in-place; rename(2)
makes X
refer to a new inode number.
When X
was a file with link count > 1 (an explicit hard link), now it doesn't refer to the same inode as before, the hard link is broken.
The obvious way to eliminate the drawback is to write the file in-place, but this is not atomic, can fail, might result in data loss etc.
Is there some way to do it atomically like rename(2)
but preserve hard links?
Perhaps to change the inode number of Y
(the temporary file) to the same as X
, and give it X
's name? An inode-level "rename."
This would effectively write the inode referred to by X
with Y
's new contents, but would not break its hard-link property, and would keep the old name.
If the hypothetical inode "rename" was atomic, then I think this would be atomic and protected against data loss / races.
rename inode system-calls hard-link write
add a comment |Â
up vote
0
down vote
favorite
The normal way to safely, atomically write a file X
on Unix is:
- Write the new file contents to a temporary file
Y
. rename(2)
Y
toX
It is protected against race conditions and unintentional data loss (where X
is destroyed but Y
is incomplete or destroyed).
The drawback (in this case) of this is that it doesn't write the inode referred to by X
in-place; rename(2)
makes X
refer to a new inode number.
When X
was a file with link count > 1 (an explicit hard link), now it doesn't refer to the same inode as before, the hard link is broken.
The obvious way to eliminate the drawback is to write the file in-place, but this is not atomic, can fail, might result in data loss etc.
Is there some way to do it atomically like rename(2)
but preserve hard links?
Perhaps to change the inode number of Y
(the temporary file) to the same as X
, and give it X
's name? An inode-level "rename."
This would effectively write the inode referred to by X
with Y
's new contents, but would not break its hard-link property, and would keep the old name.
If the hypothetical inode "rename" was atomic, then I think this would be atomic and protected against data loss / races.
rename inode system-calls hard-link write
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
The normal way to safely, atomically write a file X
on Unix is:
- Write the new file contents to a temporary file
Y
. rename(2)
Y
toX
It is protected against race conditions and unintentional data loss (where X
is destroyed but Y
is incomplete or destroyed).
The drawback (in this case) of this is that it doesn't write the inode referred to by X
in-place; rename(2)
makes X
refer to a new inode number.
When X
was a file with link count > 1 (an explicit hard link), now it doesn't refer to the same inode as before, the hard link is broken.
The obvious way to eliminate the drawback is to write the file in-place, but this is not atomic, can fail, might result in data loss etc.
Is there some way to do it atomically like rename(2)
but preserve hard links?
Perhaps to change the inode number of Y
(the temporary file) to the same as X
, and give it X
's name? An inode-level "rename."
This would effectively write the inode referred to by X
with Y
's new contents, but would not break its hard-link property, and would keep the old name.
If the hypothetical inode "rename" was atomic, then I think this would be atomic and protected against data loss / races.
rename inode system-calls hard-link write
The normal way to safely, atomically write a file X
on Unix is:
- Write the new file contents to a temporary file
Y
. rename(2)
Y
toX
It is protected against race conditions and unintentional data loss (where X
is destroyed but Y
is incomplete or destroyed).
The drawback (in this case) of this is that it doesn't write the inode referred to by X
in-place; rename(2)
makes X
refer to a new inode number.
When X
was a file with link count > 1 (an explicit hard link), now it doesn't refer to the same inode as before, the hard link is broken.
The obvious way to eliminate the drawback is to write the file in-place, but this is not atomic, can fail, might result in data loss etc.
Is there some way to do it atomically like rename(2)
but preserve hard links?
Perhaps to change the inode number of Y
(the temporary file) to the same as X
, and give it X
's name? An inode-level "rename."
This would effectively write the inode referred to by X
with Y
's new contents, but would not break its hard-link property, and would keep the old name.
If the hypothetical inode "rename" was atomic, then I think this would be atomic and protected against data loss / races.
rename inode system-calls hard-link write
rename inode system-calls hard-link write
asked 7 mins ago
cat
1,64521135
1,64521135
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f478314%2fatomically-write-a-file-without-changing-inodes-preserve-hard-link%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password