X-Git-Url: https://git.wh0rd.org/?p=dump.git;a=blobdiff_plain;f=dump%2Ftraverse.c;h=bd16f9b7a696de34a607213a7e898b92b8973c67;hp=147717ad37095eb80a40032550f92f39ec80ac6e;hb=9ca70cf6a082bb146eaaa0b09361643feca38875;hpb=5d2a3d246d400d45dfd4c49ddb588c69fb60873d diff --git a/dump/traverse.c b/dump/traverse.c index 147717a..bd16f9b 100644 --- a/dump/traverse.c +++ b/dump/traverse.c @@ -41,7 +41,7 @@ #ifndef lint static const char rcsid[] = - "$Id: traverse.c,v 1.42 2002/01/25 15:08:59 stelian Exp $"; + "$Id: traverse.c,v 1.48 2002/07/17 10:18:52 stelian Exp $"; #endif /* not lint */ #include @@ -51,6 +51,7 @@ static const char rcsid[] = #include #include #endif +#include #include #include @@ -143,15 +144,14 @@ int dump_fs_open(const char *disk, ext2_filsys *fs) dump_ino_t journal_ino = ext2_journal_ino(es); if (es->s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV){ - fprintf(stderr, "This an journal, not a filesystem!\n"); + msg("This is a journal, not a filesystem!\n"); retval = EXT2_ET_UNSUPP_FEATURE; ext2fs_close(*fs); } else if ((retval = es->s_feature_incompat & ~(EXT2_LIB_FEATURE_INCOMPAT_SUPP | EXT3_FEATURE_INCOMPAT_RECOVER))) { - fprintf(stderr, - "Unsupported feature(s) 0x%x in filesystem\n", + msg("Unsupported feature(s) 0x%x in filesystem\n", retval); retval = EXT2_ET_UNSUPP_FEATURE; ext2fs_close(*fs); @@ -218,8 +218,12 @@ blockest(struct dinode const *dp) } /* Auxiliary macro to pick up files changed since previous dump. */ +#define CSINCE(dp, t) \ + ((dp)->di_ctime >= (t)) +#define MSINCE(dp, t) \ + ((dp)->di_mtime >= (t)) #define CHANGEDSINCE(dp, t) \ - ((dp)->di_mtime >= (t) || (dp)->di_ctime >= (t)) + (CSINCE(dp, t) || MSINCE(dp, t)) /* The NODUMP_FLAG macro tests if a file has the nodump flag. */ #ifdef UF_NODUMP @@ -267,6 +271,8 @@ mapfileino(dump_ino_t ino, struct dinode const *dp, long *tapesize, int *dirskip SETINO(ino, dumpdirmap); if (WANTTODUMP(dp, ino)) { SETINO(ino, dumpinomap); + if (!MSINCE(dp, spcl.c_ddate)) + SETINO(ino, metainomap); if (mode != IFREG && mode != IFDIR && mode != IFLNK) *tapesize += 1; else @@ -663,12 +669,13 @@ searchdir(struct ext2_dir_entry *dp, int offset, int blocksize, char *buf, void ip = getino(dp->inode); if (TSTINO(dp->inode, dumpinomap)) { CLRINO(dp->inode, dumpinomap); - CLRINO(dp->inode, usedinomap); *tapesize -= blockest(ip); } - /* Add dir back to the dir map, to propagate nodump */ + /* Add dir back to the dir map and remove from + * usedinomap to propagate nodump */ if ((ip->di_mode & IFMT) == IFDIR) { SETINO(dp->inode, dumpdirmap); + CLRINO(dp->inode, usedinomap); *ret |= HASSUBDIRS; } } else { @@ -774,19 +781,24 @@ dumponeblock(ext2_filsys fs, blk_t *blocknr, e2_blkcnt_t blockcnt, * Dump the contents of an inode to tape. */ void -dumpino(struct dinode *dp, dump_ino_t ino) +dumpino(struct dinode *dp, dump_ino_t ino, int metaonly) { unsigned long cnt; fsizeT size, remaining; char buf[TP_BSIZE]; - struct old_bsd_inode obi; + struct new_bsd_inode nbi; int i; #ifdef __linux__ struct block_context bc; #else int ind_level; #endif - u_quad_t i_size = dp->di_size + ((u_quad_t) dp->di_size_high << 32); + u_quad_t i_size; + + if (metaonly) + i_size = 0; + else + i_size = dp->di_size + ((u_quad_t) dp->di_size_high << 32); if (newtape) { newtape = 0; @@ -794,27 +806,38 @@ dumpino(struct dinode *dp, dump_ino_t ino) } CLRINO(ino, dumpinomap); #ifdef __linux__ - memset(&obi, 0, sizeof(obi)); - obi.di_mode = dp->di_mode; - obi.di_uid = dp->di_uid; - obi.di_gid = dp->di_gid; - obi.di_qsize.v = i_size; - obi.di_atime = dp->di_atime; - obi.di_mtime = dp->di_mtime; - obi.di_ctime = dp->di_ctime; - obi.di_nlink = dp->di_nlink; - obi.di_blocks = dp->di_blocks; - obi.di_flags = dp->di_flags; - obi.di_gen = dp->di_gen; - memmove(&obi.di_db, &dp->di_db, (NDADDR + NIADDR) * sizeof(daddr_t)); + memset(&nbi, 0, sizeof(nbi)); + nbi.di_mode = dp->di_mode; + nbi.di_nlink = dp->di_nlink; + nbi.di_ouid = dp->di_uid; + nbi.di_ogid = dp->di_gid; + nbi.di_size = i_size; + nbi.di_atime.tv_sec = dp->di_atime; + nbi.di_mtime.tv_sec = dp->di_mtime; + nbi.di_ctime.tv_sec = dp->di_ctime; + memmove(&nbi.di_db, &dp->di_db, (NDADDR + NIADDR) * sizeof(daddr_t)); + nbi.di_flags = dp->di_flags; + nbi.di_blocks = dp->di_blocks; + nbi.di_gen = dp->di_gen; + nbi.di_uid = (((int32_t)dp->di_uidhigh) << 16) | dp->di_uid; + nbi.di_gid = (((int32_t)dp->di_gidhigh) << 16) | dp->di_gid; if (dp->di_file_acl) warn("ACLs in inode #%ld won't be dumped", (long)ino); - memmove(&spcl.c_dinode, &obi, sizeof(obi)); + memmove(&spcl.c_dinode, &nbi, sizeof(nbi)); #else /* __linux__ */ spcl.c_dinode = *dp; #endif /* __linux__ */ spcl.c_type = TS_INODE; spcl.c_count = 0; + + if (metaonly && (dp->di_mode & S_IFMT)) { + spcl.c_flags |= DR_METAONLY; + spcl.c_count = 0; + writeheader(ino); + spcl.c_flags &= ~DR_METAONLY; + return; + } + switch (dp->di_mode & S_IFMT) { case 0: @@ -940,19 +963,19 @@ static int convert_dir(struct ext2_dir_entry *dirent, int offset, int blocksize, char *buf, void *private) { struct convert_dir_context *p; - struct olddirect *dp; + struct direct *dp; int reclen; p = (struct convert_dir_context *)private; reclen = EXT2_DIR_REC_LEN((dirent->name_len & 0xFF) + 1); if (((p->offset + reclen - 1) / p->bs) != (p->offset / p->bs)) { - dp = (struct olddirect *)(p->buf + p->prev_offset); + dp = (struct direct *)(p->buf + p->prev_offset); dp->d_reclen += p->bs - (p->offset % p->bs); p->offset += p->bs - (p->offset % p->bs); } - dp = (struct olddirect *)(p->buf + p->offset); + dp = (struct direct *)(p->buf + p->offset); dp->d_ino = dirent->inode; dp->d_reclen = reclen; dp->d_namlen = dirent->name_len & 0xFF; @@ -974,7 +997,7 @@ dumpdirino(struct dinode *dp, dump_ino_t ino) { fsizeT size; char buf[TP_BSIZE]; - struct old_bsd_inode obi; + struct new_bsd_inode nbi; struct convert_dir_context cdc; errcode_t retval; struct ext2_dir_entry *de; @@ -1014,22 +1037,24 @@ dumpdirino(struct dinode *dp, dump_ino_t ino) dir_size = cdc.offset; #ifdef __linux__ - memset(&obi, 0, sizeof(obi)); - obi.di_mode = dp->di_mode; - obi.di_uid = dp->di_uid; - obi.di_gid = dp->di_gid; - obi.di_qsize.v = dir_size; /* (u_quad_t)dp->di_size; */ - obi.di_atime = dp->di_atime; - obi.di_mtime = dp->di_mtime; - obi.di_ctime = dp->di_ctime; - obi.di_nlink = dp->di_nlink; - obi.di_blocks = dp->di_blocks; - obi.di_flags = dp->di_flags; - obi.di_gen = dp->di_gen; - memmove(&obi.di_db, &dp->di_db, (NDADDR + NIADDR) * sizeof(daddr_t)); + memset(&nbi, 0, sizeof(nbi)); + nbi.di_mode = dp->di_mode; + nbi.di_nlink = dp->di_nlink; + nbi.di_ouid = dp->di_uid; + nbi.di_ogid = dp->di_gid; + nbi.di_size = dir_size; /* (u_quad_t)dp->di_size; */ + nbi.di_atime.tv_sec = dp->di_atime; + nbi.di_mtime.tv_sec = dp->di_mtime; + nbi.di_ctime.tv_sec = dp->di_ctime; + memmove(&nbi.di_db, &dp->di_db, (NDADDR + NIADDR) * sizeof(daddr_t)); + nbi.di_flags = dp->di_flags; + nbi.di_blocks = dp->di_blocks; + nbi.di_gen = dp->di_gen; + nbi.di_uid = (((int32_t)dp->di_uidhigh) << 16) | dp->di_uid; + nbi.di_gid = (((int32_t)dp->di_gidhigh) << 16) | dp->di_gid; if (dp->di_file_acl) warn("ACLs in inode #%ld won't be dumped", (long)ino); - memmove(&spcl.c_dinode, &obi, sizeof(obi)); + memmove(&spcl.c_dinode, &nbi, sizeof(nbi)); #else /* __linux__ */ spcl.c_dinode = *dp; #endif /* __linux__ */ @@ -1258,7 +1283,6 @@ void bread(daddr_t blkno, char *buf, int size) { int cnt, i; - extern int errno; loop: #ifdef __linux__ @@ -1286,11 +1310,12 @@ loop: goto loop; } if (cnt == -1) - msg("read error from %s: %s: [block %d]: count=%d\n", - disk, strerror(errno), blkno, size); + msg("read error from %s: %s: [block %d, ext2blk %d]: count=%d\n", + disk, strerror(errno), blkno, + dbtofsb(sblock, blkno), size); else - msg("short read error from %s: [block %d]: count=%d, got=%d\n", - disk, blkno, size, cnt); + msg("short read error from %s: [block %d, ext2blk %d]: count=%d, got=%d\n", + disk, blkno, dbtofsb(sblock, blkno), size, cnt); if (++breaderrors > breademax) { msg("More than %d block read errors from %d\n", breademax, disk); @@ -1318,11 +1343,12 @@ loop: if ((cnt = read(diskfd, buf, (int)dev_bsize)) == dev_bsize) continue; if (cnt == -1) { - msg("read error from %s: %s: [sector %d]: count=%d\n", - disk, strerror(errno), blkno, dev_bsize); + msg("read error from %s: %s: [sector %d, ext2blk %d]: count=%d\n", + disk, strerror(errno), blkno, + dbtofsb(sblock, blkno), dev_bsize); continue; } - msg("short read error from %s: [sector %d]: count=%d, got=%d\n", - disk, blkno, dev_bsize, cnt); + msg("short read error from %s: [sector %d, ext2blk %d]: count=%d, got=%d\n", + disk, blkno, dbtofsb(sblock, blkno), dev_bsize, cnt); } }