From: Steve Magnani <steve.magnani@digidescorp.com>
To: Jan Kara <jack@suse.cz>
Cc: Jan Kara <jack@suse.com>,
linux-kernel@vger.kernel.org,
"Steven J . Magnani" <steve@digidescorp.com>
Subject: Re: [PATCH 1/1] udf: Fix incorrect final NOT_ALLOCATED (hole) extent length
Date: Wed, 26 Jun 2019 21:46:46 -0500 [thread overview]
Message-ID: <b5fcfef0-5fd4-f10a-4cce-78244aa1b227@digidescorp.com> (raw)
In-Reply-To: <20190625103019.GA1994@quack2.suse.cz>
Hi Jan,
On 6/25/19 5:30 AM, Jan Kara wrote:
> 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 <steve@digidescorp.com>
> 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!
That sounds reasonable, but at first glance I think it might be more
confusing. The API as I reworked it now communicates two different
(although related) things - the number of blocks that need to be added,
and the number of bytes within the last block that are part of the file.
This is able to cover both the corner case of extending within the last
file block and extending beyond that:
partial_final_block = newsize & (sb->s_blocksize - 1);
/* File has extent covering the new size (could happen when extending
* inside a block)? */
if (etype == -1) {
if (partial_final_block)
offset++;
} else {
/* Extending file within the last file block */
offset = 0; /* Don't add any new blocks */
}
If it were as simple as passing to udf_do_extend_file() a loff_t
specifying the number of bytes to add, including both full blocks and a
final partial block, I would agree with you. But this isn't enough
information for udf_do_extend_file() to know whether the final partial
block requires a new block or not.
I will think about it some more. Maybe moving the 'extending within the
last file block' case out to udf_extend_file() would help.
Steve
prev parent reply other threads:[~2019-06-27 2:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-04 12:31 [PATCH 0/1] udf: Incorrect " Steve Magnani
2019-06-04 12:31 ` [PATCH 1/1] udf: Fix incorrect " Steve Magnani
2019-06-04 12:36 ` Steve Magnani
2019-06-16 16:28 ` Steve Magnani
2019-06-19 6:47 ` Jan Kara
2019-06-19 11:47 ` Steve Magnani
2019-06-25 10:30 ` Jan Kara
2019-06-27 2:46 ` Steve Magnani [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b5fcfef0-5fd4-f10a-4cce-78244aa1b227@digidescorp.com \
--to=steve.magnani@digidescorp.com \
--cc=jack@suse.com \
--cc=jack@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=steve@digidescorp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®