From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72B4AC433ED for ; Wed, 5 May 2021 17:26:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 05E946105A for ; Wed, 5 May 2021 17:26:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 05E946105A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8B0A06B0070; Wed, 5 May 2021 13:26:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8614F6B0071; Wed, 5 May 2021 13:26:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 751326B0072; Wed, 5 May 2021 13:26:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0109.hostedemail.com [216.40.44.109]) by kanga.kvack.org (Postfix) with ESMTP id 58CB26B0070 for ; Wed, 5 May 2021 13:26:49 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 130133651 for ; Wed, 5 May 2021 17:26:49 +0000 (UTC) X-FDA: 78107857338.26.DABD197 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf05.hostedemail.com (Postfix) with ESMTP id 65856E00012F for ; Wed, 5 May 2021 17:26:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=nI9lCM1C11RSMX9mr5wZgr4g67mkfOZVIXRulnGLED0=; b=NVEbDkgSTcGEjcdWw2YB2EKFR4 sKdm3fflfwJg/yVRja8shrLxdPXgSo6pI5hgfQamAuyQ1uXWxl2ZcUv0M3bnSCtoHIcpRoBomdX98 JMoKYthWHWyN/IYsog5rj407j1Ko00Z6glZk42QlfeIc8R9H0VTqNBXg1ohpAZKp15jsqgkxYd6of F+u/NyKwZAnQ/Gh7cIgFHkordBG2IwMcdzSIGUYkVZ6tVYOy0f6T24T+uHjgz+e0ol9hqBArhRJei Q/ZjGq8u5LIiwXBvoxNXPtCJF2q4mEVkl+wAe4uZfJ+JCS+Aex97d2jl2DAKTkVgg0W6C4DnTPFpJ Na9mTyZQ==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1leKOS-000abl-5P; Wed, 05 May 2021 16:29:45 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org Subject: [PATCH v9 69/96] mm/filemap: Add folio_mkwrite_check_truncate Date: Wed, 5 May 2021 16:06:01 +0100 Message-Id: <20210505150628.111735-70-willy@infradead.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210505150628.111735-1-willy@infradead.org> References: <20210505150628.111735-1-willy@infradead.org> MIME-Version: 1.0 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=NVEbDkgS; spf=none (imf05.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 65856E00012F X-Stat-Signature: 14r6yfr7xauzcugxf51d7zs5jju5r8nb Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf05; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620235604-791865 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This is the folio equivalent of page_mkwrite_check_truncate(). Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/pagemap.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 2f896574aad7..8fd00dc5ebd5 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -1195,6 +1195,34 @@ static inline unsigned long dir_pages(struct inode= *inode) PAGE_SHIFT; } =20 +/** + * folio_mkwrite_check_truncate - check if folio was truncated + * @folio: the folio to check + * @inode: the inode to check the folio against + * + * Return: the number of bytes in the folio up to EOF, + * or -EFAULT if the folio was truncated. + */ +static inline ssize_t folio_mkwrite_check_truncate(struct folio *folio, + struct inode *inode) +{ + loff_t size =3D i_size_read(inode); + pgoff_t index =3D size >> PAGE_SHIFT; + size_t offset =3D offset_in_folio(folio, size); + + if (!folio->mapping) + return -EFAULT; + + /* folio is wholly inside EOF */ + if (folio_next_index(folio) - 1 < index) + return folio_size(folio); + /* folio is wholly past EOF */ + if (folio->index > index || !offset) + return -EFAULT; + /* folio is partially inside EOF */ + return offset; +} + /** * page_mkwrite_check_truncate - check if page was truncated * @page: the page to check --=20 2.30.2