-/* -------------------------------------------------------------------------
- * File: fs/jffs2/xattr.c
- * XATTR support on JFFS2 FileSystem
+/*
+ * JFFS2 -- Journalling Flash File System, Version 2.
*
- * Implemented by KaiGai Kohei <kaigai@ak.jp.nec.com>
- * Copyright (C) 2006 NEC Corporation
+ * Copyright (C) 2006 NEC Corporation
*
- * For licensing information, see the file 'LICENCE' in the jffs2 directory.
- * ------------------------------------------------------------------------- */
-
+ * Created by KaiGai Kohei <kaigai@ak.jp.nec.com>
+ *
+ * For licensing information, see the file 'LICENCE' in this directory.
+ *
+ */
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/fs.h>
* 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, phys_ofs)
+ * 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, phys_ofs)
+ * create_xattr_datum(c, xprefix, xname, xvalue, xsize)
* is used to create new xdatum and write to medium.
* -------------------------------------------------- */
{
/* must be called under down_write(xattr_sem) */
struct jffs2_raw_xattr rx;
- uint32_t length;
+ size_t length;
int rc;
if (!xd->node) {
sizeof(struct jffs2_unknown_node),
&length, (char *)&rx);
if (rc || length != sizeof(struct jffs2_unknown_node)) {
- JFFS2_ERROR("jffs2_flash_read()=%d, req=%u, read=%u at %#08x\n",
+ JFFS2_ERROR("jffs2_flash_read()=%d, req=%zu, read=%zu at %#08x\n",
rc, sizeof(struct jffs2_unknown_node),
length, ref_offset(xd->node));
}
rc = jffs2_flash_write(c, ref_offset(xd->node), sizeof(rx),
&length, (char *)&rx);
if (rc || length != sizeof(struct jffs2_raw_xattr)) {
- JFFS2_ERROR("jffs2_flash_write()=%d, req=%u, wrote=%u ar %#08x\n",
+ JFFS2_ERROR("jffs2_flash_write()=%d, req=%zu, wrote=%zu ar %#08x\n",
rc, sizeof(rx), length, ref_offset(xd->node));
}
}
rc = jffs2_flash_read(c, ref_offset(xd->node), sizeof(rx), &readlen, (char *)&rx);
if (rc || readlen != sizeof(rx)) {
- JFFS2_WARNING("jffs2_flash_read()=%d, req=%u, read=%u at %#08x\n",
+ JFFS2_WARNING("jffs2_flash_read()=%d, req=%zu, read=%zu at %#08x\n",
rc, sizeof(rx), readlen, ref_offset(xd->node));
return rc ? rc : -EIO;
}
length, &readlen, data);
if (ret || length!=readlen) {
- JFFS2_WARNING("jffs2_flash_read() returned %d, request=%d, readlen=%d, at %#08x\n",
+ JFFS2_WARNING("jffs2_flash_read() returned %d, request=%d, readlen=%zu, at %#08x\n",
ret, length, readlen, ref_offset(xd->node));
kfree(data);
return ret ? ret : -EIO;
return rc;
}
-static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd, uint32_t phys_ofs)
+static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
{
/* must be called under down_write(xattr_sem) */
- struct jffs2_raw_xattr rx;
struct jffs2_raw_node_ref *raw;
+ struct jffs2_raw_xattr rx;
struct kvec vecs[2];
- uint32_t length;
+ size_t length;
int rc, totlen;
+ uint32_t phys_ofs = write_ofs(c);
BUG_ON(!xd->xname);
vecs[1].iov_len = xd->name_len + 1 + xd->value_len;
totlen = vecs[0].iov_len + vecs[1].iov_len;
- raw = jffs2_alloc_raw_node_ref();
- if (!raw)
- return -ENOMEM;
- raw->flash_offset = phys_ofs;
- raw->__totlen = PAD(totlen);
- raw->next_phys = NULL;
- raw->next_in_ino = (void *)xd;
-
/* Setup raw-xattr */
rx.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
rx.nodetype = cpu_to_je16(JFFS2_NODETYPE_XATTR);
rc = jffs2_flash_writev(c, vecs, 2, phys_ofs, &length, 0);
if (rc || totlen != length) {
- JFFS2_WARNING("jffs2_flash_writev()=%d, req=%u, wrote=%u, at %#08x\n",
+ JFFS2_WARNING("jffs2_flash_writev()=%d, req=%u, wrote=%zu, at %#08x\n",
rc, totlen, length, phys_ofs);
rc = rc ? rc : -EIO;
- if (length) {
- raw->flash_offset |= REF_OBSOLETE;
- raw->next_in_ino = NULL;
- jffs2_add_physical_node_ref(c, raw);
- jffs2_mark_node_obsolete(c, raw);
- } else {
- jffs2_free_raw_node_ref(raw);
- }
+ if (length)
+ jffs2_add_physical_node_ref(c, phys_ofs | REF_OBSOLETE, PAD(totlen), NULL);
+
return rc;
}
- BUG_ON(raw->__totlen < sizeof(struct jffs2_raw_xattr));
+
/* success */
- raw->flash_offset |= REF_PRISTINE;
- jffs2_add_physical_node_ref(c, raw);
+ raw = jffs2_add_physical_node_ref(c, phys_ofs | REF_PRISTINE, PAD(totlen), NULL);
+ /* FIXME */ raw->next_in_ino = (void *)xd;
+
if (xd->node)
delete_xattr_datum_node(c, xd);
xd->node = raw;
static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c,
int xprefix, const char *xname,
- const char *xvalue, int xsize,
- uint32_t phys_ofs)
+ const char *xvalue, int xsize)
{
/* must be called under down_write(xattr_sem) */
struct jffs2_xattr_datum *xd;
xd->value_len = xsize;
xd->data_crc = crc32(0, data, xd->name_len + 1 + xd->value_len);
- rc = save_xattr_datum(c, xd, phys_ofs);
+ rc = save_xattr_datum(c, xd);
if (rc) {
kfree(xd->xname);
jffs2_free_xattr_datum(xd);
return xd;
}
-/* -------- xdatum related functions ----------------
+/* -------- xref related functions ------------------
* verify_xattr_ref(c, ref)
* is used to load xref information from medium. Because summary data does not
* contain xid/ino, it's necessary to verify once while mounting process.
* delete_xattr_ref(c, ref)
* is used to delete jffs2_xattr_ref object. If the reference counter of xdatum
* is refered by this xref become 0, delete_xattr_datum() is called later.
- * save_xattr_ref(c, ref, phys_ofs)
+ * save_xattr_ref(c, ref)
* is used to write xref to medium.
- * create_xattr_ref(c, ic, xd, phys_ofs)
+ * create_xattr_ref(c, ic, xd)
* is used to create a new xref and write to medium.
* jffs2_xattr_delete_inode(c, ic)
* is called to remove xrefs related to obsolete inode when inode is unlinked.
rc = jffs2_flash_read(c, ref_offset(ref->node), sizeof(rr), &readlen, (char *)&rr);
if (rc || sizeof(rr) != readlen) {
- JFFS2_WARNING("jffs2_flash_read()=%d, req=%u, read=%u, at %#08x\n",
+ JFFS2_WARNING("jffs2_flash_read()=%d, req=%zu, read=%zu, at %#08x\n",
rc, sizeof(rr), readlen, ref_offset(ref->node));
return rc ? rc : -EIO;
}
|| je16_to_cpu(rr.nodetype) != JFFS2_NODETYPE_XREF
|| je32_to_cpu(rr.totlen) != PAD(sizeof(rr))) {
JFFS2_ERROR("inconsistent xref at %#08x, magic=%#04x/%#04x, "
- "nodetype=%#04x/%#04x, totlen=%u/%u\n",
+ "nodetype=%#04x/%#04x, totlen=%u/%zu\n",
ref_offset(ref->node), je16_to_cpu(rr.magic), JFFS2_MAGIC_BITMASK,
je16_to_cpu(rr.nodetype), JFFS2_NODETYPE_XREF,
je32_to_cpu(rr.totlen), PAD(sizeof(rr)));
static void delete_xattr_ref_node(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
{
struct jffs2_raw_xref rr;
- uint32_t length;
+ size_t length;
int rc;
if (jffs2_sum_active()) {
sizeof(struct jffs2_unknown_node),
&length, (char *)&rr);
if (rc || length != sizeof(struct jffs2_unknown_node)) {
- JFFS2_ERROR("jffs2_flash_read()=%d, req=%u, read=%u at %#08x\n",
+ JFFS2_ERROR("jffs2_flash_read()=%d, req=%zu, read=%zu at %#08x\n",
rc, sizeof(struct jffs2_unknown_node),
length, ref_offset(ref->node));
}
rc = jffs2_flash_write(c, ref_offset(ref->node), sizeof(rr),
&length, (char *)&rr);
if (rc || length != sizeof(struct jffs2_raw_xref)) {
- JFFS2_ERROR("jffs2_flash_write()=%d, req=%u, wrote=%u at %#08x\n",
+ JFFS2_ERROR("jffs2_flash_write()=%d, req=%zu, wrote=%zu at %#08x\n",
rc, sizeof(rr), length, ref_offset(ref->node));
}
}
jffs2_free_xattr_ref(ref);
}
-static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref, uint32_t phys_ofs)
+static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
{
/* must be called under down_write(xattr_sem) */
struct jffs2_raw_node_ref *raw;
struct jffs2_raw_xref rr;
- uint32_t length;
+ size_t length;
+ uint32_t phys_ofs = write_ofs(c);
int ret;
- raw = jffs2_alloc_raw_node_ref();
- if (!raw)
- return -ENOMEM;
- raw->flash_offset = phys_ofs;
- raw->__totlen = PAD(sizeof(rr));
- raw->next_phys = NULL;
- raw->next_in_ino = (void *)ref;
-
rr.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
rr.nodetype = cpu_to_je16(JFFS2_NODETYPE_XREF);
rr.totlen = cpu_to_je32(PAD(sizeof(rr)));
ret = jffs2_flash_write(c, phys_ofs, sizeof(rr), &length, (char *)&rr);
if (ret || sizeof(rr) != length) {
- JFFS2_WARNING("jffs2_flash_write() returned %d, request=%u, retlen=%u, at %#08x\n",
+ JFFS2_WARNING("jffs2_flash_write() returned %d, request=%zu, retlen=%zu, at %#08x\n",
ret, sizeof(rr), length, phys_ofs);
ret = ret ? ret : -EIO;
- if (length) {
- raw->flash_offset |= REF_OBSOLETE;
- raw->next_in_ino = NULL;
- jffs2_add_physical_node_ref(c, raw);
- jffs2_mark_node_obsolete(c, raw);
- } else {
- jffs2_free_raw_node_ref(raw);
- }
+ if (length)
+ jffs2_add_physical_node_ref(c, phys_ofs | REF_OBSOLETE, PAD(sizeof(rr)), NULL);
+
return ret;
}
- raw->flash_offset |= REF_PRISTINE;
- jffs2_add_physical_node_ref(c, raw);
+ raw = jffs2_add_physical_node_ref(c, phys_ofs | REF_PRISTINE, PAD(sizeof(rr)), NULL);
+ /* FIXME */ raw->next_in_ino = (void *)ref;
if (ref->node)
delete_xattr_ref_node(c, ref);
ref->node = raw;
}
static struct jffs2_xattr_ref *create_xattr_ref(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic,
- struct jffs2_xattr_datum *xd, uint32_t phys_ofs)
+ struct jffs2_xattr_datum *xd)
{
/* must be called under down_write(xattr_sem) */
struct jffs2_xattr_ref *ref;
ref->ic = ic;
ref->xd = xd;
- ret = save_xattr_ref(c, ref, phys_ofs);
+ ret = save_xattr_ref(c, ref);
if (ret) {
jffs2_free_xattr_ref(ref);
return ERR_PTR(ret);
struct jffs2_inode_cache *ic = f->inocache;
struct jffs2_xattr_datum *xd;
struct jffs2_xattr_ref *ref, *newref, **pref;
- uint32_t phys_ofs, length, request;
+ uint32_t length, request;
int rc;
rc = check_xattr_ref_inode(c, ic);
return rc;
request = PAD(sizeof(struct jffs2_raw_xattr) + strlen(xname) + 1 + size);
- rc = jffs2_reserve_space(c, request, &phys_ofs, &length,
+ rc = jffs2_reserve_space(c, request, &length,
ALLOC_NORMAL, JFFS2_SUMMARY_XATTR_SIZE);
if (rc) {
JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request);
goto out;
}
found:
- xd = create_xattr_datum(c, xprefix, xname, buffer, size, phys_ofs);
+ xd = create_xattr_datum(c, xprefix, xname, buffer, size);
if (IS_ERR(xd)) {
rc = PTR_ERR(xd);
goto out;
/* create xattr_ref */
request = PAD(sizeof(struct jffs2_raw_xref));
- rc = jffs2_reserve_space(c, request, &phys_ofs, &length,
+ rc = jffs2_reserve_space(c, request, &length,
ALLOC_NORMAL, JFFS2_SUMMARY_XREF_SIZE);
if (rc) {
JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request);
down_write(&c->xattr_sem);
if (ref)
*pref = ref->next;
- newref = create_xattr_ref(c, ic, xd, phys_ofs);
+ newref = create_xattr_ref(c, ic, xd);
if (IS_ERR(newref)) {
if (ref) {
ref->next = ic->xref;
* -------------------------------------------------- */
int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
{
- uint32_t phys_ofs, totlen, length, old_ofs;
+ uint32_t totlen, length, old_ofs;
int rc = -EINVAL;
down_write(&c->xattr_sem);
} else if (unlikely(rc < 0))
goto out;
}
- rc = jffs2_reserve_space_gc(c, totlen, &phys_ofs, &length, JFFS2_SUMMARY_XATTR_SIZE);
+ rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XATTR_SIZE);
if (rc || length < totlen) {
JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, totlen);
rc = rc ? rc : -EBADFD;
goto out;
}
- rc = save_xattr_datum(c, xd, phys_ofs);
+ rc = save_xattr_datum(c, xd);
if (!rc)
dbg_xattr("xdatum (xid=%u, version=%u) GC'ed from %#08x to %08x\n",
xd->xid, xd->version, old_ofs, ref_offset(xd->node));
int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
{
- uint32_t phys_ofs, totlen, length, old_ofs;
+ uint32_t totlen, length, old_ofs;
int rc = -EINVAL;
down_write(&c->xattr_sem);
if (totlen != sizeof(struct jffs2_raw_xref))
goto out;
- rc = jffs2_reserve_space_gc(c, totlen, &phys_ofs, &length, JFFS2_SUMMARY_XREF_SIZE);
+ rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XREF_SIZE);
if (rc || length < totlen) {
JFFS2_WARNING("%s: jffs2_reserve_space() = %d, request = %u\n",
__FUNCTION__, rc, totlen);
rc = rc ? rc : -EBADFD;
goto out;
}
- rc = save_xattr_ref(c, ref, phys_ofs);
+ rc = save_xattr_ref(c, ref);
if (!rc)
dbg_xattr("xref (ino=%u, xid=%u) GC'ed from %#08x to %08x\n",
ref->ic->ino, ref->xd->xid, old_ofs, ref_offset(ref->node));