2
* This file is part of UBIFS.
4
* Copyright (C) 2006-2008 Nokia Corporation.
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.
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
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
19
* Authors: Adrian Hunter
20
* Artem Bityutskiy (Битюцкий Артём)
24
* This file implements commit-related functionality of the LEB properties
32
* free_obsolete_cnodes - free obsolete cnodes for commit end.
33
* @c: UBIFS file-system description object
35
static void free_obsolete_cnodes(struct ubifs_info *c)
37
struct ubifs_cnode *cnode, *cnext;
45
if (test_bit(OBSOLETE_CNODE, &cnode->flags))
49
} while (cnext != c->lpt_cnext);
54
* first_nnode - find the first nnode in memory.
55
* @c: UBIFS file-system description object
56
* @hght: height of tree where nnode found is returned here
58
* This function returns a pointer to the nnode found or %NULL if no nnode is
59
* found. This function is a helper to 'ubifs_lpt_free()'.
61
static struct ubifs_nnode *first_nnode(struct ubifs_info *c, int *hght)
63
struct ubifs_nnode *nnode;
70
for (h = 1; h < c->lpt_hght; h++) {
72
for (i = 0; i < UBIFS_LPT_FANOUT; i++) {
73
if (nnode->nbranch[i].nnode) {
75
nnode = nnode->nbranch[i].nnode;
87
* next_nnode - find the next nnode in memory.
88
* @c: UBIFS file-system description object
89
* @nnode: nnode from which to start.
90
* @hght: height of tree where nnode is, is passed and returned here
92
* This function returns a pointer to the nnode found or %NULL if no nnode is
93
* found. This function is a helper to 'ubifs_lpt_free()'.
95
static struct ubifs_nnode *next_nnode(struct ubifs_info *c,
96
struct ubifs_nnode *nnode, int *hght)
98
struct ubifs_nnode *parent;
101
parent = nnode->parent;
104
if (nnode->iip == UBIFS_LPT_FANOUT - 1) {
108
for (iip = nnode->iip + 1; iip < UBIFS_LPT_FANOUT; iip++) {
109
nnode = parent->nbranch[iip].nnode;
117
for (h = *hght + 1; h < c->lpt_hght; h++) {
119
for (i = 0; i < UBIFS_LPT_FANOUT; i++) {
120
if (nnode->nbranch[i].nnode) {
122
nnode = nnode->nbranch[i].nnode;
134
* ubifs_lpt_free - free resources owned by the LPT.
135
* @c: UBIFS file-system description object
136
* @wr_only: free only resources used for writing
138
void ubifs_lpt_free(struct ubifs_info *c, int wr_only)
140
struct ubifs_nnode *nnode;
143
/* Free write-only things first */
145
free_obsolete_cnodes(c); /* Leftover from a failed commit */
157
/* Now free the rest */
159
nnode = first_nnode(c, &hght);
161
for (i = 0; i < UBIFS_LPT_FANOUT; i++)
162
kfree(nnode->nbranch[i].nnode);
163
nnode = next_nnode(c, nnode, &hght);
165
for (i = 0; i < LPROPS_HEAP_CNT; i++)
166
kfree(c->lpt_heap[i].arr);
167
kfree(c->dirty_idx.arr);
170
kfree(c->lpt_nod_buf);