Deleted Image FS remains accessable
Timothy Baldwin (184) 242 posts |
If an image file which contains an open file is deleted (which requires the image to be on a filing system that supports unlinking open files) the contents of the image file remains accessible, except for listing the root directory of the image file. If the image file is replaced with a directory, the directory can be listed but other operations are applied to the image. If the image file is replaced with another image, full access to the contents of the original image is restored. Once the files are closed normality is restored, potentially losing the files written to the old image. |
Rick Murray (539) 13850 posts |
Therein lies the problem. One can’t delete opened files under RISC OS (I don’t think even Econet permitted that to happen) so attempts to do so are likely to cause weird things to happen.
I’d be inclined to blame the underlying filesystem more than RISC OS. Two questions:
What image FS are you using? SparkFS tries to close files when “doing nothing”. I created “test/zip” and put a few files in there. The handle was released in a couple of seconds. Further access to the archive reopened the file, briefly. |
Timothy Baldwin (184) 242 posts |
Whilst is is documented that OS_File 6 is documented as giving an error if the file is open “An error is generated if the object is locked against deletion, or if it is a directory which is not empty, or is already open.”, but this is not required of FSEntry_File 6 “You should return an error if the object is locked against deletion, but not if the object does not exist.” It is possible to delete open files on ResourceFS (using ResourceFS_DeregisterFiles), in that case that is a use after free bug resulting on arbitrary file contents, data aborts, or reading memory mapped IO.
Because that’s what Linux does, and it’s a thin wrapper over Linux. RPCEmu HostFS is similar.
No the file is not deleted until all file handles (and other references) are closed.
I’ve tested with DOSFS and TBAFS. Did you have a file in the image open? If so, and the image is on FileCore I get an error. |
Rick Murray (539) 13850 posts |
I think we are running into a grey area here thanks to some rather bad wording in the PRM. If the file does not exist, FSEntry_File 6 does not need to return an error; but it should return an error if the file is locked against deletion.
Then it will need to be handled as an emulation-specific issue.
Oh, I’ve run into HostFS before. I have a program that creates a file, sets its type accordingly, and then writes data to it.
Tested with SparkFS. Created “__test/zip”. Copied “35LCD” (my little LCD’s mode file) into it. Opened a handle to the 35LCD file. And, of course, we could debate the fact that the Wimp really ought to be passing around a lot more informational messages than it does (files closed, alphabet changed, etc) but that’s a whole different topic. ;-) |
nemo (145) 2554 posts |
That is not deleting a file. That is the equivalent of pushing eject on a floppy drive or yanking a USB stick. There’s nothing the filing system can do about any of these scenarios. You appear to be describing an emulator bug. |
Timothy Baldwin (184) 242 posts |
That should, and does, result in an a request to re-insert the media or an error being raised, unlike the behaviour of ResourceFS which try to return whatever happens at that memory address.
The PRMs define “locked” as meaning protected against deletion, so no. Re RPCEmu HostFS:
RPCEmu HostFS doesn’t use dot-prefixed extensions, are thinking of VirtualRPC HostFS? (There are at least 3 programs by the name HostFS)
Judging by reading the source both Sunfish and ex-Acorn NFS allow deleting (not just unlinking) open files, but more importantly nothing done under RISC OS can stop a unix program deleting a file that is open in RISC OS. There is also a pure RISC OS of way creating this mess, first open an image over ShareFS then rename the directory containing the image directly on the underlying filesystem. There also is a similar inconsistency in the PRMs as to whether renaming an open file is permitted. To prevent unlinking open files there are 4 approaches I can think of:
Approach 1 provides full compatibility with a single RISC OS computer without causing side-effects such as being being unable to delete a different path which contains alternative links to open files. Approach 4 is compatible with multiple instances of RISC OS, but only works where the files have write permission. Does any other program fail like Fileswitch, that is fail if a open file is deleted (or renamed) but work correctly if directory containing the open file is renamed on the same instance of RISC OS? Does any (set of) program attempt to delete an open file and malfunction if it succeeds in deleting the open file? I propose extending FSEntry_File and FSEntry_Open to return a persistent file identifier that Fileswitch and other programs can use to detect if a file has been replaced, and to find an appropriate handle when a moved image is found. |
nemo (145) 2554 posts |
Tim correctly pointed out
This is indeed a long-standing ResourceFS problem which is not specifically to do with your original subject of images – it has always allowed you to Deregister an open file. This is because it does not keep any record of which files it has opened (and, equally, FileSwitch which does know gets no chance to object to the file disappearing). ResourceFS could keep a record (best option), or it could enumerate open files on Deregister. It could then mark such open files as invalid. (I don’t think it’s worth arranging for ResourceFS to ask FileSwitch et al for permission via ServiceCall or equiv.) However, there are things that use magic knowledge about ResourceFS to access data directly. These things are unlikely to notice files closing or new ServiceCalls. In other words, it was always an API design flaw. It’s very much a special case.
All bets are off with ‘remote’ filing systems. The remote machine can be unplugged at any time. One would hope the local FS would notice and return a Channel error or more verbose equivalent. This can apply to a Host filing system too, as you point out.
Well yes, about everything. Rick helpfully experimented
An arguable position, but as we’ve discussed regarding StopClose0 and CloseHook – closing someone else’s file especially with handle reuse is a very bad idea. The now-inaccessible file should go into a zombie state and the FS return a Channel error or equivalent. (I keep saying Channel, but I can’t remember why. Econet?) Tim concluded
Which isn’t going to help any existing FSes, if I understand you correctly. |
Rick Murray (539) 13850 posts |
Econet probably did, but it’s origin was what the tape filing system used to say if you used a “channel” (file handle) that you hadn’t yet opened. Real blast from the past there. I propose we resurrect Channel to give as the error for all “some twat closed your file so you’re screwed” situations. :-) |
nemo (145) 2554 posts |
Is Channel error Nº5? |
Steve Pampling (1551) 8172 posts |
The door is that way —→ |
André Timmermans (100) 655 posts |
On topic of Image filing systems leftovers, I just noticed today that if I perform an “Open directory” in a StrongHelp document and quit StrongHelp the directory is left on screen. |