ceph_shutdown(cmount);
}
+
+TEST(LibCephFS, Lseek) {
+ struct ceph_mount_info *cmount;
+ ASSERT_EQ(0, ceph_create(&cmount, NULL));
+ ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL));
+ ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL));
+ ASSERT_EQ(0, ceph_mount(cmount, "/"));
+
+ char c_path[1024];
+ sprintf(c_path, "test_lseek_%d", getpid());
+ int fd = ceph_open(cmount, c_path, O_RDWR|O_CREAT|O_TRUNC, 0666);
+ ASSERT_LT(0, fd);
+
+ const char *out_buf = "hello world";
+ size_t size = strlen(out_buf);
+ ASSERT_EQ(ceph_write(cmount, fd, out_buf, size, 0), (int)size);
+
+ /* basic SEEK_SET/END/CUR tests */
+ ASSERT_EQ(0, ceph_lseek(cmount, fd, 0, SEEK_SET));
+ ASSERT_EQ(size, ceph_lseek(cmount, fd, 0, SEEK_END));
+ ASSERT_EQ(0, ceph_lseek(cmount, fd, -size, SEEK_CUR));
+
+ /* Test basic functionality and out of bounds conditions for SEEK_HOLE/DATA */
+#ifdef SEEK_HOLE
+ ASSERT_EQ(size, ceph_lseek(cmount, fd, 0, SEEK_HOLE));
+ ASSERT_EQ(-ENXIO, ceph_lseek(cmount, fd, -1, SEEK_HOLE));
+ ASSERT_EQ(-ENXIO, ceph_lseek(cmount, fd, size + 1, SEEK_HOLE));
+#endif
+#ifdef SEEK_DATA
+ ASSERT_EQ(0, ceph_lseek(cmount, fd, 0, SEEK_DATA));
+ ASSERT_EQ(-ENXIO, ceph_lseek(cmount, fd, -1, SEEK_DATA));
+ ASSERT_EQ(-ENXIO, ceph_lseek(cmount, fd, size + 1, SEEK_DATA));
+#endif
+
+ ASSERT_EQ(0, ceph_close(cmount, fd));
+ ceph_shutdown(cmount);
+}