readonly mode when mounting a partition

I think we need a way to handle read only partitions. I think that every time somone tryes to write or change something on a partition there should be a callback to the FileSystem implementation for that partition and if the partition is readonly the user should get an error. is this possible? if not than we should have a standard exception like ReadOnlyFileSystemException that can be thrown in all write methods if the FS is readonly. And this exception can be processed somewhere else. What do you think?

ReadOnlyFileSystemException seems a good choice

By throwing ReadOnlyFileSystemException that extends IOException,
we can transparently inform the caller of a read method (OutputStream) of a problem.

FileSystem interface should have 2 methods named setReadOnly an isReadOnly, otherwise the specified , the FS is R/W (except for CDROM, but R/W if CDRW).

who can do that?

I don't have enaugh knowledge about the FS module to do this but maybe one of you can do it. I think this exception should be thrown before reaching the driver but I am not sure if there is such place. Anyhow it would be nice to have it. Will someone do it?

I will do that

It seem not too difficult to do for a first contribution to the dev.

As soon as I can (I asked epr for an access to CVS), I will add it to the FS module.

FileHandleImpl

Probably org.jnode.fs.service.def.FileHandleImp() is a good place to add this, imho.
Ext2 currently handles this in the Ext2Directory (I seem to forgot to add it to Ext2File), throwing an IOException if a file is added to a readOnly fileSystem, but I will remove it if you add it to the VFS layer.

As Levente has suggested it, it would be good if we could remount a partition with different fs options. Could you look into that?

Andras

Yes and no

In FileSystem, we can handle this better because not only files can't be wrote, there is also directory and at lower all sectors of the file system.

In FileHandleImpl, we can force the file to be readonly if the FileSystem is readonly. But I don't see a direct reference to the FileSystem.

we need than an exception

We need more than an exception, we need also a mechanism that can handle this kind of exception and present it to the user somehow. The question :"what heapens when the exception is thrown?" must have also an answer.

FileNotFoundException

Currently FileOutputStream throws a FileNotFoundException if the attempt to write the file fails. This conforms to Sun's FileOutputStream implementation, with the exception that it adds the text "(Read-only filesystem)" to the exception's description:
Exception in thread "main" java.io.FileNotFoundException: /cdrom/file1 (Read-only file system)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.(FileOutputStream.java:176)
at java.io.FileOutputStream.(FileOutputStream.java:70)
at WriteTest.main(WriteTest.java:5)

In JNode I have added the IOException as root cause to the FileNotFoundException, but if we define a separate ReadOnlyFileSystemException then it's possible to implement it similar to the Sun's solution and append a little explanation to the description.

Is this what you though of?

Yes, we need

I agree with you but for a first time :
- we only need to throw this exception without modification to the rest of the code
- we will just have a bad stacktrace with an IOException (the ReadOnlyFileSystemException in fact).

For a second time, we can handle this ReadOnlyFileSystemException in the shell for example (and later in the GUI).

Good idea!

It would be useful to have a simple command for mounting and unmounting partitions with support for mounting in read-only and read-write modes. Something similar to the 'mount' command in Linux.