Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp770664imm; Wed, 4 Jul 2018 05:49:00 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf57Rlq4W2+Et5nW3wTf1bxxedzcVCshwwXunmPEwgIAcMgBqJT2KzDjDB+LzcH+ifQ5krM X-Received: by 2002:a17:902:44a4:: with SMTP id l33-v6mr2020589pld.134.1530708540448; Wed, 04 Jul 2018 05:49:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530708540; cv=none; d=google.com; s=arc-20160816; b=GDmsGDzWa5EUa03kuzHNLiCTxvMpNjeqjbdqXirB+5bdqJAoHIw4Isi1eHq6Gy8lQ0 uGTRpzc2ZLET3ss6twt0AFiaNEwJXwIJRGqcYvHoRLycJRy9T809lOo4Zvt4JAv9diw9 D5Lx58KNHTcA2E9iniDrtP2380Q9Lbcaevp3Jf+m2vU5DSkJHYNwQoB22iwe0cl3bTik ayXTKczBIa7LTzx5l83WsFHsmmEDOhG81hB+Bn8Ts+ho1izFQJKlWu2XgN0w2yL2pt77 XNt4lnKMDkl6oHs6ydIiF9G0/8PgSiXijbNYGNEdNO75GEn/966sLojFK4ExFJhoMphs rB7Q== 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:arc-authentication-results; bh=j2aU0DnB0BLVRk10blVMOQpNLxZDoitX6A212GpK2gY=; b=R/K7CxnNGT+MMQRol2YG50mn3YTWD87e9olv3i6qRkebRbdXPvGNSxKdm7rPW7UoUp 4LwjG/E/WeqkHG562WhNT+NebriY1HwQiqQ54hP8lMkgo/7FSDO8f5gOhvoR0iETdAhd lAFG9We82mjw3aOdjeszDlHc21jPYGVfqqNFz1hTApFl3ZNNEQVJ9ROdgIRNmLfMluNA rYJ34t+ykf4ULjqct3zqRP1LSGC8oIcI16zZjQ9ZXcbviUhIF4A65GbgPdcXtV4leYam 1URDRxH/YRqdPgxh1fXGneVI39WCadVWGE5+oxZkeqXSq3atZxAzEKYC0A1y0KJJ5Nfk Q+JA== 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 x19-v6si3022709pgl.660.2018.07.04.05.48.46; Wed, 04 Jul 2018 05:49:00 -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 S1752724AbeGDMrE (ORCPT + 99 others); Wed, 4 Jul 2018 08:47:04 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:45967 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934563AbeGDMmX (ORCPT ); Wed, 4 Jul 2018 08:42:23 -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 1fah6m-0001dR-Nj; Wed, 04 Jul 2018 14:42:08 +0200 Received: from sha by dude.hi.pengutronix.de with local (Exim 4.91) (envelope-from ) id 1fah6l-0005ZA-HD; Wed, 04 Jul 2018 14:42:07 +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 09/25] ubifs: add separate functions to init/crc a node Date: Wed, 4 Jul 2018 14:41:21 +0200 Message-Id: <20180704124137.13396-10-s.hauer@pengutronix.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180704124137.13396-1-s.hauer@pengutronix.de> References: <20180704124137.13396-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 fe77e9625e84..eeb8fb073d33 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 92574045e030..485de4e27f96 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h @@ -1480,6 +1480,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