FreeBSD/sys/fs/nandfs/nandfs_subr.c
/*
 * Search for the last super root recorded.
 */
Search for the last super root recorded.
Search for the last super root recorded .
int
nandfs_search_super_root(struct nandfs_device *nandfsdev)
{
	struct nandfs_super_block *super;
	struct nandfs_segment_summary segsum;
	uint64_t seg_start, seg_end, cno, seq, create, pseg;
	uint64_t segnum;
	int error, found;
	error = found = 0;
	pseg = nandfsdev->nd_super.s_last_pseg;
	segnum = nandfs_get_segnum_of_block(nandfsdev, pseg);
	cno = nandfsdev->nd_super.s_last_cno;
	create = seq = 0;
	DPRINTF(VOLUMES, ("%s: start in pseg %#jx\n", __func__,
	    (uintmax_t)pseg));
	for (;;) {
		error = nandfs_load_segsum(nandfsdev, pseg, &segsum);
		if (error)
			break;
		if (segsum.ss_seq < seq || segsum.ss_create < create)
			break;
		if (segsum.ss_flags & NANDFS_SS_SR) {
			error = nandfs_load_super_root(nandfsdev, &segsum, pseg);
			if (error)
				break;	
			found = 1;
			super = &nandfsdev->nd_super;
			nandfsdev->nd_last_segsum = segsum;
			super->s_last_pseg = pseg;
			super->s_last_cno = cno++;
			super->s_last_seq = segsum.ss_seq;
			super->s_state = NANDFS_VALID_FS;
			seq = segsum.ss_seq;
			create = segsum.ss_create;
		} else {
			seq = segsum.ss_seq;
			create = segsum.ss_create;
		}
		pseg += segsum.ss_nblocks;
		DPRINTF(VOLUMES, ("%s: next partial seg is %jx\n", __func__,
		    (uintmax_t)pseg));
		nandfs_get_segment_range(nandfsdev, segnum, &seg_start,
		    &seg_end);
		if (pseg >= seg_end) {
			pseg = segsum.ss_next;
			DPRINTF(VOLUMES,
			    (" partial seg oor next is %jx[%jx - %jx]\n",
			    (uintmax_t)pseg, (uintmax_t)seg_start,
			    (uintmax_t)seg_end));
		}
		segnum = nandfs_get_segnum_of_block(nandfsdev, pseg);
	}
	if (error && !found)
		return (error);
	return (0);
}
int nandfs_search_super_root ( struct nandfs_device * nandfsdev ) { struct nandfs_super_block * super ; struct nandfs_segment_summary segsum ; uint64_t seg_start , seg_end , cno , seq , create , pseg ; uint64_t segnum ; int error , found ; error = found = 0 ; pseg = nandfsdev -> nd_super . s_last_pseg ; segnum = nandfs_get_segnum_of_block ( nandfsdev , pseg ) ; cno = nandfsdev -> nd_super . s_last_cno ; create = seq = 0 ; DPRINTF ( VOLUMES , ( " \n " , __func__ , ( uintmax_t ) pseg ) ) ; for ( ; ; ) { error = nandfs_load_segsum ( nandfsdev , pseg , & segsum ) ; if ( error ) break ; if ( segsum . ss_seq < seq || segsum . ss_create < create ) break ; if ( segsum . ss_flags & NANDFS_SS_SR ) { error = nandfs_load_super_root ( nandfsdev , & segsum , pseg ) ; if ( error ) break ; found = 1 ; super = & nandfsdev -> nd_super ; nandfsdev -> nd_last_segsum = segsum ; super -> s_last_pseg = pseg ; super -> s_last_cno = cno ++ ; super -> s_last_seq = segsum . ss_seq ; super -> s_state = NANDFS_VALID_FS ; seq = segsum . ss_seq ; create = segsum . ss_create ; } else { seq = segsum . ss_seq ; create = segsum . ss_create ; } pseg += segsum . ss_nblocks ; DPRINTF ( VOLUMES , ( " \n " , __func__ , ( uintmax_t ) pseg ) ) ; nandfs_get_segment_range ( nandfsdev , segnum , & seg_start , & seg_end ) ; if ( pseg >= seg_end ) { pseg = segsum . ss_next ; DPRINTF ( VOLUMES , ( " \n " , ( uintmax_t ) pseg , ( uintmax_t ) seg_start , ( uintmax_t ) seg_end ) ) ; } segnum = nandfs_get_segnum_of_block ( nandfsdev , pseg ) ; } if ( error && ! found ) return ( error ) ; return ( 0 ) ; }
Search for the last super root recorded.
Search for the last super root recorded .
/* Search for last super root */ /* Try to load super root */ /* confused */ /* Calculate next partial segment location */ /* Did we reach the end of the segment? if so, go to the next */