mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
Add exception
"add exception in java sdk" Signed-off-by: zhangxiangping <240133996@qq.com>
This commit is contained in:
parent
3d3377c150
commit
fa2ae70c98
@ -6,6 +6,9 @@ import com.sun.jna.Pointer;
|
||||
import io.chubao.fs.CfsLibrary.Dirent;
|
||||
import io.chubao.fs.CfsLibrary.DirentArray;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
public class CfsMount {
|
||||
// Open flags
|
||||
public static final int O_RDONLY = 0;
|
||||
@ -36,6 +39,9 @@ public class CfsMount {
|
||||
public static final int SETATTR_MTIME = 8;
|
||||
public static final int SETATTR_ATIME = 16;
|
||||
|
||||
//success single
|
||||
public static final int SUCCESS = 0;
|
||||
|
||||
private CfsLibrary libcfs;
|
||||
private String libpath;
|
||||
private long cid; // client id allocated by libcfs library
|
||||
@ -66,16 +72,28 @@ public class CfsMount {
|
||||
return libcfs.cfs_getcwd(this.cid);
|
||||
}
|
||||
|
||||
public int getAttr(String path, CfsLibrary.StatInfo stat) {
|
||||
return libcfs.cfs_getattr(this.cid, path, stat);
|
||||
public int getAttr(String path, CfsLibrary.StatInfo stat) throws FileNotFoundException {
|
||||
int result = libcfs.cfs_getattr(this.cid, path, stat);
|
||||
if (result != SUCCESS) {
|
||||
throw new FileNotFoundException("getAttr failed :" + path + " code : " + result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int setAttr(String path, CfsLibrary.StatInfo stat, int mask) {
|
||||
return libcfs.cfs_setattr(this.cid, path, stat, mask);
|
||||
public int setAttr(String path, CfsLibrary.StatInfo stat, int mask) throws FileNotFoundException {
|
||||
int result = libcfs.cfs_setattr(this.cid, path, stat, mask);
|
||||
if (result != SUCCESS) {
|
||||
throw new FileNotFoundException("setAttr failed : " + path + " code : " + result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int open(String path, int flags, int mode) {
|
||||
return libcfs.cfs_open(this.cid, path, flags, mode);
|
||||
public int open(String path, int flags, int mode) throws FileNotFoundException {
|
||||
int result = libcfs.cfs_open(this.cid, path, flags, mode);
|
||||
if (result < 0) {
|
||||
throw new FileNotFoundException("open failed : " + path + " code : " + result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void close(int fd) {
|
||||
@ -112,23 +130,40 @@ public class CfsMount {
|
||||
return (int) arrSize;
|
||||
}
|
||||
|
||||
public int mkdirs(String path, int mode) {
|
||||
return libcfs.cfs_mkdirs(this.cid, path, mode);
|
||||
public int mkdirs(String path, int mode) throws IOException {
|
||||
int result = libcfs.cfs_mkdirs(this.cid, path, mode);
|
||||
if (result != SUCCESS) {
|
||||
throw new IOException("mkdirs failed : " + path + " code : " + result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int rmdir(String path) {
|
||||
return libcfs.cfs_rmdir(this.cid, path);
|
||||
public int rmdir(String path) throws FileNotFoundException {
|
||||
int result = libcfs.cfs_rmdir(this.cid, path);
|
||||
if (result != SUCCESS) {
|
||||
throw new FileNotFoundException("rmdir failed : " + path + " code : " + result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int unlink(String path) {
|
||||
return libcfs.cfs_unlink(this.cid, path);
|
||||
public int unlink(String path) throws FileNotFoundException {
|
||||
int result = libcfs.cfs_unlink(this.cid, path);
|
||||
if (result != SUCCESS) {
|
||||
throw new FileNotFoundException("unlink failed : " + path + " code : " + result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int rename(String from, String to) {
|
||||
return libcfs.cfs_rename(this.cid, from, to);
|
||||
public int rename(String from, String to) throws FileNotFoundException {
|
||||
int result = libcfs.cfs_rename(this.cid, from, to);
|
||||
if (result != SUCCESS) {
|
||||
throw new FileNotFoundException("rename failed: from: " + from + " to: " + to);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int fchmod(int fd, int mode) {
|
||||
return libcfs.cfs_fchmod(this.cid, fd, mode);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,8 +2,10 @@ package io.chubao.fs;
|
||||
|
||||
import io.chubao.fs.CfsLibrary.Dirent;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
public class TestCfsClient {
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws FileNotFoundException {
|
||||
CfsMount mnt = new CfsMount("/usr/lib/libcfs.so");
|
||||
|
||||
mnt.setClient("volName", "ltptest");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user