]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/jffs2/xattr.c
[PATCH] x86_64: Calgary IOMMU - move valid_dma_direction into the callers
[linux-2.6-omap-h63xx.git] / fs / jffs2 / xattr.c
index 057bd4dcf665361c461c24bc65a80ad2e3d5d940..2d82e250be34e234ec6f533b8f37b1620b88e04c 100644 (file)
@@ -49,9 +49,9 @@
  *   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.
  * -------------------------------------------------- */
 
@@ -111,7 +111,7 @@ static void delete_xattr_datum_node(struct jffs2_sb_info *c, struct jffs2_xattr_
 {
        /* must be called under down_write(xattr_sem) */
        struct jffs2_raw_xattr rx;
-       uint32_t length;
+       size_t length;
        int rc;
 
        if (!xd->node) {
@@ -124,14 +124,14 @@ static void delete_xattr_datum_node(struct jffs2_sb_info *c, struct jffs2_xattr_
                                      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));
                }
        }
@@ -169,7 +169,7 @@ static int do_verify_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_dat
 
        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;
        }
@@ -240,7 +240,7 @@ static int do_load_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum
                               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;
@@ -301,14 +301,15 @@ static int load_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *x
        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);
 
@@ -318,14 +319,6 @@ static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *x
        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);
@@ -342,23 +335,19 @@ static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *x
 
        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;
@@ -371,8 +360,7 @@ static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *x
 
 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;
@@ -421,7 +409,7 @@ static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c,
        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);
@@ -448,9 +436,9 @@ static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c,
  * 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.
@@ -471,7 +459,7 @@ static int verify_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref
 
        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;
        }
@@ -487,7 +475,7 @@ static int verify_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref
            || 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)));
@@ -514,7 +502,7 @@ static int verify_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref
 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()) {
@@ -523,14 +511,14 @@ static void delete_xattr_ref_node(struct jffs2_sb_info *c, struct jffs2_xattr_re
                                      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));
                }
        }
@@ -556,22 +544,15 @@ static void delete_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *re
        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)));
@@ -583,22 +564,17 @@ static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref,
 
        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;
@@ -609,7 +585,7 @@ static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref,
 }
 
 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;
@@ -621,7 +597,7 @@ static struct jffs2_xattr_ref *create_xattr_ref(struct jffs2_sb_info *c, struct
        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);
@@ -1067,7 +1043,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
        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);
@@ -1075,7 +1051,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
                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);
@@ -1122,7 +1098,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
                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;
@@ -1132,7 +1108,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
 
        /* 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);
@@ -1146,7 +1122,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
        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;
@@ -1175,7 +1151,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
  * -------------------------------------------------- */
 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);
@@ -1195,13 +1171,13 @@ int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xatt
                } 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));
@@ -1213,7 +1189,7 @@ int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xatt
 
 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);
@@ -1224,14 +1200,14 @@ int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_
        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));