private static native int native_ceph_chmod(long mountp, String path, int mode);
+ /**
+ * Change file mode of an open file.
+ *
+ * @param fd The open file descriptor to change the mode bits on.
+ * @param mode New mode bits.
+ */
+ public void fchmod(int fd, int mode) {
+ rlock.lock();
+ try {
+ native_ceph_fchmod(instance_ptr, fd, mode);
+ } finally {
+ rlock.unlock();
+ }
+ }
+
+ private static native int native_ceph_fchmod(long mountp, int fd, int mode);
+
/**
* Truncate a file to a specified length.
*
return ret;
}
+/*
+ * Class: com_ceph_fs_CephMount
+ * Method: native_ceph_fchmod
+ * Signature: (JII)I
+ */
+JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1fchmod
+ (JNIEnv *env, jclass clz, jlong j_mntp, jint j_fd, jint j_mode)
+{
+ struct ceph_mount_info *cmount = get_ceph_mount(j_mntp);
+ CephContext *cct = ceph_get_mount_context(cmount);
+ int ret;
+
+ CHECK_MOUNTED(cmount, -1);
+
+ ldout(cct, 10) << "jni: fchmod: fd " << (int)j_fd << " mode " << (int)j_mode << dendl;
+
+ ret = ceph_fchmod(cmount, (int)j_fd, (int)j_mode);
+
+ ldout(cct, 10) << "jni: fchmod: exit ret " << ret << dendl;
+
+ if (ret)
+ handle_error(env, ret);
+
+ return ret;
+}
+
/*
* Class: com_ceph_fs_CephMount
* Method: native_ceph_truncate
mount.unlink(path);
}
+ /*
+ * fchmod
+ */
+
+ @Test
+ public void test_fchmod() throws Exception {
+ /* create a file */
+ String path = makePath();
+ int fd = createFile(path, 1);
+
+ CephStat st = new CephStat();
+ mount.lstat(path, st);
+
+ /* flip a bit */
+ int mode = st.mode;
+ if ((mode & 1) != 0)
+ mode -= 1;
+ else
+ mode += 1;
+
+ mount.fchmod(fd, mode);
+ mount.close(fd);
+
+ CephStat st2 = new CephStat();
+ mount.lstat(path, st2);
+ assertTrue(st2.mode == mode);
+
+ mount.unlink(path);
+ }
+
/*
* truncate
*/
public void test_get_pool_replication() throws Exception {
mount.get_pool_replication(1);
}
+
+ @Test(expected=CephNotMountedException.class)
+ public void test_fchmod() throws Exception {
+ mount.fchmod(1, 0);
+ }
}