- fprintf(stderr, "usage: %s <filepath>\n",
- prog);
- fprintf(stderr, "the absolute path of a test file on a "
- "lustre file system is needed.\n");
- exit(1);
+ int fd2, rc, len, offset;
+ struct stat st;
+ char *readbuf = NULL;
+
+ /* Open the file handle */
+ fd2 = open_by_handle_at(mnt_fd, fh, O_RDONLY);
+ if (fd2 < 0) {
+ fprintf(stderr, "open_by_handle_at(%s) error: %s\n", filename,
+ strerror(errno));
+ rc = errno;
+ goto out_f_handle;
+ }
+
+ /* Get file size */
+ bzero(&st, sizeof(struct stat));
+ rc = fstat(fd2, &st);
+ if (rc < 0) {
+ fprintf(stderr, "fstat(%s) error: %s\n", filename,
+ strerror(errno));
+ rc = errno;
+ goto out_fd2;
+ }
+
+ /* we can't check a ctime due unlink update */
+ if (st_orig->st_size != st.st_size ||
+ st_orig->st_ino != st.st_ino ||
+ st_orig->st_mtime != st.st_mtime) {
+ fprintf(stderr, "stat data does not match between fopen "
+ "and fhandle case\n");
+ rc = EINVAL;
+ goto out_fd2;
+ }
+
+ if (st.st_size) {
+ len = st.st_blksize;
+ readbuf = malloc(len);
+ if (readbuf == NULL) {
+ fprintf(stderr, "malloc(%d) error: %s\n", len,
+ strerror(errno));
+ rc = errno;
+ goto out_fd2;
+ }
+
+ for (offset = 0; offset < st.st_size; offset += len) {
+ /* read from the file */
+ rc = read(fd2, readbuf, len);
+ if (rc < 0) {
+ fprintf(stderr, "read(%s) error: %s\n",
+ filename, strerror(errno));
+ rc = errno;
+ goto out_readbuf;
+ }
+ }
+ }
+ rc = 0;
+out_readbuf:
+ free(readbuf);
+out_fd2:
+ close(fd2);
+out_f_handle:
+ return rc;