2 * JFFS2 -- Journalling Flash File System, Version 2.
4 * Copyright © 2006 NEC Corporation
6 * Created by KaiGai Kohei <kaigai@ak.jp.nec.com>
8 * For licensing information, see the file 'LICENCE' in this directory.
12 #include <linux/kernel.h>
13 #include <linux/slab.h>
15 #include <linux/time.h>
16 #include <linux/pagemap.h>
17 #include <linux/highmem.h>
18 #include <linux/crc32.h>
19 #include <linux/jffs2.h>
20 #include <linux/xattr.h>
21 #include <linux/mtd/mtd.h>
23 /* -------- xdatum related functions ----------------
24 * xattr_datum_hashkey(xprefix, xname, xvalue, xsize)
25 * is used to calcurate xdatum hashkey. The reminder of hashkey into XATTRINDEX_HASHSIZE is
26 * the index of the xattr name/value pair cache (c->xattrindex).
27 * is_xattr_datum_unchecked(c, xd)
28 * returns 1, if xdatum contains any unchecked raw nodes. if all raw nodes are not
29 * unchecked, it returns 0.
30 * unload_xattr_datum(c, xd)
31 * is used to release xattr name/value pair and detach from c->xattrindex.
32 * reclaim_xattr_datum(c)
33 * is used to reclaim xattr name/value pairs on the xattr name/value pair cache when
34 * memory usage by cache is over c->xdatum_mem_threshold. Currentry, this threshold
35 * is hard coded as 32KiB.
36 * do_verify_xattr_datum(c, xd)
37 * is used to load the xdatum informations without name/value pair from the medium.
38 * It's necessary once, because those informations are not collected during mounting
39 * process when EBS is enabled.
40 * 0 will be returned, if success. An negative return value means recoverable error, and
41 * positive return value means unrecoverable error. Thus, caller must remove this xdatum
42 * and xref when it returned positive value.
43 * do_load_xattr_datum(c, xd)
44 * is used to load name/value pair from the medium.
45 * The meanings of return value is same as do_verify_xattr_datum().
46 * load_xattr_datum(c, xd)
47 * is used to be as a wrapper of do_verify_xattr_datum() and do_load_xattr_datum().
48 * If xd need to call do_verify_xattr_datum() at first, it's called before calling
49 * do_load_xattr_datum(). The meanings of return value is same as do_verify_xattr_datum().
50 * save_xattr_datum(c, xd)
51 * is used to write xdatum to medium. xd->version will be incremented.
52 * create_xattr_datum(c, xprefix, xname, xvalue, xsize)
53 * is used to create new xdatum and write to medium.
54 * unrefer_xattr_datum(c, xd)
55 * is used to delete a xdatum. When nobody refers this xdatum, JFFS2_XFLAGS_DEAD
56 * is set on xd->flags and chained xattr_dead_list or release it immediately.
57 * In the first case, the garbage collector release it later.
58 * -------------------------------------------------- */
59 static uint32_t xattr_datum_hashkey(int xprefix
, const char *xname
, const char *xvalue
, int xsize
)
61 int name_len
= strlen(xname
);
63 return crc32(xprefix
, xname
, name_len
) ^ crc32(xprefix
, xvalue
, xsize
);
66 static int is_xattr_datum_unchecked(struct jffs2_sb_info
*c
, struct jffs2_xattr_datum
*xd
)
68 struct jffs2_raw_node_ref
*raw
;
71 spin_lock(&c
->erase_completion_lock
);
72 for (raw
=xd
->node
; raw
!= (void *)xd
; raw
=raw
->next_in_ino
) {
73 if (ref_flags(raw
) == REF_UNCHECKED
) {
78 spin_unlock(&c
->erase_completion_lock
);
82 static void unload_xattr_datum(struct jffs2_sb_info
*c
, struct jffs2_xattr_datum
*xd
)
84 /* must be called under down_write(xattr_sem) */
85 D1(dbg_xattr("%s: xid=%u, version=%u\n", __FUNCTION__
, xd
->xid
, xd
->version
));
87 c
->xdatum_mem_usage
-= (xd
->name_len
+ 1 + xd
->value_len
);
91 list_del_init(&xd
->xindex
);
97 static void reclaim_xattr_datum(struct jffs2_sb_info
*c
)
99 /* must be called under down_write(xattr_sem) */
100 struct jffs2_xattr_datum
*xd
, *_xd
;
101 uint32_t target
, before
;
102 static int index
= 0;
105 if (c
->xdatum_mem_threshold
> c
->xdatum_mem_usage
)
108 before
= c
->xdatum_mem_usage
;
109 target
= c
->xdatum_mem_usage
* 4 / 5; /* 20% reduction */
110 for (count
= 0; count
< XATTRINDEX_HASHSIZE
; count
++) {
111 list_for_each_entry_safe(xd
, _xd
, &c
->xattrindex
[index
], xindex
) {
112 if (xd
->flags
& JFFS2_XFLAGS_HOT
) {
113 xd
->flags
&= ~JFFS2_XFLAGS_HOT
;
114 } else if (!(xd
->flags
& JFFS2_XFLAGS_BIND
)) {
115 unload_xattr_datum(c
, xd
);
117 if (c
->xdatum_mem_usage
<= target
)
120 index
= (index
+1) % XATTRINDEX_HASHSIZE
;
123 JFFS2_NOTICE("xdatum_mem_usage from %u byte to %u byte (%u byte reclaimed)\n",
124 before
, c
->xdatum_mem_usage
, before
- c
->xdatum_mem_usage
);
127 static int do_verify_xattr_datum(struct jffs2_sb_info
*c
, struct jffs2_xattr_datum
*xd
)
129 /* must be called under down_write(xattr_sem) */
130 struct jffs2_eraseblock
*jeb
;
131 struct jffs2_raw_node_ref
*raw
;
132 struct jffs2_raw_xattr rx
;
134 uint32_t crc
, offset
, totlen
;
137 spin_lock(&c
->erase_completion_lock
);
138 offset
= ref_offset(xd
->node
);
139 if (ref_flags(xd
->node
) == REF_PRISTINE
)
141 spin_unlock(&c
->erase_completion_lock
);
143 rc
= jffs2_flash_read(c
, offset
, sizeof(rx
), &readlen
, (char *)&rx
);
144 if (rc
|| readlen
!= sizeof(rx
)) {
145 JFFS2_WARNING("jffs2_flash_read()=%d, req=%zu, read=%zu at %#08x\n",
146 rc
, sizeof(rx
), readlen
, offset
);
147 return rc
? rc
: -EIO
;
149 crc
= crc32(0, &rx
, sizeof(rx
) - 4);
150 if (crc
!= je32_to_cpu(rx
.node_crc
)) {
151 JFFS2_ERROR("node CRC failed at %#08x, read=%#08x, calc=%#08x\n",
152 offset
, je32_to_cpu(rx
.hdr_crc
), crc
);
153 xd
->flags
|= JFFS2_XFLAGS_INVALID
;
156 totlen
= PAD(sizeof(rx
) + rx
.name_len
+ 1 + je16_to_cpu(rx
.value_len
));
157 if (je16_to_cpu(rx
.magic
) != JFFS2_MAGIC_BITMASK
158 || je16_to_cpu(rx
.nodetype
) != JFFS2_NODETYPE_XATTR
159 || je32_to_cpu(rx
.totlen
) != totlen
160 || je32_to_cpu(rx
.xid
) != xd
->xid
161 || je32_to_cpu(rx
.version
) != xd
->version
) {
162 JFFS2_ERROR("inconsistent xdatum at %#08x, magic=%#04x/%#04x, "
163 "nodetype=%#04x/%#04x, totlen=%u/%u, xid=%u/%u, version=%u/%u\n",
164 offset
, je16_to_cpu(rx
.magic
), JFFS2_MAGIC_BITMASK
,
165 je16_to_cpu(rx
.nodetype
), JFFS2_NODETYPE_XATTR
,
166 je32_to_cpu(rx
.totlen
), totlen
,
167 je32_to_cpu(rx
.xid
), xd
->xid
,
168 je32_to_cpu(rx
.version
), xd
->version
);
169 xd
->flags
|= JFFS2_XFLAGS_INVALID
;
172 xd
->xprefix
= rx
.xprefix
;
173 xd
->name_len
= rx
.name_len
;
174 xd
->value_len
= je16_to_cpu(rx
.value_len
);
175 xd
->data_crc
= je32_to_cpu(rx
.data_crc
);
177 spin_lock(&c
->erase_completion_lock
);
179 for (raw
=xd
->node
; raw
!= (void *)xd
; raw
=raw
->next_in_ino
) {
180 jeb
= &c
->blocks
[ref_offset(raw
) / c
->sector_size
];
181 totlen
= PAD(ref_totlen(c
, jeb
, raw
));
182 if (ref_flags(raw
) == REF_UNCHECKED
) {
183 c
->unchecked_size
-= totlen
; c
->used_size
+= totlen
;
184 jeb
->unchecked_size
-= totlen
; jeb
->used_size
+= totlen
;
186 raw
->flash_offset
= ref_offset(raw
) | ((xd
->node
==raw
) ? REF_PRISTINE
: REF_NORMAL
);
188 spin_unlock(&c
->erase_completion_lock
);
190 /* unchecked xdatum is chained with c->xattr_unchecked */
191 list_del_init(&xd
->xindex
);
193 dbg_xattr("success on verfying xdatum (xid=%u, version=%u)\n",
194 xd
->xid
, xd
->version
);
199 static int do_load_xattr_datum(struct jffs2_sb_info
*c
, struct jffs2_xattr_datum
*xd
)
201 /* must be called under down_write(xattr_sem) */
204 uint32_t crc
, length
;
205 int i
, ret
, retry
= 0;
207 BUG_ON(ref_flags(xd
->node
) != REF_PRISTINE
);
208 BUG_ON(!list_empty(&xd
->xindex
));
210 length
= xd
->name_len
+ 1 + xd
->value_len
;
211 data
= kmalloc(length
, GFP_KERNEL
);
215 ret
= jffs2_flash_read(c
, ref_offset(xd
->node
)+sizeof(struct jffs2_raw_xattr
),
216 length
, &readlen
, data
);
218 if (ret
|| length
!=readlen
) {
219 JFFS2_WARNING("jffs2_flash_read() returned %d, request=%d, readlen=%zu, at %#08x\n",
220 ret
, length
, readlen
, ref_offset(xd
->node
));
222 return ret
? ret
: -EIO
;
225 data
[xd
->name_len
] = '\0';
226 crc
= crc32(0, data
, length
);
227 if (crc
!= xd
->data_crc
) {
228 JFFS2_WARNING("node CRC failed (JFFS2_NODETYPE_XREF)"
229 " at %#08x, read: 0x%08x calculated: 0x%08x\n",
230 ref_offset(xd
->node
), xd
->data_crc
, crc
);
232 xd
->flags
|= JFFS2_XFLAGS_INVALID
;
236 xd
->flags
|= JFFS2_XFLAGS_HOT
;
238 xd
->xvalue
= data
+ xd
->name_len
+1;
240 c
->xdatum_mem_usage
+= length
;
242 xd
->hashkey
= xattr_datum_hashkey(xd
->xprefix
, xd
->xname
, xd
->xvalue
, xd
->value_len
);
243 i
= xd
->hashkey
% XATTRINDEX_HASHSIZE
;
244 list_add(&xd
->xindex
, &c
->xattrindex
[i
]);
247 reclaim_xattr_datum(c
);
252 dbg_xattr("success on loading xdatum (xid=%u, xprefix=%u, xname='%s')\n",
253 xd
->xid
, xd
->xprefix
, xd
->xname
);
258 static int load_xattr_datum(struct jffs2_sb_info
*c
, struct jffs2_xattr_datum
*xd
)
260 /* must be called under down_write(xattr_sem);
261 * rc < 0 : recoverable error, try again
263 * rc > 0 : Unrecoverable error, this node should be deleted.
267 BUG_ON(xd
->flags
& JFFS2_XFLAGS_DEAD
);
270 if (xd
->flags
& JFFS2_XFLAGS_INVALID
)
272 if (unlikely(is_xattr_datum_unchecked(c
, xd
)))
273 rc
= do_verify_xattr_datum(c
, xd
);
275 rc
= do_load_xattr_datum(c
, xd
);
279 static int save_xattr_datum(struct jffs2_sb_info
*c
, struct jffs2_xattr_datum
*xd
)
281 /* must be called under down_write(xattr_sem) */
282 struct jffs2_raw_xattr rx
;
286 uint32_t phys_ofs
= write_ofs(c
);
289 BUG_ON(xd
->flags
& (JFFS2_XFLAGS_DEAD
|JFFS2_XFLAGS_INVALID
));
291 vecs
[0].iov_base
= &rx
;
292 vecs
[0].iov_len
= sizeof(rx
);
293 vecs
[1].iov_base
= xd
->xname
;
294 vecs
[1].iov_len
= xd
->name_len
+ 1 + xd
->value_len
;
295 totlen
= vecs
[0].iov_len
+ vecs
[1].iov_len
;
297 /* Setup raw-xattr */
298 memset(&rx
, 0, sizeof(rx
));
299 rx
.magic
= cpu_to_je16(JFFS2_MAGIC_BITMASK
);
300 rx
.nodetype
= cpu_to_je16(JFFS2_NODETYPE_XATTR
);
301 rx
.totlen
= cpu_to_je32(PAD(totlen
));
302 rx
.hdr_crc
= cpu_to_je32(crc32(0, &rx
, sizeof(struct jffs2_unknown_node
) - 4));
304 rx
.xid
= cpu_to_je32(xd
->xid
);
305 rx
.version
= cpu_to_je32(++xd
->version
);
306 rx
.xprefix
= xd
->xprefix
;
307 rx
.name_len
= xd
->name_len
;
308 rx
.value_len
= cpu_to_je16(xd
->value_len
);
309 rx
.data_crc
= cpu_to_je32(crc32(0, vecs
[1].iov_base
, vecs
[1].iov_len
));
310 rx
.node_crc
= cpu_to_je32(crc32(0, &rx
, sizeof(struct jffs2_raw_xattr
) - 4));
312 rc
= jffs2_flash_writev(c
, vecs
, 2, phys_ofs
, &length
, 0);
313 if (rc
|| totlen
!= length
) {
314 JFFS2_WARNING("jffs2_flash_writev()=%d, req=%u, wrote=%zu, at %#08x\n",
315 rc
, totlen
, length
, phys_ofs
);
318 jffs2_add_physical_node_ref(c
, phys_ofs
| REF_OBSOLETE
, PAD(totlen
), NULL
);
323 jffs2_add_physical_node_ref(c
, phys_ofs
| REF_PRISTINE
, PAD(totlen
), (void *)xd
);
325 dbg_xattr("success on saving xdatum (xid=%u, version=%u, xprefix=%u, xname='%s')\n",
326 xd
->xid
, xd
->version
, xd
->xprefix
, xd
->xname
);
331 static struct jffs2_xattr_datum
*create_xattr_datum(struct jffs2_sb_info
*c
,
332 int xprefix
, const char *xname
,
333 const char *xvalue
, int xsize
)
335 /* must be called under down_write(xattr_sem) */
336 struct jffs2_xattr_datum
*xd
;
337 uint32_t hashkey
, name_len
;
341 /* Search xattr_datum has same xname/xvalue by index */
342 hashkey
= xattr_datum_hashkey(xprefix
, xname
, xvalue
, xsize
);
343 i
= hashkey
% XATTRINDEX_HASHSIZE
;
344 list_for_each_entry(xd
, &c
->xattrindex
[i
], xindex
) {
345 if (xd
->hashkey
==hashkey
346 && xd
->xprefix
==xprefix
347 && xd
->value_len
==xsize
348 && !strcmp(xd
->xname
, xname
)
349 && !memcmp(xd
->xvalue
, xvalue
, xsize
)) {
350 atomic_inc(&xd
->refcnt
);
355 /* Not found, Create NEW XATTR-Cache */
356 name_len
= strlen(xname
);
358 xd
= jffs2_alloc_xattr_datum();
360 return ERR_PTR(-ENOMEM
);
362 data
= kmalloc(name_len
+ 1 + xsize
, GFP_KERNEL
);
364 jffs2_free_xattr_datum(xd
);
365 return ERR_PTR(-ENOMEM
);
368 memcpy(data
+ name_len
+ 1, xvalue
, xsize
);
370 atomic_set(&xd
->refcnt
, 1);
371 xd
->xid
= ++c
->highest_xid
;
372 xd
->flags
|= JFFS2_XFLAGS_HOT
;
373 xd
->xprefix
= xprefix
;
375 xd
->hashkey
= hashkey
;
377 xd
->xvalue
= data
+ name_len
+ 1;
378 xd
->name_len
= name_len
;
379 xd
->value_len
= xsize
;
380 xd
->data_crc
= crc32(0, data
, xd
->name_len
+ 1 + xd
->value_len
);
382 rc
= save_xattr_datum(c
, xd
);
385 jffs2_free_xattr_datum(xd
);
389 /* Insert Hash Index */
390 i
= hashkey
% XATTRINDEX_HASHSIZE
;
391 list_add(&xd
->xindex
, &c
->xattrindex
[i
]);
393 c
->xdatum_mem_usage
+= (xd
->name_len
+ 1 + xd
->value_len
);
394 reclaim_xattr_datum(c
);
399 static void unrefer_xattr_datum(struct jffs2_sb_info
*c
, struct jffs2_xattr_datum
*xd
)
401 /* must be called under down_write(xattr_sem) */
402 if (atomic_dec_and_lock(&xd
->refcnt
, &c
->erase_completion_lock
)) {
403 unload_xattr_datum(c
, xd
);
404 xd
->flags
|= JFFS2_XFLAGS_DEAD
;
405 if (xd
->node
== (void *)xd
) {
406 BUG_ON(!(xd
->flags
& JFFS2_XFLAGS_INVALID
));
407 jffs2_free_xattr_datum(xd
);
409 list_add(&xd
->xindex
, &c
->xattr_dead_list
);
411 spin_unlock(&c
->erase_completion_lock
);
413 dbg_xattr("xdatum(xid=%u, version=%u) was removed.\n",
414 xd
->xid
, xd
->version
);
418 /* -------- xref related functions ------------------
419 * verify_xattr_ref(c, ref)
420 * is used to load xref information from medium. Because summary data does not
421 * contain xid/ino, it's necessary to verify once while mounting process.
422 * save_xattr_ref(c, ref)
423 * is used to write xref to medium. If delete marker is marked, it write
424 * a delete marker of xref into medium.
425 * create_xattr_ref(c, ic, xd)
426 * is used to create a new xref and write to medium.
427 * delete_xattr_ref(c, ref)
428 * is used to delete jffs2_xattr_ref. It marks xref XREF_DELETE_MARKER,
429 * and allows GC to reclaim those physical nodes.
430 * jffs2_xattr_delete_inode(c, ic)
431 * is called to remove xrefs related to obsolete inode when inode is unlinked.
432 * jffs2_xattr_free_inode(c, ic)
433 * is called to release xattr related objects when unmounting.
434 * check_xattr_ref_inode(c, ic)
435 * is used to confirm inode does not have duplicate xattr name/value pair.
436 * -------------------------------------------------- */
437 static int verify_xattr_ref(struct jffs2_sb_info
*c
, struct jffs2_xattr_ref
*ref
)
439 struct jffs2_eraseblock
*jeb
;
440 struct jffs2_raw_node_ref
*raw
;
441 struct jffs2_raw_xref rr
;
443 uint32_t crc
, offset
, totlen
;
446 spin_lock(&c
->erase_completion_lock
);
447 if (ref_flags(ref
->node
) != REF_UNCHECKED
)
449 offset
= ref_offset(ref
->node
);
450 spin_unlock(&c
->erase_completion_lock
);
452 rc
= jffs2_flash_read(c
, offset
, sizeof(rr
), &readlen
, (char *)&rr
);
453 if (rc
|| sizeof(rr
) != readlen
) {
454 JFFS2_WARNING("jffs2_flash_read()=%d, req=%zu, read=%zu, at %#08x\n",
455 rc
, sizeof(rr
), readlen
, offset
);
456 return rc
? rc
: -EIO
;
459 crc
= crc32(0, &rr
, sizeof(rr
) - 4);
460 if (crc
!= je32_to_cpu(rr
.node_crc
)) {
461 JFFS2_ERROR("node CRC failed at %#08x, read=%#08x, calc=%#08x\n",
462 offset
, je32_to_cpu(rr
.node_crc
), crc
);
465 if (je16_to_cpu(rr
.magic
) != JFFS2_MAGIC_BITMASK
466 || je16_to_cpu(rr
.nodetype
) != JFFS2_NODETYPE_XREF
467 || je32_to_cpu(rr
.totlen
) != PAD(sizeof(rr
))) {
468 JFFS2_ERROR("inconsistent xref at %#08x, magic=%#04x/%#04x, "
469 "nodetype=%#04x/%#04x, totlen=%u/%zu\n",
470 offset
, je16_to_cpu(rr
.magic
), JFFS2_MAGIC_BITMASK
,
471 je16_to_cpu(rr
.nodetype
), JFFS2_NODETYPE_XREF
,
472 je32_to_cpu(rr
.totlen
), PAD(sizeof(rr
)));
475 ref
->ino
= je32_to_cpu(rr
.ino
);
476 ref
->xid
= je32_to_cpu(rr
.xid
);
477 ref
->xseqno
= je32_to_cpu(rr
.xseqno
);
478 if (ref
->xseqno
> c
->highest_xseqno
)
479 c
->highest_xseqno
= (ref
->xseqno
& ~XREF_DELETE_MARKER
);
481 spin_lock(&c
->erase_completion_lock
);
483 for (raw
=ref
->node
; raw
!= (void *)ref
; raw
=raw
->next_in_ino
) {
484 jeb
= &c
->blocks
[ref_offset(raw
) / c
->sector_size
];
485 totlen
= PAD(ref_totlen(c
, jeb
, raw
));
486 if (ref_flags(raw
) == REF_UNCHECKED
) {
487 c
->unchecked_size
-= totlen
; c
->used_size
+= totlen
;
488 jeb
->unchecked_size
-= totlen
; jeb
->used_size
+= totlen
;
490 raw
->flash_offset
= ref_offset(raw
) | ((ref
->node
==raw
) ? REF_PRISTINE
: REF_NORMAL
);
492 spin_unlock(&c
->erase_completion_lock
);
494 dbg_xattr("success on verifying xref (ino=%u, xid=%u) at %#08x\n",
495 ref
->ino
, ref
->xid
, ref_offset(ref
->node
));
499 static int save_xattr_ref(struct jffs2_sb_info
*c
, struct jffs2_xattr_ref
*ref
)
501 /* must be called under down_write(xattr_sem) */
502 struct jffs2_raw_xref rr
;
504 uint32_t xseqno
, phys_ofs
= write_ofs(c
);
507 rr
.magic
= cpu_to_je16(JFFS2_MAGIC_BITMASK
);
508 rr
.nodetype
= cpu_to_je16(JFFS2_NODETYPE_XREF
);
509 rr
.totlen
= cpu_to_je32(PAD(sizeof(rr
)));
510 rr
.hdr_crc
= cpu_to_je32(crc32(0, &rr
, sizeof(struct jffs2_unknown_node
) - 4));
512 xseqno
= (c
->highest_xseqno
+= 2);
513 if (is_xattr_ref_dead(ref
)) {
514 xseqno
|= XREF_DELETE_MARKER
;
515 rr
.ino
= cpu_to_je32(ref
->ino
);
516 rr
.xid
= cpu_to_je32(ref
->xid
);
518 rr
.ino
= cpu_to_je32(ref
->ic
->ino
);
519 rr
.xid
= cpu_to_je32(ref
->xd
->xid
);
521 rr
.xseqno
= cpu_to_je32(xseqno
);
522 rr
.node_crc
= cpu_to_je32(crc32(0, &rr
, sizeof(rr
) - 4));
524 ret
= jffs2_flash_write(c
, phys_ofs
, sizeof(rr
), &length
, (char *)&rr
);
525 if (ret
|| sizeof(rr
) != length
) {
526 JFFS2_WARNING("jffs2_flash_write() returned %d, request=%zu, retlen=%zu, at %#08x\n",
527 ret
, sizeof(rr
), length
, phys_ofs
);
528 ret
= ret
? ret
: -EIO
;
530 jffs2_add_physical_node_ref(c
, phys_ofs
| REF_OBSOLETE
, PAD(sizeof(rr
)), NULL
);
535 ref
->xseqno
= xseqno
;
536 jffs2_add_physical_node_ref(c
, phys_ofs
| REF_PRISTINE
, PAD(sizeof(rr
)), (void *)ref
);
538 dbg_xattr("success on saving xref (ino=%u, xid=%u)\n", ref
->ic
->ino
, ref
->xd
->xid
);
543 static struct jffs2_xattr_ref
*create_xattr_ref(struct jffs2_sb_info
*c
, struct jffs2_inode_cache
*ic
,
544 struct jffs2_xattr_datum
*xd
)
546 /* must be called under down_write(xattr_sem) */
547 struct jffs2_xattr_ref
*ref
;
550 ref
= jffs2_alloc_xattr_ref();
552 return ERR_PTR(-ENOMEM
);
556 ret
= save_xattr_ref(c
, ref
);
558 jffs2_free_xattr_ref(ref
);
563 ref
->next
= ic
->xref
;
566 return ref
; /* success */
569 static void delete_xattr_ref(struct jffs2_sb_info
*c
, struct jffs2_xattr_ref
*ref
)
571 /* must be called under down_write(xattr_sem) */
572 struct jffs2_xattr_datum
*xd
;
575 ref
->xseqno
|= XREF_DELETE_MARKER
;
576 ref
->ino
= ref
->ic
->ino
;
577 ref
->xid
= ref
->xd
->xid
;
578 spin_lock(&c
->erase_completion_lock
);
579 ref
->next
= c
->xref_dead_list
;
580 c
->xref_dead_list
= ref
;
581 spin_unlock(&c
->erase_completion_lock
);
583 dbg_xattr("xref(ino=%u, xid=%u, xseqno=%u) was removed.\n",
584 ref
->ino
, ref
->xid
, ref
->xseqno
);
586 unrefer_xattr_datum(c
, xd
);
589 void jffs2_xattr_delete_inode(struct jffs2_sb_info
*c
, struct jffs2_inode_cache
*ic
)
591 /* It's called from jffs2_clear_inode() on inode removing.
592 When an inode with XATTR is removed, those XATTRs must be removed. */
593 struct jffs2_xattr_ref
*ref
, *_ref
;
595 if (!ic
|| ic
->nlink
> 0)
598 down_write(&c
->xattr_sem
);
599 for (ref
= ic
->xref
; ref
; ref
= _ref
) {
601 delete_xattr_ref(c
, ref
);
604 up_write(&c
->xattr_sem
);
607 void jffs2_xattr_free_inode(struct jffs2_sb_info
*c
, struct jffs2_inode_cache
*ic
)
609 /* It's called from jffs2_free_ino_caches() until unmounting FS. */
610 struct jffs2_xattr_datum
*xd
;
611 struct jffs2_xattr_ref
*ref
, *_ref
;
613 down_write(&c
->xattr_sem
);
614 for (ref
= ic
->xref
; ref
; ref
= _ref
) {
617 if (atomic_dec_and_test(&xd
->refcnt
)) {
618 unload_xattr_datum(c
, xd
);
619 jffs2_free_xattr_datum(xd
);
621 jffs2_free_xattr_ref(ref
);
624 up_write(&c
->xattr_sem
);
627 static int check_xattr_ref_inode(struct jffs2_sb_info
*c
, struct jffs2_inode_cache
*ic
)
629 /* success of check_xattr_ref_inode() means taht inode (ic) dose not have
630 * duplicate name/value pairs. If duplicate name/value pair would be found,
631 * one will be removed.
633 struct jffs2_xattr_ref
*ref
, *cmp
, **pref
, **pcmp
;
636 if (likely(ic
->flags
& INO_FLAGS_XATTR_CHECKED
))
638 down_write(&c
->xattr_sem
);
641 for (ref
=ic
->xref
, pref
=&ic
->xref
; ref
; pref
=&ref
->next
, ref
=ref
->next
) {
642 if (!ref
->xd
->xname
) {
643 rc
= load_xattr_datum(c
, ref
->xd
);
644 if (unlikely(rc
> 0)) {
646 delete_xattr_ref(c
, ref
);
648 } else if (unlikely(rc
< 0))
651 for (cmp
=ref
->next
, pcmp
=&ref
->next
; cmp
; pcmp
=&cmp
->next
, cmp
=cmp
->next
) {
652 if (!cmp
->xd
->xname
) {
653 ref
->xd
->flags
|= JFFS2_XFLAGS_BIND
;
654 rc
= load_xattr_datum(c
, cmp
->xd
);
655 ref
->xd
->flags
&= ~JFFS2_XFLAGS_BIND
;
656 if (unlikely(rc
> 0)) {
658 delete_xattr_ref(c
, cmp
);
660 } else if (unlikely(rc
< 0))
663 if (ref
->xd
->xprefix
== cmp
->xd
->xprefix
664 && !strcmp(ref
->xd
->xname
, cmp
->xd
->xname
)) {
665 if (ref
->xseqno
> cmp
->xseqno
) {
667 delete_xattr_ref(c
, cmp
);
670 delete_xattr_ref(c
, ref
);
676 ic
->flags
|= INO_FLAGS_XATTR_CHECKED
;
678 up_write(&c
->xattr_sem
);
683 /* -------- xattr subsystem functions ---------------
684 * jffs2_init_xattr_subsystem(c)
685 * is used to initialize semaphore and list_head, and some variables.
686 * jffs2_find_xattr_datum(c, xid)
687 * is used to lookup xdatum while scanning process.
688 * jffs2_clear_xattr_subsystem(c)
689 * is used to release any xattr related objects.
690 * jffs2_build_xattr_subsystem(c)
691 * is used to associate xdatum and xref while super block building process.
692 * jffs2_setup_xattr_datum(c, xid, version)
693 * is used to insert xdatum while scanning process.
694 * -------------------------------------------------- */
695 void jffs2_init_xattr_subsystem(struct jffs2_sb_info
*c
)
699 for (i
=0; i
< XATTRINDEX_HASHSIZE
; i
++)
700 INIT_LIST_HEAD(&c
->xattrindex
[i
]);
701 INIT_LIST_HEAD(&c
->xattr_unchecked
);
702 INIT_LIST_HEAD(&c
->xattr_dead_list
);
703 c
->xref_dead_list
= NULL
;
706 init_rwsem(&c
->xattr_sem
);
708 c
->highest_xseqno
= 0;
709 c
->xdatum_mem_usage
= 0;
710 c
->xdatum_mem_threshold
= 32 * 1024; /* Default 32KB */
713 static struct jffs2_xattr_datum
*jffs2_find_xattr_datum(struct jffs2_sb_info
*c
, uint32_t xid
)
715 struct jffs2_xattr_datum
*xd
;
716 int i
= xid
% XATTRINDEX_HASHSIZE
;
718 /* It's only used in scanning/building process. */
719 BUG_ON(!(c
->flags
& (JFFS2_SB_FLAG_SCANNING
|JFFS2_SB_FLAG_BUILDING
)));
721 list_for_each_entry(xd
, &c
->xattrindex
[i
], xindex
) {
728 void jffs2_clear_xattr_subsystem(struct jffs2_sb_info
*c
)
730 struct jffs2_xattr_datum
*xd
, *_xd
;
731 struct jffs2_xattr_ref
*ref
, *_ref
;
734 for (ref
=c
->xref_temp
; ref
; ref
= _ref
) {
736 jffs2_free_xattr_ref(ref
);
739 for (ref
=c
->xref_dead_list
; ref
; ref
= _ref
) {
741 jffs2_free_xattr_ref(ref
);
744 for (i
=0; i
< XATTRINDEX_HASHSIZE
; i
++) {
745 list_for_each_entry_safe(xd
, _xd
, &c
->xattrindex
[i
], xindex
) {
746 list_del(&xd
->xindex
);
749 jffs2_free_xattr_datum(xd
);
753 list_for_each_entry_safe(xd
, _xd
, &c
->xattr_dead_list
, xindex
) {
754 list_del(&xd
->xindex
);
755 jffs2_free_xattr_datum(xd
);
759 #define XREF_TMPHASH_SIZE (128)
760 void jffs2_build_xattr_subsystem(struct jffs2_sb_info
*c
)
762 struct jffs2_xattr_ref
*ref
, *_ref
;
763 struct jffs2_xattr_ref
*xref_tmphash
[XREF_TMPHASH_SIZE
];
764 struct jffs2_xattr_datum
*xd
, *_xd
;
765 struct jffs2_inode_cache
*ic
;
766 struct jffs2_raw_node_ref
*raw
;
767 int i
, xdatum_count
= 0, xdatum_unchecked_count
= 0, xref_count
= 0;
768 int xdatum_orphan_count
= 0, xref_orphan_count
= 0, xref_dead_count
= 0;
770 BUG_ON(!(c
->flags
& JFFS2_SB_FLAG_BUILDING
));
772 /* Phase.1 : Merge same xref */
773 for (i
=0; i
< XREF_TMPHASH_SIZE
; i
++)
774 xref_tmphash
[i
] = NULL
;
775 for (ref
=c
->xref_temp
; ref
; ref
=_ref
) {
776 struct jffs2_xattr_ref
*tmp
;
779 if (ref_flags(ref
->node
) != REF_PRISTINE
) {
780 if (verify_xattr_ref(c
, ref
)) {
781 BUG_ON(ref
->node
->next_in_ino
!= (void *)ref
);
782 ref
->node
->next_in_ino
= NULL
;
783 jffs2_mark_node_obsolete(c
, ref
->node
);
784 jffs2_free_xattr_ref(ref
);
789 i
= (ref
->ino
^ ref
->xid
) % XREF_TMPHASH_SIZE
;
790 for (tmp
=xref_tmphash
[i
]; tmp
; tmp
=tmp
->next
) {
791 if (tmp
->ino
== ref
->ino
&& tmp
->xid
== ref
->xid
)
796 if (ref
->xseqno
> tmp
->xseqno
) {
797 tmp
->xseqno
= ref
->xseqno
;
798 raw
->next_in_ino
= tmp
->node
;
801 raw
->next_in_ino
= tmp
->node
->next_in_ino
;
802 tmp
->node
->next_in_ino
= raw
;
804 jffs2_free_xattr_ref(ref
);
807 ref
->next
= xref_tmphash
[i
];
808 xref_tmphash
[i
] = ref
;
813 /* Phase.2 : Bind xref with inode_cache and xattr_datum */
814 for (i
=0; i
< XREF_TMPHASH_SIZE
; i
++) {
815 for (ref
=xref_tmphash
[i
]; ref
; ref
=_ref
) {
818 if (is_xattr_ref_dead(ref
)) {
819 ref
->next
= c
->xref_dead_list
;
820 c
->xref_dead_list
= ref
;
824 /* At this point, ref->xid and ref->ino contain XID and inode number.
825 ref->xd and ref->ic are not valid yet. */
826 xd
= jffs2_find_xattr_datum(c
, ref
->xid
);
827 ic
= jffs2_get_ino_cache(c
, ref
->ino
);
829 dbg_xattr("xref(ino=%u, xid=%u, xseqno=%u) is orphan.\n",
830 ref
->ino
, ref
->xid
, ref
->xseqno
);
831 ref
->xseqno
|= XREF_DELETE_MARKER
;
832 ref
->next
= c
->xref_dead_list
;
833 c
->xref_dead_list
= ref
;
839 atomic_inc(&xd
->refcnt
);
840 ref
->next
= ic
->xref
;
845 /* Phase.3 : Link unchecked xdatum to xattr_unchecked list */
846 for (i
=0; i
< XATTRINDEX_HASHSIZE
; i
++) {
847 list_for_each_entry_safe(xd
, _xd
, &c
->xattrindex
[i
], xindex
) {
849 list_del_init(&xd
->xindex
);
850 if (!atomic_read(&xd
->refcnt
)) {
851 dbg_xattr("xdatum(xid=%u, version=%u) is orphan.\n",
852 xd
->xid
, xd
->version
);
853 xd
->flags
|= JFFS2_XFLAGS_DEAD
;
854 list_add(&xd
->xindex
, &c
->xattr_unchecked
);
855 xdatum_orphan_count
++;
858 if (is_xattr_datum_unchecked(c
, xd
)) {
859 dbg_xattr("unchecked xdatum(xid=%u, version=%u)\n",
860 xd
->xid
, xd
->version
);
861 list_add(&xd
->xindex
, &c
->xattr_unchecked
);
862 xdatum_unchecked_count
++;
867 JFFS2_NOTICE("complete building xattr subsystem, %u of xdatum"
868 " (%u unchecked, %u orphan) and "
869 "%u of xref (%u dead, %u orphan) found.\n",
870 xdatum_count
, xdatum_unchecked_count
, xdatum_orphan_count
,
871 xref_count
, xref_dead_count
, xref_orphan_count
);
874 struct jffs2_xattr_datum
*jffs2_setup_xattr_datum(struct jffs2_sb_info
*c
,
875 uint32_t xid
, uint32_t version
)
877 struct jffs2_xattr_datum
*xd
;
879 xd
= jffs2_find_xattr_datum(c
, xid
);
881 xd
= jffs2_alloc_xattr_datum();
883 return ERR_PTR(-ENOMEM
);
885 xd
->version
= version
;
886 if (xd
->xid
> c
->highest_xid
)
887 c
->highest_xid
= xd
->xid
;
888 list_add_tail(&xd
->xindex
, &c
->xattrindex
[xid
% XATTRINDEX_HASHSIZE
]);
893 /* -------- xattr subsystem functions ---------------
894 * xprefix_to_handler(xprefix)
895 * is used to translate xprefix into xattr_handler.
896 * jffs2_listxattr(dentry, buffer, size)
897 * is an implementation of listxattr handler on jffs2.
898 * do_jffs2_getxattr(inode, xprefix, xname, buffer, size)
899 * is an implementation of getxattr handler on jffs2.
900 * do_jffs2_setxattr(inode, xprefix, xname, buffer, size, flags)
901 * is an implementation of setxattr handler on jffs2.
902 * -------------------------------------------------- */
903 struct xattr_handler
*jffs2_xattr_handlers
[] = {
904 &jffs2_user_xattr_handler
,
905 #ifdef CONFIG_JFFS2_FS_SECURITY
906 &jffs2_security_xattr_handler
,
908 #ifdef CONFIG_JFFS2_FS_POSIX_ACL
909 &jffs2_acl_access_xattr_handler
,
910 &jffs2_acl_default_xattr_handler
,
912 &jffs2_trusted_xattr_handler
,
916 static struct xattr_handler
*xprefix_to_handler(int xprefix
) {
917 struct xattr_handler
*ret
;
920 case JFFS2_XPREFIX_USER
:
921 ret
= &jffs2_user_xattr_handler
;
923 #ifdef CONFIG_JFFS2_FS_SECURITY
924 case JFFS2_XPREFIX_SECURITY
:
925 ret
= &jffs2_security_xattr_handler
;
928 #ifdef CONFIG_JFFS2_FS_POSIX_ACL
929 case JFFS2_XPREFIX_ACL_ACCESS
:
930 ret
= &jffs2_acl_access_xattr_handler
;
932 case JFFS2_XPREFIX_ACL_DEFAULT
:
933 ret
= &jffs2_acl_default_xattr_handler
;
936 case JFFS2_XPREFIX_TRUSTED
:
937 ret
= &jffs2_trusted_xattr_handler
;
946 ssize_t
jffs2_listxattr(struct dentry
*dentry
, char *buffer
, size_t size
)
948 struct inode
*inode
= dentry
->d_inode
;
949 struct jffs2_inode_info
*f
= JFFS2_INODE_INFO(inode
);
950 struct jffs2_sb_info
*c
= JFFS2_SB_INFO(inode
->i_sb
);
951 struct jffs2_inode_cache
*ic
= f
->inocache
;
952 struct jffs2_xattr_ref
*ref
, **pref
;
953 struct jffs2_xattr_datum
*xd
;
954 struct xattr_handler
*xhandle
;
958 rc
= check_xattr_ref_inode(c
, ic
);
962 down_read(&c
->xattr_sem
);
965 for (ref
=ic
->xref
, pref
=&ic
->xref
; ref
; pref
=&ref
->next
, ref
=ref
->next
) {
966 BUG_ON(ref
->ic
!= ic
);
969 /* xdatum is unchached */
972 up_read(&c
->xattr_sem
);
973 down_write(&c
->xattr_sem
);
976 rc
= load_xattr_datum(c
, xd
);
977 if (unlikely(rc
> 0)) {
979 delete_xattr_ref(c
, ref
);
981 } else if (unlikely(rc
< 0))
985 xhandle
= xprefix_to_handler(xd
->xprefix
);
989 rc
= xhandle
->list(inode
, buffer
+len
, size
-len
, xd
->xname
, xd
->name_len
);
991 rc
= xhandle
->list(inode
, NULL
, 0, xd
->xname
, xd
->name_len
);
1000 up_read(&c
->xattr_sem
);
1002 up_write(&c
->xattr_sem
);
1007 int do_jffs2_getxattr(struct inode
*inode
, int xprefix
, const char *xname
,
1008 char *buffer
, size_t size
)
1010 struct jffs2_inode_info
*f
= JFFS2_INODE_INFO(inode
);
1011 struct jffs2_sb_info
*c
= JFFS2_SB_INFO(inode
->i_sb
);
1012 struct jffs2_inode_cache
*ic
= f
->inocache
;
1013 struct jffs2_xattr_datum
*xd
;
1014 struct jffs2_xattr_ref
*ref
, **pref
;
1017 rc
= check_xattr_ref_inode(c
, ic
);
1021 down_read(&c
->xattr_sem
);
1023 for (ref
=ic
->xref
, pref
=&ic
->xref
; ref
; pref
=&ref
->next
, ref
=ref
->next
) {
1024 BUG_ON(ref
->ic
!=ic
);
1027 if (xd
->xprefix
!= xprefix
)
1030 /* xdatum is unchached */
1033 up_read(&c
->xattr_sem
);
1034 down_write(&c
->xattr_sem
);
1037 rc
= load_xattr_datum(c
, xd
);
1038 if (unlikely(rc
> 0)) {
1040 delete_xattr_ref(c
, ref
);
1042 } else if (unlikely(rc
< 0)) {
1047 if (!strcmp(xname
, xd
->xname
)) {
1053 memcpy(buffer
, xd
->xvalue
, rc
);
1062 up_read(&c
->xattr_sem
);
1064 up_write(&c
->xattr_sem
);
1069 int do_jffs2_setxattr(struct inode
*inode
, int xprefix
, const char *xname
,
1070 const char *buffer
, size_t size
, int flags
)
1072 struct jffs2_inode_info
*f
= JFFS2_INODE_INFO(inode
);
1073 struct jffs2_sb_info
*c
= JFFS2_SB_INFO(inode
->i_sb
);
1074 struct jffs2_inode_cache
*ic
= f
->inocache
;
1075 struct jffs2_xattr_datum
*xd
;
1076 struct jffs2_xattr_ref
*ref
, *newref
, **pref
;
1077 uint32_t length
, request
;
1080 rc
= check_xattr_ref_inode(c
, ic
);
1084 request
= PAD(sizeof(struct jffs2_raw_xattr
) + strlen(xname
) + 1 + size
);
1085 rc
= jffs2_reserve_space(c
, request
, &length
,
1086 ALLOC_NORMAL
, JFFS2_SUMMARY_XATTR_SIZE
);
1088 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc
, request
);
1092 /* Find existing xattr */
1093 down_write(&c
->xattr_sem
);
1095 for (ref
=ic
->xref
, pref
=&ic
->xref
; ref
; pref
=&ref
->next
, ref
=ref
->next
) {
1097 if (xd
->xprefix
!= xprefix
)
1100 rc
= load_xattr_datum(c
, xd
);
1101 if (unlikely(rc
> 0)) {
1103 delete_xattr_ref(c
, ref
);
1105 } else if (unlikely(rc
< 0))
1108 if (!strcmp(xd
->xname
, xname
)) {
1109 if (flags
& XATTR_CREATE
) {
1116 ref
->xseqno
|= XREF_DELETE_MARKER
;
1117 rc
= save_xattr_ref(c
, ref
);
1120 spin_lock(&c
->erase_completion_lock
);
1121 ref
->next
= c
->xref_dead_list
;
1122 c
->xref_dead_list
= ref
;
1123 spin_unlock(&c
->erase_completion_lock
);
1124 unrefer_xattr_datum(c
, xd
);
1128 ref
->xseqno
&= ~XREF_DELETE_MARKER
;
1136 if (flags
& XATTR_REPLACE
) {
1145 xd
= create_xattr_datum(c
, xprefix
, xname
, buffer
, size
);
1150 up_write(&c
->xattr_sem
);
1151 jffs2_complete_reservation(c
);
1153 /* create xattr_ref */
1154 request
= PAD(sizeof(struct jffs2_raw_xref
));
1155 rc
= jffs2_reserve_space(c
, request
, &length
,
1156 ALLOC_NORMAL
, JFFS2_SUMMARY_XREF_SIZE
);
1157 down_write(&c
->xattr_sem
);
1159 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc
, request
);
1160 unrefer_xattr_datum(c
, xd
);
1161 up_write(&c
->xattr_sem
);
1166 newref
= create_xattr_ref(c
, ic
, xd
);
1167 if (IS_ERR(newref
)) {
1169 ref
->next
= ic
->xref
;
1172 rc
= PTR_ERR(newref
);
1173 unrefer_xattr_datum(c
, xd
);
1175 delete_xattr_ref(c
, ref
);
1178 up_write(&c
->xattr_sem
);
1179 jffs2_complete_reservation(c
);
1183 /* -------- garbage collector functions -------------
1184 * jffs2_garbage_collect_xattr_datum(c, xd, raw)
1185 * is used to move xdatum into new node.
1186 * jffs2_garbage_collect_xattr_ref(c, ref, raw)
1187 * is used to move xref into new node.
1188 * jffs2_verify_xattr(c)
1189 * is used to call do_verify_xattr_datum() before garbage collecting.
1190 * jffs2_release_xattr_datum(c, xd)
1191 * is used to release an in-memory object of xdatum.
1192 * jffs2_release_xattr_ref(c, ref)
1193 * is used to release an in-memory object of xref.
1194 * -------------------------------------------------- */
1195 int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info
*c
, struct jffs2_xattr_datum
*xd
,
1196 struct jffs2_raw_node_ref
*raw
)
1198 uint32_t totlen
, length
, old_ofs
;
1201 down_write(&c
->xattr_sem
);
1202 if (xd
->node
!= raw
)
1204 if (xd
->flags
& (JFFS2_XFLAGS_DEAD
|JFFS2_XFLAGS_INVALID
))
1207 rc
= load_xattr_datum(c
, xd
);
1209 rc
= (rc
> 0) ? 0 : rc
;
1212 old_ofs
= ref_offset(xd
->node
);
1213 totlen
= PAD(sizeof(struct jffs2_raw_xattr
)
1214 + xd
->name_len
+ 1 + xd
->value_len
);
1215 rc
= jffs2_reserve_space_gc(c
, totlen
, &length
, JFFS2_SUMMARY_XATTR_SIZE
);
1217 JFFS2_WARNING("jffs2_reserve_space_gc()=%d, request=%u\n", rc
, totlen
);
1220 rc
= save_xattr_datum(c
, xd
);
1222 dbg_xattr("xdatum (xid=%u, version=%u) GC'ed from %#08x to %08x\n",
1223 xd
->xid
, xd
->version
, old_ofs
, ref_offset(xd
->node
));
1226 jffs2_mark_node_obsolete(c
, raw
);
1227 up_write(&c
->xattr_sem
);
1231 int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info
*c
, struct jffs2_xattr_ref
*ref
,
1232 struct jffs2_raw_node_ref
*raw
)
1234 uint32_t totlen
, length
, old_ofs
;
1237 down_write(&c
->xattr_sem
);
1240 if (ref
->node
!= raw
)
1242 if (is_xattr_ref_dead(ref
) && (raw
->next_in_ino
== (void *)ref
))
1245 old_ofs
= ref_offset(ref
->node
);
1246 totlen
= ref_totlen(c
, c
->gcblock
, ref
->node
);
1248 rc
= jffs2_reserve_space_gc(c
, totlen
, &length
, JFFS2_SUMMARY_XREF_SIZE
);
1250 JFFS2_WARNING("%s: jffs2_reserve_space_gc() = %d, request = %u\n",
1251 __FUNCTION__
, rc
, totlen
);
1252 rc
= rc
? rc
: -EBADFD
;
1255 rc
= save_xattr_ref(c
, ref
);
1257 dbg_xattr("xref (ino=%u, xid=%u) GC'ed from %#08x to %08x\n",
1258 ref
->ic
->ino
, ref
->xd
->xid
, old_ofs
, ref_offset(ref
->node
));
1261 jffs2_mark_node_obsolete(c
, raw
);
1262 up_write(&c
->xattr_sem
);
1266 int jffs2_verify_xattr(struct jffs2_sb_info
*c
)
1268 struct jffs2_xattr_datum
*xd
, *_xd
;
1269 struct jffs2_eraseblock
*jeb
;
1270 struct jffs2_raw_node_ref
*raw
;
1274 down_write(&c
->xattr_sem
);
1275 list_for_each_entry_safe(xd
, _xd
, &c
->xattr_unchecked
, xindex
) {
1276 rc
= do_verify_xattr_datum(c
, xd
);
1279 list_del_init(&xd
->xindex
);
1280 spin_lock(&c
->erase_completion_lock
);
1281 for (raw
=xd
->node
; raw
!= (void *)xd
; raw
=raw
->next_in_ino
) {
1282 if (ref_flags(raw
) != REF_UNCHECKED
)
1284 jeb
= &c
->blocks
[ref_offset(raw
) / c
->sector_size
];
1285 totlen
= PAD(ref_totlen(c
, jeb
, raw
));
1286 c
->unchecked_size
-= totlen
; c
->used_size
+= totlen
;
1287 jeb
->unchecked_size
-= totlen
; jeb
->used_size
+= totlen
;
1288 raw
->flash_offset
= ref_offset(raw
)
1289 | ((xd
->node
== (void *)raw
) ? REF_PRISTINE
: REF_NORMAL
);
1291 if (xd
->flags
& JFFS2_XFLAGS_DEAD
)
1292 list_add(&xd
->xindex
, &c
->xattr_dead_list
);
1293 spin_unlock(&c
->erase_completion_lock
);
1295 up_write(&c
->xattr_sem
);
1296 return list_empty(&c
->xattr_unchecked
) ? 1 : 0;
1299 void jffs2_release_xattr_datum(struct jffs2_sb_info
*c
, struct jffs2_xattr_datum
*xd
)
1301 /* must be called under spin_lock(&c->erase_completion_lock) */
1302 if (atomic_read(&xd
->refcnt
) || xd
->node
!= (void *)xd
)
1305 list_del(&xd
->xindex
);
1306 jffs2_free_xattr_datum(xd
);
1309 void jffs2_release_xattr_ref(struct jffs2_sb_info
*c
, struct jffs2_xattr_ref
*ref
)
1311 /* must be called under spin_lock(&c->erase_completion_lock) */
1312 struct jffs2_xattr_ref
*tmp
, **ptmp
;
1314 if (ref
->node
!= (void *)ref
)
1317 for (tmp
=c
->xref_dead_list
, ptmp
=&c
->xref_dead_list
; tmp
; ptmp
=&tmp
->next
, tmp
=tmp
->next
) {
1323 jffs2_free_xattr_ref(ref
);