return result;
}
+/*
+ * Class: org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method: ceph_stat
+ * Signature: (Ljava/lang/String;Lorg/apache/hadoop/fs/ceph/CephFileSystem/Stat;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1stat
+(JNIEnv * env, jobject obj, jstring j_path, jobject j_stat) {
+ //setup variables
+ struct stat st;
+ const char* c_path = env->GetStringUTFChars(j_path, 0);
+
+ jclass cls = env->GetObjectClass(j_stat);
+ jfieldID c_size_id = env->GetFieldID(cls, "size", "J");
+ jfieldID c_dir_id = env->GetFieldID(cls, "is_dir", "Z");
+ jfieldID c_block_id = env->GetFieldID(cls, "block_size", "J");
+ jfieldID c_mod_id = env->GetFieldID(cls, "mod_time", "J");
+ jfieldID c_access_id = env->GetFieldID(cls, "access_time", "J");
+ jfieldID c_mode_id = env->GetFieldID(cls, "mode", "I");
+ jfieldID c_user_id = env->GetFieldID(cls, "user_id", "I");
+ jfieldID c_group_id = env->GetFieldID(cls, "group_id", "I");
+
+ //do actual lstat
+ int r = ceph_lstat(c_path, &st);
+
+ if (r < 0) { //clean up variables and fail out; file DNE or Ceph broke
+ env->ReleaseStringUTFChars(j_path, c_path);
+ return false;
+ }
+
+ //put variables from struct stat into Java
+ env->SetLongField(j_stat, c_size_id, (long)st.st_size);
+ env->SetBooleanField(j_stat, c_dir_id, (0 != S_ISDIR(st.st_mode)));
+ env->SetLongField(j_stat, c_block_id, (long)st.st_blksize);
+ env->SetLongField(j_stat, c_mod_id, (long long)st.st_mtime);
+ env->SetLongField(j_stat, c_access_id, (long long)st.st_atime);
+ env->SetIntField(j_stat, c_mode_id, (int)st.st_mode);
+ env->SetIntField(j_stat, c_user_id, (int)st.st_uid);
+ env->SetIntField(j_stat, c_group_id, (int)st.st_gid);
+
+ //clean up variables
+ env->ReleaseStringUTFChars(j_path, c_path);
+
+ //return happy
+ return true;
+}
JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephOutputStream_ceph_1write
(JNIEnv *, jobject, jint, jbyteArray, jint, jint);
+/*
+ * Class: org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method: ceph_stat
+ * Signature: (Ljava/lang/String;Lorg/apache/hadoop/fs/ceph/CephFileSystem/Stat;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1stat
+ (JNIEnv *, jobject, jstring, jobject);
+
#ifdef __cplusplus
}
#endif
import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.FsPermission;
+import org.apache.hadoop.fs.permission.FsAction;
import org.apache.hadoop.util.Progressable;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.CreateFlag;
private native int ceph_open_for_read(String path);
private native int ceph_open_for_overwrite(String path, int mode);
private native boolean ceph_kill_client();
-
+ private native boolean ceph_stat(String path, Stat fill);
public CephFileSystem() {
debug("CephFileSystem:enter");
root = new Path("/");
public FileStatus getFileStatus(Path p) throws IOException {
debug("getFileStatus:enter with path " + p);
Path abs_p = makeAbsolute(p);
- // For the moment, hardwired replication and modification time
+ // For the moment, hardwired replication
int replication = 2;
- int mod_time = 0;
FileStatus status;
- if (isFile(abs_p)) {
- debug("getFileStatus: is file");
- status = new FileStatus(__getLength(abs_p), false, replication, getBlockSize(abs_p),
- mod_time, abs_p);
- }
- else if (__isDirectory(abs_p)) {
- debug("getFileStatus: is directory");
- status = new FileStatus( 0, true, replication, 0,
- mod_time, abs_p);
+ Stat lstat = new Stat();
+ if(ceph_stat(abs_p.toString(), lstat)) {
+ status = new FileStatus(lstat.size, lstat.is_dir, replication,
+ lstat.block_size, lstat.mod_time, lstat.access_time,
+ new FsPermission((short)lstat.mode),
+ new Integer(lstat.user_id).toString(),
+ new Integer(lstat.group_id).toString(), abs_p);
}
else { //fail out
- throw new FileNotFoundException("org.apache.hadoop.fs.ceph.CephFileSystem: File "
- + p + " does not exist.");
+ throw new FileNotFoundException("org.apache.hadoop.fs.ceph.CephFileSystem: File "
+ + p + " does not exist or could not be accessed");
}
debug("getFileStatus:exit");
return status;
return statuses;
}
+ @Override
+ public void setPermission(Path p, FsPermission permission) throws IOException {
+
+ }
public FSDataOutputStream create(Path f,
FsPermission permission,
EnumSet<CreateFlag> flag,
if (debug) System.err.println(statement);
}
- // diagnostic methods
-
- /* void dump() throws IOException {
- store.dump();
- }
-
- void purge() throws IOException {
- store.purge();
- }*/
-
+ private class Stat {
+ public long size;
+ public boolean is_dir;
+ public long block_size;
+ public long mod_time;
+ public long access_time;
+ public int mode;
+ public int user_id;
+ public int group_id;
+
+ public Stat(){}
+ }
}
JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1kill_1client
(JNIEnv *, jobject);
+/*
+ * Class: org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method: ceph_stat
+ * Signature: (Ljava/lang/String;Lorg/apache/hadoop/fs/ceph/CephFileSystem/Stat;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1stat
+ (JNIEnv *, jobject, jstring, jobject);
+
#ifdef __cplusplus
}
#endif