aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jffs2/xattr.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/jffs2/xattr.c')
-rw-r--r--fs/jffs2/xattr.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
index 76d166140381..008f91b1c171 100644
--- a/fs/jffs2/xattr.c
+++ b/fs/jffs2/xattr.c
@@ -49,9 +49,9 @@
49 * is used to be as a wrapper of do_verify_xattr_datum() and do_load_xattr_datum(). 49 * is used to be as a wrapper of do_verify_xattr_datum() and do_load_xattr_datum().
50 * If xd need to call do_verify_xattr_datum() at first, it's called before calling 50 * If xd need to call do_verify_xattr_datum() at first, it's called before calling
51 * do_load_xattr_datum(). The meanings of return value is same as do_verify_xattr_datum(). 51 * do_load_xattr_datum(). The meanings of return value is same as do_verify_xattr_datum().
52 * save_xattr_datum(c, xd, phys_ofs) 52 * save_xattr_datum(c, xd)
53 * is used to write xdatum to medium. xd->version will be incremented. 53 * is used to write xdatum to medium. xd->version will be incremented.
54 * create_xattr_datum(c, xprefix, xname, xvalue, xsize, phys_ofs) 54 * create_xattr_datum(c, xprefix, xname, xvalue, xsize)
55 * is used to create new xdatum and write to medium. 55 * is used to create new xdatum and write to medium.
56 * -------------------------------------------------- */ 56 * -------------------------------------------------- */
57 57
@@ -301,7 +301,7 @@ static int load_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *x
301 return rc; 301 return rc;
302} 302}
303 303
304static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd, uint32_t phys_ofs) 304static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
305{ 305{
306 /* must be called under down_write(xattr_sem) */ 306 /* must be called under down_write(xattr_sem) */
307 struct jffs2_raw_xattr rx; 307 struct jffs2_raw_xattr rx;
@@ -309,6 +309,7 @@ static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *x
309 struct kvec vecs[2]; 309 struct kvec vecs[2];
310 uint32_t length; 310 uint32_t length;
311 int rc, totlen; 311 int rc, totlen;
312 uint32_t phys_ofs = write_ofs(c);
312 313
313 BUG_ON(!xd->xname); 314 BUG_ON(!xd->xname);
314 315
@@ -369,8 +370,7 @@ static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *x
369 370
370static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c, 371static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c,
371 int xprefix, const char *xname, 372 int xprefix, const char *xname,
372 const char *xvalue, int xsize, 373 const char *xvalue, int xsize)
373 uint32_t phys_ofs)
374{ 374{
375 /* must be called under down_write(xattr_sem) */ 375 /* must be called under down_write(xattr_sem) */
376 struct jffs2_xattr_datum *xd; 376 struct jffs2_xattr_datum *xd;
@@ -419,7 +419,7 @@ static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c,
419 xd->value_len = xsize; 419 xd->value_len = xsize;
420 xd->data_crc = crc32(0, data, xd->name_len + 1 + xd->value_len); 420 xd->data_crc = crc32(0, data, xd->name_len + 1 + xd->value_len);
421 421
422 rc = save_xattr_datum(c, xd, phys_ofs); 422 rc = save_xattr_datum(c, xd);
423 if (rc) { 423 if (rc) {
424 kfree(xd->xname); 424 kfree(xd->xname);
425 jffs2_free_xattr_datum(xd); 425 jffs2_free_xattr_datum(xd);
@@ -446,9 +446,9 @@ static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c,
446 * delete_xattr_ref(c, ref) 446 * delete_xattr_ref(c, ref)
447 * is used to delete jffs2_xattr_ref object. If the reference counter of xdatum 447 * is used to delete jffs2_xattr_ref object. If the reference counter of xdatum
448 * is refered by this xref become 0, delete_xattr_datum() is called later. 448 * is refered by this xref become 0, delete_xattr_datum() is called later.
449 * save_xattr_ref(c, ref, phys_ofs) 449 * save_xattr_ref(c, ref)
450 * is used to write xref to medium. 450 * is used to write xref to medium.
451 * create_xattr_ref(c, ic, xd, phys_ofs) 451 * create_xattr_ref(c, ic, xd)
452 * is used to create a new xref and write to medium. 452 * is used to create a new xref and write to medium.
453 * jffs2_xattr_delete_inode(c, ic) 453 * jffs2_xattr_delete_inode(c, ic)
454 * is called to remove xrefs related to obsolete inode when inode is unlinked. 454 * is called to remove xrefs related to obsolete inode when inode is unlinked.
@@ -554,12 +554,13 @@ static void delete_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *re
554 jffs2_free_xattr_ref(ref); 554 jffs2_free_xattr_ref(ref);
555} 555}
556 556
557static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref, uint32_t phys_ofs) 557static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
558{ 558{
559 /* must be called under down_write(xattr_sem) */ 559 /* must be called under down_write(xattr_sem) */
560 struct jffs2_raw_node_ref *raw; 560 struct jffs2_raw_node_ref *raw;
561 struct jffs2_raw_xref rr; 561 struct jffs2_raw_xref rr;
562 uint32_t length; 562 uint32_t length;
563 uint32_t phys_ofs = write_ofs(c);
563 int ret; 564 int ret;
564 565
565 raw = jffs2_alloc_raw_node_ref(); 566 raw = jffs2_alloc_raw_node_ref();
@@ -604,7 +605,7 @@ static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref,
604} 605}
605 606
606static struct jffs2_xattr_ref *create_xattr_ref(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic, 607static struct jffs2_xattr_ref *create_xattr_ref(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic,
607 struct jffs2_xattr_datum *xd, uint32_t phys_ofs) 608 struct jffs2_xattr_datum *xd)
608{ 609{
609 /* must be called under down_write(xattr_sem) */ 610 /* must be called under down_write(xattr_sem) */
610 struct jffs2_xattr_ref *ref; 611 struct jffs2_xattr_ref *ref;
@@ -616,7 +617,7 @@ static struct jffs2_xattr_ref *create_xattr_ref(struct jffs2_sb_info *c, struct
616 ref->ic = ic; 617 ref->ic = ic;
617 ref->xd = xd; 618 ref->xd = xd;
618 619
619 ret = save_xattr_ref(c, ref, phys_ofs); 620 ret = save_xattr_ref(c, ref);
620 if (ret) { 621 if (ret) {
621 jffs2_free_xattr_ref(ref); 622 jffs2_free_xattr_ref(ref);
622 return ERR_PTR(ret); 623 return ERR_PTR(ret);
@@ -1062,7 +1063,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
1062 struct jffs2_inode_cache *ic = f->inocache; 1063 struct jffs2_inode_cache *ic = f->inocache;
1063 struct jffs2_xattr_datum *xd; 1064 struct jffs2_xattr_datum *xd;
1064 struct jffs2_xattr_ref *ref, *newref, **pref; 1065 struct jffs2_xattr_ref *ref, *newref, **pref;
1065 uint32_t phys_ofs, length, request; 1066 uint32_t length, request;
1066 int rc; 1067 int rc;
1067 1068
1068 rc = check_xattr_ref_inode(c, ic); 1069 rc = check_xattr_ref_inode(c, ic);
@@ -1070,7 +1071,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
1070 return rc; 1071 return rc;
1071 1072
1072 request = PAD(sizeof(struct jffs2_raw_xattr) + strlen(xname) + 1 + size); 1073 request = PAD(sizeof(struct jffs2_raw_xattr) + strlen(xname) + 1 + size);
1073 rc = jffs2_reserve_space(c, request, &phys_ofs, &length, 1074 rc = jffs2_reserve_space(c, request, &length,
1074 ALLOC_NORMAL, JFFS2_SUMMARY_XATTR_SIZE); 1075 ALLOC_NORMAL, JFFS2_SUMMARY_XATTR_SIZE);
1075 if (rc) { 1076 if (rc) {
1076 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request); 1077 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request);
@@ -1117,7 +1118,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
1117 goto out; 1118 goto out;
1118 } 1119 }
1119 found: 1120 found:
1120 xd = create_xattr_datum(c, xprefix, xname, buffer, size, phys_ofs); 1121 xd = create_xattr_datum(c, xprefix, xname, buffer, size);
1121 if (IS_ERR(xd)) { 1122 if (IS_ERR(xd)) {
1122 rc = PTR_ERR(xd); 1123 rc = PTR_ERR(xd);
1123 goto out; 1124 goto out;
@@ -1127,7 +1128,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
1127 1128
1128 /* create xattr_ref */ 1129 /* create xattr_ref */
1129 request = PAD(sizeof(struct jffs2_raw_xref)); 1130 request = PAD(sizeof(struct jffs2_raw_xref));
1130 rc = jffs2_reserve_space(c, request, &phys_ofs, &length, 1131 rc = jffs2_reserve_space(c, request, &length,
1131 ALLOC_NORMAL, JFFS2_SUMMARY_XREF_SIZE); 1132 ALLOC_NORMAL, JFFS2_SUMMARY_XREF_SIZE);
1132 if (rc) { 1133 if (rc) {
1133 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request); 1134 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request);
@@ -1141,7 +1142,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
1141 down_write(&c->xattr_sem); 1142 down_write(&c->xattr_sem);
1142 if (ref) 1143 if (ref)
1143 *pref = ref->next; 1144 *pref = ref->next;
1144 newref = create_xattr_ref(c, ic, xd, phys_ofs); 1145 newref = create_xattr_ref(c, ic, xd);
1145 if (IS_ERR(newref)) { 1146 if (IS_ERR(newref)) {
1146 if (ref) { 1147 if (ref) {
1147 ref->next = ic->xref; 1148 ref->next = ic->xref;
@@ -1170,7 +1171,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
1170 * -------------------------------------------------- */ 1171 * -------------------------------------------------- */
1171int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) 1172int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
1172{ 1173{
1173 uint32_t phys_ofs, totlen, length, old_ofs; 1174 uint32_t totlen, length, old_ofs;
1174 int rc = -EINVAL; 1175 int rc = -EINVAL;
1175 1176
1176 down_write(&c->xattr_sem); 1177 down_write(&c->xattr_sem);
@@ -1190,13 +1191,13 @@ int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xatt
1190 } else if (unlikely(rc < 0)) 1191 } else if (unlikely(rc < 0))
1191 goto out; 1192 goto out;
1192 } 1193 }
1193 rc = jffs2_reserve_space_gc(c, totlen, &phys_ofs, &length, JFFS2_SUMMARY_XATTR_SIZE); 1194 rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XATTR_SIZE);
1194 if (rc || length < totlen) { 1195 if (rc || length < totlen) {
1195 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, totlen); 1196 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, totlen);
1196 rc = rc ? rc : -EBADFD; 1197 rc = rc ? rc : -EBADFD;
1197 goto out; 1198 goto out;
1198 } 1199 }
1199 rc = save_xattr_datum(c, xd, phys_ofs); 1200 rc = save_xattr_datum(c, xd);
1200 if (!rc) 1201 if (!rc)
1201 dbg_xattr("xdatum (xid=%u, version=%u) GC'ed from %#08x to %08x\n", 1202 dbg_xattr("xdatum (xid=%u, version=%u) GC'ed from %#08x to %08x\n",
1202 xd->xid, xd->version, old_ofs, ref_offset(xd->node)); 1203 xd->xid, xd->version, old_ofs, ref_offset(xd->node));
@@ -1208,7 +1209,7 @@ int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xatt
1208 1209
1209int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref) 1210int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
1210{ 1211{
1211 uint32_t phys_ofs, totlen, length, old_ofs; 1212 uint32_t totlen, length, old_ofs;
1212 int rc = -EINVAL; 1213 int rc = -EINVAL;
1213 1214
1214 down_write(&c->xattr_sem); 1215 down_write(&c->xattr_sem);
@@ -1219,14 +1220,14 @@ int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_
1219 if (totlen != sizeof(struct jffs2_raw_xref)) 1220 if (totlen != sizeof(struct jffs2_raw_xref))
1220 goto out; 1221 goto out;
1221 1222
1222 rc = jffs2_reserve_space_gc(c, totlen, &phys_ofs, &length, JFFS2_SUMMARY_XREF_SIZE); 1223 rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XREF_SIZE);
1223 if (rc || length < totlen) { 1224 if (rc || length < totlen) {
1224 JFFS2_WARNING("%s: jffs2_reserve_space() = %d, request = %u\n", 1225 JFFS2_WARNING("%s: jffs2_reserve_space() = %d, request = %u\n",
1225 __FUNCTION__, rc, totlen); 1226 __FUNCTION__, rc, totlen);
1226 rc = rc ? rc : -EBADFD; 1227 rc = rc ? rc : -EBADFD;
1227 goto out; 1228 goto out;
1228 } 1229 }
1229 rc = save_xattr_ref(c, ref, phys_ofs); 1230 rc = save_xattr_ref(c, ref);
1230 if (!rc) 1231 if (!rc)
1231 dbg_xattr("xref (ino=%u, xid=%u) GC'ed from %#08x to %08x\n", 1232 dbg_xattr("xref (ino=%u, xid=%u) GC'ed from %#08x to %08x\n",
1232 ref->ic->ino, ref->xd->xid, old_ofs, ref_offset(ref->node)); 1233 ref->ic->ino, ref->xd->xid, old_ofs, ref_offset(ref->node));