Lines Matching refs:xd

71 static int is_xattr_datum_unchecked(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)  in is_xattr_datum_unchecked()  argument
77 for (raw=xd->node; raw != (void *)xd; raw=raw->next_in_ino) { in is_xattr_datum_unchecked()
87 static void unload_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) in unload_xattr_datum() argument
90 D1(dbg_xattr("%s: xid=%u, version=%u\n", __func__, xd->xid, xd->version)); in unload_xattr_datum()
91 if (xd->xname) { in unload_xattr_datum()
92 c->xdatum_mem_usage -= (xd->name_len + 1 + xd->value_len); in unload_xattr_datum()
93 kfree(xd->xname); in unload_xattr_datum()
96 list_del_init(&xd->xindex); in unload_xattr_datum()
97 xd->hashkey = 0; in unload_xattr_datum()
98 xd->xname = NULL; in unload_xattr_datum()
99 xd->xvalue = NULL; in unload_xattr_datum()
105 struct jffs2_xattr_datum *xd, *_xd; in reclaim_xattr_datum() local
116 list_for_each_entry_safe(xd, _xd, &c->xattrindex[index], xindex) { in reclaim_xattr_datum()
117 if (xd->flags & JFFS2_XFLAGS_HOT) { in reclaim_xattr_datum()
118 xd->flags &= ~JFFS2_XFLAGS_HOT; in reclaim_xattr_datum()
119 } else if (!(xd->flags & JFFS2_XFLAGS_BIND)) { in reclaim_xattr_datum()
120 unload_xattr_datum(c, xd); in reclaim_xattr_datum()
132 static int do_verify_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) in do_verify_xattr_datum() argument
143 offset = ref_offset(xd->node); in do_verify_xattr_datum()
144 if (ref_flags(xd->node) == REF_PRISTINE) in do_verify_xattr_datum()
158 xd->flags |= JFFS2_XFLAGS_INVALID; in do_verify_xattr_datum()
165 || je32_to_cpu(rx.xid) != xd->xid in do_verify_xattr_datum()
166 || je32_to_cpu(rx.version) != xd->version) { in do_verify_xattr_datum()
172 je32_to_cpu(rx.xid), xd->xid, in do_verify_xattr_datum()
173 je32_to_cpu(rx.version), xd->version); in do_verify_xattr_datum()
174 xd->flags |= JFFS2_XFLAGS_INVALID; in do_verify_xattr_datum()
177 xd->xprefix = rx.xprefix; in do_verify_xattr_datum()
178 xd->name_len = rx.name_len; in do_verify_xattr_datum()
179 xd->value_len = je16_to_cpu(rx.value_len); in do_verify_xattr_datum()
180 xd->data_crc = je32_to_cpu(rx.data_crc); in do_verify_xattr_datum()
184 for (raw=xd->node; raw != (void *)xd; raw=raw->next_in_ino) { in do_verify_xattr_datum()
191 raw->flash_offset = ref_offset(raw) | ((xd->node==raw) ? REF_PRISTINE : REF_NORMAL); in do_verify_xattr_datum()
196 list_del_init(&xd->xindex); in do_verify_xattr_datum()
199 xd->xid, xd->version); in do_verify_xattr_datum()
204 static int do_load_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) in do_load_xattr_datum() argument
212 BUG_ON(ref_flags(xd->node) != REF_PRISTINE); in do_load_xattr_datum()
213 BUG_ON(!list_empty(&xd->xindex)); in do_load_xattr_datum()
215 length = xd->name_len + 1 + xd->value_len; in do_load_xattr_datum()
220 ret = jffs2_flash_read(c, ref_offset(xd->node)+sizeof(struct jffs2_raw_xattr), in do_load_xattr_datum()
225 ret, length, readlen, ref_offset(xd->node)); in do_load_xattr_datum()
230 data[xd->name_len] = '\0'; in do_load_xattr_datum()
232 if (crc != xd->data_crc) { in do_load_xattr_datum()
235 ref_offset(xd->node), xd->data_crc, crc); in do_load_xattr_datum()
237 xd->flags |= JFFS2_XFLAGS_INVALID; in do_load_xattr_datum()
241 xd->flags |= JFFS2_XFLAGS_HOT; in do_load_xattr_datum()
242 xd->xname = data; in do_load_xattr_datum()
243 xd->xvalue = data + xd->name_len+1; in do_load_xattr_datum()
247 xd->hashkey = xattr_datum_hashkey(xd->xprefix, xd->xname, xd->xvalue, xd->value_len); in do_load_xattr_datum()
248 i = xd->hashkey % XATTRINDEX_HASHSIZE; in do_load_xattr_datum()
249 list_add(&xd->xindex, &c->xattrindex[i]); in do_load_xattr_datum()
253 if (!xd->xname) in do_load_xattr_datum()
258 xd->xid, xd->xprefix, xd->xname); in do_load_xattr_datum()
263 static int load_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) in load_xattr_datum() argument
272 BUG_ON(xd->flags & JFFS2_XFLAGS_DEAD); in load_xattr_datum()
273 if (xd->xname) in load_xattr_datum()
275 if (xd->flags & JFFS2_XFLAGS_INVALID) in load_xattr_datum()
277 if (unlikely(is_xattr_datum_unchecked(c, xd))) in load_xattr_datum()
278 rc = do_verify_xattr_datum(c, xd); in load_xattr_datum()
280 rc = do_load_xattr_datum(c, xd); in load_xattr_datum()
284 static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) in save_xattr_datum() argument
293 BUG_ON(!xd->xname); in save_xattr_datum()
294 BUG_ON(xd->flags & (JFFS2_XFLAGS_DEAD|JFFS2_XFLAGS_INVALID)); in save_xattr_datum()
298 vecs[1].iov_base = xd->xname; in save_xattr_datum()
299 vecs[1].iov_len = xd->name_len + 1 + xd->value_len; in save_xattr_datum()
309 rx.xid = cpu_to_je32(xd->xid); in save_xattr_datum()
310 rx.version = cpu_to_je32(++xd->version); in save_xattr_datum()
311 rx.xprefix = xd->xprefix; in save_xattr_datum()
312 rx.name_len = xd->name_len; in save_xattr_datum()
313 rx.value_len = cpu_to_je16(xd->value_len); in save_xattr_datum()
328 jffs2_add_physical_node_ref(c, phys_ofs | REF_PRISTINE, PAD(totlen), (void *)xd); in save_xattr_datum()
331 xd->xid, xd->version, xd->xprefix, xd->xname); in save_xattr_datum()
341 struct jffs2_xattr_datum *xd; in create_xattr_datum() local
349 list_for_each_entry(xd, &c->xattrindex[i], xindex) { in create_xattr_datum()
350 if (xd->hashkey==hashkey in create_xattr_datum()
351 && xd->xprefix==xprefix in create_xattr_datum()
352 && xd->value_len==xsize in create_xattr_datum()
353 && !strcmp(xd->xname, xname) in create_xattr_datum()
354 && !memcmp(xd->xvalue, xvalue, xsize)) { in create_xattr_datum()
355 atomic_inc(&xd->refcnt); in create_xattr_datum()
356 return xd; in create_xattr_datum()
363 xd = jffs2_alloc_xattr_datum(); in create_xattr_datum()
364 if (!xd) in create_xattr_datum()
369 jffs2_free_xattr_datum(xd); in create_xattr_datum()
375 atomic_set(&xd->refcnt, 1); in create_xattr_datum()
376 xd->xid = ++c->highest_xid; in create_xattr_datum()
377 xd->flags |= JFFS2_XFLAGS_HOT; in create_xattr_datum()
378 xd->xprefix = xprefix; in create_xattr_datum()
380 xd->hashkey = hashkey; in create_xattr_datum()
381 xd->xname = data; in create_xattr_datum()
382 xd->xvalue = data + name_len + 1; in create_xattr_datum()
383 xd->name_len = name_len; in create_xattr_datum()
384 xd->value_len = xsize; in create_xattr_datum()
385 xd->data_crc = crc32(0, data, xd->name_len + 1 + xd->value_len); in create_xattr_datum()
387 rc = save_xattr_datum(c, xd); in create_xattr_datum()
389 kfree(xd->xname); in create_xattr_datum()
390 jffs2_free_xattr_datum(xd); in create_xattr_datum()
396 list_add(&xd->xindex, &c->xattrindex[i]); in create_xattr_datum()
398 c->xdatum_mem_usage += (xd->name_len + 1 + xd->value_len); in create_xattr_datum()
401 return xd; in create_xattr_datum()
404 static void unrefer_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) in unrefer_xattr_datum() argument
407 if (atomic_dec_and_lock(&xd->refcnt, &c->erase_completion_lock)) { in unrefer_xattr_datum()
408 unload_xattr_datum(c, xd); in unrefer_xattr_datum()
409 xd->flags |= JFFS2_XFLAGS_DEAD; in unrefer_xattr_datum()
410 if (xd->node == (void *)xd) { in unrefer_xattr_datum()
411 BUG_ON(!(xd->flags & JFFS2_XFLAGS_INVALID)); in unrefer_xattr_datum()
412 jffs2_free_xattr_datum(xd); in unrefer_xattr_datum()
414 list_add(&xd->xindex, &c->xattr_dead_list); in unrefer_xattr_datum()
419 xd->xid, xd->version); in unrefer_xattr_datum()
526 rr.xid = cpu_to_je32(ref->xd->xid); in save_xattr_ref()
545 dbg_xattr("success on saving xref (ino=%u, xid=%u)\n", ref->ic->ino, ref->xd->xid); in save_xattr_ref()
551 struct jffs2_xattr_datum *xd) in create_xattr_ref() argument
561 ref->xd = xd; in create_xattr_ref()
579 struct jffs2_xattr_datum *xd; in delete_xattr_ref() local
581 xd = ref->xd; in delete_xattr_ref()
584 ref->xid = ref->xd->xid; in delete_xattr_ref()
593 unrefer_xattr_datum(c, xd); in delete_xattr_ref()
617 struct jffs2_xattr_datum *xd; in jffs2_xattr_free_inode() local
623 xd = ref->xd; in jffs2_xattr_free_inode()
624 if (atomic_dec_and_test(&xd->refcnt)) { in jffs2_xattr_free_inode()
625 unload_xattr_datum(c, xd); in jffs2_xattr_free_inode()
626 jffs2_free_xattr_datum(xd); in jffs2_xattr_free_inode()
649 if (!ref->xd->xname) { in check_xattr_ref_inode()
650 rc = load_xattr_datum(c, ref->xd); in check_xattr_ref_inode()
659 if (!cmp->xd->xname) { in check_xattr_ref_inode()
660 ref->xd->flags |= JFFS2_XFLAGS_BIND; in check_xattr_ref_inode()
661 rc = load_xattr_datum(c, cmp->xd); in check_xattr_ref_inode()
662 ref->xd->flags &= ~JFFS2_XFLAGS_BIND; in check_xattr_ref_inode()
670 if (ref->xd->xprefix == cmp->xd->xprefix in check_xattr_ref_inode()
671 && !strcmp(ref->xd->xname, cmp->xd->xname)) { in check_xattr_ref_inode()
727 struct jffs2_xattr_datum *xd; in jffs2_find_xattr_datum() local
733 list_for_each_entry(xd, &c->xattrindex[i], xindex) { in jffs2_find_xattr_datum()
734 if (xd->xid==xid) in jffs2_find_xattr_datum()
735 return xd; in jffs2_find_xattr_datum()
742 struct jffs2_xattr_datum *xd, *_xd; in jffs2_clear_xattr_subsystem() local
757 list_for_each_entry_safe(xd, _xd, &c->xattrindex[i], xindex) { in jffs2_clear_xattr_subsystem()
758 list_del(&xd->xindex); in jffs2_clear_xattr_subsystem()
759 kfree(xd->xname); in jffs2_clear_xattr_subsystem()
760 jffs2_free_xattr_datum(xd); in jffs2_clear_xattr_subsystem()
764 list_for_each_entry_safe(xd, _xd, &c->xattr_dead_list, xindex) { in jffs2_clear_xattr_subsystem()
765 list_del(&xd->xindex); in jffs2_clear_xattr_subsystem()
766 jffs2_free_xattr_datum(xd); in jffs2_clear_xattr_subsystem()
768 list_for_each_entry_safe(xd, _xd, &c->xattr_unchecked, xindex) { in jffs2_clear_xattr_subsystem()
769 list_del(&xd->xindex); in jffs2_clear_xattr_subsystem()
770 jffs2_free_xattr_datum(xd); in jffs2_clear_xattr_subsystem()
779 struct jffs2_xattr_datum *xd, *_xd; in jffs2_build_xattr_subsystem() local
841 xd = jffs2_find_xattr_datum(c, ref->xid); in jffs2_build_xattr_subsystem()
843 if (!xd || !ic || !ic->pino_nlink) { in jffs2_build_xattr_subsystem()
852 ref->xd = xd; in jffs2_build_xattr_subsystem()
854 atomic_inc(&xd->refcnt); in jffs2_build_xattr_subsystem()
862 list_for_each_entry_safe(xd, _xd, &c->xattrindex[i], xindex) { in jffs2_build_xattr_subsystem()
864 list_del_init(&xd->xindex); in jffs2_build_xattr_subsystem()
865 if (!atomic_read(&xd->refcnt)) { in jffs2_build_xattr_subsystem()
867 xd->xid, xd->version); in jffs2_build_xattr_subsystem()
868 xd->flags |= JFFS2_XFLAGS_DEAD; in jffs2_build_xattr_subsystem()
869 list_add(&xd->xindex, &c->xattr_unchecked); in jffs2_build_xattr_subsystem()
873 if (is_xattr_datum_unchecked(c, xd)) { in jffs2_build_xattr_subsystem()
875 xd->xid, xd->version); in jffs2_build_xattr_subsystem()
876 list_add(&xd->xindex, &c->xattr_unchecked); in jffs2_build_xattr_subsystem()
892 struct jffs2_xattr_datum *xd; in jffs2_setup_xattr_datum() local
894 xd = jffs2_find_xattr_datum(c, xid); in jffs2_setup_xattr_datum()
895 if (!xd) { in jffs2_setup_xattr_datum()
896 xd = jffs2_alloc_xattr_datum(); in jffs2_setup_xattr_datum()
897 if (!xd) in jffs2_setup_xattr_datum()
899 xd->xid = xid; in jffs2_setup_xattr_datum()
900 xd->version = version; in jffs2_setup_xattr_datum()
901 if (xd->xid > c->highest_xid) in jffs2_setup_xattr_datum()
902 c->highest_xid = xd->xid; in jffs2_setup_xattr_datum()
903 list_add_tail(&xd->xindex, &c->xattrindex[xid % XATTRINDEX_HASHSIZE]); in jffs2_setup_xattr_datum()
905 return xd; in jffs2_setup_xattr_datum()
968 struct jffs2_xattr_datum *xd; in jffs2_listxattr() local
983 xd = ref->xd; in jffs2_listxattr()
984 if (!xd->xname) { in jffs2_listxattr()
992 rc = load_xattr_datum(c, xd); in jffs2_listxattr()
1001 xhandle = xprefix_to_handler(xd->xprefix); in jffs2_listxattr()
1006 rc = prefix_len + xd->name_len + 1; in jffs2_listxattr()
1015 memcpy(buffer, xd->xname, xd->name_len); in jffs2_listxattr()
1016 buffer += xd->name_len; in jffs2_listxattr()
1037 struct jffs2_xattr_datum *xd; in do_jffs2_getxattr() local
1050 xd = ref->xd; in do_jffs2_getxattr()
1051 if (xd->xprefix != xprefix) in do_jffs2_getxattr()
1053 if (!xd->xname) { in do_jffs2_getxattr()
1061 rc = load_xattr_datum(c, xd); in do_jffs2_getxattr()
1071 if (!strcmp(xname, xd->xname)) { in do_jffs2_getxattr()
1072 rc = xd->value_len; in do_jffs2_getxattr()
1077 memcpy(buffer, xd->xvalue, rc); in do_jffs2_getxattr()
1099 struct jffs2_xattr_datum *xd; in do_jffs2_setxattr() local
1120 xd = ref->xd; in do_jffs2_setxattr()
1121 if (xd->xprefix != xprefix) in do_jffs2_setxattr()
1123 if (!xd->xname) { in do_jffs2_setxattr()
1124 rc = load_xattr_datum(c, xd); in do_jffs2_setxattr()
1132 if (!strcmp(xd->xname, xname)) { in do_jffs2_setxattr()
1139 ref->xid = xd->xid; in do_jffs2_setxattr()
1148 unrefer_xattr_datum(c, xd); in do_jffs2_setxattr()
1151 ref->xd = xd; in do_jffs2_setxattr()
1169 xd = create_xattr_datum(c, xprefix, xname, buffer, size); in do_jffs2_setxattr()
1170 if (IS_ERR(xd)) { in do_jffs2_setxattr()
1171 rc = PTR_ERR(xd); in do_jffs2_setxattr()
1184 unrefer_xattr_datum(c, xd); in do_jffs2_setxattr()
1190 newref = create_xattr_ref(c, ic, xd); in do_jffs2_setxattr()
1197 unrefer_xattr_datum(c, xd); in do_jffs2_setxattr()
1219 int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd, in jffs2_garbage_collect_xattr_datum() argument
1226 if (xd->node != raw) in jffs2_garbage_collect_xattr_datum()
1228 if (xd->flags & (JFFS2_XFLAGS_DEAD|JFFS2_XFLAGS_INVALID)) in jffs2_garbage_collect_xattr_datum()
1231 rc = load_xattr_datum(c, xd); in jffs2_garbage_collect_xattr_datum()
1236 old_ofs = ref_offset(xd->node); in jffs2_garbage_collect_xattr_datum()
1238 + xd->name_len + 1 + xd->value_len); in jffs2_garbage_collect_xattr_datum()
1244 rc = save_xattr_datum(c, xd); in jffs2_garbage_collect_xattr_datum()
1247 xd->xid, xd->version, old_ofs, ref_offset(xd->node)); in jffs2_garbage_collect_xattr_datum()
1281 ref->ic->ino, ref->xd->xid, old_ofs, ref_offset(ref->node)); in jffs2_garbage_collect_xattr_ref()
1291 struct jffs2_xattr_datum *xd, *_xd; in jffs2_verify_xattr() local
1298 list_for_each_entry_safe(xd, _xd, &c->xattr_unchecked, xindex) { in jffs2_verify_xattr()
1299 rc = do_verify_xattr_datum(c, xd); in jffs2_verify_xattr()
1302 list_del_init(&xd->xindex); in jffs2_verify_xattr()
1304 for (raw=xd->node; raw != (void *)xd; raw=raw->next_in_ino) { in jffs2_verify_xattr()
1312 | ((xd->node == (void *)raw) ? REF_PRISTINE : REF_NORMAL); in jffs2_verify_xattr()
1314 if (xd->flags & JFFS2_XFLAGS_DEAD) in jffs2_verify_xattr()
1315 list_add(&xd->xindex, &c->xattr_dead_list); in jffs2_verify_xattr()
1322 void jffs2_release_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) in jffs2_release_xattr_datum() argument
1325 if (atomic_read(&xd->refcnt) || xd->node != (void *)xd) in jffs2_release_xattr_datum()
1328 list_del(&xd->xindex); in jffs2_release_xattr_datum()
1329 jffs2_free_xattr_datum(xd); in jffs2_release_xattr_datum()