X-Git-Url: https://git.wh0rd.org/?p=dump.git;a=blobdiff_plain;f=dump%2Ftraverse.c;h=f762cf4b1c455c985ee2473b9536d1bd3578f7b0;hp=64c32a5b75fc253e0ef4864c58f9c9c1b3fe81e3;hb=70deb804d2211535f1f188a14e8fc867db9c6625;hpb=cca7148b36e60b4671518602ff9a7c2d0c22a7b2 diff --git a/dump/traverse.c b/dump/traverse.c index 64c32a5..f762cf4 100644 --- a/dump/traverse.c +++ b/dump/traverse.c @@ -37,7 +37,7 @@ #ifndef lint static const char rcsid[] = - "$Id: traverse.c,v 1.66 2005/05/02 15:10:46 stelian Exp $"; + "$Id: traverse.c,v 1.74 2011/06/10 13:41:41 stelian Exp $"; #endif /* not lint */ #include @@ -77,6 +77,7 @@ static const char rcsid[] = #include #include "dump.h" +#include "indexer.h" #define HASDUMPEDFILE 0x1 #define HASSUBDIRS 0x2 @@ -99,7 +100,7 @@ static int dirindir __P((dump_ino_t ino, daddr_t blkno, int level, long *size)); static void dmpindir __P((dump_ino_t ino, daddr_t blk, int level, fsizeT *size)); static int searchdir __P((dump_ino_t ino, daddr_t blkno, long size, long filesize)); #endif -static void mapfileino __P((dump_ino_t ino, struct dinode const *dp, long *tapesize, int *dirskipped)); +static void mapfileino __P((dump_ino_t ino, struct dinode const *dp, long long *tapesize, int *dirskipped)); static void dump_xattr __P((dump_ino_t ino, struct dinode *dp)); #ifdef HAVE_EXT2_JOURNAL_INUM @@ -240,7 +241,7 @@ blockest(struct dinode const *dp) #define MSINCE(dp, t) \ ((dp)->di_mtime >= (t)) #define CHANGEDSINCE(dp, t) \ - (CSINCE(dp, t) || MSINCE(dp, t)) + CSINCE(dp, t) /* The NODUMP_FLAG macro tests if a file has the nodump flag. */ #ifdef UF_NODUMP @@ -260,7 +261,7 @@ blockest(struct dinode const *dp) * copy of the given inode, or be NULL (in which case it is fetched.) */ static void -mapfileino(dump_ino_t ino, struct dinode const *dp, long *tapesize, int *dirskipped) +mapfileino(dump_ino_t ino, struct dinode const *dp, long long *tapesize, int *dirskipped) { int mode; @@ -315,7 +316,7 @@ mapfileino(dump_ino_t ino, struct dinode const *dp, long *tapesize, int *dirskip */ #ifdef __linux__ int -mapfiles(UNUSED(dump_ino_t maxino), long *tapesize) +mapfiles(UNUSED(dump_ino_t maxino), long long *tapesize) { ext2_ino_t ino; int anydirskipped = 0; @@ -359,7 +360,7 @@ mapfiles(UNUSED(dump_ino_t maxino), long *tapesize) } #else int -mapfiles(dump_ino_t maxino, long *tapesize) +mapfiles(dump_ino_t maxino, long long *tapesize) { dump_ino_t ino; int anydirskipped = 0; @@ -378,7 +379,7 @@ mapfiles(dump_ino_t maxino, long *tapesize) #ifdef __linux__ int -maponefile(UNUSED(dump_ino_t maxino), long *tapesize, char *directory) +maponefile(UNUSED(dump_ino_t maxino), long long *tapesize, char *directory) { errcode_t retval; ext2_ino_t dir_ino; @@ -426,7 +427,7 @@ maponefile(UNUSED(dump_ino_t maxino), long *tapesize, char *directory) #ifdef __linux__ struct mapfile_context { - long *tapesize; + long long *tapesize; int *anydirskipped; }; @@ -468,7 +469,7 @@ mapfilesindir(struct ext2_dir_entry *dirent, UNUSED(int offset), * the directories in the filesystem. */ int -mapfilesfromdir(UNUSED(dump_ino_t maxino), long *tapesize, char *directory) +mapfilesfromdir(UNUSED(dump_ino_t maxino), long long *tapesize, char *directory) { errcode_t retval; struct mapfile_context mfc; @@ -530,7 +531,7 @@ mapfilesfromdir(UNUSED(dump_ino_t maxino), long *tapesize, char *directory) struct mapdirs_context { int *ret; int nodump; - long *tapesize; + long long *tapesize; }; #endif @@ -547,7 +548,7 @@ struct mapdirs_context { * pass using this algorithm. */ int -mapdirs(dump_ino_t maxino, long *tapesize) +mapdirs(dump_ino_t maxino, long long *tapesize) { struct dinode *dp; int isdir; @@ -574,9 +575,10 @@ mapdirs(dump_ino_t maxino, long *tapesize) * in usedinomap, but we have to go through it anyway * to propagate the nodump attribute. */ + if ((isdir & 1) == 0) + continue; nodump = (TSTINO(ino, usedinomap) == 0); - if ((isdir & 1) == 0 || - (TSTINO(ino, dumpinomap) && nodump == 0)) + if (TSTINO(ino, dumpinomap) && nodump == 0) continue; dp = getino(ino); #ifdef __linux__ @@ -672,7 +674,7 @@ searchdir(struct ext2_dir_entry *dp, UNUSED(int offset), { struct mapdirs_context *mdc; int *ret; - long *tapesize; + long long *tapesize; struct dinode *ip; mdc = (struct mapdirs_context *)private; @@ -777,8 +779,6 @@ dumponeblock(UNUSED(ext2_filsys fs), blk_t *blocknr, e2_blkcnt_t blockcnt, struct block_context *p; e2_blkcnt_t i; - if (blockcnt < NDADDR) - return 0; p = (struct block_context *)private; for (i = p->next_block; i < blockcnt; i++) { p->buf[p->cnt++] = 0; @@ -835,6 +835,8 @@ dump_xattr(dump_ino_t ino, struct dinode *dp) { spcl.c_flags |= DR_EXTATTRIBUTES; spcl.c_extattributes = EXT_XATTR; spcl.c_count = howmany(EXT2_INODE_SIZE(fs->super), TP_BSIZE); + for (i = 0; i < spcl.c_count; i++) + spcl.c_addr[i] = 1; writeheader(ino); for (i = 0, cp = xattr; i < spcl.c_count; i++, cp += TP_BSIZE) writerec(cp, 0); @@ -867,8 +869,9 @@ dump_xattr(dump_ino_t ino, struct dinode *dp) { void dumpino(struct dinode *dp, dump_ino_t ino, int metaonly) { - unsigned long cnt; - fsizeT size, remaining; + //unsigned long cnt; + //fsizeT size; + fsizeT remaining; char buf[TP_BSIZE]; struct new_bsd_inode nbi; int i; @@ -912,6 +915,8 @@ dumpino(struct dinode *dp, dump_ino_t ino, int metaonly) spcl.c_type = TS_INODE; spcl.c_count = 0; + indexer->addInode(dp, ino, metaonly); + if (metaonly && (dp->di_mode & S_IFMT)) { spcl.c_flags |= DR_METAONLY; spcl.c_count = 0; @@ -986,27 +991,14 @@ dumpino(struct dinode *dp, dump_ino_t ino, int metaonly) msg("Warning: undefined file type 0%o\n", dp->di_mode & IFMT); return; } - if (i_size > (u_quad_t)NDADDR * sblock->fs_bsize) -#ifdef __linux__ - cnt = NDADDR * EXT2_FRAGS_PER_BLOCK(fs->super); -#else - cnt = NDADDR * sblock->fs_frag; -#endif - else - cnt = howmany(i_size, sblock->fs_fsize); - blksout(&dp->di_db[0], cnt, ino); - if ((quad_t) (size = i_size - NDADDR * sblock->fs_bsize) <= 0) { - dump_xattr(ino, dp); - return; - } #ifdef __linux__ bc.max = NINDIR(sblock) * EXT2_FRAGS_PER_BLOCK(fs->super); bc.buf = (int *)malloc (bc.max * sizeof (int)); bc.cnt = 0; bc.ino = ino; - bc.next_block = NDADDR; + bc.next_block = 0; - ext2fs_block_iterate2(fs, (ext2_ino_t)ino, 0, NULL, dumponeblock, (void *)&bc); + ext2fs_block_iterate2(fs, (ext2_ino_t)ino, BLOCK_FLAG_DATA_ONLY, NULL, dumponeblock, (void *)&bc); /* deal with holes at the end of the inode */ if (i_size > ((u_quad_t)bc.next_block) * sblock->fs_fsize) { remaining = i_size - ((u_quad_t)bc.next_block) * sblock->fs_fsize; @@ -1024,6 +1016,15 @@ dumpino(struct dinode *dp, dump_ino_t ino, int metaonly) free(bc.buf); dump_xattr(ino, dp); #else + if (i_size > (u_quad_t)NDADDR * sblock->fs_bsize) + cnt = NDADDR * sblock->fs_frag; + else + cnt = howmany(i_size, sblock->fs_fsize); + blksout(&dp->di_db[0], cnt, ino); + if ((quad_t) (size = i_size - NDADDR * sblock->fs_bsize) <= 0) { + dump_xattr(ino, dp); + return; + } for (ind_level = 0; ind_level < NIADDR; ind_level++) { dmpindir(ino, dp->di_ib[ind_level], ind_level, &size); if (size <= 0) @@ -1103,6 +1104,8 @@ convert_dir(struct ext2_dir_entry *dirent, UNUSED(int offset), p->prev_offset = p->offset; p->offset += reclen; + //indexer->addDirEntry(dirent, offset, blocksize, buf, private); + return 0; } @@ -1206,6 +1209,8 @@ dumpdirino(struct dinode *dp, dump_ino_t ino) spcl.c_type = TS_ADDR; } + indexer->addInode(dp, ino, 0); + (void)free(cdc.buf); dump_xattr(ino, dp); } @@ -1351,6 +1356,7 @@ mkchecksum(union u_spcl *tmpspcl) void writeheader(dump_ino_t ino) { + char *state; /* need to have some place to put this! */ spcl.c_inumber = ino; spcl.c_magic = NFS_MAGIC; mkchecksum((union u_spcl *)&spcl);