able to write named attributes to a read only file (Solaris)
Rajendra Gutupalli
Rajendra.Gutupalli at Sun.COM
Tue Jun 10 03:23:15 PDT 2008
Hi Alan,
It is surprising that I am able to add named attributes to a file with
read only permissions in Solaris where as it throws FSE:Permission
denied in Linux for the read only file.
Please see the following series of events I did in Solaris machine.
1) created a file "testfile1" set permissions to 777 and added a named
attribute attr.2
2) changed the file "testfile1" permissions to 400 and tried adding
attribute attr.3. it went successfully and used 'runat' command tool to
see what are the attributes in files namespace.
3) changed file permissions of a attribute attr.3 and tried to
replace the attribute now I got FSE: Permission denied exception.
4) Again I added one more attribute attr.4 . it is successfully added to
the same file "testfile1" with .
5) finally checked file permissions.
Here the file "testfile1" lies in NFSV4 mounted volume. I tried in local
file system in Solaris and the behavior was same.
<machine details>
bash-3.00$ uname -a
SunOS m/c name 5.10 Generic_120012-14 i86pc i386 i86pc
</machine details>
<begin>
1)
bash-3.00$ touch testfile1
bash-3.00$ chmod 777 testfile1
bash-3.00$ ls -l testfile1
-rwxrwxrwx 1 rg157576 staff 0 Jun 10 14:55 testfile1
bash-3.00$ $jdk/java NamedTest testfile1
new value hello
2)
bash-3.00$ chmod 400 testfile1
bash-3.00$ ls -l testfile1
-r-------- 1 rg157576 staff 0 Jun 10 14:56 testfile1
bash-3.00$ $jdk/java NamedTest testfile1
new value hello
bash-3.00$ runat testfile1 /bin/sh
$ ls -l
total 4
-rwxrwxrwx 1 rg157576 staff 5 Jun 10 14:56 attr.2
-rwxrwxrwx 1 rg157576 staff 5 Jun 10 14:58 attr.3
3)
$ chmod 400 attr.3
$ exit
bash-3.00$ $jdk/java NamedTest testfile1
Exception in thread "main" java.nio.file.FileSystemException: testfile1:
Unable to get write extended attribute 'attr.3': Permission denied
at
sun.nio.fs.SolarisNamedAttributeView.write(SolarisNamedAttributeView.java:204)
at NamedTest.main(NamedTest.java:13)
bash-3.00$ $jdk/java NamedTest testfile1
new value hello
bash-3.00$ runat testfile1 /bin/sh
$ ls -l
total 6
-rwxrwxrwx 1 rg157576 staff 5 Jun 10 14:56 attr.2
-r-------- 1 rg157576 staff 5 Jun 10 14:58 attr.3
-rwxrwxrwx 1 rg157576 staff 5 Jun 10 15:00 attr.4
bash-3.00$ ls -l testfile1
-r-------- 1 rg157576 staff 0 Jun 10 14:56 testfile1
<end>
<code>
bash-3.00$ cat NamedTest.java
import java.nio.ByteBuffer;
import java.nio.file.*;
import java.nio.file.attribute.*;
public class NamedTest {
public static void main(String... args) throws Exception {
Path path = Path.get(args[0]);
ByteBuffer bb =ByteBuffer.allocate(20);
NamedAttributeView nav =
path.newFileAttributeView(NamedAttributeView.class,true);
ByteBuffer bb1 = ByteBuffer.wrap("hello".getBytes());
nav.write("attr.4",bb1);
ByteBuffer bb2 = ByteBuffer.allocate(20);
nav.read("attr.4",bb2);
System.out.println("new value " + new String(bb2.array()));
}
}
</code>
Thanks
Rajendra.
More information about the nio-dev
mailing list