uboot/fs/ubifs/log.c
<<
>>
Prefs
   1/*
   2 * This file is part of UBIFS.
   3 *
   4 * 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
  18 *
  19 * Authors: Artem Bityutskiy (Битюцкий Артём)
  20 *          Adrian Hunter
  21 */
  22
  23/*
  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
  27 * journal.
  28 */
  29
  30#include "ubifs.h"
  31
  32/**
  33 * ubifs_search_bud - search bud LEB.
  34 * @c: UBIFS file-system description object
  35 * @lnum: logical eraseblock number to search
  36 *
  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.
  39 */
  40struct ubifs_bud *ubifs_search_bud(struct ubifs_info *c, int lnum)
  41{
  42        struct rb_node *p;
  43        struct ubifs_bud *bud;
  44
  45        spin_lock(&c->buds_lock);
  46        p = c->buds.rb_node;
  47        while (p) {
  48                bud = rb_entry(p, struct ubifs_bud, rb);
  49                if (lnum < bud->lnum)
  50                        p = p->rb_left;
  51                else if (lnum > bud->lnum)
  52                        p = p->rb_right;
  53                else {
  54                        spin_unlock(&c->buds_lock);
  55                        return bud;
  56                }
  57        }
  58        spin_unlock(&c->buds_lock);
  59        return NULL;
  60}
  61
  62/**
  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
  66 */
  67void ubifs_add_bud(struct ubifs_info *c, struct ubifs_bud *bud)
  68{
  69        struct rb_node **p, *parent = NULL;
  70        struct ubifs_bud *b;
  71        struct ubifs_jhead *jhead;
  72
  73        spin_lock(&c->buds_lock);
  74        p = &c->buds.rb_node;
  75        while (*p) {
  76                parent = *p;
  77                b = rb_entry(parent, struct ubifs_bud, rb);
  78                ubifs_assert(bud->lnum != b->lnum);
  79                if (bud->lnum < b->lnum)
  80                        p = &(*p)->rb_left;
  81                else
  82                        p = &(*p)->rb_right;
  83        }
  84
  85        rb_link_node(&bud->rb, parent, p);
  86        rb_insert_color(&bud->rb, &c->buds);
  87        if (c->jheads) {
  88                jhead = &c->jheads[bud->jhead];
  89                list_add_tail(&bud->list, &jhead->buds_list);
  90        } else
  91                ubifs_assert(c->replaying && (c->vfs_sb->s_flags & MS_RDONLY));
  92
  93        /*
  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
  97         * scanned.
  98         */
  99        c->bud_bytes += c->leb_size - bud->start;
 100
 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);
 104}
 105