147082Smckusick /*- 247082Smckusick * Copyright (c) 1980, 1988, 1991 The Regents of the University of California. 347082Smckusick * All rights reserved. 447082Smckusick * 547082Smckusick * %sccs.include.redist.c% 622041Sdist */ 75329Smckusic 822041Sdist #ifndef lint 9*55288Sbostic static char sccsid[] = "@(#)traverse.c 5.20 (Berkeley) 07/16/92"; 1046584Storek #endif /* not lint */ 1122041Sdist 1250499Smckusick #ifdef sunos 1350499Smckusick #include <stdio.h> 1450499Smckusick #include <ctype.h> 1546795Sbostic #include <sys/param.h> 1651605Sbostic #include <ufs/fs.h> 1750499Smckusick #else 1850499Smckusick #include <sys/param.h> 1954070Smckusick #include <ufs/ffs/fs.h> 2054070Smckusick #endif 2153657Smckusick #include <sys/time.h> 2254070Smckusick #include <sys/stat.h> 2351605Sbostic #include <ufs/ufs/dir.h> 2451605Sbostic #include <ufs/ufs/dinode.h> 2546795Sbostic #include <protocols/dumprestore.h> 2646795Sbostic #ifdef __STDC__ 2746795Sbostic #include <unistd.h> 2846795Sbostic #include <string.h> 2946795Sbostic #endif 301426Sroot #include "dump.h" 311426Sroot 3246792Smckusick void dmpindir(); 3346792Smckusick #define HASDUMPEDFILE 0x1 3446792Smckusick #define HASSUBDIRS 0x2 3546584Storek 3646584Storek /* 3746584Storek * This is an estimation of the number of TP_BSIZE blocks in the file. 3846584Storek * It estimates the number of blocks in files with holes by assuming 3946584Storek * that all of the blocks accounted for by di_blocks are data blocks 4046584Storek * (when some of the blocks are usually used for indirect pointers); 4146584Storek * hence the estimate may be high. 4246584Storek */ 4346792Smckusick long 4447058Smckusick blockest(dp) 4547058Smckusick register struct dinode *dp; 4646584Storek { 4746792Smckusick long blkest, sizeest; 4846584Storek 4946584Storek /* 5047058Smckusick * dp->di_size is the size of the file in bytes. 5147058Smckusick * dp->di_blocks stores the number of sectors actually in the file. 5246584Storek * If there are more sectors than the size would indicate, this just 5346584Storek * means that there are indirect blocks in the file or unused 5446584Storek * sectors in the last file block; we can safely ignore these 5546792Smckusick * (blkest = sizeest below). 5646584Storek * If the file is bigger than the number of sectors would indicate, 5746584Storek * then the file has holes in it. In this case we must use the 5846584Storek * block count to estimate the number of data blocks used, but 5946584Storek * we use the actual size for estimating the number of indirect 6046792Smckusick * dump blocks (sizeest vs. blkest in the indirect block 6146792Smckusick * calculation). 6246584Storek */ 6347058Smckusick blkest = howmany(dbtob(dp->di_blocks), TP_BSIZE); 6447058Smckusick sizeest = howmany(dp->di_size, TP_BSIZE); 6546792Smckusick if (blkest > sizeest) 6646792Smckusick blkest = sizeest; 6747058Smckusick if (dp->di_size > sblock->fs_bsize * NDADDR) { 6846584Storek /* calculate the number of indirect blocks on the dump tape */ 6946792Smckusick blkest += 7046792Smckusick howmany(sizeest - NDADDR * sblock->fs_bsize / TP_BSIZE, 7146584Storek TP_NINDIR); 7246584Storek } 7346792Smckusick return (blkest + 1); 7446584Storek } 7546584Storek 7646792Smckusick /* 7746792Smckusick * Dump pass 1. 7846792Smckusick * 7946792Smckusick * Walk the inode list for a filesystem to find all allocated inodes 8046792Smckusick * that have been modified since the previous dump time. Also, find all 8146792Smckusick * the directories in the filesystem. 8246792Smckusick */ 8346792Smckusick mapfiles(maxino, tapesize) 8446792Smckusick ino_t maxino; 8546792Smckusick long *tapesize; 8646584Storek { 8746792Smckusick register int mode; 8846792Smckusick register ino_t ino; 8946792Smckusick register struct dinode *dp; 9046792Smckusick int anydirskipped = 0; 9146584Storek 9246792Smckusick for (ino = 0; ino < maxino; ino++) { 9346792Smckusick dp = getino(ino); 9446792Smckusick if ((mode = (dp->di_mode & IFMT)) == 0) 9546792Smckusick continue; 9646792Smckusick SETINO(ino, usedinomap); 9746792Smckusick if (mode == IFDIR) 9846792Smckusick SETINO(ino, dumpdirmap); 9954070Smckusick if ((dp->di_mtime.ts_sec >= spcl.c_ddate || 10054070Smckusick dp->di_ctime.ts_sec >= spcl.c_ddate) 10154070Smckusick #ifndef sunos 10254070Smckusick && (dp->di_flags & NODUMP) != NODUMP 10354070Smckusick #endif 10454070Smckusick ) { 10546792Smckusick SETINO(ino, dumpinomap); 10646792Smckusick if (mode != IFREG && mode != IFDIR && mode != IFLNK) { 10746792Smckusick *tapesize += 1; 10846792Smckusick continue; 10946792Smckusick } 11046792Smckusick *tapesize += blockest(dp); 11146792Smckusick continue; 11246792Smckusick } 11346792Smckusick if (mode == IFDIR) 11446792Smckusick anydirskipped = 1; 11546792Smckusick } 11646792Smckusick /* 11746792Smckusick * Restore gets very upset if the root is not dumped, 11846792Smckusick * so ensure that it always is dumped. 11946792Smckusick */ 12051374Smckusick SETINO(ROOTINO, dumpinomap); 12146792Smckusick return (anydirskipped); 12246584Storek } 12346584Storek 12446792Smckusick /* 12546792Smckusick * Dump pass 2. 12646792Smckusick * 12746792Smckusick * Scan each directory on the filesystem to see if it has any modified 12846792Smckusick * files in it. If it does, and has not already been added to the dump 12946792Smckusick * list (because it was itself modified), then add it. If a directory 13046792Smckusick * has not been modified itself, contains no modified files and has no 13146792Smckusick * subdirectories, then it can be deleted from the dump list and from 13246792Smckusick * the list of directories. By deleting it from the list of directories, 13346792Smckusick * its parent may now qualify for the same treatment on this or a later 13446792Smckusick * pass using this algorithm. 13546792Smckusick */ 13646792Smckusick mapdirs(maxino, tapesize) 13746792Smckusick ino_t maxino; 13846792Smckusick long *tapesize; 13946792Smckusick { 14046792Smckusick register struct dinode *dp; 14147058Smckusick register int i, dirty; 14225797Smckusick register char *map; 14346792Smckusick register ino_t ino; 14454070Smckusick long filesize; 14546792Smckusick int ret, change = 0; 1461426Sroot 14746792Smckusick for (map = dumpdirmap, ino = 0; ino < maxino; ) { 14846584Storek if ((ino % NBBY) == 0) 14947058Smckusick dirty = *map++; 15046792Smckusick else 15147058Smckusick dirty >>= 1; 1524702Smckusic ino++; 15347058Smckusick if ((dirty & 1) == 0 || TSTINO(ino, dumpinomap)) 15446792Smckusick continue; 15546792Smckusick dp = getino(ino); 15646792Smckusick filesize = dp->di_size; 15746792Smckusick for (ret = 0, i = 0; filesize > 0 && i < NDADDR; i++) { 15846792Smckusick if (dp->di_db[i] != 0) 15946792Smckusick ret |= searchdir(ino, dp->di_db[i], 16046796Smckusick dblksize(sblock, dp, i), filesize); 16146792Smckusick if (ret & HASDUMPEDFILE) 16246792Smckusick filesize = 0; 16346792Smckusick else 16446792Smckusick filesize -= sblock->fs_bsize; 16546792Smckusick } 16646792Smckusick for (i = 0; filesize > 0 && i < NIADDR; i++) { 16746792Smckusick if (dp->di_ib[i] == 0) 16846792Smckusick continue; 16946792Smckusick ret |= dirindir(ino, dp->di_ib[i], i, &filesize); 17046792Smckusick } 17146792Smckusick if (ret & HASDUMPEDFILE) { 17246792Smckusick if (!TSTINO(ino, dumpinomap)) { 17346792Smckusick SETINO(ino, dumpinomap); 17446792Smckusick *tapesize += blockest(dp); 17546792Smckusick } 17646792Smckusick change = 1; 17746792Smckusick continue; 17846792Smckusick } 17946792Smckusick if ((ret & HASSUBDIRS) == 0) { 18046792Smckusick if (!TSTINO(ino, dumpinomap)) { 18146792Smckusick CLRINO(ino, dumpdirmap); 18246792Smckusick change = 1; 18346792Smckusick } 18446792Smckusick } 1851426Sroot } 18646792Smckusick return (change); 1871426Sroot } 1881426Sroot 18946792Smckusick /* 19046792Smckusick * Read indirect blocks, and pass the data blocks to be searched 19146792Smckusick * as directories. Quit as soon as any entry is found that will 19246792Smckusick * require the directory to be dumped. 19346792Smckusick */ 19454070Smckusick dirindir(ino, blkno, ind_level, filesize) 19546792Smckusick ino_t ino; 19646792Smckusick daddr_t blkno; 19754070Smckusick int ind_level; 19854070Smckusick long *filesize; 1991426Sroot { 20046792Smckusick int ret = 0; 20146792Smckusick register int i; 20246792Smckusick daddr_t idblk[MAXNINDIR]; 2031426Sroot 20454070Smckusick bread(fsbtodb(sblock, blkno), (char *)idblk, (int)sblock->fs_bsize); 20554070Smckusick if (ind_level <= 0) { 20646792Smckusick for (i = 0; *filesize > 0 && i < NINDIR(sblock); i++) { 20746792Smckusick blkno = idblk[i]; 20846792Smckusick if (blkno != 0) 20946796Smckusick ret |= searchdir(ino, blkno, sblock->fs_bsize, 21054070Smckusick *filesize); 21146792Smckusick if (ret & HASDUMPEDFILE) 21246792Smckusick *filesize = 0; 21346792Smckusick else 21446792Smckusick *filesize -= sblock->fs_bsize; 2151426Sroot } 21646792Smckusick return (ret); 2175329Smckusic } 21854070Smckusick ind_level--; 21946792Smckusick for (i = 0; *filesize > 0 && i < NINDIR(sblock); i++) { 22046792Smckusick blkno = idblk[i]; 22146792Smckusick if (blkno != 0) 22254070Smckusick ret |= dirindir(ino, blkno, ind_level, filesize); 2235329Smckusic } 22446792Smckusick return (ret); 2251426Sroot } 2261426Sroot 22746792Smckusick /* 22846792Smckusick * Scan a disk block containing directory information looking to see if 22946792Smckusick * any of the entries are on the dump list and to see if the directory 23046792Smckusick * contains any subdirectories. 23146792Smckusick */ 23246796Smckusick searchdir(ino, blkno, size, filesize) 23346792Smckusick ino_t ino; 23446792Smckusick daddr_t blkno; 23554070Smckusick register long size; 23654070Smckusick long filesize; 2375329Smckusic { 23846792Smckusick register struct direct *dp; 23946792Smckusick register long loc; 24046792Smckusick char dblk[MAXBSIZE]; 2415329Smckusic 24254070Smckusick bread(fsbtodb(sblock, blkno), dblk, (int)size); 24346796Smckusick if (filesize < size) 24446796Smckusick size = filesize; 24546792Smckusick for (loc = 0; loc < size; ) { 24646792Smckusick dp = (struct direct *)(dblk + loc); 24746792Smckusick if (dp->d_reclen == 0) { 24846792Smckusick msg("corrupted directory, inumber %d\n", ino); 24946792Smckusick break; 2505329Smckusic } 25146792Smckusick loc += dp->d_reclen; 25246792Smckusick if (dp->d_ino == 0) 25346792Smckusick continue; 25446792Smckusick if (dp->d_name[0] == '.') { 25546792Smckusick if (dp->d_name[1] == '\0') 25646792Smckusick continue; 25746792Smckusick if (dp->d_name[1] == '.' && dp->d_name[2] == '\0') 25846792Smckusick continue; 2595329Smckusic } 26046792Smckusick if (TSTINO(dp->d_ino, dumpinomap)) 26146792Smckusick return (HASDUMPEDFILE); 26246792Smckusick if (TSTINO(dp->d_ino, dumpdirmap)) 26346792Smckusick return (HASSUBDIRS); 2645329Smckusic } 26546792Smckusick return (0); 2665329Smckusic } 2675329Smckusic 26846792Smckusick /* 26946792Smckusick * Dump passes 3 and 4. 27046792Smckusick * 27146792Smckusick * Dump the contents of an inode to tape. 27246792Smckusick */ 27346584Storek void 27447058Smckusick dumpino(dp, ino) 27547058Smckusick register struct dinode *dp; 27646792Smckusick ino_t ino; 27717234Smckusick { 27854596Smckusick int ind_level, cnt; 2794777Smckusic long size; 28054596Smckusick char buf[TP_BSIZE]; 2811426Sroot 28246792Smckusick if (newtape) { 2831426Sroot newtape = 0; 28446792Smckusick dumpmap(dumpinomap, TS_BITS, ino); 2851426Sroot } 28646792Smckusick CLRINO(ino, dumpinomap); 28747058Smckusick spcl.c_dinode = *dp; 2881426Sroot spcl.c_type = TS_INODE; 2891426Sroot spcl.c_count = 0; 29054596Smckusick switch (IFTODT(dp->di_mode)) { 29154596Smckusick 29254596Smckusick case DT_UNKNOWN: 29354596Smckusick /* 29454596Smckusick * Freed inode. 29554596Smckusick */ 29617234Smckusick return; 29754596Smckusick 29854596Smckusick case DT_LNK: 29954596Smckusick /* 30054596Smckusick * Check for short symbolic link. 30154596Smckusick */ 30254596Smckusick if (dp->di_size > 0 && 30354596Smckusick dp->di_size < sblock->fs_maxsymlinklen) { 30454596Smckusick spcl.c_addr[0] = 1; 30554596Smckusick spcl.c_count = 1; 30654596Smckusick writeheader(ino); 30754596Smckusick bcopy((caddr_t)dp->di_shortlink, buf, 30854596Smckusick (u_long)dp->di_size); 30954596Smckusick buf[dp->di_size] = '\0'; 31054596Smckusick writerec(buf, 0); 31154596Smckusick return; 31254596Smckusick } 31354596Smckusick /* fall through */ 31454596Smckusick 31554596Smckusick case DT_DIR: 31654596Smckusick case DT_REG: 31754596Smckusick if (dp->di_size > 0) 31854596Smckusick break; 31954596Smckusick /* fall through */ 32054596Smckusick 32154596Smckusick case DT_FIFO: 32254596Smckusick case DT_SOCK: 32354596Smckusick case DT_CHR: 32454596Smckusick case DT_BLK: 32546792Smckusick writeheader(ino); 3261426Sroot return; 32754596Smckusick 32854596Smckusick default: 32954596Smckusick msg("Warning: undefined file type 0%o\n", dp->di_mode & IFMT); 33054596Smckusick return; 3311426Sroot } 33247058Smckusick if (dp->di_size > NDADDR * sblock->fs_bsize) 33346792Smckusick cnt = NDADDR * sblock->fs_frag; 3344777Smckusic else 33547058Smckusick cnt = howmany(dp->di_size, sblock->fs_fsize); 33647058Smckusick blksout(&dp->di_db[0], cnt, ino); 33747058Smckusick if ((size = dp->di_size - NDADDR * sblock->fs_bsize) <= 0) 3384777Smckusic return; 33954070Smckusick for (ind_level = 0; ind_level < NIADDR; ind_level++) { 34054070Smckusick dmpindir(ino, dp->di_ib[ind_level], ind_level, &size); 3414777Smckusic if (size <= 0) 3424777Smckusic return; 3434777Smckusic } 3441426Sroot } 3451426Sroot 34646792Smckusick /* 34746792Smckusick * Read indirect blocks, and pass the data blocks to be dumped. 34846792Smckusick */ 34946584Storek void 35054070Smckusick dmpindir(ino, blk, ind_level, size) 35146792Smckusick ino_t ino; 3524777Smckusic daddr_t blk; 35354070Smckusick int ind_level; 3544777Smckusic long *size; 3551426Sroot { 3564777Smckusic int i, cnt; 3575329Smckusic daddr_t idblk[MAXNINDIR]; 3581426Sroot 3594777Smckusic if (blk != 0) 36054070Smckusick bread(fsbtodb(sblock, blk), (char *)idblk, (int) sblock->fs_bsize); 3614777Smckusic else 36254070Smckusick bzero((char *)idblk, (int)sblock->fs_bsize); 36354070Smckusick if (ind_level <= 0) { 3645329Smckusic if (*size < NINDIR(sblock) * sblock->fs_bsize) 3655329Smckusic cnt = howmany(*size, sblock->fs_fsize); 3664777Smckusic else 3675329Smckusic cnt = NINDIR(sblock) * sblock->fs_frag; 3685329Smckusic *size -= NINDIR(sblock) * sblock->fs_bsize; 36946792Smckusick blksout(&idblk[0], cnt, ino); 3704777Smckusic return; 3711426Sroot } 37254070Smckusick ind_level--; 3735329Smckusic for (i = 0; i < NINDIR(sblock); i++) { 37454070Smckusick dmpindir(ino, idblk[i], ind_level, size); 3754777Smckusic if (*size <= 0) 3764777Smckusic return; 3774777Smckusic } 3781426Sroot } 3791426Sroot 38046792Smckusick /* 38146792Smckusick * Collect up the data into tape record sized buffers and output them. 38246792Smckusick */ 38346584Storek void 38446792Smckusick blksout(blkp, frags, ino) 3854777Smckusic daddr_t *blkp; 3864777Smckusic int frags; 38746792Smckusick ino_t ino; 3884777Smckusic { 38946584Storek register daddr_t *bp; 3905329Smckusic int i, j, count, blks, tbperdb; 3914777Smckusic 3929403Smckusick blks = howmany(frags * sblock->fs_fsize, TP_BSIZE); 39346584Storek tbperdb = sblock->fs_bsize >> tp_bshift; 3944777Smckusic for (i = 0; i < blks; i += TP_NINDIR) { 3954777Smckusic if (i + TP_NINDIR > blks) 3964777Smckusic count = blks; 3974777Smckusic else 3984777Smckusic count = i + TP_NINDIR; 3994777Smckusic for (j = i; j < count; j++) 4005329Smckusic if (blkp[j / tbperdb] != 0) 4014777Smckusic spcl.c_addr[j - i] = 1; 4024777Smckusic else 4034777Smckusic spcl.c_addr[j - i] = 0; 4044777Smckusic spcl.c_count = count - i; 40546792Smckusick writeheader(ino); 40646584Storek bp = &blkp[i / tbperdb]; 40746584Storek for (j = i; j < count; j += tbperdb, bp++) 40846584Storek if (*bp != 0) 4095329Smckusic if (j + tbperdb <= count) 41054070Smckusick dumpblock(*bp, (int)sblock->fs_bsize); 4114777Smckusic else 41246792Smckusick dumpblock(*bp, (count - j) * TP_BSIZE); 4134777Smckusic spcl.c_type = TS_ADDR; 4144777Smckusic } 4154777Smckusic } 4164777Smckusic 41746792Smckusick /* 41846792Smckusick * Dump a map to the tape. 41946792Smckusick */ 42046584Storek void 42146792Smckusick dumpmap(map, type, ino) 4225329Smckusic char *map; 42346792Smckusick int type; 42446792Smckusick ino_t ino; 4251426Sroot { 42646792Smckusick register int i; 4271426Sroot char *cp; 4281426Sroot 42946792Smckusick spcl.c_type = type; 43046792Smckusick spcl.c_count = howmany(mapsize * sizeof(char), TP_BSIZE); 43146792Smckusick writeheader(ino); 4325329Smckusic for (i = 0, cp = map; i < spcl.c_count; i++, cp += TP_BSIZE) 43354596Smckusick writerec(cp, 0); 4341426Sroot } 4351426Sroot 43646792Smckusick /* 43746792Smckusick * Write a header record to the dump tape. 43846792Smckusick */ 43946584Storek void 44046792Smckusick writeheader(ino) 44146792Smckusick ino_t ino; 4421426Sroot { 44346792Smckusick register long sum, cnt, *lp; 4441426Sroot 4451426Sroot spcl.c_inumber = ino; 4468368Smckusick spcl.c_magic = NFS_MAGIC; 4471426Sroot spcl.c_checksum = 0; 44846792Smckusick lp = (long *)&spcl; 44946792Smckusick sum = 0; 45046792Smckusick cnt = sizeof(union u_spcl) / (4 * sizeof(long)); 45146792Smckusick while (--cnt >= 0) { 45246792Smckusick sum += *lp++; 45346792Smckusick sum += *lp++; 45446792Smckusick sum += *lp++; 45546792Smckusick sum += *lp++; 45624168Smckusick } 45746792Smckusick spcl.c_checksum = CHECKSUM - sum; 45854596Smckusick writerec((char *)&spcl, 1); 4591426Sroot } 4601426Sroot 4614702Smckusic struct dinode * 46246792Smckusick getino(inum) 46346792Smckusick ino_t inum; 4644702Smckusic { 4654702Smckusic static daddr_t minino, maxino; 46646792Smckusick static struct dinode inoblock[MAXINOPB]; 4674702Smckusic 46846792Smckusick curino = inum; 46946792Smckusick if (inum >= minino && inum < maxino) 47046792Smckusick return (&inoblock[inum - minino]); 47154070Smckusick bread(fsbtodb(sblock, itod(sblock, inum)), (char *)inoblock, 47254070Smckusick (int)sblock->fs_bsize); 47346792Smckusick minino = inum - (inum % INOPB(sblock)); 4745329Smckusic maxino = minino + INOPB(sblock); 47546792Smckusick return (&inoblock[inum - minino]); 4764702Smckusic } 4774702Smckusic 47846792Smckusick /* 47946792Smckusick * Read a chunk of data from the disk. 48046792Smckusick * Try to recover from hard errors by reading in sector sized pieces. 48146792Smckusick * Error recovery is attempted at most BREADEMAX times before seeking 48246792Smckusick * consent from the operator to continue. 48346792Smckusick */ 4841426Sroot int breaderrors = 0; 4851426Sroot #define BREADEMAX 32 4861426Sroot 48746584Storek void 48846792Smckusick bread(blkno, buf, size) 48946792Smckusick daddr_t blkno; 49046792Smckusick char *buf; 49146792Smckusick int size; 4921426Sroot { 49346792Smckusick int cnt, i; 49434359Skarels extern int errno; 4951426Sroot 49615095Smckusick loop: 49754070Smckusick if ((int)lseek(diskfd, ((off_t)blkno << dev_bshift), 0) < 0) 4981426Sroot msg("bread: lseek fails\n"); 49946792Smckusick if ((cnt = read(diskfd, buf, size)) == size) 50015095Smckusick return; 50146792Smckusick if (blkno + (size / dev_bsize) > fsbtodb(sblock, sblock->fs_size)) { 50215095Smckusick /* 50315095Smckusick * Trying to read the final fragment. 50415095Smckusick * 50515095Smckusick * NB - dump only works in TP_BSIZE blocks, hence 50630560Smckusick * rounds `dev_bsize' fragments up to TP_BSIZE pieces. 50715095Smckusick * It should be smarter about not actually trying to 50815095Smckusick * read more than it can get, but for the time being 50915095Smckusick * we punt and scale back the read only when it gets 51015095Smckusick * us into trouble. (mkm 9/25/83) 51115095Smckusick */ 51246792Smckusick size -= dev_bsize; 51315095Smckusick goto loop; 5141426Sroot } 51550905Smckusick if (cnt == -1) 51650905Smckusick msg("read error from %s: %s: [block %d]: count=%d\n", 51750905Smckusick disk, strerror(errno), blkno, size); 51850905Smckusick else 51950905Smckusick msg("short read error from %s: [block %d]: count=%d, got=%d\n", 52050905Smckusick disk, blkno, size, cnt); 52146584Storek if (++breaderrors > BREADEMAX) { 52215095Smckusick msg("More than %d block read errors from %d\n", 52315095Smckusick BREADEMAX, disk); 52415095Smckusick broadcast("DUMP IS AILING!\n"); 52515095Smckusick msg("This is an unrecoverable error.\n"); 52615095Smckusick if (!query("Do you want to attempt to continue?")){ 527*55288Sbostic dumpabort(0); 52815095Smckusick /*NOTREACHED*/ 52915095Smckusick } else 53015095Smckusick breaderrors = 0; 53115095Smckusick } 53234359Skarels /* 53334359Skarels * Zero buffer, then try to read each sector of buffer separately. 53434359Skarels */ 53546792Smckusick bzero(buf, size); 53646792Smckusick for (i = 0; i < size; i += dev_bsize, buf += dev_bsize, blkno++) { 53754070Smckusick if ((int)lseek(diskfd, ((off_t)blkno << dev_bshift), 0) < 0) 53834359Skarels msg("bread: lseek2 fails!\n"); 53954070Smckusick if ((cnt = read(diskfd, buf, (int)dev_bsize)) == dev_bsize) 54050905Smckusick continue; 54150905Smckusick if (cnt == -1) { 54250905Smckusick msg("read error from %s: %s: [sector %d]: count=%d\n", 54350905Smckusick disk, strerror(errno), blkno, dev_bsize); 54450905Smckusick continue; 54550905Smckusick } 54650905Smckusick msg("short read error from %s: [sector %d]: count=%d, got=%d\n", 54750905Smckusick disk, blkno, dev_bsize, cnt); 54834359Skarels } 5491426Sroot } 550