fsdbutil.c (161558) | fsdbutil.c (207141) |
---|---|
1/* $NetBSD: fsdbutil.c,v 1.2 1995/10/08 23:18:12 thorpej Exp $ */ 2 3/* 4 * Copyright (c) 1995 John T. Kohl 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 16 unchanged lines hidden (view full) --- 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31#ifndef lint 32static const char rcsid[] = | 1/* $NetBSD: fsdbutil.c,v 1.2 1995/10/08 23:18:12 thorpej Exp $ */ 2 3/* 4 * Copyright (c) 1995 John T. Kohl 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 16 unchanged lines hidden (view full) --- 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31#ifndef lint 32static const char rcsid[] = |
33 "$FreeBSD: head/sbin/fsdb/fsdbutil.c 161558 2006-08-23 22:44:00Z ceri $"; | 33 "$FreeBSD: head/sbin/fsdb/fsdbutil.c 207141 2010-04-24 07:05:35Z jeff $"; |
34#endif /* not lint */ 35 36#include <sys/param.h> 37#include <ctype.h> 38#include <err.h> 39#include <grp.h> 40#include <pwd.h> 41#include <stdint.h> --- 5 unchanged lines hidden (view full) --- 47#include <ufs/ffs/fs.h> 48 49#include <sys/ioctl.h> 50 51#include "fsdb.h" 52#include "fsck.h" 53 54static int charsperline(void); | 34#endif /* not lint */ 35 36#include <sys/param.h> 37#include <ctype.h> 38#include <err.h> 39#include <grp.h> 40#include <pwd.h> 41#include <stdint.h> --- 5 unchanged lines hidden (view full) --- 47#include <ufs/ffs/fs.h> 48 49#include <sys/ioctl.h> 50 51#include "fsdb.h" 52#include "fsck.h" 53 54static int charsperline(void); |
55static int printindir(ufs2_daddr_t blk, int level, char *bufp); | 55static void printindir(ufs2_daddr_t blk, int level, char *bufp); |
56static void printblocks(ino_t inum, union dinode *dp); 57 58char ** 59crack(char *line, int *argc) 60{ 61 static char *argv[8]; 62 int i; 63 char *p, *val; --- 157 unchanged lines hidden (view full) --- 221 columns = 80; /* last resort */ 222 return (columns); 223} 224 225 226/* 227 * Recursively print a list of indirect blocks. 228 */ | 56static void printblocks(ino_t inum, union dinode *dp); 57 58char ** 59crack(char *line, int *argc) 60{ 61 static char *argv[8]; 62 int i; 63 char *p, *val; --- 157 unchanged lines hidden (view full) --- 221 columns = 80; /* last resort */ 222 return (columns); 223} 224 225 226/* 227 * Recursively print a list of indirect blocks. 228 */ |
229static int | 229static void |
230printindir(ufs2_daddr_t blk, int level, char *bufp) 231{ 232 struct bufarea buf, *bp; 233 char tempbuf[32]; /* enough to print an ufs2_daddr_t */ 234 int i, j, cpl, charssofar; 235 ufs2_daddr_t blkno; 236 | 230printindir(ufs2_daddr_t blk, int level, char *bufp) 231{ 232 struct bufarea buf, *bp; 233 char tempbuf[32]; /* enough to print an ufs2_daddr_t */ 234 int i, j, cpl, charssofar; 235 ufs2_daddr_t blkno; 236 |
237 if (blk == 0) 238 return; 239 printf("%jd (%d) =>\n", (intmax_t)blk, level); |
|
237 if (level == 0) { 238 /* for the final indirect level, don't use the cache */ 239 bp = &buf; 240 bp->b_un.b_buf = bufp; 241 bp->b_prev = bp->b_next = bp; 242 initbarea(bp); 243 244 getblk(bp, blk, sblock.fs_bsize); 245 } else 246 bp = getdatablk(blk, sblock.fs_bsize); 247 248 cpl = charsperline(); 249 for (i = charssofar = 0; i < NINDIR(&sblock); i++) { 250 if (sblock.fs_magic == FS_UFS1_MAGIC) 251 blkno = bp->b_un.b_indir1[i]; 252 else 253 blkno = bp->b_un.b_indir2[i]; | 240 if (level == 0) { 241 /* for the final indirect level, don't use the cache */ 242 bp = &buf; 243 bp->b_un.b_buf = bufp; 244 bp->b_prev = bp->b_next = bp; 245 initbarea(bp); 246 247 getblk(bp, blk, sblock.fs_bsize); 248 } else 249 bp = getdatablk(blk, sblock.fs_bsize); 250 251 cpl = charsperline(); 252 for (i = charssofar = 0; i < NINDIR(&sblock); i++) { 253 if (sblock.fs_magic == FS_UFS1_MAGIC) 254 blkno = bp->b_un.b_indir1[i]; 255 else 256 blkno = bp->b_un.b_indir2[i]; |
254 if (blkno == 0) { 255 if (level == 0) 256 putchar('\n'); 257 return 0; 258 } | 257 if (blkno == 0) 258 continue; |
259 j = sprintf(tempbuf, "%jd", (intmax_t)blkno); 260 if (level == 0) { 261 charssofar += j; 262 if (charssofar >= cpl - 2) { 263 putchar('\n'); 264 charssofar = j; 265 } 266 } 267 fputs(tempbuf, stdout); 268 if (level == 0) { 269 printf(", "); 270 charssofar += 2; 271 } else { 272 printf(" =>\n"); | 259 j = sprintf(tempbuf, "%jd", (intmax_t)blkno); 260 if (level == 0) { 261 charssofar += j; 262 if (charssofar >= cpl - 2) { 263 putchar('\n'); 264 charssofar = j; 265 } 266 } 267 fputs(tempbuf, stdout); 268 if (level == 0) { 269 printf(", "); 270 charssofar += 2; 271 } else { 272 printf(" =>\n"); |
273 if (printindir(blkno, level - 1, bufp) == 0) 274 return 0; | 273 printindir(blkno, level - 1, bufp); 274 printf("\n"); 275 charssofar = 0; |
275 } 276 } 277 if (level == 0) 278 putchar('\n'); | 276 } 277 } 278 if (level == 0) 279 putchar('\n'); |
279 return 1; | 280 return; |
280} 281 282 283/* 284 * Print the block pointers for one inode. 285 */ 286static void 287printblocks(ino_t inum, union dinode *dp) --- 16 unchanged lines hidden (view full) --- 304 blkno = DIP(dp, di_db[i]); 305 printf("%jd", (intmax_t)blkno); 306 if (--ndb == 0 && (offset = blkoff(&sblock, DIP(dp, di_size))) != 0) { 307 nfrags = numfrags(&sblock, fragroundup(&sblock, offset)); 308 printf(" (%d frag%s)", nfrags, nfrags > 1? "s": ""); 309 } 310 } 311 putchar('\n'); | 281} 282 283 284/* 285 * Print the block pointers for one inode. 286 */ 287static void 288printblocks(ino_t inum, union dinode *dp) --- 16 unchanged lines hidden (view full) --- 305 blkno = DIP(dp, di_db[i]); 306 printf("%jd", (intmax_t)blkno); 307 if (--ndb == 0 && (offset = blkoff(&sblock, DIP(dp, di_size))) != 0) { 308 nfrags = numfrags(&sblock, fragroundup(&sblock, offset)); 309 printf(" (%d frag%s)", nfrags, nfrags > 1? "s": ""); 310 } 311 } 312 putchar('\n'); |
312 if (DIP(dp, di_ib[0]) == 0) | 313 if (ndb == 0) |
313 return; 314 315 bufp = malloc((unsigned int)sblock.fs_bsize); 316 if (bufp == 0) 317 errx(EEXIT, "cannot allocate indirect block buffer"); 318 printf("Indirect blocks:\n"); 319 for (i = 0; i < NIADDR; i++) | 314 return; 315 316 bufp = malloc((unsigned int)sblock.fs_bsize); 317 if (bufp == 0) 318 errx(EEXIT, "cannot allocate indirect block buffer"); 319 printf("Indirect blocks:\n"); 320 for (i = 0; i < NIADDR; i++) |
320 if (printindir(DIP(dp, di_ib[i]), i, bufp) == 0) 321 break; | 321 printindir(DIP(dp, di_ib[i]), i, bufp); |
322 free(bufp); 323} 324 325 326int 327checkactive(void) 328{ 329 if (!curinode) { --- 48 unchanged lines hidden --- | 322 free(bufp); 323} 324 325 326int 327checkactive(void) 328{ 329 if (!curinode) { --- 48 unchanged lines hidden --- |