EMCECS / nfs-client-java

Native Java NFS client
Apache License 2.0
70 stars 33 forks source link

problems about creating directorys #16

Closed AveiShriety closed 6 years ago

AveiShriety commented 7 years ago

@DavidASeibert sorry to ask you some questions agagin! When I create a Single level directory under the nfs-server export directory(e.g : /sharefiles/) ,such as /sharefiles/one, use the java code: NfsSetAttributes nfsSetAttr = new NfsSetAttributes(); nfsSetAttr.setMode((long) (0x00100 + 0x00080 + 0x00040 + 0x00020 + 0x00010 + 0x00008 + 0x00004 + 0x00002)); Nfs3 nfs3 = new Nfs3("192.168.209.94", "/sharefiles/", new CredentialUnix(0, 0, null), 3); Nfs3File test = new Nfs3File(nfs3, "/one/"); test.mkdir(nfsSetAttr); I can create directory /sharefiles/one in the nfs-server.

But, when I want to create Multilevel directory, such as /sharefiles/one/two/three/four/, it throws error java.io.FileNotFoundException: The file handle is null, so this file does not exist., the code: NfsSetAttributes nfsSetAttr = new NfsSetAttributes(); nfsSetAttr.setMode((long) (0x00100 + 0x00080 + 0x00040 + 0x00020 + 0x00010 + 0x00008 + 0x00004 + 0x00002)); Nfs3 nfs3 = new Nfs3("192.168.209.94", "/sharefiles/", new CredentialUnix(0, 0, null), 3); Nfs3File test = new Nfs3File(nfs3, "/one/two/three/four/"); test.mkdir(nfsSetAttr);

So, I wonder how to create Multilevel directory???

DavidASeibert commented 7 years ago

@AveiShriety The NfsFile interface follows the same pattern as java.io.File. Just as for the File class, there are two ways to create multiple directories in a hierarchy. First, create one directory at a time using mkdir(). In this case, the parent directory must already exist. Second, create all necessary directories with default attributes using mkdirs(), then set the attributes later for each.

AveiShriety commented 7 years ago

@DavidASeibert yeah,to your first suggestion, I could do it. Also, I want to learn the second. Like your second suggestion, I use the java code: NfsSetAttributes attr = new NfsSetAttributes(); attr.setMode((long) (0x00100 + 0x00080 + 0x00040 + 0x00020 + 0x00010 + 0x00008 + 0x00004 + 0x00002)); Nfs3 nfs33 = new Nfs3(server, export, new CredentialUnix(0, 0, null), 3); Nfs3File test3 = new Nfs3File(nfs33, "/201706/J030/b04b4758-f98b-4626-8677-386bcedb2278/"); test3.mkdirs(); test3.setAttributes(attr); But error occurs: com.emc.ecs.nfsclient.nfs.NfsException: Error in NfsMkdirRequest serviceVersion:3 xid:-1737996880 usePrivilegedPort:false fileHandle:[107, 41, 1, 0, 0, 0, 2, 0, 107, 41, 1, 0, 0, 0, 2, 0, 67, 49, 122, -26, 80, 2, 18, -4, -61, -113, 117, 20, -97, 26, 37, -63] name:201706 attributes: [mode :null uid: null gid: null size: null atime: timeSettingType:0, [seconds :0 nseconds: 0] mtime: timeSettingType:0, [seconds :0 nseconds: 0]] error code:com.emc.ecs.nfsclient.nfs.NfsStatus@4926097b

Is it wrong in my code? I sincerely want you to help me!

DavidASeibert commented 7 years ago

From the message, it's failing on the first directory creation. My guess is that root doesn't have write permission to the share root folder, although I can't be sure from the error message. You may need to run in the debugger to get more information.

At any rate, your code looks very much like some code from one of my unit tests, https://github.com/EMCECS/nfs-client-java/blob/master/src/test/java/com/emc/ecs/nfsclient/nfs/io/Test_Nfs3File.java#testFileAndDirectoryCreationAndDeletion (line 103). That code works if root has write permission for the share root, so your code should also work.

AveiShriety commented 7 years ago

yeah, it works in my own test environment, but in others' environment, it has the same problem. So I think the key may be the options in nfs server. Always, thank you!

DavidASeibert commented 6 years ago

No client problem remains to be fixed, so I will close this issue.

TheGoldenTiger commented 3 years ago

@AveiShriety How is this problem solved? Is it convenient to answer it, thank you.

601485773 commented 2 years ago

@AveiShriety When creating multi-level directory, I also encountered the same problem, how to solve it? thank you