mirage / ocaml-vhd

Read and write .vhd format data
Other
9 stars 20 forks source link

CA-212154 retry if lseek(2) doesn't support SEEK_DATA, SEEK_HOLE #35

Closed lindig closed 8 years ago

lindig commented 8 years ago

This commit adds support for file systems that don't support lseek(.., SEEK_HOLE) and lseek(,,,, SEEK_DATA). It corrects a bug that was introduced in a previous pull request https://github.com/djs55/ocaml-vhd/pull/34. See a discussion of the design there. The bug introduced there was:

#if defined(SEEK_HOLE)
  c_ret = lseek(c_fd, c_ofs, SEEK_HOLE);
  /* retry, if SEEK_HOLE not supported on this file system */
  if (c_ret == -1 && errno == EINVAL)
    c_ret = lseek(c_fd, c_ofs, SEEK_END);  /* <<< HERE */
#else
  /* Set the file pointer to the end of the file; pretend
     there is no hole */
  c_ret = lseek(c_fd, 0, SEEK_END);
#endif

The offset when calling lseek in the retry must be 0, not c_ofs - just like in the #else case.

jonludlam commented 8 years ago

The tests are failing due to the lack of an opam file. This has been fixed in master, so I'm going to merge this anyway.