[mythtv-users] Remove corruption in video stream

Simon linux at thehobsons.co.uk
Fri Oct 14 19:37:37 UTC 2022


John <jksjdevelop at gmail.com> wrote:

> As the job writes over the original file, it would cause problems presumably if instigated by the recording finishing if somebody was watching it at the time.

It depends.
The “sane” way to do it would be to create a new file, and only when that’s successfully completed, move or delete the old file out of the way and rename the new file into place. As long as this is done, something already using the file will be able to continue doing so.

A bit more detail.
On Unix filesystems, files are stored just as a numbered file (inode). An inode can have zero or more directory entries that point to it - you can see the inodes if you use the -i option to ls, and you can see the number of links to an inode when using the -l option. When you use ln to create a new hard link to a file (i.e. not using -s to create a soft link), all it does is create a new directory entry using the same inode.
As long as there is 1 or more directory entry linking to an inode, it will be kept on disk. When you delete a directory entry, and it is the last one pointing to a particular inode then the inode will be sent for deletion.
But, if a process has the file (inode) open (e.g. a frontend is treating it for display), then it won’t be deleted until it is closed. If you watch carefully, you can see how a file can be deleted, but if it’s still open then the free disk space doesn’t re-appear - only when the file is closed will you see the disk space re-appear. I.e., if a program has a file open, the system will not “pull the rug” from under it.

This is how so much admin (e.g. system updates) can be done on a live Unix/unix-like system. Already open binaries (e.g. your shell, web & mail servers, etc) will continue running even when they are replaced - the executing image will remain as an inode even though it no longer has any directory entries pointing to it. When the updates are finished, restarting the process will then free up the old binary (whose inode can then be deleted) and start using the new binary.


Simon



More information about the mythtv-users mailing list