Lines Matching refs:xd
32 * is_xattr_datum_unchecked(c, xd)
35 * unload_xattr_datum(c, xd)
41 * do_verify_xattr_datum(c, xd)
48 * do_load_xattr_datum(c, xd)
51 * load_xattr_datum(c, xd)
53 * If xd need to call do_verify_xattr_datum() at first, it's called before calling
55 * save_xattr_datum(c, xd)
56 * is used to write xdatum to medium. xd->version will be incremented.
59 * unrefer_xattr_datum(c, xd)
61 * is set on xd->flags and chained xattr_dead_list or release it immediately.
71 static int is_xattr_datum_unchecked(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
77 for (raw=xd->node; raw != (void *)xd; raw=raw->next_in_ino) {
87 static void unload_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
90 D1(dbg_xattr("%s: xid=%u, version=%u\n", __func__, xd->xid, xd->version));
91 if (xd->xname) {
92 c->xdatum_mem_usage -= (xd->name_len + 1 + xd->value_len);
93 kfree(xd->xname);
96 list_del_init(&xd->xindex);
97 xd->hashkey = 0;
98 xd->xname = NULL;
99 xd->xvalue = NULL;
105 struct jffs2_xattr_datum *xd, *_xd;
116 list_for_each_entry_safe(xd, _xd, &c->xattrindex[index], xindex) {
117 if (xd->flags & JFFS2_XFLAGS_HOT) {
118 xd->flags &= ~JFFS2_XFLAGS_HOT;
119 } else if (!(xd->flags & JFFS2_XFLAGS_BIND)) {
120 unload_xattr_datum(c, xd);
132 static int do_verify_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
143 offset = ref_offset(xd->node);
144 if (ref_flags(xd->node) == REF_PRISTINE)
158 xd->flags |= JFFS2_XFLAGS_INVALID;
165 || je32_to_cpu(rx.xid) != xd->xid
166 || je32_to_cpu(rx.version) != xd->version) {
172 je32_to_cpu(rx.xid), xd->xid,
173 je32_to_cpu(rx.version), xd->version);
174 xd->flags |= JFFS2_XFLAGS_INVALID;
177 xd->xprefix = rx.xprefix;
178 xd->name_len = rx.name_len;
179 xd->value_len = je16_to_cpu(rx.value_len);
180 xd->data_crc = je32_to_cpu(rx.data_crc);
184 for (raw=xd->node; raw != (void *)xd; raw=raw->next_in_ino) {
191 raw->flash_offset = ref_offset(raw) | ((xd->node==raw) ? REF_PRISTINE : REF_NORMAL);
196 list_del_init(&xd->xindex);
199 xd->xid, xd->version);
204 static int do_load_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
212 BUG_ON(ref_flags(xd->node) != REF_PRISTINE);
213 BUG_ON(!list_empty(&xd->xindex));
215 length = xd->name_len + 1 + xd->value_len;
220 ret = jffs2_flash_read(c, ref_offset(xd->node)+sizeof(struct jffs2_raw_xattr),
225 ret, length, readlen, ref_offset(xd->node));
230 data[xd->name_len] = '\0';
232 if (crc != xd->data_crc) {
235 ref_offset(xd->node), xd->data_crc, crc);
237 xd->flags |= JFFS2_XFLAGS_INVALID;
241 xd->flags |= JFFS2_XFLAGS_HOT;
242 xd->xname = data;
243 xd->xvalue = data + xd->name_len+1;
247 xd->hashkey = xattr_datum_hashkey(xd->xprefix, xd->xname, xd->xvalue, xd->value_len);
248 i = xd->hashkey % XATTRINDEX_HASHSIZE;
249 list_add(&xd->xindex, &c->xattrindex[i]);
253 if (!xd->xname)
258 xd->xid, xd->xprefix, xd->xname);
263 static int load_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
272 BUG_ON(xd->flags & JFFS2_XFLAGS_DEAD);
273 if (xd->xname)
275 if (xd->flags & JFFS2_XFLAGS_INVALID)
277 if (unlikely(is_xattr_datum_unchecked(c, xd)))
278 rc = do_verify_xattr_datum(c, xd);
280 rc = do_load_xattr_datum(c, xd);
284 static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
293 BUG_ON(!xd->xname);
294 BUG_ON(xd->flags & (JFFS2_XFLAGS_DEAD|JFFS2_XFLAGS_INVALID));
298 vecs[1].iov_base = xd->xname;
299 vecs[1].iov_len = xd->name_len + 1 + xd->value_len;
309 rx.xid = cpu_to_je32(xd->xid);
310 rx.version = cpu_to_je32(++xd->version);
311 rx.xprefix = xd->xprefix;
312 rx.name_len = xd->name_len;
313 rx.value_len = cpu_to_je16(xd->value_len);
328 jffs2_add_physical_node_ref(c, phys_ofs | REF_PRISTINE, PAD(totlen), (void *)xd);
331 xd->xid, xd->version, xd->xprefix, xd->xname);
341 struct jffs2_xattr_datum *xd;
349 list_for_each_entry(xd, &c->xattrindex[i], xindex) {
350 if (xd->hashkey==hashkey
351 && xd->xprefix==xprefix
352 && xd->value_len==xsize
353 && !strcmp(xd->xname, xname)
354 && !memcmp(xd->xvalue, xvalue, xsize)) {
355 atomic_inc(&xd->refcnt);
356 return xd;
363 xd = jffs2_alloc_xattr_datum();
364 if (!xd)
369 jffs2_free_xattr_datum(xd);
375 atomic_set(&xd->refcnt, 1);
376 xd->xid = ++c->highest_xid;
377 xd->flags |= JFFS2_XFLAGS_HOT;
378 xd->xprefix = xprefix;
380 xd->hashkey = hashkey;
381 xd->xname = data;
382 xd->xvalue = data + name_len + 1;
383 xd->name_len = name_len;
384 xd->value_len = xsize;
385 xd->data_crc = crc32(0, data, xd->name_len + 1 + xd->value_len);
387 rc = save_xattr_datum(c, xd);
389 kfree(xd->xname);
390 jffs2_free_xattr_datum(xd);
396 list_add(&xd->xindex, &c->xattrindex[i]);
398 c->xdatum_mem_usage += (xd->name_len + 1 + xd->value_len);
401 return xd;
404 static void unrefer_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
407 if (atomic_dec_and_lock(&xd->refcnt, &c->erase_completion_lock)) {
408 unload_xattr_datum(c, xd);
409 xd->flags |= JFFS2_XFLAGS_DEAD;
410 if (xd->node == (void *)xd) {
411 BUG_ON(!(xd->flags & JFFS2_XFLAGS_INVALID));
412 jffs2_free_xattr_datum(xd);
414 list_add(&xd->xindex, &c->xattr_dead_list);
419 xd->xid, xd->version);
430 * create_xattr_ref(c, ic, xd)
526 rr.xid = cpu_to_je32(ref->xd->xid);
545 dbg_xattr("success on saving xref (ino=%u, xid=%u)\n", ref->ic->ino, ref->xd->xid);
551 struct jffs2_xattr_datum *xd)
561 ref->xd = xd;
579 struct jffs2_xattr_datum *xd;
581 xd = ref->xd;
584 ref->xid = ref->xd->xid;
593 unrefer_xattr_datum(c, xd);
617 struct jffs2_xattr_datum *xd;
623 xd = ref->xd;
624 if (atomic_dec_and_test(&xd->refcnt)) {
625 unload_xattr_datum(c, xd);
626 jffs2_free_xattr_datum(xd);
649 if (!ref->xd->xname) {
650 rc = load_xattr_datum(c, ref->xd);
659 if (!cmp->xd->xname) {
660 ref->xd->flags |= JFFS2_XFLAGS_BIND;
661 rc = load_xattr_datum(c, cmp->xd);
662 ref->xd->flags &= ~JFFS2_XFLAGS_BIND;
670 if (ref->xd->xprefix == cmp->xd->xprefix
671 && !strcmp(ref->xd->xname, cmp->xd->xname)) {
727 struct jffs2_xattr_datum *xd;
733 list_for_each_entry(xd, &c->xattrindex[i], xindex) {
734 if (xd->xid==xid)
735 return xd;
742 struct jffs2_xattr_datum *xd, *_xd;
757 list_for_each_entry_safe(xd, _xd, &c->xattrindex[i], xindex) {
758 list_del(&xd->xindex);
759 kfree(xd->xname);
760 jffs2_free_xattr_datum(xd);
764 list_for_each_entry_safe(xd, _xd, &c->xattr_dead_list, xindex) {
765 list_del(&xd->xindex);
766 jffs2_free_xattr_datum(xd);
768 list_for_each_entry_safe(xd, _xd, &c->xattr_unchecked, xindex) {
769 list_del(&xd->xindex);
770 jffs2_free_xattr_datum(xd);
779 struct jffs2_xattr_datum *xd, *_xd;
843 ref->xd and ref->ic are not valid yet. */
844 xd = jffs2_find_xattr_datum(c, ref->xid);
846 if (!xd || !ic || !ic->pino_nlink) {
855 ref->xd = xd;
857 atomic_inc(&xd->refcnt);
865 list_for_each_entry_safe(xd, _xd, &c->xattrindex[i], xindex) {
867 list_del_init(&xd->xindex);
868 if (!atomic_read(&xd->refcnt)) {
870 xd->xid, xd->version);
871 xd->flags |= JFFS2_XFLAGS_DEAD;
872 list_add(&xd->xindex, &c->xattr_unchecked);
876 if (is_xattr_datum_unchecked(c, xd)) {
878 xd->xid, xd->version);
879 list_add(&xd->xindex, &c->xattr_unchecked);
897 struct jffs2_xattr_datum *xd;
899 xd = jffs2_find_xattr_datum(c, xid);
900 if (!xd) {
901 xd = jffs2_alloc_xattr_datum();
902 if (!xd)
904 xd->xid = xid;
905 xd->version = version;
906 if (xd->xid > c->highest_xid)
907 c->highest_xid = xd->xid;
908 list_add_tail(&xd->xindex, &c->xattrindex[xid % XATTRINDEX_HASHSIZE]);
910 return xd;
973 struct jffs2_xattr_datum *xd;
988 xd = ref->xd;
989 if (!xd->xname) {
997 rc = load_xattr_datum(c, xd);
1006 xhandle = xprefix_to_handler(xd->xprefix);
1011 rc = prefix_len + xd->name_len + 1;
1020 memcpy(buffer, xd->xname, xd->name_len);
1021 buffer += xd->name_len;
1042 struct jffs2_xattr_datum *xd;
1055 xd = ref->xd;
1056 if (xd->xprefix != xprefix)
1058 if (!xd->xname) {
1066 rc = load_xattr_datum(c, xd);
1076 if (!strcmp(xname, xd->xname)) {
1077 rc = xd->value_len;
1082 memcpy(buffer, xd->xvalue, rc);
1104 struct jffs2_xattr_datum *xd;
1125 xd = ref->xd;
1126 if (xd->xprefix != xprefix)
1128 if (!xd->xname) {
1129 rc = load_xattr_datum(c, xd);
1137 if (!strcmp(xd->xname, xname)) {
1144 ref->xid = xd->xid;
1153 unrefer_xattr_datum(c, xd);
1156 ref->xd = xd;
1174 xd = create_xattr_datum(c, xprefix, xname, buffer, size);
1175 if (IS_ERR(xd)) {
1176 rc = PTR_ERR(xd);
1189 unrefer_xattr_datum(c, xd);
1195 newref = create_xattr_ref(c, ic, xd);
1202 unrefer_xattr_datum(c, xd);
1213 * jffs2_garbage_collect_xattr_datum(c, xd, raw)
1219 * jffs2_release_xattr_datum(c, xd)
1224 int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd,
1231 if (xd->node != raw)
1233 if (xd->flags & (JFFS2_XFLAGS_DEAD|JFFS2_XFLAGS_INVALID))
1236 rc = load_xattr_datum(c, xd);
1241 old_ofs = ref_offset(xd->node);
1243 + xd->name_len + 1 + xd->value_len);
1249 rc = save_xattr_datum(c, xd);
1252 xd->xid, xd->version, old_ofs, ref_offset(xd->node));
1286 ref->ic->ino, ref->xd->xid, old_ofs, ref_offset(ref->node));
1296 struct jffs2_xattr_datum *xd, *_xd;
1303 list_for_each_entry_safe(xd, _xd, &c->xattr_unchecked, xindex) {
1304 rc = do_verify_xattr_datum(c, xd);
1307 list_del_init(&xd->xindex);
1309 for (raw=xd->node; raw != (void *)xd; raw=raw->next_in_ino) {
1317 | ((xd->node == (void *)raw) ? REF_PRISTINE : REF_NORMAL);
1319 if (xd->flags & JFFS2_XFLAGS_DEAD)
1320 list_add(&xd->xindex, &c->xattr_dead_list);
1327 void jffs2_release_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
1330 if (atomic_read(&xd->refcnt) || xd->node != (void *)xd)
1333 list_del(&xd->xindex);
1334 jffs2_free_xattr_datum(xd);