hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/ubifs/tnc_commit.c
....@@ -1,20 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * This file is part of UBIFS.
34 *
45 * Copyright (C) 2006-2008 Nokia Corporation.
5
- *
6
- * This program is free software; you can redistribute it and/or modify it
7
- * under the terms of the GNU General Public License version 2 as published by
8
- * the Free Software Foundation.
9
- *
10
- * This program is distributed in the hope that it will be useful, but WITHOUT
11
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13
- * more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * this program; if not, write to the Free Software Foundation, Inc., 51
17
- * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
186 *
197 * Authors: Adrian Hunter
208 * Artem Bityutskiy (Битюцкий Артём)
....@@ -38,6 +26,7 @@
3826 struct ubifs_znode *znode, int lnum, int offs, int len)
3927 {
4028 struct ubifs_znode *zp;
29
+ u8 hash[UBIFS_HASH_ARR_SZ];
4130 int i, err;
4231
4332 /* Make index node */
....@@ -52,6 +41,7 @@
5241 br->lnum = cpu_to_le32(zbr->lnum);
5342 br->offs = cpu_to_le32(zbr->offs);
5443 br->len = cpu_to_le32(zbr->len);
44
+ ubifs_copy_hash(c, zbr->hash, ubifs_branch_hash(c, br));
5545 if (!zbr->lnum || !zbr->len) {
5646 ubifs_err(c, "bad ref in znode");
5747 ubifs_dump_znode(c, znode);
....@@ -62,6 +52,7 @@
6252 }
6353 }
6454 ubifs_prepare_node(c, idx, len, 0);
55
+ ubifs_node_calc_hash(c, idx, hash);
6556
6657 znode->lnum = lnum;
6758 znode->offs = offs;
....@@ -78,10 +69,12 @@
7869 zbr->lnum = lnum;
7970 zbr->offs = offs;
8071 zbr->len = len;
72
+ ubifs_copy_hash(c, hash, zbr->hash);
8173 } else {
8274 c->zroot.lnum = lnum;
8375 c->zroot.offs = offs;
8476 c->zroot.len = len;
77
+ ubifs_copy_hash(c, hash, c->zroot.hash);
8578 }
8679 c->calc_idx_sz += ALIGN(len, 8);
8780
....@@ -667,6 +660,8 @@
667660 znode->cnext = c->cnext;
668661 break;
669662 }
663
+ znode->cparent = znode->parent;
664
+ znode->ciip = znode->iip;
670665 znode->cnext = cnext;
671666 znode = cnext;
672667 cnt += 1;
....@@ -860,6 +855,8 @@
860855 }
861856
862857 while (1) {
858
+ u8 hash[UBIFS_HASH_ARR_SZ];
859
+
863860 cond_resched();
864861
865862 znode = cnext;
....@@ -877,6 +874,7 @@
877874 br->lnum = cpu_to_le32(zbr->lnum);
878875 br->offs = cpu_to_le32(zbr->offs);
879876 br->len = cpu_to_le32(zbr->len);
877
+ ubifs_copy_hash(c, zbr->hash, ubifs_branch_hash(c, br));
880878 if (!zbr->lnum || !zbr->len) {
881879 ubifs_err(c, "bad ref in znode");
882880 ubifs_dump_znode(c, znode);
....@@ -888,6 +886,23 @@
888886 }
889887 len = ubifs_idx_node_sz(c, znode->child_cnt);
890888 ubifs_prepare_node(c, idx, len, 0);
889
+ ubifs_node_calc_hash(c, idx, hash);
890
+
891
+ mutex_lock(&c->tnc_mutex);
892
+
893
+ if (znode->cparent)
894
+ ubifs_copy_hash(c, hash,
895
+ znode->cparent->zbranch[znode->ciip].hash);
896
+
897
+ if (znode->parent) {
898
+ if (!ubifs_zn_obsolete(znode))
899
+ ubifs_copy_hash(c, hash,
900
+ znode->parent->zbranch[znode->iip].hash);
901
+ } else {
902
+ ubifs_copy_hash(c, hash, c->zroot.hash);
903
+ }
904
+
905
+ mutex_unlock(&c->tnc_mutex);
891906
892907 /* Determine the index node position */
893908 if (lnum == -1) {