suj.c (256281) | suj.c (260178) |
---|---|
1/*- 2 * Copyright 2009, 2010 Jeffrey W. Roberson <jeff@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright 2009, 2010 Jeffrey W. Roberson <jeff@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: stable/10/sbin/fsck_ffs/suj.c 248658 2013-03-23 20:00:02Z mckusick $"); | 28__FBSDID("$FreeBSD: stable/10/sbin/fsck_ffs/suj.c 260178 2014-01-02 01:44:14Z scottl $"); |
29 30#include <sys/param.h> 31#include <sys/disk.h> 32#include <sys/disklabel.h> 33#include <sys/mount.h> 34#include <sys/stat.h> 35 36#include <ufs/ufs/ufsmount.h> --- 83 unchanged lines hidden (view full) --- 120 struct suj_ino *sc_lastino; 121 struct suj_blk *sc_lastblk; 122 uint8_t *sc_cgbuf; 123 struct cg *sc_cgp; 124 int sc_dirty; 125 int sc_cgx; 126}; 127 | 29 30#include <sys/param.h> 31#include <sys/disk.h> 32#include <sys/disklabel.h> 33#include <sys/mount.h> 34#include <sys/stat.h> 35 36#include <ufs/ufs/ufsmount.h> --- 83 unchanged lines hidden (view full) --- 120 struct suj_ino *sc_lastino; 121 struct suj_blk *sc_lastblk; 122 uint8_t *sc_cgbuf; 123 struct cg *sc_cgp; 124 int sc_dirty; 125 int sc_cgx; 126}; 127 |
128LIST_HEAD(cghd, suj_cg) cghash[SUJ_HASHSIZE]; 129LIST_HEAD(dblkhd, data_blk) dbhash[SUJ_HASHSIZE]; 130struct suj_cg *lastcg; 131struct data_blk *lastblk; | 128static LIST_HEAD(cghd, suj_cg) cghash[SUJ_HASHSIZE]; 129static LIST_HEAD(dblkhd, data_blk) dbhash[SUJ_HASHSIZE]; 130static struct suj_cg *lastcg; 131static struct data_blk *lastblk; |
132 | 132 |
133TAILQ_HEAD(seghd, suj_seg) allsegs; 134uint64_t oldseq; | 133static TAILQ_HEAD(seghd, suj_seg) allsegs; 134static uint64_t oldseq; |
135static struct uufsd *disk = NULL; 136static struct fs *fs = NULL; | 135static struct uufsd *disk = NULL; 136static struct fs *fs = NULL; |
137ino_t sujino; | 137static ino_t sujino; |
138 139/* 140 * Summary statistics. 141 */ | 138 139/* 140 * Summary statistics. 141 */ |
142uint64_t freefrags; 143uint64_t freeblocks; 144uint64_t freeinos; 145uint64_t freedir; 146uint64_t jbytes; 147uint64_t jrecs; | 142static uint64_t freefrags; 143static uint64_t freeblocks; 144static uint64_t freeinos; 145static uint64_t freedir; 146static uint64_t jbytes; 147static uint64_t jrecs; |
148 149static jmp_buf jmpbuf; 150 151typedef void (*ino_visitor)(ino_t, ufs_lbn_t, ufs2_daddr_t, int); 152static void err_suj(const char *, ...) __dead2; 153static void ino_trunc(ino_t, off_t); 154static void ino_decr(ino_t); 155static void ino_adjust(struct suj_ino *); 156static void ino_build(struct suj_ino *); 157static int blk_isfree(ufs2_daddr_t); | 148 149static jmp_buf jmpbuf; 150 151typedef void (*ino_visitor)(ino_t, ufs_lbn_t, ufs2_daddr_t, int); 152static void err_suj(const char *, ...) __dead2; 153static void ino_trunc(ino_t, off_t); 154static void ino_decr(ino_t); 155static void ino_adjust(struct suj_ino *); 156static void ino_build(struct suj_ino *); 157static int blk_isfree(ufs2_daddr_t); |
158static void initsuj(void); |
|
158 159static void * 160errmalloc(size_t n) 161{ 162 void *a; 163 164 a = Malloc(n); 165 if (a == NULL) --- 2242 unchanged lines hidden (view full) --- 2408 int jb_head; /* Allocator head. */ 2409 int jb_off; /* Allocator extent offset. */ 2410}; 2411struct jextent { 2412 ufs2_daddr_t je_daddr; /* Disk block address. */ 2413 int je_blocks; /* Disk block count. */ 2414}; 2415 | 159 160static void * 161errmalloc(size_t n) 162{ 163 void *a; 164 165 a = Malloc(n); 166 if (a == NULL) --- 2242 unchanged lines hidden (view full) --- 2409 int jb_head; /* Allocator head. */ 2410 int jb_off; /* Allocator extent offset. */ 2411}; 2412struct jextent { 2413 ufs2_daddr_t je_daddr; /* Disk block address. */ 2414 int je_blocks; /* Disk block count. */ 2415}; 2416 |
2416struct jblocks *suj_jblocks; | 2417static struct jblocks *suj_jblocks; |
2417 2418static struct jblocks * 2419jblocks_create(void) 2420{ 2421 struct jblocks *jblocks; 2422 int size; 2423 2424 jblocks = errmalloc(sizeof(*jblocks)); --- 243 unchanged lines hidden (view full) --- 2668{ 2669 union dinode *jip; 2670 union dinode *ip; 2671 uint64_t blocks; 2672 int retval; 2673 struct suj_seg *seg; 2674 struct suj_seg *segn; 2675 | 2418 2419static struct jblocks * 2420jblocks_create(void) 2421{ 2422 struct jblocks *jblocks; 2423 int size; 2424 2425 jblocks = errmalloc(sizeof(*jblocks)); --- 243 unchanged lines hidden (view full) --- 2669{ 2670 union dinode *jip; 2671 union dinode *ip; 2672 uint64_t blocks; 2673 int retval; 2674 struct suj_seg *seg; 2675 struct suj_seg *segn; 2676 |
2677 initsuj(); |
|
2676 opendisk(filesys); | 2678 opendisk(filesys); |
2677 TAILQ_INIT(&allsegs); | |
2678 2679 /* 2680 * Set an exit point when SUJ check failed 2681 */ 2682 retval = setjmp(jmpbuf); 2683 if (retval != 0) { 2684 pwarn("UNEXPECTED SU+J INCONSISTENCY\n"); 2685 TAILQ_FOREACH_SAFE(seg, &allsegs, ss_next, segn) { --- 72 unchanged lines hidden (view full) --- 2758 printf("** %jd journal records in %jd bytes for %.2f%% utilization\n", 2759 jrecs, jbytes, ((float)jrecs / (float)(jbytes / JREC_SIZE)) * 100); 2760 printf("** Freed %jd inodes (%jd dirs) %jd blocks, and %jd frags.\n", 2761 freeinos, freedir, freeblocks, freefrags); 2762 } 2763 2764 return (0); 2765} | 2679 2680 /* 2681 * Set an exit point when SUJ check failed 2682 */ 2683 retval = setjmp(jmpbuf); 2684 if (retval != 0) { 2685 pwarn("UNEXPECTED SU+J INCONSISTENCY\n"); 2686 TAILQ_FOREACH_SAFE(seg, &allsegs, ss_next, segn) { --- 72 unchanged lines hidden (view full) --- 2759 printf("** %jd journal records in %jd bytes for %.2f%% utilization\n", 2760 jrecs, jbytes, ((float)jrecs / (float)(jbytes / JREC_SIZE)) * 100); 2761 printf("** Freed %jd inodes (%jd dirs) %jd blocks, and %jd frags.\n", 2762 freeinos, freedir, freeblocks, freefrags); 2763 } 2764 2765 return (0); 2766} |
2767 2768static void 2769initsuj(void) 2770{ 2771 int i; 2772 2773 for (i = 0; i < SUJ_HASHSIZE; i++) { 2774 LIST_INIT(&cghash[i]); 2775 LIST_INIT(&dbhash[i]); 2776 } 2777 lastcg = NULL; 2778 lastblk = NULL; 2779 TAILQ_INIT(&allsegs); 2780 oldseq = 0; 2781 disk = NULL; 2782 fs = NULL; 2783 sujino = 0; 2784 freefrags = 0; 2785 freeblocks = 0; 2786 freeinos = 0; 2787 freedir = 0; 2788 jbytes = 0; 2789 jrecs = 0; 2790 suj_jblocks = NULL; 2791} |
|