Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp3599206ybd; Tue, 25 Jun 2019 05:31:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqwmgcmC2Hnc6XN69xU6E6cCfCV9Xp4cmbtq9EAHQFkpE5Ff5DycPJrlwxrsXG03oej6Gb86 X-Received: by 2002:a63:4d4a:: with SMTP id n10mr32869889pgl.396.1561465869645; Tue, 25 Jun 2019 05:31:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561465869; cv=none; d=google.com; s=arc-20160816; b=dxyKKVWeNQ06e8qntt2/RKvwNsJW+5upvJDaNAfc4SJoPfNJukluJRYQHqNl5U5uop NEr8vVgNKJfFhbPqPgHzPnrlvZTsh+Pxj+dQylneISE1SsP7pTEahqeO0JD4b5AFhDzd rJRzeKJYaxXhwqRdFlcf3KaYXFpv70IQ9QU2X8OVWCF/WBY3jKPFybroyVWsbxXytvR9 XWt2P5Bd0/gquR3pGPc/+bz0ZrCUCwszMFYoxZ+It6P/ylK92DOgyjsrsA7WQb7u2r2c OYEF3KyQyudi1g5RdBHpPpgwfgkYgju2xRP0tfwtjtuJbEg6fva/L3IfQRdV1kbw27Aw D3iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=y0TPhyKW6uKohaQ6oQ7dM94wwnVME2RlCTShdiiyRxY=; b=dzmGDyehKttdOAydRUsSz/7BW8W+kkesRZwq098qhx4EWukwmL5FxBnrlvs7f+L7uy rzVuKf9x+Jk7TkYDa9FcTQan+BzglmxBjQOPTvDlO+Wdsj/A89+nu0CkCEhAHnUOvHxD ISNwm4bfPP4pIe3tiWqSx0j9we+oKI75KPGwfkWVtJrZbwa7Es2JspeYUgan0vlyN/FJ tb4mxdaPbZ7/IrYZOqf7ot/Cbqi/3YG2Fmagg1jN7lL5uNia7jnOsLT5XpL0OVz1gD5P U/yPWEy1OrfH/48PBqyJFdPAaFX2eXeT3SoCkC1cgDXw2LIQVR3UpgfsuHrV7Qs5fq67 m0yg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d5si2867193pjo.80.2019.06.25.05.30.53; Tue, 25 Jun 2019 05:31:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729304AbfFYKge (ORCPT + 99 others); Tue, 25 Jun 2019 06:36:34 -0400 Received: from mx2.suse.de ([195.135.220.15]:43724 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728377AbfFYKge (ORCPT ); Tue, 25 Jun 2019 06:36:34 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id E2921ACCE; Tue, 25 Jun 2019 10:36:32 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id A1B321E4323; Tue, 25 Jun 2019 12:30:19 +0200 (CEST) Date: Tue, 25 Jun 2019 12:30:19 +0200 From: Jan Kara To: Steve Magnani Cc: Jan Kara , linux-kernel@vger.kernel.org, "Steven J . Magnani" Subject: Re: [PATCH 1/1] udf: Fix incorrect final NOT_ALLOCATED (hole) extent length Message-ID: <20190625103019.GA1994@quack2.suse.cz> References: <20190604123158.12741-1-steve@digidescorp.com> <20190604123158.12741-2-steve@digidescorp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190604123158.12741-2-steve@digidescorp.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 04-06-19 07:31:58, Steve Magnani wrote: > In some cases, using the 'truncate' command to extend a UDF file results > in a mismatch between the length of the file's extents (specifically, due > to incorrect length of the final NOT_ALLOCATED extent) and the information > (file) length. The discrepancy can prevent other operating systems > (i.e., Windows 10) from opening the file. > > Two particular errors have been observed when extending a file: > > 1. The final extent is larger than it should be, having been rounded up > to a multiple of the block size. > > B. The final extent is not shorter than it should be, due to not having > been updated when the file's information length was increased. > > The first case could represent a design error, if coded intentionally > due to a misinterpretation of scantily-documented ECMA-167 "file tail" > rules. The standard specifies that the tail, if present, consists of > a sequence of "unrecorded and allocated" extents (only). > > Signed-off-by: Steven J. Magnani Thanks for the testcase and the patch! I finally got to reading through this in detail. In udf driver in Linux we are generally fine with the last extent being rounded up to the block size. udf_truncate_tail_extent() is generally responsible for truncating the last extent to appropriate size once we are done with the inode. However there are two problems with this: 1) We used to do this inside udf_clear_inode() back in the old days but then switched to a different scheme in commit 2c948b3f86e5f "udf: Avoid IO in udf_clear_inode". So this actually breaks workloads where user calls truncate(2) directly and there's no place where udf_truncate_tail_extent() gets called. 2) udf_extend_file() sets i_lenExtents == i_size although the last extent isn't properly rounded so even if udf_truncate_tail_extent() gets called (which is actually the case for truncate(1) which does open, ftruncate, close), it will think it has nothing to do and exit. Now 2) is easily fixed by setting i_lenExtents to real length of extents we have created. However that still leaves problem 1) which isn't easy to deal with. After some though I think that your solution of making udf_do_extend_file() always create appropriately sized extents makes sense. However I dislike the calling convention you've chosen. When udf_do_extend_file() needs to now byte length, then why not pass it to it directly, instead of somewhat cumbersome "sector length + byte offset" pair? Will you update the patch please? Thanks! Honza -- Jan Kara SUSE Labs, CR