Return-Path: <awaresystems.be+caf_=filtered=awaresystems.be@gmail.com>
Delivered-To: filtered@awaresystems.be
Received: from mx2.public.one.com ([10.246.18.22])
	by mail6.local.one.com (Dovecot) with LMTP id COw4NqVnI1lHqwAAsyOMew
	for <filtered@awaresystems.be>; Mon, 22 May 2017 22:51:01 +0000
X-HalOne-ID: 1ef3d37f-3f41-11e7-a670-b82a72d88088
Received: from mail-oi0-f42.google.com (unknown [209.85.218.42])
	by mx2.public.one.com (Halon) with ESMTPS
	id 1ef3d37f-3f41-11e7-a670-b82a72d88088;
	Mon, 22 May 2017 22:50:59 +0000 (UTC)
Received: by mail-oi0-f42.google.com with SMTP id w10so180679532oif.0
        for <filtered@awaresystems.be>; Mon, 22 May 2017 15:50:59 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-original-authentication-results:x-gm-message-state:delivered-to
         :date:from:to:in-reply-to:message-id:references:user-agent
         :mime-version:cc:subject:precedence:list-id:list-unsubscribe
         :list-archive:list-post:list-help:list-subscribe
         :content-transfer-encoding:sender:errors-to;
        bh=fnLRgkIgNz3Zzi927+fmaT8encd6puNkfHMZ06MIXeg=;
        b=SVkFVCXGGKECNr2oRo/Q1r0AoGnIVpCVEB4EZrJOFuayJlisyZbKXgonpN+1fZCV4T
         VogW//OKXwwbYNyqXbws55es4Ya5FKO6ZgrnEkac2CFQZ78IjotKfxgYX859AIRIZvd6
         r0+49KUxlVyQDyUBXoVRYdBL/8XR9iaoiIiJw7KidXkzrar4qGVGQEW1z2k2+wWTAPFE
         ZRNBpY/0TKirT6PkZePlolTdi7AJsRaYfiS8E079ZZLF/O8smg5InTpfFvrFY1m7+mEB
         /Q0llUrtOSpDdJ3tW9ccNmnTbiui5cwjyGkovBE0Sl0Vx4DXHa5hhS7PWLVQSVBcBwbU
         0GZA==
X-Original-Authentication-Results: mx.google.com;       spf=neutral (google.com: 94.23.4.142 is neither permitted nor denied by best guess record for domain of tiff-bounces@lists.maptools.org) smtp.mailfrom=tiff-bounces@lists.maptools.org
X-Gm-Message-State: AODbwcDr0E5IPqgjCq9wHdR9JsG9EWBeaZpWaRCx4A4wzx0MXiHfL7iE
	COMRQ0aA3lio5LBgcpsMAsOG/pZADOpcac4cJhj4lw==
X-Received: by 10.202.222.70 with SMTP id v67mr11791905oig.88.1495493457802;
        Mon, 22 May 2017 15:50:57 -0700 (PDT)
X-Forwarded-To: filtered@awaresystems.be
X-Forwarded-For: awaresystems.be@gmail.com filtered@awaresystems.be
Delivered-To: awaresystems.be@gmail.com
Received: by 10.202.104.144 with SMTP id o16csp1440404oik;
        Mon, 22 May 2017 15:50:56 -0700 (PDT)
X-Received: by 10.28.191.26 with SMTP id p26mr72215wmf.54.1495493456361;
        Mon, 22 May 2017 15:50:56 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1495493456; cv=none;
        d=google.com; s=arc-20160816;
        b=LKXTnGi8rMB/6VWXRvIngM2Ryo6e3cz2T1yEJ46d/cPjnw15V8S1vMLBEfgWe7ThdO
         DE9WtNCx8aXddJ5kmvYalW+4l0nekh6mue5nkoAlDvWaksC4xxBGs3zz7SVeNbk3IoBS
         K2Kj876Tka3ESYcRfx8WN6gs3MZnUTsOBA/X/lIPtWASsIPYCxaf22VR43V7oOWb56ak
         VUu5xKkvYQCRgwDPzdlwqOMAGULsUk8X67pFJ7gSava5GlbVZRgs6CReGBbAAcMEM4bG
         il2MaZGngC8LIXRZSAFGVmw05ISArOyL0zD9OOtSskUiVS+W+FIvYVLLKcRauO2i/dds
         hAtA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help
         :list-post:list-archive:list-unsubscribe:list-id:precedence:subject
         :cc:mime-version:user-agent:references:message-id:in-reply-to:to
         :from:date:arc-authentication-results;
        bh=fnLRgkIgNz3Zzi927+fmaT8encd6puNkfHMZ06MIXeg=;
        b=A2lD28Jd/5zKD1tRDYGnQF1mtQqOVGKCkfRRb3tajV4TiEy+8Pq7RnFsFVGniAIU7c
         +FTG2Y/FFWnALrJPIptm3f0orLHsVA7fhsAauRG6FLwwmPFdMPLl1bGsf7KHOuhdzmmN
         z/iPfU6W7XO2xQpl8b/U/snML5yGhbQA5XTEUbGYHWDabfDxpenvttTVDja7MFMbhrCY
         DPrD+xJGqAynE2coLgPo20s69l7AABXfXN3RpEhvT2+hlZ71CrXcmdh4/Xv+eZWWXNvE
         8Nr6smgOWFRskLItY+ydEVtf4uW6kl+Miiv8Wvr+cn4aVfeoPCjIVBfNPEuQCOIcX4k8
         asvA==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=neutral (google.com: 94.23.4.142 is neither permitted nor denied by best guess record for domain of tiff-bounces@lists.maptools.org) smtp.mailfrom=tiff-bounces@lists.maptools.org
Return-Path: <tiff-bounces@lists.maptools.org>
Received: from lists.maptools.org (ks365428.kimsufi.com. [94.23.4.142])
        by mx.google.com with ESMTP id e133si111348wma.1.2017.05.22.15.50.55;
        Mon, 22 May 2017 15:50:56 -0700 (PDT)
Received-SPF: neutral (google.com: 94.23.4.142 is neither permitted nor denied by best guess record for domain of tiff-bounces@lists.maptools.org) client-ip=94.23.4.142;
Authentication-Results: mx.google.com;
       spf=neutral (google.com: 94.23.4.142 is neither permitted nor denied by best guess record for domain of tiff-bounces@lists.maptools.org) smtp.mailfrom=tiff-bounces@lists.maptools.org
Received: from [10.1.0.241] (localhost.localdomain [127.0.0.1])
	by lists.maptools.org (Postfix) with ESMTP id 97E7335C073;
	Mon, 22 May 2017 17:49:58 -0500 (EST)
Received: from smtp.simplesystems.org (smtp.simplesystems.org [65.66.246.90])
	by lists.maptools.org (Postfix) with ESMTPS id 7D6C235C033
	for <tiff@lists.maptools.org>; Mon, 22 May 2017 17:44:27 -0500 (EST)
Received: from scrappy.simplesystems.org (scrappy.simplesystems.org
	[65.66.246.73])
	by smtp.simplesystems.org (8.14.4+Sun/8.14.4) with ESMTP id
	v4MMiCZj018991; Mon, 22 May 2017 17:44:13 -0500 (CDT)
Date: Mon, 22 May 2017 17:44:12 -0500 (CDT)
From: Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
X-X-Sender: bfriesen@scrappy.simplesystems.org
To: Roger Leigh <rleigh@codelibre.net>
In-Reply-To: <f56844eb-50b6-c3cb-d634-688dccc35bad@codelibre.net>
Message-ID: <alpine.GSO.2.20.1705221735170.23240@scrappy.simplesystems.org>
References: <f56844eb-50b6-c3cb-d634-688dccc35bad@codelibre.net>
User-Agent: Alpine 2.20 (GSO 67 2015-01-07)
MIME-Version: 1.0
X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16
	(smtp.simplesystems.org [65.66.246.90]);
	Mon, 22 May 2017 17:44:13 -0500 (CDT)
Cc: TIFF mailing list <tiff@lists.maptools.org>
Subject: Re: [Tiff] Support for fsync
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: TIFF and libtiff discussion <tiff.lists.maptools.org>
List-Unsubscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=unsubscribe>
List-Archive: <http://lists.maptools.org/mailman/private/tiff>
List-Post: <mailto:tiff@lists.maptools.org>
List-Help: <mailto:tiff-request@lists.maptools.org?subject=help>
List-Subscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=subscribe>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org

On Mon, 22 May 2017, Roger Leigh wrote:
>
> Would it be worth considering the addition of a new function e.g.
> TIFFSync[Data] which would simply call fsync(2) or its Windows
> equivalent on the open file?  It could potentially also call TIFFlush
> internally to be sure it's committing a consistent state.  This would
> mean I can issue TIFFSync() prior to TIFFClose, or TIFFSyncData as I
> write out each IFD, and be sure the the data writes completed when the
> call returns (or failed).

GraphicsMagick provides an option (MAGICK_IO_FSYNC=TRUE environment 
variable) to fsync after a file is written.  I don't know if anyone 
uses it.

I think that your proposal worth considering and implementing.  All 
that is needed is a source patch, with associated documentation.

Unless the parent directory is also synchronized, there is a 
possibility of losing a whole new file, even if fsync has been called 
on the file.  For example:

#include <sys/types.h>
#include <dirent.h>

// Synchronize a specified directory path to underlying store
int sync_directory(const char *dirpath)
{
     int status = 0;
     DIR * dir = opendir(dirpath);
     if ( dir != NULL )
     {
         int dfd = dirfd(dir);
         if ( dfd >= 0 )
         {
             // Synchronize directory entry of the given file
             status = fsync(dfd);
         }
         else
         {
             status = -1;
         }
         closedir(dir);
     }
     else
     {
         status = -1;
     }
     return status;
}

Note that there is also fdopendir() which opens the directory of a 
open file descriptor fd, which libtiff may already have.  This may be 
easier than using opendir().

Bob
-- 
Bob Friesenhahn
bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/
_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
