#7 Improve fsck.gfs2 testability
Merged 2 months ago by andyp. Opened 2 months ago by andyp.

file modified
+27 -27
@@ -22,7 +22,7 @@ 

   *

   * Returns: 1 if there are any remaining references to this block, else 0.

   */

- static int find_remove_dup(struct lgfs2_inode *ip, uint64_t block,

+ static int find_remove_dup(struct fsck_cx *cx, struct lgfs2_inode *ip, uint64_t block,

  			   const char *btype, int *removed_last_meta)

  {

  	struct duptree *dt;
@@ -30,7 +30,7 @@ 

  	int deleted_a_meta_ref = 0;

  	int meta_refs_left = 0;

  

- 	dt = dupfind(block);

+ 	dt = dupfind(cx, block);

  	if (!dt)

  		return 0;

  
@@ -45,7 +45,7 @@ 

  	if (dt->refs == 0) {

  		log_info( _("This was the last reference: it's no longer a "

  			    "duplicate.\n"));

- 		dup_delete(dt); /* not duplicate now */

+ 		dup_delete(cx, dt); /* not duplicate now */

  		if (deleted_a_meta_ref) {

  			log_debug("Removed the last reference as metadata.\n");

  			*removed_last_meta = 1;
@@ -73,7 +73,7 @@ 

   * If it has been identified as duplicate, remove the duplicate reference.

   * If all duplicate references have been removed, delete the block.

   */

- static int delete_block_if_notdup(struct lgfs2_inode *ip, uint64_t block,

+ static int delete_block_if_notdup(struct fsck_cx *cx, struct lgfs2_inode *ip, uint64_t block,

  				  struct lgfs2_buffer_head **bh,

  				  const char *btype, int *was_duplicate,

  				  void *private)
@@ -91,7 +91,7 @@ 

  		        btype, block, block, ip->i_num.in_addr, ip->i_num.in_addr);

  		return META_IS_GOOD;

  	}

- 	if (find_remove_dup(ip, block, btype, &removed_lastmeta)) { /* a dup */

+ 	if (find_remove_dup(cx, ip, block, btype, &removed_lastmeta)) { /* a dup */

  		if (was_duplicate) {

  			if (removed_lastmeta)

  				log_debug("Removed last reference as meta.\n");
@@ -103,13 +103,13 @@ 

  		          "because it's referenced by another inode.\n"),

  		        ip->i_num.in_addr, ip->i_num.in_addr, block, block);

  	} else {

- 		check_n_fix_bitmap(ip->i_sbd, ip->i_rgd, block, 0,

+ 		check_n_fix_bitmap(cx, ip->i_rgd, block, 0,

  				   GFS2_BLKST_FREE);

  	}

  	return META_IS_GOOD;

  }

  

- static int remove_dentry(struct lgfs2_inode *ip, struct gfs2_dirent *dent,

+ static int remove_dentry(struct fsck_cx *cx, struct lgfs2_inode *ip, struct gfs2_dirent *dent,

  			 struct gfs2_dirent *prev_de,

  			 struct lgfs2_buffer_head *bh,

  			 char *filename, uint32_t *count, int *lindex,
@@ -131,10 +131,10 @@ 

  

  }

  

- int remove_dentry_from_dir(struct lgfs2_sbd *sdp, uint64_t dir,

- 			   uint64_t dentryblock)

+ int remove_dentry_from_dir(struct fsck_cx *cx, uint64_t dir, uint64_t dentryblock)

  {

  	struct metawalk_fxns remove_dentry_fxns = {0};

+ 	struct lgfs2_sbd *sdp = cx->sdp;

  	struct lgfs2_inode *ip;

  	int q;

  	int error;
@@ -161,12 +161,12 @@ 

  	}

  	/* Need to run check_dir with a private var of dentryblock,

  	 * and fxns that remove that dentry if found */

- 	error = check_dir(sdp, ip, &remove_dentry_fxns);

+ 	error = check_dir(cx, ip, &remove_dentry_fxns);

  	fsck_inode_put(&ip);

  	return error;

  }

  

- int delete_metadata(struct iptr iptr, struct lgfs2_buffer_head **bh, int h, int *is_valid,

+ int delete_metadata(struct fsck_cx *cx, struct iptr iptr, struct lgfs2_buffer_head **bh, int h, int *is_valid,

  		    int *was_duplicate, void *private)

  {

  	struct lgfs2_inode *ip = iptr.ipt_ip;
@@ -174,25 +174,25 @@ 

  

  	*is_valid = 1;

  	*was_duplicate = 0;

- 	return delete_block_if_notdup(ip, block, bh, _("metadata"),

+ 	return delete_block_if_notdup(cx, ip, block, bh, _("metadata"),

  				      was_duplicate, private);

  }

  

- int delete_leaf(struct lgfs2_inode *ip, uint64_t block, void *private)

+ int delete_leaf(struct fsck_cx *cx, struct lgfs2_inode *ip, uint64_t block, void *private)

  {

- 	return delete_block_if_notdup(ip, block, NULL, _("leaf"), NULL,

+ 	return delete_block_if_notdup(cx, ip, block, NULL, _("leaf"), NULL,

  				      private);

  }

  

- int delete_data(struct lgfs2_inode *ip, uint64_t metablock,

+ int delete_data(struct fsck_cx *cx, struct lgfs2_inode *ip, uint64_t metablock,

  		uint64_t block, void *private, struct lgfs2_buffer_head *bh,

  		__be64 *ptr)

  {

- 	return delete_block_if_notdup(ip, block, NULL, _("data"), NULL,

+ 	return delete_block_if_notdup(cx, ip, block, NULL, _("data"), NULL,

  				      private);

  }

  

- static int del_eattr_generic(struct lgfs2_inode *ip, uint64_t block,

+ static int del_eattr_generic(struct fsck_cx *cx, struct lgfs2_inode *ip, uint64_t block,

  			     uint64_t parent, struct lgfs2_buffer_head **bh,

  			     void *private, const char *eatype)

  {
@@ -204,7 +204,7 @@ 

  		q = bitmap_type(ip->i_sbd, block);

  		if (q == GFS2_BLKST_FREE)

  			was_free = 1;

- 		ret = delete_block_if_notdup(ip, block, NULL, eatype,

+ 		ret = delete_block_if_notdup(cx, ip, block, NULL, eatype,

  					     NULL, private);

  		if (!ret) {

  			*bh = lgfs2_bread(ip->i_sbd, block);
@@ -223,21 +223,21 @@ 

  	return ret;

  }

  

- int delete_eattr_indir(struct lgfs2_inode *ip, uint64_t block, uint64_t parent,

+ int delete_eattr_indir(struct fsck_cx *cx, struct lgfs2_inode *ip, uint64_t block, uint64_t parent,

  		       struct lgfs2_buffer_head **bh, void *private)

  {

- 	return del_eattr_generic(ip, block, parent, bh, private,

+ 	return del_eattr_generic(cx, ip, block, parent, bh, private,

  				 _("extended attribute"));

  }

  

- int delete_eattr_leaf(struct lgfs2_inode *ip, uint64_t block, uint64_t parent,

+ int delete_eattr_leaf(struct fsck_cx *cx, struct lgfs2_inode *ip, uint64_t block, uint64_t parent,

  		      struct lgfs2_buffer_head **bh, void *private)

  {

- 	return del_eattr_generic(ip, block, parent, bh, private,

+ 	return del_eattr_generic(cx, ip, block, parent, bh, private,

  				 _("indirect extended attribute"));

  }

  

- int delete_eattr_entry(struct lgfs2_inode *ip, struct lgfs2_buffer_head *leaf_bh,

+ int delete_eattr_entry(struct fsck_cx *cx, struct lgfs2_inode *ip, struct lgfs2_buffer_head *leaf_bh,

  		       struct gfs2_ea_header *ea_hdr,

  		       struct gfs2_ea_header *ea_hdr_prev, void *private)

  {
@@ -277,7 +277,7 @@ 

  	return 0;

  }

  

- int delete_eattr_extentry(struct lgfs2_inode *ip, int i, __be64 *ea_data_ptr,

+ int delete_eattr_extentry(struct fsck_cx *cx, struct lgfs2_inode *ip, int i, __be64 *ea_data_ptr,

  			  struct lgfs2_buffer_head *leaf_bh, uint32_t tot_ealen,

  			  struct gfs2_ea_header *ea_hdr,

  			  struct gfs2_ea_header *ea_hdr_prev, void *private)
@@ -285,19 +285,19 @@ 

  	uint64_t block = be64_to_cpu(*ea_data_ptr);

  	int error;

  

- 	error = delete_block_if_notdup(ip, block, NULL,

+ 	error = delete_block_if_notdup(cx, ip, block, NULL,

  				       _("extended attribute"), NULL, private);

  	if (error) {

  		log_err(_("Bad extended attribute found at block %"PRIu64 " (0x%"PRIx64")"),

  		        be64_to_cpu(*ea_data_ptr), be64_to_cpu(*ea_data_ptr));

- 		if (query( _("Repair the bad Extended Attribute? (y/n) "))) {

+ 		if (query(cx, _("Repair the bad Extended Attribute? (y/n) "))) {

  			ea_hdr->ea_num_ptrs = i;

  			ea_hdr->ea_data_len = cpu_to_be32(tot_ealen);

  			*ea_data_ptr = 0;

  			lgfs2_bmodified(leaf_bh);

  			/* Endianness doesn't matter in this case because it's

  			   a single byte. */

- 			fsck_bitmap_set(ip, ip->i_eattr,

+ 			fsck_bitmap_set(cx, ip, ip->i_eattr,

  					_("extended attribute"),

  					ip->i_sbd->gfs1 ? GFS2_BLKST_DINODE :

  					GFS2_BLKST_USED);

file modified
+9 -10
@@ -4,28 +4,27 @@ 

  #include "util.h"

  #include "metawalk.h"

  

- extern int delete_metadata(struct iptr iptr, struct lgfs2_buffer_head **bh, int h, int *is_valid,

- 			   int *was_duplicate, void *private);

- extern int delete_leaf(struct lgfs2_inode *ip, uint64_t block, void *private);

- extern int delete_data(struct lgfs2_inode *ip, uint64_t metablock,

+ extern int delete_metadata(struct fsck_cx *cx, struct iptr iptr, struct lgfs2_buffer_head **bh,

+                            int h, int *is_valid, int *was_duplicate, void *private);

+ extern int delete_leaf(struct fsck_cx *cx, struct lgfs2_inode *ip, uint64_t block, void *private);

+ extern int delete_data(struct fsck_cx *cx, struct lgfs2_inode *ip, uint64_t metablock,

  		       uint64_t block, void *private,

  		       struct lgfs2_buffer_head *bh, __be64 *ptr);

- extern int delete_eattr_indir(struct lgfs2_inode *ip, uint64_t block, uint64_t parent,

+ extern int delete_eattr_indir(struct fsck_cx *cx, struct lgfs2_inode *ip, uint64_t block, uint64_t parent,

  		       struct lgfs2_buffer_head **bh, void *private);

- extern int delete_eattr_leaf(struct lgfs2_inode *ip, uint64_t block, uint64_t parent,

+ extern int delete_eattr_leaf(struct fsck_cx *cx, struct lgfs2_inode *ip, uint64_t block, uint64_t parent,

  		      struct lgfs2_buffer_head **bh, void *private);

- extern int delete_eattr_entry(struct lgfs2_inode *ip,

+ extern int delete_eattr_entry(struct fsck_cx *cx, struct lgfs2_inode *ip,

  			      struct lgfs2_buffer_head *leaf_bh,

  			      struct gfs2_ea_header *ea_hdr,

  			      struct gfs2_ea_header *ea_hdr_prev,

  			      void *private);

- extern int delete_eattr_extentry(struct lgfs2_inode *ip, int i,

+ extern int delete_eattr_extentry(struct fsck_cx *cx, struct lgfs2_inode *ip, int i,

  				 __be64 *ea_data_ptr,

  				 struct lgfs2_buffer_head *leaf_bh,

  				 uint32_t tot_ealen,

  				 struct gfs2_ea_header *ea_hdr,

  				 struct gfs2_ea_header *ea_hdr_prev,

  				 void *private);

- extern int remove_dentry_from_dir(struct lgfs2_sbd *sdp, uint64_t dir,

- 						   uint64_t dentryblock);

+ extern int remove_dentry_from_dir(struct fsck_cx *cx, uint64_t dir, uint64_t dentryblock);

  #endif

file modified
+4 -4
@@ -10,7 +10,7 @@ 

  

  #include "fsck.h"

  

- void gfs2_special_free(struct special_blocks *blist)

+ void special_free(struct special_blocks *blist)

  {

  	struct special_blocks *f;

  
@@ -36,7 +36,7 @@ 

  	return NULL;

  }

  

- static void gfs2_special_add(struct special_blocks *blocklist, uint64_t block)

+ static void special_add(struct special_blocks *blocklist, uint64_t block)

  {

  	struct special_blocks *b;

  
@@ -48,9 +48,9 @@ 

  	}

  }

  

- void gfs2_special_set(struct special_blocks *blocklist, uint64_t block)

+ void special_set(struct special_blocks *blocklist, uint64_t block)

  {

  	if (blockfind(blocklist, block))

  		return;

- 	gfs2_special_add(blocklist, block);

+ 	special_add(blocklist, block);

  }

file modified
+38 -43
@@ -27,7 +27,7 @@ 

  static osi_list_t sd_revoke_list;

  static unsigned int sd_replay_tail;

  

- struct gfs2_revoke_replay {

+ struct revoke_replay {

  	osi_list_t rr_list;

  	uint64_t rr_blkno;

  	unsigned int rr_where;
@@ -36,11 +36,11 @@ 

  static int revoke_add(struct lgfs2_sbd *sdp, uint64_t blkno, unsigned int where)

  {

  	osi_list_t *tmp, *head = &sd_revoke_list;

- 	struct gfs2_revoke_replay *rr;

+ 	struct revoke_replay *rr;

  	int found = 0;

  

  	osi_list_foreach(tmp, head) {

- 		rr = osi_list_entry(tmp, struct gfs2_revoke_replay, rr_list);

+ 		rr = osi_list_entry(tmp, struct revoke_replay, rr_list);

  		if (rr->rr_blkno == blkno) {

  			found = 1;

  			break;
@@ -52,7 +52,7 @@ 

  		return 0;

  	}

  

- 	rr = malloc(sizeof(struct gfs2_revoke_replay));

+ 	rr = malloc(sizeof(struct revoke_replay));

  	if (!rr)

  		return -ENOMEM;

  
@@ -65,12 +65,12 @@ 

  static int revoke_check(struct lgfs2_sbd *sdp, uint64_t blkno, unsigned int where)

  {

  	osi_list_t *tmp;

- 	struct gfs2_revoke_replay *rr;

+ 	struct revoke_replay *rr;

  	int wrap, a, b;

  	int found = 0;

  

  	osi_list_foreach(tmp, &sd_revoke_list) {

- 		rr = osi_list_entry(tmp, struct gfs2_revoke_replay, rr_list);

+ 		rr = osi_list_entry(tmp, struct revoke_replay, rr_list);

  		if (rr->rr_blkno == blkno) {

  			found = 1;

  			break;
@@ -89,10 +89,10 @@ 

  static void revoke_clean(struct lgfs2_sbd *sdp)

  {

  	osi_list_t *head = &sd_revoke_list;

- 	struct gfs2_revoke_replay *rr;

+ 	struct revoke_replay *rr;

  

  	while (!osi_list_empty(head)) {

- 		rr = osi_list_entry(head->next, struct gfs2_revoke_replay, rr_list);

+ 		rr = osi_list_entry(head->next, struct revoke_replay, rr_list);

  		osi_list_del(&rr->rr_list);

  		free(rr);

  	}
@@ -450,11 +450,11 @@ 

   * mounted by other nodes in the cluster, which is dangerous and therefore,

   * we should warn the user to run fsck.gfs2 manually when it's safe.

   */

- int preen_is_safe(struct lgfs2_sbd *sdp, int preen, int force_check)

+ int preen_is_safe(struct lgfs2_sbd *sdp, const struct fsck_options * const opts)

  {

- 	if (!preen)       /* If preen was not specified */

+ 	if (!opts->preen)

  		return 1; /* not called by rc.sysinit--we're okay to preen */

- 	if (force_check)  /* If check was forced by the user? */

+ 	if (opts->force)

  		return 1; /* user's responsibility--we're okay to preen */

  	if (!memcmp(sdp->sd_lockproto + 5, "nolock", 6))

  		return 1; /* local file system--preen is okay */
@@ -476,8 +476,7 @@ 

   * Returns: errno

   */

  

- static int gfs2_recover_journal(struct lgfs2_inode *ip, int j, int preen,

- 				int force_check, int *was_clean)

+ static int recover_journal(struct lgfs2_inode *ip, int j, struct fsck_cx *cx, int *was_clean)

  {

  	struct lgfs2_sbd *sdp = ip->i_sbd;

  	struct lgfs2_log_header head;
@@ -499,12 +498,12 @@ 

  		}

  	}

  	if (error) {

- 		if (opts.no) {

+ 		if (cx->opts->no) {

  			log_err( _("Journal #%d (\"journal%d\") is corrupt\n"),j+1, j);

  			log_err( _("Not fixing it due to the -n option.\n"));

  			goto out;

  		}

- 		if (!preen_is_safe(sdp, preen, force_check)) {

+ 		if (!preen_is_safe(sdp, cx->opts)) {

  			log_err(_("Journal #%d (\"journal%d\") is corrupt.\n"),

  				j+1, j);

  			log_err(_("I'm not fixing it because it may be unsafe:\n"
@@ -515,7 +514,7 @@ 

  				 "without -a or -p.\n"));

  			goto out;

  		}

- 		if (!query( _("\nJournal #%d (\"journal%d\") is "

+ 		if (!query(cx, _("\nJournal #%d (\"journal%d\") is "

  			      "corrupt.  Okay to repair it? (y/n)"),

  			    j+1, j)) {

  			log_err( _("jid=%u: The journal was not repaired.\n"),
@@ -543,12 +542,12 @@ 

  		*was_clean = 1;

  		return 0;

  	}

- 	if (opts.no) {

+ 	if (cx->opts->no) {

  		log_err(_("Journal #%d (\"journal%d\") is dirty\n"),j+1, j);

  		log_err(_("not replaying due to the -n option.\n"));

  		goto out;

  	}

- 	if (!preen_is_safe(sdp, preen, force_check)) {

+ 	if (!preen_is_safe(sdp, cx->opts)) {

  		log_err( _("Journal #%d (\"journal%d\") is dirty\n"), j+1, j);

  		log_err( _("I'm not replaying it because it may be unsafe:\n"

  			   "Locking protocol is not lock_nolock and "
@@ -559,7 +558,7 @@ 

  		error = FSCK_ERROR;

  		goto out;

  	}

- 	if (!query( _("\nJournal #%d (\"journal%d\") is dirty.  Okay to "

+ 	if (!query(cx, _("\nJournal #%d (\"journal%d\") is dirty.  Okay to "

  		      "replay it? (y/n)"), j+1, j))

  		goto reinit;

  
@@ -596,7 +595,7 @@ 

  	}

  	log_err( _("jid=%u: Failed\n"), j);

  reinit:

- 	if (query( _("Do you want to clear the journal instead? (y/n)"))) {

+ 	if (query(cx, _("Do you want to clear the journal instead? (y/n)"))) {

  		error = lgfs2_write_journal(sdp->md.journal[j], sdp->sd_bsize,

  				      sdp->md.journal[j]->i_size /

  				      sdp->sd_bsize);
@@ -620,7 +619,7 @@ 

  	return META_IS_GOOD;

  }

  

- static int rangecheck_jmeta(struct iptr iptr, struct lgfs2_buffer_head **bh, int h,

+ static int rangecheck_jmeta(struct fsck_cx *cx, struct iptr iptr, struct lgfs2_buffer_head **bh, int h,

                              int *is_valid, int *was_duplicate, void *private)

  {

  	struct lgfs2_inode *ip = iptr.ipt_ip;
@@ -648,7 +647,7 @@ 

  	return rc;

  }

  

- static int rangecheck_jdata(struct lgfs2_inode *ip, uint64_t metablock,

+ static int rangecheck_jdata(struct fsck_cx *cx, struct lgfs2_inode *ip, uint64_t metablock,

  			    uint64_t block, void *private,

  			    struct lgfs2_buffer_head *bh, __be64 *ptr)

  {
@@ -675,11 +674,14 @@ 

   *

   * Returns: 0 on success, -1 on failure

   */

- int replay_journals(struct lgfs2_sbd *sdp, int preen, int force_check,

- 		    int *clean_journals)

+ int replay_journals(struct fsck_cx *cx, int *clean_journals)

  {

+ 	struct lgfs2_sbd *sdp = cx->sdp;

+ 	int dirty_journals = 0;

+ 	int gave_msg = 0;

+ 	int error = 0;

+ 	int clean = 0;

  	int i;

- 	int clean = 0, dirty_journals = 0, error = 0, gave_msg = 0;

  

  	*clean_journals = 0;

  
@@ -687,7 +689,7 @@ 

  

  	for(i = 0; i < sdp->md.journals; i++) {

  		if (sdp->md.journal[i]) {

- 			error = check_metatree(sdp->md.journal[i],

+ 			error = check_metatree(cx, sdp->md.journal[i],

  					       &rangecheck_journal);

  			if (error)

  				/* Don't use fsck_inode_put here because it's a
@@ -707,13 +709,11 @@ 

  			if (sdp->jsize == LGFS2_DEFAULT_JSIZE && jsize &&

  			    jsize != sdp->jsize)

  				sdp->jsize = jsize;

- 			error = gfs2_recover_journal(sdp->md.journal[i], i,

- 						     preen, force_check,

- 						     &clean);

+ 			error = recover_journal(sdp->md.journal[i], i, cx, &clean);

  			if (!clean)

  				dirty_journals++;

- 			if (!gave_msg && dirty_journals == 1 && !opts.no &&

- 			    preen_is_safe(sdp, preen, force_check)) {

+ 			if (!gave_msg && dirty_journals == 1 && !cx->opts->no &&

+ 			    preen_is_safe(sdp, cx->opts)) {

  				gave_msg = 1;

  				log_notice( _("Recovering journals (this may "

  					      "take a while)\n"));
@@ -808,7 +808,7 @@ 

   * This function makes sure the directory entries of the jindex are valid.

   * If they're not '.' or '..' they better have the form journalXXX.

   */

- static int check_jindex_dent(struct lgfs2_inode *ip, struct gfs2_dirent *dent,

+ static int check_jindex_dent(struct fsck_cx *cx, struct lgfs2_inode *ip, struct gfs2_dirent *dent,

  			     struct gfs2_dirent *prev_de,

  			     struct lgfs2_buffer_head *bh, char *filename,

  			     uint32_t *count, int *lindex, void *priv)
@@ -869,14 +869,9 @@ 

  	return 0;

  }

  

- /**

-  * init_jindex - read in the rindex file

-  */

- int init_jindex(struct lgfs2_sbd *sdp, int allow_ji_rebuild)

+ int init_jindex(struct fsck_cx *cx, int allow_ji_rebuild)

  {

- 	/*******************************************************************

- 	 ******************  Fill in journal information  ******************

- 	 *******************************************************************/

+ 	struct lgfs2_sbd *sdp = cx->sdp;

  

  	log_debug(_("Validating the journal index.\n"));

  	/* rgrepair requires the journals be read in in order to distinguish
@@ -894,7 +889,7 @@ 

  				   "corrupt.\n"));

  			return -1;

  		}

- 		if (!query( _("The gfs2 system jindex inode is missing. "

+ 		if (!query(cx, _("The gfs2 system jindex inode is missing. "

  			      "Okay to rebuild it? (y/n) "))) {

  			log_crit(_("Error: cannot proceed without a valid "

  				   "jindex file.\n"));
@@ -916,15 +911,15 @@ 

  

  		log_debug(_("Checking the integrity of the journal index.\n"));

  		if (sdp->md.jiinode->i_flags & GFS2_DIF_EXHASH)

- 			error = check_leaf_blks(sdp->md.jiinode,

+ 			error = check_leaf_blks(cx, sdp->md.jiinode,

  						&jindex_check_fxns);

  		else

- 			error = check_linear_dir(sdp->md.jiinode,

+ 			error = check_linear_dir(cx, sdp->md.jiinode,

  						 sdp->md.jiinode->i_bh,

  						 &jindex_check_fxns);

  		if (error) {

  			log_err(_("The system journal index is damaged.\n"));

- 			if (!query( _("Okay to rebuild it? (y/n) "))) {

+ 			if (!query(cx, _("Okay to rebuild it? (y/n) "))) {

  				log_crit(_("Error: cannot proceed without a "

  					   "valid jindex file.\n"));

  				return -1;

file modified
+3 -4
@@ -3,12 +3,11 @@ 

  

  #include "libgfs2.h"

  

- extern int replay_journals(struct lgfs2_sbd *sdp, int preen, int force_check,

- 			   int *clean_journals);

- extern int preen_is_safe(struct lgfs2_sbd *sdp, int preen, int force_check);

+ extern int replay_journals(struct fsck_cx *cx, int *clean_journals);

+ extern int preen_is_safe(struct lgfs2_sbd *sdp, const struct fsck_options * const opts);

  

  extern int ji_update(struct lgfs2_sbd *sdp);

  extern int build_jindex(struct lgfs2_sbd *sdp);

- extern int init_jindex(struct lgfs2_sbd *sdp, int allow_ji_rebuild);

+ extern int init_jindex(struct fsck_cx *cx, int allow_ji_rebuild);

  #endif /* __FS_RECOVERY_H__ */

  

file modified
+36 -32
@@ -10,7 +10,7 @@ 

  #define FSCK_HASH_SIZE          (1 << FSCK_HASH_SHIFT)

  #define FSCK_HASH_MASK          (FSCK_HASH_SIZE - 1)

  

- #define query(fmt, args...) fsck_query(fmt, ##args)

+ #define query(cx, fmt, args...) fsck_query(cx, fmt, ##args)

  

  /*

   * Exit codes used by fsck-type programs
@@ -27,7 +27,7 @@ 

  

  #define BAD_POINTER_TOLERANCE 10 /* How many bad pointers is too many? */

  

- struct gfs2_bmap {

+ struct bmap {

  	uint64_t size;

  	uint64_t mapsize;

  	unsigned char *map;
@@ -108,41 +108,48 @@ 

  			   must have been converted from gfs2_convert. */

  };

  

+ struct fsck_options {

+ 	char *device;

+ 	unsigned int yes:1;

+ 	unsigned int no:1;

+ 	unsigned int preen:1;

+ 	unsigned int force:1;

+ };

+ 

+ struct fsck_cx {

+ 	struct lgfs2_sbd *sdp;

+ 	struct osi_root dup_blocks;

+ 	struct osi_root dirtree;

+ 	struct osi_root inodetree;

+ 	const struct fsck_options * const opts;

+ };

+ 

  extern struct lgfs2_inode *fsck_load_inode(struct lgfs2_sbd *sdp, uint64_t block);

  extern struct lgfs2_inode *fsck_inode_get(struct lgfs2_sbd *sdp,

  					 struct lgfs2_rgrp_tree *rgd,

  					 struct lgfs2_buffer_head *bh);

  extern void fsck_inode_put(struct lgfs2_inode **ip);

  

- extern int initialize(struct lgfs2_sbd *sdp, int force_check, int preen,

- 		      int *all_clean);

- extern void destroy(struct lgfs2_sbd *sdp);

- extern int pass1(struct lgfs2_sbd *sdp);

- extern int pass1b(struct lgfs2_sbd *sdp);

- extern int pass1c(struct lgfs2_sbd *sdp);

- extern int pass2(struct lgfs2_sbd *sdp);

- extern int pass3(struct lgfs2_sbd *sdp);

- extern int pass4(struct lgfs2_sbd *sdp);

- extern int pass5(struct lgfs2_sbd *sdp, struct gfs2_bmap *bl);

- extern int rindex_repair(struct lgfs2_sbd *sdp, int trust_lvl, int *ok);

- extern int fsck_query(const char *format, ...)

- 	__attribute__((format(printf,1,2)));

- extern struct dir_info *dirtree_find(uint64_t block);

- extern void dup_delete(struct duptree *dt);

- extern void dirtree_delete(struct dir_info *b);

+ extern int initialize(struct fsck_cx *cx, int *all_clean);

+ extern void destroy(struct fsck_cx *cx);

+ extern int pass1(struct fsck_cx *cx);

+ extern int pass1b(struct fsck_cx *cx);

+ extern int pass1c(struct fsck_cx *cx);

+ extern int pass2(struct fsck_cx *cx);

+ extern int pass3(struct fsck_cx *cx);

+ extern int pass4(struct fsck_cx *cx);

+ extern int pass5(struct fsck_cx *cx, struct bmap *bl);

+ extern int rindex_repair(struct fsck_cx *cx, int trust_lvl, int *ok);

+ extern int fsck_query(struct fsck_cx *cx, const char *format, ...)

+ 	__attribute__((format(printf,2,3)));

+ extern struct dir_info *dirtree_find(struct fsck_cx *cx, uint64_t block);

+ extern void dup_delete(struct fsck_cx *cx, struct duptree *dt);

+ extern void dirtree_delete(struct fsck_cx *cx, struct dir_info *b);

  

  /* FIXME: Hack to get this going for pass2 - this should be pulled out

   * of pass1 and put somewhere else... */

- struct dir_info *dirtree_insert(struct lgfs2_inum inum);

- 

- struct gfs2_options {

- 	char *device;

- 	unsigned int yes:1;

- 	unsigned int no:1;

- 	unsigned int query:1;

- };

+ struct dir_info *dirtree_insert(struct fsck_cx *cx, struct lgfs2_inum inum);

  

- extern struct gfs2_options opts;

  extern struct lgfs2_inode *lf_dip; /* Lost and found directory inode */

  extern int lf_was_created;

  extern uint64_t last_fs_block, last_reported_block;
@@ -151,9 +158,6 @@ 

  extern int errors_found, errors_corrected;

  extern uint64_t last_data_block;

  extern uint64_t first_data_block;

- extern struct osi_root dup_blocks;

- extern struct osi_root dirtree;

- extern struct osi_root inodetree;

  extern int dups_found; /* How many duplicate references have we found? */

  extern int dups_found_first; /* How many duplicates have we found the original

  				reference for? */
@@ -197,8 +201,8 @@ 

  };

  

  extern struct special_blocks *blockfind(struct special_blocks *blist, uint64_t num);

- extern void gfs2_special_set(struct special_blocks *blocklist, uint64_t block);

- extern void gfs2_special_free(struct special_blocks *blist);

+ extern void special_set(struct special_blocks *blocklist, uint64_t block);

+ extern void special_free(struct special_blocks *blist);

  extern int sb_fixed;

  extern int build_per_node(struct lgfs2_sbd *sdp);

  

file modified
+108 -95
@@ -67,36 +67,36 @@ 

  	return 0;

  }

  

- static void gfs2_dup_free(void)

+ static void dup_free(struct fsck_cx *cx)

  {

  	struct osi_node *n;

  	struct duptree *dt;

  

- 	while ((n = osi_first(&dup_blocks))) {

+ 	while ((n = osi_first(&cx->dup_blocks))) {

  		dt = (struct duptree *)n;

- 		dup_delete(dt);

+ 		dup_delete(cx, dt);

  	}

  }

  

- static void gfs2_dirtree_free(void)

+ static void dirtree_free(struct fsck_cx *cx)

  {

  	struct osi_node *n;

  	struct dir_info *dt;

  

- 	while ((n = osi_first(&dirtree))) {

+ 	while ((n = osi_first(&cx->dirtree))) {

  		dt = (struct dir_info *)n;

- 		dirtree_delete(dt);

+ 		dirtree_delete(cx, dt);

  	}

  }

  

- static void gfs2_inodetree_free(void)

+ static void inodetree_free(struct fsck_cx *cx)

  {

  	struct osi_node *n;

  	struct inode_info *dt;

  

- 	while ((n = osi_first(&inodetree))) {

+ 	while ((n = osi_first(&cx->inodetree))) {

  		dt = (struct inode_info *)n;

- 		inodetree_delete(dt);

+ 		inodetree_delete(cx, dt);

  	}

  }

  
@@ -109,14 +109,14 @@ 

   *

   * Returns: Nothing

   */

- static void empty_super_block(struct lgfs2_sbd *sdp)

+ static void empty_super_block(struct fsck_cx *cx)

  {

  	log_info( _("Freeing buffers.\n"));

- 	lgfs2_rgrp_free(sdp, &sdp->rgtree);

+ 	lgfs2_rgrp_free(cx->sdp, &cx->sdp->rgtree);

  

- 	gfs2_inodetree_free();

- 	gfs2_dirtree_free();

- 	gfs2_dup_free();

+ 	inodetree_free(cx);

+ 	dirtree_free(cx);

+ 	dup_free(cx);

  }

  

  
@@ -185,12 +185,13 @@ 

  /**

   * check_rgrp_integrity - verify a rgrp free block count against the bitmap

   */

- static void check_rgrp_integrity(struct lgfs2_sbd *sdp, struct lgfs2_rgrp_tree *rgd,

+ static void check_rgrp_integrity(struct fsck_cx *cx, struct lgfs2_rgrp_tree *rgd,

  				 int *fixit, int *this_rg_fixed,

  				 int *this_rg_bad, int *this_rg_cleaned)

  {

  	uint32_t rg_free, rg_reclaimed, rg_unlinked, rg_usedmeta, rg_useddi;

  	int rgb, x, y, off, bytes_to_check, total_bytes_to_check, asked = 0;

+ 	struct lgfs2_sbd *sdp = cx->sdp;

  	unsigned int state;

  	uint64_t diblock;

  	struct lgfs2_buffer_head *bh;
@@ -264,7 +265,7 @@ 

  						  "metadata in resource group "

  						  "%"PRIu64" (0x%"PRIx64")? (y/n)"),

  					        rgd->rt_addr, rgd->rt_addr);

- 					if (query("%s", msg))

+ 					if (query(cx, "%s", msg))

  						*fixit = 1;

  				}

  				if (!(*fixit)) {
@@ -323,7 +324,7 @@ 

  		log_err( _("Error: resource group %"PRIu64" (0x%"PRIx64"): "

  			   "free space (%d) does not match bitmap (%d)\n"),

  		        rgd->rt_addr, rgd->rt_addr, rgd->rt_free, rg_free);

- 		if (query( _("Fix the rgrp free blocks count? (y/n)"))) {

+ 		if (query(cx, _("Fix the rgrp free blocks count? (y/n)"))) {

  			rgd->rt_free = rg_free;

  			if (sdp->gfs1)

  				lgfs2_gfs_rgrp_out(rgd, rgd->bits[0].bi_data);
@@ -344,7 +345,7 @@ 

  		log_err(_("Error: resource group %"PRIu64" (0x%"PRIx64"): "

  			   "free meta (%d) does not match bitmap (%d)\n"),

  		        rgd->rt_addr, rgd->rt_addr, rgd->rt_freemeta, rg_unlinked);

- 		if (query( _("Fix the rgrp free meta blocks count? (y/n)"))) {

+ 		if (query(cx, _("Fix the rgrp free meta blocks count? (y/n)"))) {

  			rgd->rt_freemeta = rg_unlinked;

  			lgfs2_gfs_rgrp_out(rgd, rgd->bits[0].bi_data);

  			rgd->bits[0].bi_modified = 1;
@@ -359,7 +360,7 @@ 

  		log_err(_("Error: resource group %"PRIu64" (0x%"PRIx64"): used dinode "

  			   "count (%d) does not match bitmap (%d)\n"),

  		        rgd->rt_addr, rgd->rt_addr, rgd->rt_useddi, rg_useddi);

- 		if (query( _("Fix the rgrp used dinode block count? (y/n)"))) {

+ 		if (query(cx, _("Fix the rgrp used dinode block count? (y/n)"))) {

  			rgd->rt_useddi = rg_useddi;

  			lgfs2_gfs_rgrp_out(rgd, rgd->bits[0].bi_data);

  			rgd->bits[0].bi_modified = 1;
@@ -374,7 +375,7 @@ 

  		log_err(_("Error: resource group %"PRIu64" (0x%"PRIx64"): used "

  			   "metadata (%d) does not match bitmap (%d)\n"),

  		        rgd->rt_addr, rgd->rt_addr, rgd->rt_usedmeta, rg_usedmeta);

- 		if (query( _("Fix the rgrp used meta blocks count? (y/n)"))) {

+ 		if (query(cx, _("Fix the rgrp used meta blocks count? (y/n)"))) {

  			rgd->rt_usedmeta = rg_usedmeta;

  			lgfs2_gfs_rgrp_out(rgd, rgd->bits[0].bi_data);

  			rgd->bits[0].bi_modified = 1;
@@ -392,7 +393,7 @@ 

   *

   * Returns: 0 on success, 1 if errors were detected

   */

- static void check_rgrps_integrity(struct lgfs2_sbd *sdp)

+ static void check_rgrps_integrity(struct fsck_cx *cx)

  {

  	struct osi_node *n, *next = NULL;

  	int rgs_good = 0, rgs_bad = 0, rgs_fixed = 0, rgs_cleaned = 0;
@@ -401,12 +402,12 @@ 

  	int reclaim_unlinked = 0;

  

  	log_info( _("Checking the integrity of all resource groups.\n"));

- 	for (n = osi_first(&sdp->rgtree); n; n = next) {

+ 	for (n = osi_first(&cx->sdp->rgtree); n; n = next) {

  		next = osi_next(n);

  		rgd = (struct lgfs2_rgrp_tree *)n;

  		if (fsck_abort)

  			return;

- 		check_rgrp_integrity(sdp, rgd, &reclaim_unlinked,

+ 		check_rgrp_integrity(cx, rgd, &reclaim_unlinked,

  				     &was_fixed, &was_bad, &was_cleaned);

  		if (was_fixed)

  			rgs_fixed++;
@@ -429,18 +430,16 @@ 

  	}

  }

  

- /**

-  * rebuild_master - rebuild a destroyed master directory

-  */

- static int rebuild_master(struct lgfs2_sbd *sdp)

+ static int rebuild_sysdir(struct fsck_cx *cx)

  {

+ 	struct lgfs2_sbd *sdp = cx->sdp;

  	struct lgfs2_inum inum;

  	struct lgfs2_buffer_head *bh = NULL;

  	int err = 0;

  

- 	log_err(_("The system master directory seems to be destroyed.\n"));

- 	if (!query(_("Okay to rebuild it? (y/n)"))) {

- 		log_err(_("System master not rebuilt; aborting.\n"));

+ 	log_err(_("The system directory seems to be destroyed.\n"));

+ 	if (!query(cx, _("Okay to rebuild it? (y/n)"))) {

+ 		log_err(_("System directory not rebuilt; aborting.\n"));

  		return -1;

  	}

  	log_err(_("Trying to rebuild the master directory.\n"));
@@ -590,8 +589,10 @@ 

   * allow_rebuild: 0 if rebuilds are not allowed

   *                1 if rebuilds are allowed

   */

- static void lookup_per_node(struct lgfs2_sbd *sdp, int allow_rebuild)

+ static void lookup_per_node(struct fsck_cx *cx, int allow_rebuild)

  {

+ 	struct lgfs2_sbd *sdp = cx->sdp;

+ 

  	if (sdp->md.pinode)

  		return;

  
@@ -605,7 +606,7 @@ 

  		return;

  	}

  

- 	if (query( _("The gfs2 system per_node directory "

+ 	if (query(cx, _("The gfs2 system per_node directory "

  		     "inode is missing. Okay to rebuild it? (y/n) "))) {

  		int err;

  
@@ -625,7 +626,7 @@ 

  

  #define RA_WINDOW 32

  

- static unsigned gfs2_rgrp_reada(struct lgfs2_sbd *sdp, unsigned cur_window,

+ static unsigned rgrp_reada(struct lgfs2_sbd *sdp, unsigned cur_window,

  				struct osi_node *n)

  {

  	struct lgfs2_rgrp_tree *rgd;
@@ -673,7 +674,7 @@ 

  		rgd = (struct lgfs2_rgrp_tree *)n;

  		/* Readahead resource group headers */

  		if (ra_window < RA_WINDOW/2)

- 			ra_window = gfs2_rgrp_reada(sdp, ra_window, n);

+ 			ra_window = rgrp_reada(sdp, ra_window, n);

  		/* Read resource group header */

  		errblock = lgfs2_rgrp_read(sdp, rgd);

  		if (errblock)
@@ -697,7 +698,7 @@ 

  	return -1;

  }

  

- static int fetch_rgrps_level(struct lgfs2_sbd *sdp, enum rgindex_trust_level lvl, uint64_t *count, int *ok)

+ static int fetch_rgrps_level(struct fsck_cx *cx, enum rgindex_trust_level lvl, uint64_t *count, int *ok)

  {

  	int ret = 1;

  
@@ -718,13 +719,13 @@ 

  

  	log_notice(_("Level %d resource group check: %s.\n"), lvl + 1, level_desc[lvl]);

  

- 	if (rindex_repair(sdp, lvl, ok) != 0)

+ 	if (rindex_repair(cx, lvl, ok) != 0)

  		goto fail;

  

- 	if (lgfs2_rindex_read(sdp, count, ok) != 0 || !*ok)

+ 	if (lgfs2_rindex_read(cx->sdp, count, ok) != 0 || !*ok)

  		goto fail;

  

- 	ret = read_rgrps(sdp, *count);

+ 	ret = read_rgrps(cx->sdp, *count);

  	if (ret != 0)

  		goto fail;

  
@@ -742,7 +743,7 @@ 

  /**

   * fetch_rgrps - fetch the resource groups from disk, and check their integrity

   */

- static int fetch_rgrps(struct lgfs2_sbd *sdp)

+ static int fetch_rgrps(struct fsck_cx *cx)

  {

  	enum rgindex_trust_level trust_lvl;

  	uint64_t rgcount;
@@ -752,7 +753,7 @@ 

  	for (trust_lvl = BLIND_FAITH; trust_lvl <= INDIGNATION; trust_lvl++) {

  		int ret = 0;

  

- 		ret = fetch_rgrps_level(sdp, trust_lvl, &rgcount, &ok);

+ 		ret = fetch_rgrps_level(cx, trust_lvl, &rgcount, &ok);

  		if (ret == 0)

  			break;

  		if (fsck_abort)
@@ -765,7 +766,7 @@ 

  	}

  	log_info( _("%"PRIu64" resource groups found.\n"), rgcount);

  

- 	check_rgrps_integrity(sdp);

+ 	check_rgrps_integrity(cx);

  	return 0;

  }

  
@@ -774,8 +775,9 @@ 

   *

   * Returns: 0 on success, -1 on failure

   */

- static int init_system_inodes(struct lgfs2_sbd *sdp)

+ static int init_system_inodes(struct fsck_cx *cx)

  {

+ 	struct lgfs2_sbd *sdp = cx->sdp;

  	__be64 inumbuf = 0;

  	char *buf;

  	int err;
@@ -798,7 +800,7 @@ 

  		/* Look for "inum" entry in master dinode */

  		lgfs2_lookupi(sdp->master_dir, "inum", 4, &sdp->md.inum);

  		if (!sdp->md.inum) {

- 			if (!query( _("The gfs2 system inum inode is missing. "

+ 			if (!query(cx, _("The gfs2 system inum inode is missing. "

  				      "Okay to rebuild it? (y/n) "))) {

  				log_err( _("fsck.gfs2 cannot continue without "

  					   "a valid inum file; aborting.\n"));
@@ -831,7 +833,7 @@ 

  		/* In gfs1, the license_di is always 3 blocks after the jindex_di */

  		if ((sdp->sd_license_di.in_addr != sdp->sd_jindex_di.in_addr + 3) ||

  		    (sdp->sd_license_di.in_formal_ino != sdp->sd_jindex_di.in_addr + 3)) {

- 			if (!query( _("The gfs system statfs inode pointer is incorrect. "

+ 			if (!query(cx, _("The gfs system statfs inode pointer is incorrect. "

  				      "Okay to correct? (y/n) "))) {

  				log_err( _("fsck.gfs2 cannot continue without a valid "

  					   "statfs file; aborting.\n"));
@@ -849,7 +851,7 @@ 

  	} else

  		lgfs2_lookupi(sdp->master_dir, "statfs", 6, &sdp->md.statfs);

  	if (!sdp->gfs1 && !sdp->md.statfs) {

- 		if (!query( _("The gfs2 system statfs inode is missing. "

+ 		if (!query(cx, _("The gfs2 system statfs inode is missing. "

  			      "Okay to rebuild it? (y/n) "))) {

  			log_err( _("fsck.gfs2 cannot continue without a valid "

  				   "statfs file; aborting.\n"));
@@ -888,7 +890,7 @@ 

  		/* In gfs1, the quota_di is always 2 blocks after the jindex_di */

  		if ((sdp->sd_quota_di.in_addr != sdp->sd_jindex_di.in_addr + 2) ||

  		    (sdp->sd_quota_di.in_formal_ino != sdp->sd_jindex_di.in_addr + 2)) {

- 			if (!query( _("The gfs system quota inode pointer is incorrect. "

+ 			if (!query(cx, _("The gfs system quota inode pointer is incorrect. "

  				      " Okay to correct? (y/n) "))) {

  				log_err( _("fsck.gfs2 cannot continue without a valid "

  					   "quota file; aborting.\n"));
@@ -906,7 +908,7 @@ 

  	} else

  		lgfs2_lookupi(sdp->master_dir, "quota", 5, &sdp->md.qinode);

  	if (!sdp->gfs1 && !sdp->md.qinode) {

- 		if (!query( _("The gfs2 system quota inode is missing. "

+ 		if (!query(cx, _("The gfs2 system quota inode is missing. "

  			      "Okay to rebuild it? (y/n) "))) {

  			log_crit(_("System quota inode was not "

  				   "rebuilt.  Aborting.\n"));
@@ -928,7 +930,7 @@ 

  	/* Try to lookup the per_node inode.  If it was missing, it is now

  	   safe to rebuild it. */

  	if (!sdp->gfs1)

- 		lookup_per_node(sdp, 1);

+ 		lookup_per_node(cx, 1);

  

  	/*******************************************************************

  	 *******  Now, set boundary fields in the super block  *************
@@ -941,7 +943,7 @@ 

  

  	return 0;

   fail:

- 	empty_super_block(sdp);

+ 	empty_super_block(cx);

  

  	return -1;

  }
@@ -968,8 +970,9 @@ 

   * the per_node directory will have a ".." entry that will lead us to

   * the master dinode if it's been destroyed.

   */

- static void peruse_system_dinode(struct lgfs2_sbd *sdp, struct lgfs2_inode *ip)

+ static void peruse_system_dinode(struct fsck_cx *cx, struct lgfs2_inode *ip)

  {

+ 	struct lgfs2_sbd *sdp = cx->sdp;

  	struct lgfs2_inode *child_ip;

  	struct lgfs2_inum inum;

  	int error;
@@ -1057,8 +1060,9 @@ 

   * peruse_user_dinode - process a user dinode trying to find the root directory

   *

   */

- static void peruse_user_dinode(struct lgfs2_sbd *sdp, struct lgfs2_inode *ip)

+ static void peruse_user_dinode(struct fsck_cx *cx, struct lgfs2_inode *ip)

  {

+ 	struct lgfs2_sbd *sdp = cx->sdp;

  	struct lgfs2_inode *parent_ip;

  	struct lgfs2_inum inum;

  	int error;
@@ -1083,7 +1087,7 @@ 

  		log_warn(_("Found a copy of the root directory in a journal "

  			   "at block: 0x%"PRIx64".\n"),

  			 ip->i_bh->b_blocknr);

- 		if (!query(_("Do you want to replace the root dinode from the copy? (y/n)"))) {

+ 		if (!query(cx, _("Do you want to replace the root dinode from the copy? (y/n)"))) {

  			log_err(_("Damaged root dinode not fixed.\n"));

  			return;

  		}
@@ -1190,8 +1194,9 @@ 

   * peruse_metadata - check a range of blocks for metadata

   * Assumes: device is open.

   */

- static int peruse_metadata(struct lgfs2_sbd *sdp, uint64_t startblock)

+ static int peruse_metadata(struct fsck_cx *cx, uint64_t startblock)

  {

+ 	struct lgfs2_sbd *sdp = cx->sdp;

  	uint64_t blk, max_rg_size;

  	struct lgfs2_buffer_head *bh;

  	struct lgfs2_inode *ip;
@@ -1207,9 +1212,9 @@ 

  		ip = lgfs2_inode_get(sdp, bh);

  		ip->bh_owned = 1; /* lgfs2_inode_put() will free the bh */

  		if (ip->i_flags & GFS2_DIF_SYSTEM)

- 			peruse_system_dinode(sdp, ip);

+ 			peruse_system_dinode(cx, ip);

  		else

- 			peruse_user_dinode(sdp, ip);

+ 			peruse_user_dinode(cx, ip);

  	}

  	return 0;

  }
@@ -1219,8 +1224,9 @@ 

   * Assumes: device is open.

   *          The biggest RG size is 2GB

   */

- static int sb_repair(struct lgfs2_sbd *sdp)

+ static int sb_repair(struct fsck_cx *cx)

  {

+ 	struct lgfs2_sbd *sdp = cx->sdp;

  	uint64_t half;

  	uint32_t known_bsize = 0;

  	int error = 0;
@@ -1252,7 +1258,7 @@ 

  		return -1;

  	}

  	/* Step 2 - look for the sytem dinodes */

- 	error = peruse_metadata(sdp, (GFS2_SB_ADDR * GFS2_BASIC_BLOCK) /

+ 	error = peruse_metadata(cx, (GFS2_SB_ADDR * GFS2_BASIC_BLOCK) /

  				LGFS2_DEFAULT_BSIZE);

  	if (error)

  		return error;
@@ -1281,7 +1287,7 @@ 

  				  "reinitializing it.\n"

  				  "Hopefully everything will later "

  				  "be put into lost+found.\n"));

- 			if (!query(_("Okay to reinitialize the root "

+ 			if (!query(cx, _("Okay to reinitialize the root "

  				     "dinode? (y/n)"))) {

  				log_err(_("The root dinode was not "

  					  "reinitialized; aborting.\n"));
@@ -1296,7 +1302,7 @@ 

  		}

  	}

  	/* Step 3 - Rebuild the lock protocol and file system table name */

- 	if (query(_("Okay to fix the GFS2 superblock? (y/n)"))) {

+ 	if (query(cx, _("Okay to fix the GFS2 superblock? (y/n)"))) {

  		log_info(_("Found system master directory at: 0x%"PRIx64"\n"),

  			 sdp->sd_meta_dir.in_addr);

  		sdp->master_dir = lgfs2_inode_read(sdp, sdp->sd_meta_dir.in_addr);
@@ -1331,8 +1337,9 @@ 

   *

   * Returns: 0 on success, -1 on failure

   */

- static int fill_super_block(struct lgfs2_sbd *sdp)

+ static int fill_super_block(struct fsck_cx *cx)

  {

+ 	struct lgfs2_sbd *sdp = cx->sdp;

  	int ret;

  

  	sync();
@@ -1347,7 +1354,7 @@ 

  	}

  	ret = lgfs2_read_sb(sdp);

  	if (ret < 0) {

- 		if (sb_repair(sdp) != 0)

+ 		if (sb_repair(cx) != 0)

  			return -1; /* unrepairable, so exit */

  		/* Now that we've tried to repair it, re-read it. */

  		ret = lgfs2_read_sb(sdp);
@@ -1411,14 +1418,16 @@ 

  	return 0;

  }

  

- static int reset_journal_seg_size(struct lgfs2_sbd *sdp, unsigned int jsize, unsigned int nsegs)

+ static int reset_journal_seg_size(struct fsck_cx *cx, unsigned int jsize, unsigned int nsegs)

  {

+ 	struct lgfs2_sbd *sdp = cx->sdp;

  	unsigned int seg_size = jsize / (nsegs * sdp->sd_bsize);

+ 

  	if (!seg_size)

  		seg_size = 16; /* The default with 128MB journal and 4K bsize */

  	if (seg_size != sdp->sd_seg_size) {

  		sdp->sd_seg_size = seg_size;

- 		if (!query(_("Computed correct journal segment size to %u."

+ 		if (!query(cx, _("Computed correct journal segment size to %u."

  			     " Reset it? (y/n) "), seg_size)) {

  			log_crit(_("Error: Cannot proceed without a valid journal"

  				   " segment size value.\n"));
@@ -1429,10 +1438,11 @@ 

  	return 0;

  }

  

- static int correct_journal_seg_size(struct lgfs2_sbd *sdp)

+ static int correct_journal_seg_size(struct fsck_cx *cx)

  {

  	int count;

  	struct gfs_jindex *ji_0, *ji_1;

+ 	struct lgfs2_sbd *sdp = cx->sdp;

  	char buf[sizeof(struct gfs_jindex)];

  	unsigned int jsize = LGFS2_DEFAULT_JSIZE * 1024 * 1024;

  
@@ -1446,7 +1456,7 @@ 

  

  	if (sdp->md.journals == 1) {

  		if (sdp->sd_seg_size == 0) {

- 			if (!query(_("The gfs2 journal segment size is 0 and a"

+ 			if (!query(cx, _("The gfs2 journal segment size is 0 and a"

  				     " correct value cannot be determined in a"

  				     " single-journal filesystem.\n"

  				     "Continue with default? (y/n) "))) {
@@ -1473,7 +1483,7 @@ 

  

  	jsize = (be64_to_cpu(ji_1->ji_addr) - be64_to_cpu(ji_0->ji_addr)) * sdp->sd_bsize;

  out:

- 	return reset_journal_seg_size(sdp, jsize, be32_to_cpu(ji_0->ji_nsegment));

+ 	return reset_journal_seg_size(cx, jsize, be32_to_cpu(ji_0->ji_nsegment));

  }

  

  /*
@@ -1482,14 +1492,15 @@ 

   *

   * Returns: 0 on success, -1 on failure

   */

- static int reconstruct_journals(struct lgfs2_sbd *sdp)

+ static int reconstruct_journals(struct fsck_cx *cx)

  {

  	int i, count;

  	struct gfs_jindex *ji;

+ 	struct lgfs2_sbd *sdp = cx->sdp;

  	char buf[sizeof(struct gfs_jindex)];

  

  	/* Ensure that sb_seg_size is valid */

- 	if (correct_journal_seg_size(sdp)) {

+ 	if (correct_journal_seg_size(cx)) {

  		log_crit(_("Failed to set correct journal segment size. Cannot continue\n"));

  		return -1;

  	}
@@ -1514,8 +1525,9 @@ 

  /**

   * init_rindex - read in the rindex file

   */

- static int init_rindex(struct lgfs2_sbd *sdp)

+ static int init_rindex(struct fsck_cx *cx)

  {

+ 	struct lgfs2_sbd *sdp = cx->sdp;

  	struct lgfs2_inode *ip;

  

  	if (sdp->gfs1)
@@ -1526,7 +1538,7 @@ 

  	if (sdp->md.riinode)

  		return 0;

  

- 	if (!query( _("The gfs2 system rindex inode is missing. "

+ 	if (!query(cx, _("The gfs2 system rindex inode is missing. "

  		      "Okay to rebuild it? (y/n) "))) {

  		log_crit(_("Error: Cannot proceed without a valid rindex.\n"));

  		return -1;
@@ -1544,25 +1556,25 @@ 

   * initialize - initialize superblock pointer

   *

   */

- int initialize(struct lgfs2_sbd *sdp, int force_check, int preen,

- 	       int *all_clean)

+ int initialize(struct fsck_cx *cx, int *all_clean)

  {

+ 	struct lgfs2_sbd *sdp = cx->sdp;

  	int clean_journals = 0, open_flag;

  	int err;

  

  	*all_clean = 0;

  

- 	if (opts.no)

+ 	if (cx->opts->no)

  		open_flag = O_RDONLY;

  	else

  		open_flag = O_RDWR | O_EXCL;

  

- 	sdp->device_fd = open(opts.device, open_flag);

+ 	sdp->device_fd = open(cx->opts->device, open_flag);

  	if (sdp->device_fd < 0) {

  		struct mntent *mnt;

  		if (open_flag == O_RDONLY || errno != EBUSY) {

  			log_crit( _("Unable to open device: %s\n"),

- 				  opts.device);

+ 			         cx->opts->device);

  			return FSCK_USAGE;

  		}

  		/* We can't open it EXCL.  It may be already open rw (in which
@@ -1573,7 +1585,7 @@ 

  		   This protects against cases where the file system is LVM

  		   and perhaps mounted on a different node.

  		   Try opening without O_EXCL. */

- 		sdp->device_fd = lgfs2_open_mnt_dev(opts.device, O_RDWR, &mnt);

+ 		sdp->device_fd = lgfs2_open_mnt_dev(cx->opts->device, O_RDWR, &mnt);

  		if (sdp->device_fd < 0)

  			goto mount_fail;

  		/* If the device is mounted, but not mounted RO, fail.  This
@@ -1589,17 +1601,17 @@ 

  	}

  

  	if (lgfs2_get_dev_info(sdp->device_fd, &sdp->dinfo)) {

- 		perror(opts.device);

+ 		perror(cx->opts->device);

  		return FSCK_ERROR;

  	}

  

  	/* read in sb from disk */

- 	err = fill_super_block(sdp);

+ 	err = fill_super_block(cx);

  	if (err != FSCK_OK)

  		return err;

  

  	/* Change lock protocol to be fsck_* instead of lock_* */

- 	if (!opts.no && preen_is_safe(sdp, preen, force_check)) {

+ 	if (!cx->opts->no && preen_is_safe(sdp, cx->opts)) {

  		if (block_mounters(sdp, 1)) {

  			log_err( _("Unable to block other mounters\n"));

  			return FSCK_USAGE;
@@ -1616,7 +1628,7 @@ 

  	     sdp->master_dir->i_mh_type != GFS2_METATYPE_DI ||

  	     !sdp->master_dir->i_size)) {

  		lgfs2_inode_put(&sdp->master_dir);

- 		rebuild_master(sdp);

+ 		rebuild_sysdir(cx);

  		sdp->master_dir = lgfs2_inode_read(sdp, sdp->sd_meta_dir.in_addr);

  		if (sdp->master_dir == NULL) {

  			log_crit(_("Error reading master directory: %s\n"), strerror(errno));
@@ -1628,46 +1640,45 @@ 

  	   need to figure out what's missing from per_node. And we need all

  	   our journals to be there before we can replay them. */

  	if (!sdp->gfs1)

- 		lookup_per_node(sdp, 0);

+ 		lookup_per_node(cx, 0);

  

  	/* We need rindex first in case jindex is missing and needs to read

  	   in the rgrps before rebuilding it. However, note that if the rindex

  	   is damaged, we need the journals to repair it. That's because the

  	   journals likely contain rgrps and bitmaps, which we need to ignore

  	   when we're trying to find the rgrps. */

- 	if (init_rindex(sdp))

+ 	if (init_rindex(cx))

  		return FSCK_ERROR;

  

- 	if (fetch_rgrps(sdp))

+ 	if (fetch_rgrps(cx))

  		return FSCK_ERROR;

  

  	/* We need to read in jindex in order to replay the journals. If

  	   there's an error, we may proceed and let init_system_inodes

  	   try to rebuild it. */

- 	if (init_jindex(sdp, 1) == 0) {

+ 	if (init_jindex(cx, 1) == 0) {

  		/* If GFS, rebuild the journals. If GFS2, replay them. We don't

  		   have the smarts to replay GFS1 journals (neither did

  		   gfs_fsck). */

  		if (sdp->gfs1) {

- 			if (reconstruct_journals(sdp))

+ 			if (reconstruct_journals(cx))

  				return FSCK_ERROR;

- 		} else if (replay_journals(sdp, preen, force_check,

- 					   &clean_journals)) {

- 			if (!opts.no && preen_is_safe(sdp, preen, force_check))

+ 		} else if (replay_journals(cx, &clean_journals)) {

+ 			if (!cx->opts->no && preen_is_safe(sdp, cx->opts))

  				block_mounters(sdp, 0);

  			stack;

  			return FSCK_ERROR;

  		}

  		if (sdp->md.journals == clean_journals)

  			*all_clean = 1;

- 		else if (force_check || !preen)

+ 		else if (cx->opts->force || !cx->opts->preen)

  			log_notice( _("\nJournal recovery complete.\n"));

  

- 		if (!force_check && *all_clean && preen)

+ 		if (!cx->opts->force && *all_clean && cx->opts->preen)

  			return FSCK_OK;

  	}

  

- 	if (init_system_inodes(sdp))

+ 	if (init_system_inodes(cx))

  		return FSCK_ERROR;

  

  	return FSCK_OK;
@@ -1675,13 +1686,15 @@ 

  close_fail:

  	close(sdp->device_fd);

  mount_fail:

- 	log_crit( _("Device %s is busy.\n"), opts.device);

+ 	log_crit( _("Device %s is busy.\n"), cx->opts->device);

  	return FSCK_USAGE;

  }

  

- void destroy(struct lgfs2_sbd *sdp)

+ void destroy(struct fsck_cx *cx)

  {

- 	if (!opts.no) {

+ 	struct lgfs2_sbd *sdp = cx->sdp;

+ 

+ 	if (!cx->opts->no) {

  		if (block_mounters(sdp, 0)) {

  			log_warn( _("Unable to unblock other mounters - manual intervention required\n"));

  			log_warn( _("Use 'gfs2_tool sb <device> proto' to fix\n"));
@@ -1689,7 +1702,7 @@ 

  		log_info( _("Syncing the device.\n"));

  		fsync(sdp->device_fd);

  	}

- 	empty_super_block(sdp);

+ 	empty_super_block(cx);

  	close(sdp->device_fd);

  	if (was_mounted_ro && errors_corrected) {

  		sdp->device_fd = open("/proc/sys/vm/drop_caches", O_WRONLY);

file modified
+7 -7
@@ -12,9 +12,9 @@ 

  #include "fsck.h"

  #define _(String) gettext(String)

  

- struct inode_info *inodetree_find(uint64_t block)

+ struct inode_info *inodetree_find(struct fsck_cx *cx, uint64_t block)

  {

- 	struct osi_node *node = inodetree.osi_node;

+ 	struct osi_node *node = cx->inodetree.osi_node;

  

  	while (node) {

  		struct inode_info *data = (struct inode_info *)node;
@@ -29,9 +29,9 @@ 

  	return NULL;

  }

  

- struct inode_info *inodetree_insert(struct lgfs2_inum no)

+ struct inode_info *inodetree_insert(struct fsck_cx *cx, struct lgfs2_inum no)

  {

- 	struct osi_node **newn = &inodetree.osi_node, *parent = NULL;

+ 	struct osi_node **newn = &cx->inodetree.osi_node, *parent = NULL;

  	struct inode_info *data;

  

  	/* Figure out where to put new node */
@@ -55,13 +55,13 @@ 

  	/* Add new node and rebalance tree. */

  	data->num = no;

  	osi_link_node(&data->node, parent, newn);

- 	osi_insert_color(&data->node, &inodetree);

+ 	osi_insert_color(&data->node, &cx->inodetree);

  

  	return data;

  }

  

- void inodetree_delete(struct inode_info *b)

+ void inodetree_delete(struct fsck_cx *cx, struct inode_info *b)

  {

- 	osi_erase(&b->node, &inodetree);

+ 	osi_erase(&b->node, &cx->inodetree);

  	free(b);

  }

file modified
+5 -3
@@ -1,10 +1,12 @@ 

  #ifndef _INODE_HASH_H

  #define _INODE_HASH_H

  

+ #include "fsck.h"

+ 

  struct inode_info;

  

- extern struct inode_info *inodetree_find(uint64_t block);

- extern struct inode_info *inodetree_insert(struct lgfs2_inum no);

- extern void inodetree_delete(struct inode_info *b);

+ extern struct inode_info *inodetree_find(struct fsck_cx *cx, uint64_t block);

+ extern struct inode_info *inodetree_insert(struct fsck_cx *cx, struct lgfs2_inum no);

+ extern void inodetree_delete(struct fsck_cx *cx, struct inode_info *b);

  

  #endif /* _INODE_HASH_H */

file modified
+14 -14
@@ -15,10 +15,10 @@ 

  #include "link.h"

  #include "util.h"

  

- struct gfs2_bmap nlink1map = { 0 }; /* map of dinodes with nlink == 1 */

- struct gfs2_bmap clink1map = { 0 }; /* map of dinodes w/counted links == 1 */

+ struct bmap nlink1map = { 0 }; /* map of dinodes with nlink == 1 */

+ struct bmap clink1map = { 0 }; /* map of dinodes w/counted links == 1 */

  

- int link1_set(struct gfs2_bmap *bmap, uint64_t bblock, int mark)

+ int link1_set(struct bmap *bmap, uint64_t bblock, int mark)

  {

  	static unsigned char *byte;

  	static uint64_t b;
@@ -35,13 +35,13 @@ 

  	return 0;

  }

  

- int set_di_nlink(struct lgfs2_inode *ip)

+ int set_di_nlink(struct fsck_cx *cx, struct lgfs2_inode *ip)

  {

  	struct inode_info *ii;

  	struct dir_info *di;

  

  	if (is_dir(ip, ip->i_sbd->gfs1)) {

- 		di = dirtree_find(ip->i_num.in_addr);

+ 		di = dirtree_find(cx, ip->i_num.in_addr);

  		if (di == NULL) {

  			log_err(_("Error: directory %"PRIu64" (0x%"PRIx64") is not "

  				  "in the dir_tree (set).\n"),
@@ -58,10 +58,10 @@ 

  	/*log_debug( _("Setting link count to %u for %" PRIu64

  	  " (0x%" PRIx64 ")\n"), count, inode_no, inode_no);*/

  	/* If the list has entries, look for one that matches inode_no */

- 	ii = inodetree_find(ip->i_num.in_addr);

+ 	ii = inodetree_find(cx, ip->i_num.in_addr);

  	if (!ii) {

  		struct lgfs2_inum no = ip->i_num;

- 		ii = inodetree_insert(no);

+ 		ii = inodetree_insert(cx, no);

  	}

  	if (ii)

  		ii->di_nlink = ip->i_nlink;
@@ -77,14 +77,14 @@ 

  		    "for (0x%"PRIx64") via %s\n"),                        \

  		  referenced_from, counted_links, no_addr, why);

  

- int incr_link_count(struct lgfs2_inum no, struct lgfs2_inode *ip, const char *why)

+ int incr_link_count(struct fsck_cx *cx, struct lgfs2_inum no, struct lgfs2_inode *ip, const char *why)

  {

  	struct inode_info *ii = NULL;

  	uint64_t referenced_from = ip ? ip->i_num.in_addr : 0;

  	struct dir_info *di;

  	struct lgfs2_inode *link_ip;

  

- 	di = dirtree_find(no.in_addr);

+ 	di = dirtree_find(cx, no.in_addr);

  	if (di) {

  		if (di->dinode.in_formal_ino != no.in_formal_ino)

  			return INCR_LINK_INO_MISMATCH;
@@ -93,7 +93,7 @@ 

  		whyincr(no.in_addr, why, referenced_from, di->counted_links);

  		return INCR_LINK_GOOD;

  	}

- 	ii = inodetree_find(no.in_addr);

+ 	ii = inodetree_find(cx, no.in_addr);

  	/* If the list has entries, look for one that matches inode_no */

  	if (ii) {

  		if (ii->num.in_formal_ino != no.in_formal_ino)
@@ -122,7 +122,7 @@ 

  	/* If no match was found, it must be a hard link. In theory, it can't

  	   be a duplicate because those were resolved in pass1b. Add a new

  	   inodetree entry and set its counted links to 2 */

- 	ii = inodetree_insert(no);

+ 	ii = inodetree_insert(cx, no);

  	if (!ii) {

  		log_debug(_("Ref: 0x%"PRIx64" Error incrementing link for 0x%"PRIx64"\n"),

  		          referenced_from, no.in_addr);
@@ -148,13 +148,13 @@ 

  	            "for (0x%"PRIx64") via %s\n"),                        \

  		  referenced_from, counted_links, no_addr, why);

  

- int decr_link_count(uint64_t inode_no, uint64_t referenced_from, int gfs1,

+ int decr_link_count(struct fsck_cx *cx, uint64_t inode_no, uint64_t referenced_from, int gfs1,

  		    const char *why)

  {

  	struct inode_info *ii = NULL;

  	struct dir_info *di;

  

- 	di = dirtree_find(inode_no);

+ 	di = dirtree_find(cx, inode_no);

  	if (di) {

  		if (!di->counted_links) {

  			log_debug(_("Dir 0x%"PRIx64"'s link to 0x%"PRIx64" via %s is zero!\n"),
@@ -166,7 +166,7 @@ 

  		return 0;

  	}

  

- 	ii = inodetree_find(inode_no);

+ 	ii = inodetree_find(cx, inode_no);

  	/* If the list has entries, look for one that matches

  	 * inode_no */

  	if (ii) {

file modified
+8 -6
@@ -1,8 +1,10 @@ 

  #ifndef _LINK_H

  #define _LINK_H

  

- extern struct gfs2_bmap nlink1map; /* map of dinodes with nlink == 1 */

- extern struct gfs2_bmap clink1map; /* map of dinodes w/counted links == 1 */

+ #include "fsck.h"

+ 

+ extern struct bmap nlink1map; /* map of dinodes with nlink == 1 */

+ extern struct bmap clink1map; /* map of dinodes w/counted links == 1 */

  

  enum {

  	INCR_LINK_BAD = -1,
@@ -11,10 +13,10 @@ 

  	INCR_LINK_CHECK_ORIG = 2,

  };

  

- int link1_set(struct gfs2_bmap *bmap, uint64_t bblock, int mark);

- int set_di_nlink(struct lgfs2_inode *ip);

- int incr_link_count(struct lgfs2_inum no, struct lgfs2_inode *ip, const char *why);

- int decr_link_count(uint64_t inode_no, uint64_t referenced_from, int gfs1,

+ int link1_set(struct bmap *bmap, uint64_t bblock, int mark);

+ int set_di_nlink(struct fsck_cx *cx, struct lgfs2_inode *ip);

+ int incr_link_count(struct fsck_cx *cx, struct lgfs2_inum no, struct lgfs2_inode *ip, const char *why);

+ int decr_link_count(struct fsck_cx *cx, uint64_t inode_no, uint64_t referenced_from, int gfs1,

  		    const char *why);

  

  #endif /* _LINK_H */

file modified
+19 -18
@@ -18,7 +18,7 @@ 

  #include "metawalk.h"

  #include "util.h"

  

- static void add_dotdot(struct lgfs2_inode *ip)

+ static void add_dotdot(struct fsck_cx *cx, struct lgfs2_inode *ip)

  {

  	struct lgfs2_sbd *sdp = ip->i_sbd;

  	struct dir_info *di;
@@ -30,7 +30,7 @@ 

  

  	/* If there's a pre-existing .. directory entry, we have to

  	   back out the links. */

- 	di = dirtree_find(ip->i_num.in_addr);

+ 	di = dirtree_find(cx, ip->i_num.in_addr);

  	if (di && valid_block(sdp, di->dotdot_parent.in_addr)) {

  		struct lgfs2_inode *dip;

  
@@ -38,11 +38,11 @@ 

  		          ip->i_num.in_addr, di->dotdot_parent.in_addr);

  		dip = fsck_load_inode(sdp, di->dotdot_parent.in_addr);

  		if (dip->i_num.in_formal_ino == di->dotdot_parent.in_formal_ino) {

- 			decr_link_count(di->dotdot_parent.in_addr, ip->i_num.in_addr, sdp->gfs1,

+ 			decr_link_count(cx, di->dotdot_parent.in_addr, ip->i_num.in_addr, sdp->gfs1,

  					_(".. unlinked, moving to lost+found"));

  			if (dip->i_nlink > 0) {

  			  dip->i_nlink--;

- 			  set_di_nlink(dip); /* keep inode tree in sync */

+ 			  set_di_nlink(cx, dip); /* keep inode tree in sync */

  			  log_debug(_("Decrementing its links to %d\n"),

  				    dip->i_nlink);

  			  lgfs2_bmodified(dip->i_bh);
@@ -52,7 +52,7 @@ 

  			  log_debug(_("Its link count is %d!  Changing it to 0.\n"),

  			            dip->i_nlink);

  			  dip->i_nlink = 0;

- 			  set_di_nlink(dip); /* keep inode tree in sync */

+ 			  set_di_nlink(cx, dip); /* keep inode tree in sync */

  			  lgfs2_bmodified(dip->i_bh);

  			}

  		} else {
@@ -90,7 +90,7 @@ 

  	}

  }

  

- void make_sure_lf_exists(struct lgfs2_inode *ip)

+ void make_sure_lf_exists(struct fsck_cx *cx, struct lgfs2_inode *ip)

  {

  	struct dir_info *di;

  	struct lgfs2_sbd *sdp = ip->i_sbd;
@@ -123,7 +123,7 @@ 

  	/* lgfs2_createi will have incremented the di_nlink link count for the root

  	   directory.  We must set the nlink value in the hash table to keep

  	   them in sync so that pass4 can detect and fix any descrepancies. */

- 	set_di_nlink(sdp->md.rooti);

+ 	set_di_nlink(cx, sdp->md.rooti);

  

  	if (sdp->md.rooti->i_entries > root_entries) {

  		struct lgfs2_inum no = lf_dip->i_num;
@@ -133,27 +133,27 @@ 

  		/* FIXME: i'd feel better about this if fs_mkdir returned

  		   whether it created a new directory or just found an old one,

  		   and we used that instead of the bitmap_type to run this */

- 		dirtree_insert(no);

+ 		dirtree_insert(cx, no);

  		/* Set the bitmap AFTER the dirtree insert so that function

  		   check_n_fix_bitmap will realize it's a dinode and adjust

  		   the rgrp counts properly. */

- 		fsck_bitmap_set(ip, lf_dip->i_num.in_addr, _("lost+found dinode"), GFS2_BLKST_DINODE);

+ 		fsck_bitmap_set(cx, ip, lf_dip->i_num.in_addr, _("lost+found dinode"), GFS2_BLKST_DINODE);

  		/* root inode links to lost+found */

  		no.in_addr = sdp->md.rooti->i_num.in_addr;

  		no.in_formal_ino = sdp->md.rooti->i_num.in_formal_ino;

- 		incr_link_count(no, lf_dip, _("root"));

+ 		incr_link_count(cx, no, lf_dip, _("root"));

  		/* lost+found link for '.' from itself */

  		no.in_addr = lf_dip->i_num.in_addr;

  		no.in_formal_ino = lf_dip->i_num.in_formal_ino;

- 		incr_link_count(no, lf_dip, "\".\"");

+ 		incr_link_count(cx, no, lf_dip, "\".\"");

  		/* lost+found link for '..' back to root */

- 		incr_link_count(no, sdp->md.rooti, "\"..\"");

+ 		incr_link_count(cx, no, sdp->md.rooti, "\"..\"");

  		if (sdp->gfs1)

  			lf_dip->i_di_type = GFS_FILE_DIR;

  	}

  	log_info(_("lost+found directory is dinode %"PRIu64" (0x%"PRIx64")\n"),

  	         lf_dip->i_num.in_addr, lf_dip->i_num.in_addr);

- 	di = dirtree_find(lf_dip->i_num.in_addr);

+ 	di = dirtree_find(cx, lf_dip->i_num.in_addr);

  	if (di) {

  		log_info( _("Marking lost+found inode connected\n"));

  		di->checked = 1;
@@ -170,7 +170,8 @@ 

   *

   * Returns: 0 on success, -1 on failure.

   */

- int add_inode_to_lf(struct lgfs2_inode *ip){

+ int add_inode_to_lf(struct fsck_cx *cx, struct lgfs2_inode *ip)

+ {

  	char tmp_name[256];

  	unsigned inode_type;

  	struct lgfs2_sbd *sdp = ip->i_sbd;
@@ -178,7 +179,7 @@ 

  	int err = 0;

  	uint32_t mode;

  

- 	make_sure_lf_exists(ip);

+ 	make_sure_lf_exists(cx, ip);

  	if (ip->i_num.in_addr == lf_dip->i_num.in_addr) {

  		log_err( _("Trying to add lost+found to itself...skipping"));

  		return 0;
@@ -191,7 +192,7 @@ 

  

  	switch (mode) {

  	case S_IFDIR:

- 		add_dotdot(ip);

+ 		add_dotdot(cx, ip);

  		sprintf(tmp_name, "lost_dir_%"PRIu64, ip->i_num.in_addr);

  		inode_type = (sdp->gfs1 ? GFS_FILE_DIR : DT_DIR);

  		break;
@@ -234,11 +235,11 @@ 

  	}

  

  	/* This inode is linked from lost+found */

- 	incr_link_count(no, lf_dip, _("from lost+found"));

+ 	incr_link_count(cx, no, lf_dip, _("from lost+found"));

  	/* If it's a directory, lost+found is back-linked to it via .. */

  	if (mode == S_IFDIR) {

  		no = lf_dip->i_num;

- 		incr_link_count(no, ip, _("to lost+found"));

+ 		incr_link_count(cx, no, ip, _("to lost+found"));

  	}

  	log_notice(_("Added inode #%"PRIu64" (0x%"PRIx64") to lost+found\n"),

  	           ip->i_num.in_addr, ip->i_num.in_addr);

file modified
+2 -2
@@ -3,7 +3,7 @@ 

  

  #include "libgfs2.h"

  

- int add_inode_to_lf(struct lgfs2_inode *ip);

- void make_sure_lf_exists(struct lgfs2_inode *ip);