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: Artem Bityutskiy (Битюцкий Артём)
24 * This file is a part of UBIFS journal implementation and contains various
25 * functions which manipulate the log. The log is a fixed area on the flash
26 * which does not contain any data but refers to buds. The log is a part of the
33 * ubifs_search_bud - search bud LEB.
34 * @c: UBIFS file-system description object
35 * @lnum: logical eraseblock number to search
37 * This function searches bud LEB @lnum. Returns bud description object in case
38 * of success and %NULL if there is no bud with this LEB number.
40 struct ubifs_bud *ubifs_search_bud(struct ubifs_info *c, int lnum)
43 struct ubifs_bud *bud;
45 spin_lock(&c->buds_lock);
48 bud = rb_entry(p, struct ubifs_bud, rb);
51 else if (lnum > bud->lnum)
54 spin_unlock(&c->buds_lock);
58 spin_unlock(&c->buds_lock);
63 * ubifs_add_bud - add bud LEB to the tree of buds and its journal head list.
64 * @c: UBIFS file-system description object
65 * @bud: the bud to add
67 void ubifs_add_bud(struct ubifs_info *c, struct ubifs_bud *bud)
69 struct rb_node **p, *parent = NULL;
71 struct ubifs_jhead *jhead;
73 spin_lock(&c->buds_lock);
77 b = rb_entry(parent, struct ubifs_bud, rb);
78 ubifs_assert(bud->lnum != b->lnum);
79 if (bud->lnum < b->lnum)
85 rb_link_node(&bud->rb, parent, p);
86 rb_insert_color(&bud->rb, &c->buds);
88 jhead = &c->jheads[bud->jhead];
89 list_add_tail(&bud->list, &jhead->buds_list);
91 ubifs_assert(c->replaying && (c->vfs_sb->s_flags & MS_RDONLY));
94 * Note, although this is a new bud, we anyway account this space now,
95 * before any data has been written to it, because this is about to
96 * guarantee fixed mount time, and this bud will anyway be read and
99 c->bud_bytes += c->leb_size - bud->start;
101 dbg_log("LEB %d:%d, jhead %d, bud_bytes %lld", bud->lnum,
102 bud->start, bud->jhead, c->bud_bytes);
103 spin_unlock(&c->buds_lock);