Is fsync an appropriate way to flush writes to the disk device? In the
FreeBSD code, it is

------------------------
#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
      sleep(2);
      i = ioctl(fd, DIOCGFLUSH);
      cout << "Warning: The kernel may continue to use old or deleted
partitions.\n"
           << "You should reboot or remove the drive.\n";
      platformFound++;
#endif
------------------------

On Wed, Oct 21, 2015 at 11:06 PM, Joel Rees <joel.r...@gmail.com> wrote:
> Okay, here's my current set of diffs for gptfdisk:
> -----------------
> diff --git a/diskio-unix.cc b/diskio-unix.cc
> index af71cdb..83b60f9 100644
> --- a/diskio-unix.cc
> +++ b/diskio-unix.cc
> @@ -248,6 +248,13 @@ int DiskIO::DiskSync(void) {
>             << "You should reboot or remove the drive.\n";
>        platformFound++;
>  #endif

This is what I'm adding for the flush, since I couldn't find
DIOCGFLUSH or an equivalent:

> +#if defined (__OpenBSD__) // Shamelessly parroting the FreeBSD code.
> +      sleep(2);
> +      i = fsync(fd); // Is this how to force a flush on a disk device?
> +      cout << "Warning: The kernel may continue to use old or deleted
> partitions.\n"
> +           << "You should reboot or remove the drive.\n";
> +      platformFound++;
> +#endif
>  #ifdef __linux__
>        sleep(1); // Theoretically unnecessary, but ioctl() fails
> sometimes if omitted....
>        fsync(fd);
> diff --git a/diskio.h b/diskio.h
> index 631a43a..c198f29 100644
>
> --- a/diskio.h
> +++ b/diskio.h
> @@ -29,7 +29,7 @@
>  #include <sys/dkio.h>
>  #endif
>
> -#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined
> (__APPLE__)
> +#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined
> (__OpenBSD__) || defined (__APPLE__)
>  #define fstat64 fstat
>  #define stat64 stat
>  #endif
> diff --git a/guid.cc b/guid.cc
> index 1e73ab7..0fd8bfe 100644
> --- a/guid.cc
> +++ b/guid.cc
> @@ -147,6 +147,8 @@ void GUIDData::Randomize(void) {
>     ReverseBytes(&uuidData[4], 2);
>     ReverseBytes(&uuidData[6], 2);
>     uuidGenerated = 1;
> +#else
>
> +#  warning "not compiling in the uuid_generate()"
>  #endif
>  #if defined (_RPC_H) || defined (__RPC_H__)
>     UUID MsUuid;
> diff --git a/support.h b/support.h
> index b888d92..dd3ea03 100644
> --- a/support.h
> +++ b/support.h
> @@ -10,7 +10,7 @@
>
>  #define GPTFDISK_VERSION "1.0.1"
>
> -#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined
> (__APPLE__)
> +#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) ||
> (__OpenBSD__) || defined (__APPLE__)
>  // Darwin (Mac OS) & FreeBSD: disk IOCTLs are different, and there is
> no lseek64
>  #include <sys/disk.h>
>  #define lseek64 lseek
> -----------------
>
> Very lightly tested, but it seems to be functional, to some degree.
>
> -- Joel Rees



-- 
Joel Rees

Be careful when you look at conspiracy.
Arm yourself with knowledge of yourself, as well:
http://reiisi.blogspot.jp/2011/10/conspiracy-theories.html

Reply via email to