[cp-patches] RFC: File bug Fix and small VM interface change

Mario Torre mario.torre at aicas.com
Wed Apr 9 18:43:47 UTC 2008


Hello all!

I would like to submit this fix.

The problem is that to detect if a file is writable we actually open it
for writing... Even worse, in the case of a directory, we write to it a
temp file!

There are a number of issues that I see wrong here, but what worries me
most is that these operations can kill filesystem that reside on compact
flash memories and other devices that have a limited number of write.

The current fix does two things.

1. introduce a new method, native, canWriteDirectory(String path)
This method is meant to be implemented by whoever implements the VM
interface, so that it can do nice things with their target environment.
The default implementation works on Linux and should work on any *nix
operating systems. I've left canWriteDirectory(File file) for backward
compatibility, but I guess no one uses this anyway (it defer to the
native method).

2. Change the implementation of Java_java_io_VMFile_canWrite and
Java_java_io_VMFile_canRead so that they use cpio_checkAccess now,
instead of doing the old "The lazy man's way out" (which is also more
code, btw...)

I'm going to submit this today if no one complains, any ideas?

Ah, before I forget, there are a number of unrelated fixes like
indentation and all the function signature now reflect the fact that
these methods are static (jclass instead of jobject). It would be handy
here to use mercurial (hg record) to separate patchsets.

Mario


2008-04-09  Mario Torre  <neugens at aicas.com>
 
	* java/io/File.java (canWrite): use canWriteDirectory(String). 
	* vm/reference/java/io/VMFile.java (canWriteDirectory): new native
method. 
	* native/jni/java-io/java_io_VMFile.c: correct indentation, sync
function
	names with header file definition.
	(Java_java_io_VMFile_canRead): use cpio_checkAccess to get access
	permission. Removed unused variable.
    (Java_java_io_VMFile_canWrite): likewise.
    (Java_java_io_VMFile_canWriteDirectory): new function.
-- 
Mario Torre, Software Developer, http://www.jroller.com/neugens/
aicas Allerton Interworks Computer Automated Systems GmbH
Haid-und-Neu-Straße 18 * D-76131 Karlsruhe * Germany
http://www.aicas.com   * Tel: +49-721-663 968-53
pgp key: http://subkeys.pgp.net/ PGP Key ID: 80F240CF
Fingerprint: BA39 9666 94EC 8B73 27FA  FC7C 4086 63E3 80F2 40CF

USt-Id: DE216375633, Handelsregister HRB 109481, AG Mannheim
Geschäftsführer: Dr. James J. Hunt

Please, support open standards:
http://opendocumentfellowship.org/petition/
http://www.nosoftwarepatents.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2008-04-09-file-and-vm.patch
Type: text/x-patch
Size: 10629 bytes
Desc: not available
Url : http://developer.classpath.org/pipermail/classpath-patches/attachments/20080409/b2523588/2008-04-09-file-and-vm.bin


More information about the Classpath-patches mailing list