From owner-freebsd-fs@freebsd.org Tue Feb 2 13:26:01 2016 Return-Path: Delivered-To: freebsd-fs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A189DA97CCA for ; Tue, 2 Feb 2016 13:26:01 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 376F8B9E; Tue, 2 Feb 2016 13:26:01 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id u12DPuLB086991 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Tue, 2 Feb 2016 15:25:56 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua u12DPuLB086991 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id u12DPudA086990; Tue, 2 Feb 2016 15:25:56 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 2 Feb 2016 15:25:56 +0200 From: Konstantin Belousov To: Maxim Sobolev Cc: freebsd-fs@freebsd.org, Kirk McKusick Subject: Re: Inconsistency between lseek(SEEK_HOLE) and lseek(SEEK_DATA) Message-ID: <20160202132556.GV91220@kib.kiev.ua> References: <20160201165648.GM91220@kib.kiev.ua> <20160201182257.GN91220@kib.kiev.ua> <20160201194014.GQ91220@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Feb 2016 13:26:01 -0000 On Mon, Feb 01, 2016 at 09:17:00PM -0800, Maxim Sobolev wrote: > WRT the: > > > There is no 'hole-only' files on UFS, the last byte in the UFS file must > > be populated, either by allocated fragment if the last byte is in the > > direct blocks range, or by the full block if in the indirect range. > > Ideed, the UFS resists putting a hole at the end of the file, yet, it's > possible to arrange hole-only situation by first truncating an empty file > to some size that is greater than the target hole size, so that you get > hole of the desired size following by the bit of data, and then truncating > the resulting file back to the offset where the data starts: > > ----- > fd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, DEFFILEMODE); > if (fd == -1) { > exit (1); > } > if (ftruncate(fd, 1024 * 128) < 0) { > exit (1); > } > data = lseek(fd, 0, SEEK_DATA); > if (data >= 0 && ftruncate(fd, data) < 0) { > exit (1); > } > ----- > [sobomax@rtpdev ~/projects/freebsd11/usr.bin/lsholes]$ ./lsholes > /tmp/temp.MgoPPo > Type Start End Size > HOLE 0 98303 98304 > > Total HOLE: 98304 (100.00%) > Total DATA: 0 (0.00%) > [sobomax@rtpdev ~/projects/freebsd11/usr.bin/lsholes]$ ls -l > /tmp/temp.MgoPPo > -rw-r--r-- 1 sobomax wheel 98304 Feb 1 21:06 /tmp/temp.MgoPPo Is this on UFS ? Please provide me with the program to re-create it, if on UFS. At least fsck is not ready for files with holes at tail, and several kernel code fragments expect last byte to be allocated. I once had a patch to allow hole at tail for UFS, but I did not moved it to the committable state. > ----- > > I don't know if operating on that file would result in some data > corruption, but I also seem have no issues creating hole-only files on ZFS > using my fallocate(2) syscall.