hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/fs/ubifs/gc.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 (Битюцкий Артём)
....@@ -69,10 +57,6 @@
6957 /**
7058 * switch_gc_head - switch the garbage collection journal head.
7159 * @c: UBIFS file-system description object
72
- * @buf: buffer to write
73
- * @len: length of the buffer to write
74
- * @lnum: LEB number written is returned here
75
- * @offs: offset written is returned here
7660 *
7761 * This function switch the GC head to the next LEB which is reserved in
7862 * @c->gc_lnum. Returns %0 in case of success, %-EAGAIN if commit is required,
....@@ -254,7 +238,8 @@
254238 snod->type == UBIFS_DATA_NODE ||
255239 snod->type == UBIFS_DENT_NODE ||
256240 snod->type == UBIFS_XENT_NODE ||
257
- snod->type == UBIFS_TRUN_NODE);
241
+ snod->type == UBIFS_TRUN_NODE ||
242
+ snod->type == UBIFS_AUTH_NODE);
258243
259244 if (snod->type != UBIFS_INO_NODE &&
260245 snod->type != UBIFS_DATA_NODE &&
....@@ -364,12 +349,13 @@
364349
365350 /* Write nodes to their new location. Use the first-fit strategy */
366351 while (1) {
367
- int avail;
352
+ int avail, moved = 0;
368353 struct ubifs_scan_node *snod, *tmp;
369354
370355 /* Move data nodes */
371356 list_for_each_entry_safe(snod, tmp, &sleb->nodes, list) {
372
- avail = c->leb_size - wbuf->offs - wbuf->used;
357
+ avail = c->leb_size - wbuf->offs - wbuf->used -
358
+ ubifs_auth_node_sz(c);
373359 if (snod->len > avail)
374360 /*
375361 * Do not skip data nodes in order to optimize
....@@ -377,14 +363,21 @@
377363 */
378364 break;
379365
366
+ err = ubifs_shash_update(c, c->jheads[GCHD].log_hash,
367
+ snod->node, snod->len);
368
+ if (err)
369
+ goto out;
370
+
380371 err = move_node(c, sleb, snod, wbuf);
381372 if (err)
382373 goto out;
374
+ moved = 1;
383375 }
384376
385377 /* Move non-data nodes */
386378 list_for_each_entry_safe(snod, tmp, &nondata, list) {
387
- avail = c->leb_size - wbuf->offs - wbuf->used;
379
+ avail = c->leb_size - wbuf->offs - wbuf->used -
380
+ ubifs_auth_node_sz(c);
388381 if (avail < min)
389382 break;
390383
....@@ -402,9 +395,41 @@
402395 continue;
403396 }
404397
398
+ err = ubifs_shash_update(c, c->jheads[GCHD].log_hash,
399
+ snod->node, snod->len);
400
+ if (err)
401
+ goto out;
402
+
405403 err = move_node(c, sleb, snod, wbuf);
406404 if (err)
407405 goto out;
406
+ moved = 1;
407
+ }
408
+
409
+ if (ubifs_authenticated(c) && moved) {
410
+ struct ubifs_auth_node *auth;
411
+
412
+ auth = kmalloc(ubifs_auth_node_sz(c), GFP_NOFS);
413
+ if (!auth) {
414
+ err = -ENOMEM;
415
+ goto out;
416
+ }
417
+
418
+ err = ubifs_prepare_auth_node(c, auth,
419
+ c->jheads[GCHD].log_hash);
420
+ if (err) {
421
+ kfree(auth);
422
+ goto out;
423
+ }
424
+
425
+ err = ubifs_wbuf_write_nolock(wbuf, auth,
426
+ ubifs_auth_node_sz(c));
427
+ if (err) {
428
+ kfree(auth);
429
+ goto out;
430
+ }
431
+
432
+ ubifs_add_dirt(c, wbuf->lnum, ubifs_auth_node_sz(c));
408433 }
409434
410435 if (list_empty(&sleb->nodes) && list_empty(&nondata))