Re:Japan HP accidentally deleted 77TB data in Kyoto U. super...
by exikyut on Thursday December 30, 2021 @07:08AM
(#29736065)
> there was a goto command which was implemented by seeking on the shell-script file descriptor rather than as a shell builtin, for example.
Oh noooo I just realized you could probably implement a shared library loadable module for bash `enable` that does the same thing... just fseek()s the fd...
*Runs for the hills screaming*
Re:Japan HP accidentally deleted 77TB data in Kyoto U. super...
by sillysaurusx on Thursday December 30, 2021 @06:56AM
(#29736008)
“Emacs for example does create a new file and rename it over the old one when you save, usually, allocating a new inode as you say. By default it makes an exception if there are other hardlinks to the file.”
Though the trade off is that all operation ceases on a full hard drive.
I don’t have a better solution, but it’s worth noting.
Re:Japan HP accidentally deleted 77TB data in Kyoto U. super...
by kragen on Thursday December 30, 2021 @07:50PM
(#29743556)
Emacs gives you an error message in that case rather than destroying the old version of the file and then failing to completely write the new version, in the cases where it does the tempfile-then-rename dance. This is usually vastly preferable if Emacs or your computer crashes before you manage to free up enough space for a successful save.
It doesn't cease all operation; other Emacs features work as they normally do. Bash, by contrast, stops being able to tab-complete filenames, at precisely the time when you most need to be able to rapidly manipulate your files. At least, that's the case with the default completion setup in a few recent versions of Ubuntu.
Re:Japan HP accidentally deleted 77TB data in Kyoto U. super...
by thaumasiotes on Thursday December 30, 2021 @07:31AM
(#29736183)
Well, it looks like creating another hard link is a nearly-free solution. And beyond that, since emacs already has both behaviors, presumably you can tell it you want the in-place modification.
As I understand it, the reason for ETXTBSY ("on some old Unices...you can't overwrite a running binary") was to prevent segfaults.
cp usually just opens the file O_WRONLY|O_TRUNC, which seems like the wrong default; Emacs for example does create a new file and rename it over the old one when you save, usually, allocating a new inode as you say. By default it makes an exception if there are other hardlinks to the file.
Btrfs and xfs have a "reflink" feature that allows you to efficiently make a copy-on-write snapshot of a file, which would be ideal for this sort of thing, since the shell or whatever won't see any changes to the original file, even if it's overwritten in place. Unfortunately I don't think you can make anonymous reflinks, so for the shell to reflink a shell script when it starts executing it would need write access to somewhere in the filesystem to put the reflink, and then it would need to know how to find that place, somehow. And of course that wouldn't help if you were running on ext4fs or, I imagine, Lustre, though apparently an implementation was proposed in 02019: https://wiki.lustre.org/Lreflink_High_Level_Design