From owner-freebsd-fs@freebsd.org Tue Feb 2 18:54:14 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 F2B83A9829B for ; Tue, 2 Feb 2016 18:54:13 +0000 (UTC) (envelope-from sobomax@sippysoft.com) Received: from mail-wm0-x232.google.com (mail-wm0-x232.google.com [IPv6:2a00:1450:400c:c09::232]) (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 825B61FE9 for ; Tue, 2 Feb 2016 18:54:13 +0000 (UTC) (envelope-from sobomax@sippysoft.com) Received: by mail-wm0-x232.google.com with SMTP id l66so131079395wml.0 for ; Tue, 02 Feb 2016 10:54:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sippysoft-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=o+dBopoATNlNRnwo/8LvIhIjglNBLj83M1XVTZvf5qA=; b=uyeD6nOOl9ikdrDCE2vUMP71nE2h33pxkbharAJYuk43lqK6akKqbnsIlv4YeNheLR hNPH/wwhV+Hxzy7OTT1QIuvAVkGpZDOZYDCsd0TJY+5DEmZo0Yi7tht3qZlHayH+jHaY Yl+3dLo7GlR0Dc+ZTfx2h2Snxy3eu123mvgdTmPT8DWeRZkggkXXvs0Xau+QpszubpNe dKmC1C8UWtBy4De/jQhzlz58EyoN0UsZAUQJbIp4lsDgT5oVKDoIwkMr1zDa67Mbxg7w vjRs2VsyVnVbbIw/iWQ2Pl7bksCSzBq7RrQOTKOvZhO7DWwHKIn8Ic3vEt9iqDUrdyx4 DGHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=o+dBopoATNlNRnwo/8LvIhIjglNBLj83M1XVTZvf5qA=; b=VkOHuBfw2+5NqOqi+GZUw9XiXTSR9a3CG1Ss8OSx2YhwrPtIbPYehaHsLPy6n1Rpzo hGoksUSjdTJLG5s8jAzV60HDJKj9pG4XjqdON+h2nmByw97Twrgb2bIXL+agdYpDDU+x fvMfBcNsEN4bvAG2tXJOXbSOovkX4RAsAmTPOx4XMvp7E0XNlKZ8El400pPMnnkqeafD 2fDA/9catnG2/2kkzeq9nT8xqSaxRa8KywIeH8MSX7VkV54wctBDC6mtwZocv/WESzFA nTedbCOnX+ws03YYFb4nuTIqX595SlJ11iwDun9QXeaUNjw6YCeEuQQlgIwo9ddL9mFb d9cg== X-Gm-Message-State: AG10YOS0OmV6dT08QXeCGNYxnGtQyhBrextphaS2gxexdbYpGPXLU50K4brjZGtBs/fqPJluu/nB2UVPzyStsXyX MIME-Version: 1.0 X-Received: by 10.194.174.36 with SMTP id bp4mr29770878wjc.137.1454439252021; Tue, 02 Feb 2016 10:54:12 -0800 (PST) Received: by 10.27.39.195 with HTTP; Tue, 2 Feb 2016 10:54:11 -0800 (PST) In-Reply-To: References: <20160201165648.GM91220@kib.kiev.ua> <20160201182257.GN91220@kib.kiev.ua> <20160201194014.GQ91220@kib.kiev.ua> <20160202132556.GV91220@kib.kiev.ua> Date: Tue, 2 Feb 2016 10:54:11 -0800 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: Tue, 02 Feb 2016 18:54:14 -0000 P.S. "hole = lseek(fd, 0, SEEK_HOLE)" is superfluous there. On Tue, Feb 2, 2016 at 10:51 AM, Maxim Sobolev wrote: > Here it is, works on UFS no problems here. > ---- > #include > #include > #include > #include > #include > #include > #include > > int main(void) > { > char tempname[] = "/tmp/temp.XXXXXX"; > char *fname; > int fd, exval; > off_t hole, data; > > fname = mktemp(tempname); > if (fname == NULL) { > exit (1); > } > fd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, DEFFILEMODE); > if (fd == -1) { > exit (1); > } > if (ftruncate(fd, 1024 * 128) < 0) { > exit (1); > } > hole = lseek(fd, 0, SEEK_HOLE); > data = lseek(fd, 0, SEEK_DATA); > if (ftruncate(fd, data) < 0) { > exit (1); > } > printf("%s: %jd %jd\n", fname, (intmax_t)hole, (intmax_t)data); > exval = 0; > cleanup: > close(fd); > exit (exval); > } > ---- > > On Tue, Feb 2, 2016 at 5:25 AM, Konstantin Belousov > wrote: > >> 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. >> >> > > > -- > Maksym Sobolyev > Sippy Software, Inc. > Internet Telephony (VoIP) Experts > Tel (Canada): +1-778-783-0474 > Tel (Toll-Free): +1-855-747-7779 > Fax: +1-866-857-6942 > Web: http://www.sippysoft.com > MSN: sales@sippysoft.com > Skype: SippySoft > -- Maksym Sobolyev Sippy Software, Inc. Internet Telephony (VoIP) Experts Tel (Canada): +1-778-783-0474 Tel (Toll-Free): +1-855-747-7779 Fax: +1-866-857-6942 Web: http://www.sippysoft.com MSN: sales@sippysoft.com Skype: SippySoft