Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1780211imm; Fri, 7 Sep 2018 06:08:28 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaqrooGaO+w9qLqdI/MYMNlfD/ms69JUKqN+jUZAeGkvMyFC1dQvz8XbZUbT7mUzgdaQn1c X-Received: by 2002:a17:902:e281:: with SMTP id cf1-v6mr7900318plb.86.1536325708671; Fri, 07 Sep 2018 06:08:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536325708; cv=none; d=google.com; s=arc-20160816; b=TEuYhq4voUK70FnNtNDsVC1QIdaZg/n4l05Xea+VKlgsNuVc+5hHt2kfakZ+LMkna7 Po7qP2ljRcfT+FMxjIjiBDoO4wead7QfOlsmKBmmo/QHnw9TzX2laJXi2fWIaA/ZNC+V FIDXiKdi3F3UXq++C4qHmQm7yKvA4ENKPUznqK+1NK/pvZUfpOJppcy+9zTm7CUOvnrM oyg6uFxSMqiRuiw4twrVY6VArjhdTbtXm4OSHhE67c5oP8pDqnIsyp8gFnhArvBaYnmg /pT212jCm4elX+YxB2wJTRW3jWPZVS2X87o/bE3Pgux/PxL/HG+te8hA5tSVroHJEgt9 /i6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=LFO2ID2IFKuCnj9+/qi1oWaDtettI8eex9o0a8EHQQY=; b=xKyQ/RIerkl2iafvjO2Nmu93hAR0A/q0mLEQD95i95H1iwmnBWNFCOPHgrVLTqetxM K2DG7CVIYGzv2DiJlDqxYrG/y6RRH0eAOFnXnJ1KHtVJnG4ghCHbpx69racBPjrS5jlI RQIui4HWZLmGB7PAIRtujR8WSqj5fkP2xwqQ+nQE7J+ihCrElSJnzrz7mK/6dKgY0qm4 Ftq1aEgK2BNeVeJoKJSUrjaRGUu6rFg0Y1u4C5eEVEyq0rTUe34VtOghme0tWzkN7ehN gHnqHhhDZQ4Plagu1a+pAaG8fgXyQYQM6SBZo+CNCg+971t3fteBFnUlYqWtaIutURm/ TKGw== 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 s3-v6si8637336plb.270.2018.09.07.06.08.13; Fri, 07 Sep 2018 06:08:28 -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 S1729246AbeIGRTc (ORCPT + 99 others); Fri, 7 Sep 2018 13:19:32 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:35317 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729214AbeIGRTb (ORCPT ); Fri, 7 Sep 2018 13:19:31 -0400 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1fyG27-0007bv-Kv; Fri, 07 Sep 2018 14:38:43 +0200 Received: from sha by dude.hi.pengutronix.de with local (Exim 4.91) (envelope-from ) id 1fyG26-000626-Eb; Fri, 07 Sep 2018 14:38:42 +0200 From: Sascha Hauer To: linux-mtd@lists.infradead.org Cc: David Gstir , Richard Weinberger , kernel@pengutronix.de, linux-kernel@vger.kernel.org, Sascha Hauer Subject: [PATCH 10/25] ubifs: add separate functions to init/crc a node Date: Fri, 7 Sep 2018 14:36:31 +0200 Message-Id: <20180907123646.12688-11-s.hauer@pengutronix.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907123646.12688-1-s.hauer@pengutronix.de> References: <20180907123646.12688-1-s.hauer@pengutronix.de> X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When adding authentication support we will embed a HMAC into some nodes. To prepare these nodes we have to first initialize the nodes, then add a HMAC and finally add a CRC. To accomplish this add separate ubifs_init_node/ubifs_crc_node functions. Signed-off-by: Sascha Hauer --- fs/ubifs/io.c | 42 +++++++++++++++++++++++++++--------------- fs/ubifs/ubifs.h | 2 ++ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c index 099bec94b820..4bd61fe146e0 100644 --- a/fs/ubifs/io.c +++ b/fs/ubifs/io.c @@ -365,20 +365,8 @@ static unsigned long long next_sqnum(struct ubifs_info *c) return sqnum; } -/** - * ubifs_prepare_node - prepare node to be written to flash. - * @c: UBIFS file-system description object - * @node: the node to pad - * @len: node length - * @pad: if the buffer has to be padded - * - * This function prepares node at @node to be written to the media - it - * calculates node CRC, fills the common header, and adds proper padding up to - * the next minimum I/O unit if @pad is not zero. - */ -void ubifs_prepare_node(struct ubifs_info *c, void *node, int len, int pad) +void ubifs_init_node(struct ubifs_info *c, void *node, int len, int pad) { - uint32_t crc; struct ubifs_ch *ch = node; unsigned long long sqnum = next_sqnum(c); @@ -389,8 +377,6 @@ void ubifs_prepare_node(struct ubifs_info *c, void *node, int len, int pad) ch->group_type = UBIFS_NO_NODE_GROUP; ch->sqnum = cpu_to_le64(sqnum); ch->padding[0] = ch->padding[1] = 0; - crc = crc32(UBIFS_CRC32_INIT, node + 8, len - 8); - ch->crc = cpu_to_le32(crc); if (pad) { len = ALIGN(len, 8); @@ -399,6 +385,32 @@ void ubifs_prepare_node(struct ubifs_info *c, void *node, int len, int pad) } } +void ubifs_crc_node(struct ubifs_info *c, void *node, int len) +{ + struct ubifs_ch *ch = node; + uint32_t crc; + + crc = crc32(UBIFS_CRC32_INIT, node + 8, len - 8); + ch->crc = cpu_to_le32(crc); +} + +/** + * ubifs_prepare_node - prepare node to be written to flash. + * @c: UBIFS file-system description object + * @node: the node to pad + * @len: node length + * @pad: if the buffer has to be padded + * + * This function prepares node at @node to be written to the media - it + * calculates node CRC, fills the common header, and adds proper padding up to + * the next minimum I/O unit if @pad is not zero. + */ +void ubifs_prepare_node(struct ubifs_info *c, void *node, int len, int pad) +{ + ubifs_init_node(c, node, len, pad); + ubifs_crc_node(c, node, len); +} + /** * ubifs_prep_grp_node - prepare node of a group to be written to flash. * @c: UBIFS file-system description object diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index 93e1c34c097f..0422865661b1 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h @@ -1494,6 +1494,8 @@ int ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum, int offs); int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum, int offs, int quiet, int must_chk_crc); +void ubifs_init_node(struct ubifs_info *c, void *buf, int len, int pad); +void ubifs_crc_node(struct ubifs_info *c, void *buf, int len); void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad); void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last); int ubifs_io_init(struct ubifs_info *c); -- 2.18.0