@@ -317,20 +317,25 @@ static int jffs2_scan_xattr_node(struct jffs2_sb_info *c, struct jffs2_erasebloc
317317 struct jffs2_summary * s )
318318{
319319 struct jffs2_xattr_datum * xd ;
320- uint32_t totlen , crc ;
320+ uint32_t xid , version , totlen , crc ;
321321 int err ;
322322
323323 crc = crc32 (0 , rx , sizeof (struct jffs2_raw_xattr ) - 4 );
324324 if (crc != je32_to_cpu (rx -> node_crc )) {
325- if (je32_to_cpu (rx -> node_crc ) != 0xffffffff )
326- JFFS2_WARNING ("node CRC failed at %#08x, read=%#08x, calc=%#08x\n" ,
327- ofs , je32_to_cpu (rx -> node_crc ), crc );
325+ JFFS2_WARNING ("node CRC failed at %#08x, read=%#08x, calc=%#08x\n" ,
326+ ofs , je32_to_cpu (rx -> node_crc ), crc );
328327 if ((err = jffs2_scan_dirty_space (c , jeb , je32_to_cpu (rx -> totlen ))))
329328 return err ;
330329 return 0 ;
331330 }
332331
333- totlen = PAD (sizeof (* rx ) + rx -> name_len + 1 + je16_to_cpu (rx -> value_len ));
332+ xid = je32_to_cpu (rx -> xid );
333+ version = je32_to_cpu (rx -> version );
334+
335+ totlen = sizeof (struct jffs2_raw_xattr );
336+ if (version != XDATUM_DELETE_MARKER )
337+ totlen += rx -> name_len + 1 + je16_to_cpu (rx -> value_len );
338+ totlen = PAD (totlen );
334339 if (totlen != je32_to_cpu (rx -> totlen )) {
335340 JFFS2_WARNING ("node length mismatch at %#08x, read=%u, calc=%u\n" ,
336341 ofs , je32_to_cpu (rx -> totlen ), totlen );
@@ -339,22 +344,24 @@ static int jffs2_scan_xattr_node(struct jffs2_sb_info *c, struct jffs2_erasebloc
339344 return 0 ;
340345 }
341346
342- xd = jffs2_setup_xattr_datum (c , je32_to_cpu (rx -> xid ), je32_to_cpu (rx -> version ));
343- if (IS_ERR (xd )) {
344- if (PTR_ERR (xd ) == - EEXIST ) {
345- if ((err = jffs2_scan_dirty_space (c , jeb , PAD (je32_to_cpu (rx -> totlen )))))
346- return err ;
347- return 0 ;
348- }
347+ xd = jffs2_setup_xattr_datum (c , xid , version );
348+ if (IS_ERR (xd ))
349349 return PTR_ERR (xd );
350- }
351- xd -> xprefix = rx -> xprefix ;
352- xd -> name_len = rx -> name_len ;
353- xd -> value_len = je16_to_cpu (rx -> value_len );
354- xd -> data_crc = je32_to_cpu (rx -> data_crc );
355350
356- xd -> node = jffs2_link_node_ref (c , jeb , ofs | REF_PRISTINE , totlen , NULL );
357- /* FIXME */ xd -> node -> next_in_ino = (void * )xd ;
351+ if (xd -> version > version ) {
352+ struct jffs2_raw_node_ref * raw
353+ = jffs2_link_node_ref (c , jeb , ofs | REF_PRISTINE , totlen , NULL );
354+ raw -> next_in_ino = xd -> node -> next_in_ino ;
355+ xd -> node -> next_in_ino = raw ;
356+ } else {
357+ xd -> version = version ;
358+ xd -> xprefix = rx -> xprefix ;
359+ xd -> name_len = rx -> name_len ;
360+ xd -> value_len = je16_to_cpu (rx -> value_len );
361+ xd -> data_crc = je32_to_cpu (rx -> data_crc );
362+
363+ jffs2_link_node_ref (c , jeb , ofs | REF_PRISTINE , totlen , (void * )xd );
364+ }
358365
359366 if (jffs2_sum_active ())
360367 jffs2_sum_add_xattr_mem (s , rx , ofs - jeb -> offset );
@@ -373,9 +380,8 @@ static int jffs2_scan_xref_node(struct jffs2_sb_info *c, struct jffs2_eraseblock
373380
374381 crc = crc32 (0 , rr , sizeof (* rr ) - 4 );
375382 if (crc != je32_to_cpu (rr -> node_crc )) {
376- if (je32_to_cpu (rr -> node_crc ) != 0xffffffff )
377- JFFS2_WARNING ("node CRC failed at %#08x, read=%#08x, calc=%#08x\n" ,
378- ofs , je32_to_cpu (rr -> node_crc ), crc );
383+ JFFS2_WARNING ("node CRC failed at %#08x, read=%#08x, calc=%#08x\n" ,
384+ ofs , je32_to_cpu (rr -> node_crc ), crc );
379385 if ((err = jffs2_scan_dirty_space (c , jeb , PAD (je32_to_cpu (rr -> totlen )))))
380386 return err ;
381387 return 0 ;
@@ -395,6 +401,7 @@ static int jffs2_scan_xref_node(struct jffs2_sb_info *c, struct jffs2_eraseblock
395401 return - ENOMEM ;
396402
397403 /* BEFORE jffs2_build_xattr_subsystem() called,
404+ * and AFTER xattr_ref is marked as a dead xref,
398405 * ref->xid is used to store 32bit xid, xd is not used
399406 * ref->ino is used to store 32bit inode-number, ic is not used
400407 * Thoes variables are declared as union, thus using those
@@ -404,11 +411,13 @@ static int jffs2_scan_xref_node(struct jffs2_sb_info *c, struct jffs2_eraseblock
404411 */
405412 ref -> ino = je32_to_cpu (rr -> ino );
406413 ref -> xid = je32_to_cpu (rr -> xid );
414+ ref -> xseqno = je32_to_cpu (rr -> xseqno );
415+ if (ref -> xseqno > c -> highest_xseqno )
416+ c -> highest_xseqno = (ref -> xseqno & ~XREF_DELETE_MARKER );
407417 ref -> next = c -> xref_temp ;
408418 c -> xref_temp = ref ;
409419
410- ref -> node = jffs2_link_node_ref (c , jeb , ofs | REF_PRISTINE , PAD (je32_to_cpu (rr -> totlen )), NULL );
411- /* FIXME */ ref -> node -> next_in_ino = (void * )ref ;
420+ jffs2_link_node_ref (c , jeb , ofs | REF_PRISTINE , PAD (je32_to_cpu (rr -> totlen )), (void * )ref );
412421
413422 if (jffs2_sum_active ())
414423 jffs2_sum_add_xref_mem (s , rr , ofs - jeb -> offset );
0 commit comments