/*
* This file is part of UBIFS.
*
* Copyright (C) 2006-2008 Nokia Corporation
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: Adrian Hunter
* Artem Bityutskiy (Битюцкий Артём)
*/
/*
* This file implements functions needed to recover from unclean un-mounts.
* When UBIFS is mounted, it checks a flag on the master node to determine if
* an un-mount was completed sucessfully. If not, the process of mounting
* incorparates additional checking and fixing of on-flash data structures.
* UBIFS always cleans away all remnants of an unclean un-mount, so that
* errors do not accumulate. However UBIFS defers recovery if it is mounted
* read-only, and the flash is not modified in that case.
*/
#include <linux/crc32.h>
#include "ubifs.h"
/**
* is_empty - determine whether a buffer is empty (contains all 0xff).
* @buf: buffer to clean
* @len: length of buffer
*
* This function returns %1 if the buffer is empty (contains all 0xff) otherwise
* %0 is returned.
*/
static int is_empty(void *buf, int len)
{
uint8_t *p = buf;
int i;
for (i = 0; i < len; i++)
if (*p++ != 0xff)
return 0;
return 1;
}
/**
* get_master_node - get the last valid master node allowing for corruption.
* @c: UBIFS file-system description object
* @lnum: LEB number
* @pbuf: buffer containing the LEB read, is returned here
* @mst: master node, if found, is returned here
* @cor: corruption, if found, is returned here
*
* This function allocates a buffer, reads the LEB into it, and finds and
* returns the last valid master node allowing for one area of corruption.
* The corrupt area, if there is one, must be consistent with the assumption
* that it is the result of an unclean unmount while the master node was being
* written. Under those circumstances, it is valid to use the previously written
* master node.
*
* This function returns %0 on success and a negative error code on failure.
*/