/*
* JFFS2 -- Journalling Flash File System, Version 2.
*
* Copyright © 2006 NEC Corporation
*
* Created by KaiGai Kohei <kaigai@ak.jp.nec.com>
*
* For licensing information, see the file 'LICENCE' in this directory.
*
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#define JFFS2_XATTR_IS_CORRUPTED 1
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/time.h>
#include <linux/pagemap.h>
#include <linux/highmem.h>
#include <linux/crc32.h>
#include <linux/jffs2.h>
#include <linux/xattr.h>
#include <linux/posix_acl_xattr.h>
#include <linux/mtd/mtd.h>
#include "nodelist.h"
/* -------- xdatum related functions ----------------
* xattr_datum_hashkey(xprefix, xname, xvalue, xsize)
* is used to calcurate xdatum hashkey. The reminder of hashkey into XATTRINDEX_HASHSIZE is
* the index of the xattr name/value pair cache (c->xattrindex).
* is_xattr_datum_unchecked(c, xd)
* returns 1, if xdatum contains any unchecked raw nodes. if all raw nodes are not
* unchecked, it returns 0.
* unload_xattr_datum(c, xd)
* is used to release xattr name/value pair and detach from c->xattrindex.
* reclaim_xattr_datum(c)
* is used to reclaim xattr name/value pairs on the xattr name/value pair cache when
* memory usage by cache is over c->xdatum_mem_threshold. Currently, this threshold
* is hard coded as 32KiB.
* do_verify_xattr_datum(c, xd)
* is used to load the xdatum informations without name/value pair from the medium.
* It's necessary once, because those informations are not collected during mounting
* process when EBS is enabled.
* 0 will be returned, if success. An negative return value means recoverable error, and
* positive return value means unrecoverable error. Thus, caller must remove this xdatum
* and xref when it returned positive value.
* do_load_xattr_datum(c, xd)
* is used to load name/value pair from the medium.
* The meanings of return value is same as do_verify_xattr_datum().
* load_xattr_datum(c, xd)
* is used to be as a wrapper of do_verify_xattr_datum() and do_load_xattr_datum().
* If xd need to call do_verify_xattr_datum() at first, it's called before calling
* do_load_xattr_datum(). The meanings of return value is same as do_verify_xattr_datum().
* save_xattr_datum(c, xd)
* is used to write xdatum to medium. xd->version will be incremented.
* create_xattr_datum(c, xprefix, xname, xvalue, xsize)
* is used to create new xdatum and write to medium.
* unrefer_xattr_datum(c, xd)
* is used to delete a xdatum. When nobody refers this xdatum, JFFS2_XFLAGS_DEAD
* is set on xd->flags and chained xattr_dead_list or release it immediately.
* In the first case, the garbage collector release it later.
* -------------------------------------------------- */
static uint32_t xattr_datum_hashkey(int xprefix, const char *xname, const char *xvalue, int xsize)
{
int name_len = strlen(xname);
return crc32(xprefix, xname, name_len) ^ crc32(xprefix, xvalue, xsize);
}
static int is_xattr_datum_unchecked(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
{
struct jffs2_raw_node_ref *raw;
int rc = 0;
spin_lock(&c->erase_completion_lock);
for (raw=xd->node; raw != (void *)xd; raw=raw->next_in_ino) {
if (ref_flags(raw) == REF_UNCHECKED) {
rc = 1;
break;
}
}
spin_unlock(&c->erase_completion_lock);
return rc;
}
static