From owner-freebsd-fs@freebsd.org Mon Feb 1 17:17:51 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 A03FCA97581 for ; Mon, 1 Feb 2016 17:17:51 +0000 (UTC) (envelope-from sobomax@sippysoft.com) Received: from mail-wm0-x22f.google.com (mail-wm0-x22f.google.com [IPv6:2a00:1450:400c:c09::22f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 30C5C173D for ; Mon, 1 Feb 2016 17:17:51 +0000 (UTC) (envelope-from sobomax@sippysoft.com) Received: by mail-wm0-x22f.google.com with SMTP id l66so80631914wml.0 for ; Mon, 01 Feb 2016 09:17:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sippysoft-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=M1n+n8Ir3YhoiDIusVbeGI9fJwnN2mZCDyHQyscgUHQ=; b=pVvQLnWgBLxt39IUAsoi2xLCLaJ5s9rW6Y2zwNEc3U/skFt0z2mrNIkkq1w0xJnL+k vKs+DQ0If592N904BBpMvd2a++g18TE4KaXPT0wP1QvUHPL5ljoEiKMNloeRmT9PVuA4 wLGhzQPfi7p+REj4kPgZZhZi8ExAYzNcORWoac3FWxtq9U15fXyLiw8wZyEEfbFdWShm vJebtgoDq70X+wJ/+avooP6yGbvAfGmWxFVD17zvppMD+dhBnzKuzfZYW++jfUIb8cTn xeMCH7cpFVUrqAudEJYJc/ZEg/BbLu9q6hznWfZSN13LTOtNvUzNlcVyxyD13V20KsUB FPQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=M1n+n8Ir3YhoiDIusVbeGI9fJwnN2mZCDyHQyscgUHQ=; b=NBHJJ9Wclq4Eo89j/amhBbaWKKiA9AC/BZK1XxtKGikTIyQ2DMIPLMMYCyc81zoGNV eb+1E5BlulFo5Lug3xora3uQYEawG3Obx3H3+na59OznwNc5wJbiUygyS0sMpe2bIuI4 7drQEYTtiIJloDPjdSvoXo7xe9D7qnXWhPd7H943B1jtHtC2t8+FvtQjqBDXbEswkpCm RNTm93Dmwwx6msR9BSFiGGL1vNUFUKKevI5tqZwGs0r7BrGCccQOhNpL+whFpLRd4we7 Md2wv/ZrycHh55eyXGOp09p+Eius+iv2iCkpSl6bTldO34DCty8uyVR/9p86XSc6Kqp0 hvzg== X-Gm-Message-State: AG10YOTNiT40qwMhwwx2XNlRQPT8afhijBj2nnBmcipnDPz+rIm9uG/Ij7lUnTJPQKb+e3TaQQazXTsv5dCHhjVx MIME-Version: 1.0 X-Received: by 10.28.61.70 with SMTP id k67mr13294819wma.90.1454347069455; Mon, 01 Feb 2016 09:17:49 -0800 (PST) Sender: sobomax@sippysoft.com Received: by 10.27.39.195 with HTTP; Mon, 1 Feb 2016 09:17:49 -0800 (PST) In-Reply-To: <20160201165648.GM91220@kib.kiev.ua> References: <20160201165648.GM91220@kib.kiev.ua> Date: Mon, 1 Feb 2016 09:17:49 -0800 X-Google-Sender-Auth: -0gJIx5cFPHYOHDM4vczE3Uq9MA Message-ID: Subject: Re: Inconsistency between lseek(SEEK_HOLE) and lseek(SEEK_DATA) From: Maxim Sobolev To: Konstantin Belousov Cc: freebsd-fs@freebsd.org, Kirk McKusick Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.20 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: Mon, 01 Feb 2016 17:17:51 -0000 Here it is: The expected outcome is return code 0, the failure condition is in the lseek() returning 4 (i.e. sizeof(int)), not -1. ------ #include #include #include #include #include #include int main(void) { char tempname[] = "/tmp/temp.XXXXXX"; char *fname; int fd; off_t hole; fname = mktemp(tempname); if (fname == NULL) { exit (1); } fd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, DEFFILEMODE); if (fd == -1) { exit (1); } if (write(fd, &fd, sizeof(fd)) <= 0) { exit (1); } hole = lseek(fd, 0, SEEK_HOLE); close(fd); unlink(fname); if (hole >= 0) { fprintf(stderr, "lseek() returned %jd, not -1\n", (intmax_t)hole); exit (1); } exit (0); } ------ On Mon, Feb 1, 2016 at 8:56 AM, Konstantin Belousov wrote: > On Mon, Feb 01, 2016 at 07:57:40AM -0800, Maxim Sobolev wrote: > > Hi, > > > > I've noticed that lseek() behaved inconsistently with regards to > SEEK_HOLE > > and SEEK_DATA operations. The SEEK_HOLE on a data-only file returns > st_size > > (i.e. EOF + 1), while the SEEK_DATA on a hole-only file returns -1 and > sets > > errno to ENXIO. The latter seems to be a documented way to indicate that > > the file has no more data sections past this point. > > > > My first idea was that somehow most files has a hole attached to its end > to > > fill up the FS block, but that does not seem to be a case. Trying to > > SEEK_HOLE past the end of any of those data-only files produces an error > > (i.e. lseek(fd, st_size, SEEK_HOLE) == -1). > > > > In short, for some reason I cannot get proper ENXIO from the SEEK_HOLE. > > What currently returned implies that there is 1-byte hole attached to > each > > file past its EOF and that does not smell right. > > > > All tests are done on UFS, fairly recent 11-current. > > > > 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. > > Please show an exact minimal test case which reproduces what you > consider the bug, with the comment about the expected outcome in the > failing location. > >