]>
git.wh0rd.org - dump.git/blob - dump/traverse.c
2 * Ported to Linux's Second Extended File System as part of the
3 * dump and restore backup suit
4 * Remy Card <card@Linux.EU.Org>, 1994, 1995, 1996
9 * Copyright (c) 1980, 1988, 1991, 1993
10 * The Regents of the University of California. All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 static char sccsid
[] = "@(#)traverse.c 8.7 (Berkeley) 6/15/95";
45 #include <sys/param.h>
49 #include <linux/ext2_fs.h>
50 #include <bsdcompat.h>
55 #include <sys/vnode.h>
58 #include <ufs/fsdir.h>
59 #include <ufs/inode.h>
61 #include <ufs/ufs/dir.h>
62 #include <ufs/ufs/dinode.h>
63 #include <ufs/ffs/fs.h>
65 #endif /* __linux__ */
67 #include <protocols/dumprestore.h>
77 #include <ext2fs/ext2fs.h>
82 #define HASDUMPEDFILE 0x1
83 #define HASSUBDIRS 0x2
86 typedef quad_t fsizeT
;
92 static int dirindir
__P((ino_t ino
, daddr_t blkno
, int level
, long *size
));
94 static void dmpindir
__P((ino_t ino
, daddr_t blk
, int level
, fsizeT
*size
));
96 static int searchdir
__P((struct ext2_dir_entry
*dp
, int offset
,
97 int blocksize
, char *buf
, void *private));
99 static int searchdir
__P((ino_t ino
, daddr_t blkno
, long size
, long filesize
));
103 * This is an estimation of the number of TP_BSIZE blocks in the file.
104 * It estimates the number of blocks in files with holes by assuming
105 * that all of the blocks accounted for by di_blocks are data blocks
106 * (when some of the blocks are usually used for indirect pointers);
107 * hence the estimate may be high.
111 register struct dinode
*dp
;
113 long blkest
, sizeest
;
116 * dp->di_size is the size of the file in bytes.
117 * dp->di_blocks stores the number of sectors actually in the file.
118 * If there are more sectors than the size would indicate, this just
119 * means that there are indirect blocks in the file or unused
120 * sectors in the last file block; we can safely ignore these
121 * (blkest = sizeest below).
122 * If the file is bigger than the number of sectors would indicate,
123 * then the file has holes in it. In this case we must use the
124 * block count to estimate the number of data blocks used, but
125 * we use the actual size for estimating the number of indirect
126 * dump blocks (sizeest vs. blkest in the indirect block
129 blkest
= howmany(dbtob(dp
->di_blocks
), TP_BSIZE
);
130 sizeest
= howmany(dp
->di_size
, TP_BSIZE
);
131 if (blkest
> sizeest
)
134 if (dp
->di_size
> fs
->blocksize
* NDADDR
) {
135 /* calculate the number of indirect blocks on the dump tape */
137 howmany(sizeest
- NDADDR
* fs
->blocksize
/ TP_BSIZE
,
141 if (dp
->di_size
> sblock
->fs_bsize
* NDADDR
) {
142 /* calculate the number of indirect blocks on the dump tape */
144 howmany(sizeest
- NDADDR
* sblock
->fs_bsize
/ TP_BSIZE
,
151 /* Auxiliary macro to pick up files changed since previous dump. */
152 #define CHANGEDSINCE(dp, t) \
153 ((dp)->di_mtime >= (t) || (dp)->di_ctime >= (t))
155 /* The WANTTODUMP macro decides whether a file should be dumped. */
157 #define WANTTODUMP(dp) \
158 (CHANGEDSINCE(dp, spcl.c_ddate) && \
159 (nonodump || ((dp)->di_flags & UF_NODUMP) != UF_NODUMP))
161 #define WANTTODUMP(dp) CHANGEDSINCE(dp, spcl.c_ddate)
167 * Walk the inode list for a filesystem to find all allocated inodes
168 * that have been modified since the previous dump time. Also, find all
169 * the directories in the filesystem.
172 mapfiles(maxino
, tapesize
)
178 register struct dinode
*dp
;
179 int anydirskipped
= 0;
181 for (ino
= ROOTINO
; ino
< maxino
; ino
++) {
183 if ((mode
= (dp
->di_mode
& IFMT
)) == 0)
186 if (dp
->di_nlink
== 0 || dp
->di_dtime
!= 0)
189 SETINO(ino
, usedinomap
);
191 SETINO(ino
, dumpdirmap
);
192 if (WANTTODUMP(dp
)) {
193 SETINO(ino
, dumpinomap
);
194 if (mode
!= IFREG
&& mode
!= IFDIR
&& mode
!= IFLNK
)
197 *tapesize
+= blockest(dp
);
204 * Restore gets very upset if the root is not dumped,
205 * so ensure that it always is dumped.
207 SETINO(ROOTINO
, dumpinomap
);
208 return (anydirskipped
);
212 struct mapfile_context
{
218 mapfilesindir(dirent
, offset
, blocksize
, buf
, private)
219 struct ext2_dir_entry
*dirent
;
225 register struct dinode
*dp
;
229 struct mapfile_context
*mfc
;
232 mfc
= (struct mapfile_context
*)private;
234 if ((mode
= (dp
->di_mode
& IFMT
)) != 0 &&
235 dp
->di_nlink
!= 0 && dp
->di_dtime
== 0) {
236 SETINO(ino
, usedinomap
);
238 SETINO(ino
, dumpdirmap
);
239 if (WANTTODUMP(dp
)) {
240 SETINO(ino
, dumpinomap
);
241 if (mode
!= IFREG
&& mode
!= IFDIR
&& mode
!= IFLNK
)
244 *mfc
->tapesize
+= blockest(dp
);
247 mfc
->anydirskipped
= 1;
248 if ((dirent
->name
[0] != '.' || dirent
->name_len
!= 1) &&
249 (dirent
->name
[0] != '.' || dirent
->name
[1] != '.' ||
250 dirent
->name_len
!= 2)) {
251 retval
= ext2fs_dir_iterate(fs
, ino
, 0, NULL
,
252 mapfilesindir
, private);
264 * Walk the inode list for a filesystem to find all allocated inodes
265 * that have been modified since the previous dump time. Also, find all
266 * the directories in the filesystem.
269 mapfilesfromdir(maxino
, tapesize
, directory
)
275 struct mapfile_context mfc
;
277 char dir_name
[MAXPATHLEN
];
281 * Mark every directory in the path as being dumped
283 for (i
= 0; i
< strlen (directory
); i
++) {
284 if (directory
[i
] == '/') {
285 strncpy (dir_name
, directory
, i
);
287 retval
= ext2fs_namei(fs
, ROOTINO
, ROOTINO
, dir_name
,
290 com_err(disk
, retval
, "while translating %s",
294 /* SETINO(dir_ino, dumpinomap); */
295 SETINO(dir_ino
, dumpdirmap
);
299 * Mark the final directory
301 retval
= ext2fs_namei(fs
, ROOTINO
, ROOTINO
, directory
, &dir_ino
);
303 com_err(disk
, retval
, "while translating %s", directory
);
306 /* SETINO(dir_ino, dumpinomap); */
307 SETINO(dir_ino
, dumpdirmap
);
309 mfc
.tapesize
= tapesize
;
310 mfc
.anydirskipped
= 0;
311 retval
= ext2fs_dir_iterate(fs
, dir_ino
, 0, NULL
, mapfilesindir
,
315 com_err(disk
, retval
, "while mapping files in %s", directory
);
319 * Restore gets very upset if the root is not dumped,
320 * so ensure that it always is dumped.
322 /* SETINO(ROOTINO, dumpinomap); */
323 SETINO(ROOTINO
, dumpdirmap
);
324 return (mfc
.anydirskipped
);
331 * Scan each directory on the filesystem to see if it has any modified
332 * files in it. If it does, and has not already been added to the dump
333 * list (because it was itself modified), then add it. If a directory
334 * has not been modified itself, contains no modified files and has no
335 * subdirectories, then it can be deleted from the dump list and from
336 * the list of directories. By deleting it from the list of directories,
337 * its parent may now qualify for the same treatment on this or a later
338 * pass using this algorithm.
341 mapdirs(maxino
, tapesize
)
345 register struct dinode
*dp
;
346 register int i
, isdir
;
352 isdir
= 0; /* XXX just to get gcc to shut up */
353 for (map
= dumpdirmap
, ino
= 1; ino
< maxino
; ino
++) {
354 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
358 if ((isdir
& 1) == 0 || TSTINO(ino
, dumpinomap
))
363 ext2fs_dir_iterate(fs
, ino
, 0, NULL
, searchdir
, (void *) &ret
);
364 #else /* __linux__ */
366 filesize
= dp
->di_size
;
367 for (ret
= 0, i
= 0; filesize
> 0 && i
< NDADDR
; i
++) {
368 if (dp
->di_db
[i
] != 0)
369 ret
|= searchdir(ino
, dp
->di_db
[i
],
370 (long)dblksize(sblock
, dp
, i
),
372 if (ret
& HASDUMPEDFILE
)
375 filesize
-= sblock
->fs_bsize
;
377 for (i
= 0; filesize
> 0 && i
< NIADDR
; i
++) {
378 if (dp
->di_ib
[i
] == 0)
380 ret
|= dirindir(ino
, dp
->di_ib
[i
], i
, &filesize
);
382 #endif /* __linux__ */
383 if (ret
& HASDUMPEDFILE
) {
384 SETINO(ino
, dumpinomap
);
385 *tapesize
+= blockest(dp
);
389 if ((ret
& HASSUBDIRS
) == 0) {
390 if (!TSTINO(ino
, dumpinomap
)) {
391 CLRINO(ino
, dumpdirmap
);
401 * Read indirect blocks, and pass the data blocks to be searched
402 * as directories. Quit as soon as any entry is found that will
403 * require the directory to be dumped.
406 dirindir(ino
, blkno
, ind_level
, filesize
)
414 daddr_t idblk
[MAXNINDIR
];
416 bread(fsbtodb(sblock
, blkno
), (char *)idblk
, (int)sblock
->fs_bsize
);
417 if (ind_level
<= 0) {
418 for (i
= 0; *filesize
> 0 && i
< NINDIR(sblock
); i
++) {
421 ret
|= searchdir(ino
, blkno
, sblock
->fs_bsize
,
423 if (ret
& HASDUMPEDFILE
)
426 *filesize
-= sblock
->fs_bsize
;
431 for (i
= 0; *filesize
> 0 && i
< NINDIR(sblock
); i
++) {
434 ret
|= dirindir(ino
, blkno
, ind_level
, filesize
);
438 #endif /* !__linux__ */
441 * Scan a disk block containing directory information looking to see if
442 * any of the entries are on the dump list and to see if the directory
443 * contains any subdirectories.
447 searchdir(dp
, offset
, blocksize
, buf
, private)
448 struct ext2_dir_entry
*dp
;
454 int *ret
= (int *) private;
458 if (dp
->name
[0] == '.') {
459 if (dp
->name_len
== 1)
461 if (dp
->name
[1] == '.' && dp
->name_len
== 2)
464 if (TSTINO(dp
->inode
, dumpinomap
)) {
465 *ret
|= HASDUMPEDFILE
;
466 if (*ret
& HASSUBDIRS
)
469 if (TSTINO(dp
->inode
, dumpdirmap
)) {
471 if (*ret
& HASDUMPEDFILE
)
477 #else /* __linux__ */
480 searchdir(ino
, blkno
, size
, filesize
)
486 register struct direct
*dp
;
487 register long loc
, ret
= 0;
490 bread(fsbtodb(sblock
, blkno
), dblk
, (int)size
);
493 for (loc
= 0; loc
< size
; ) {
494 dp
= (struct direct
*)(dblk
+ loc
);
495 if (dp
->d_reclen
== 0) {
496 msg("corrupted directory, inumber %d\n", ino
);
502 if (dp
->d_name
[0] == '.') {
503 if (dp
->d_name
[1] == '\0')
505 if (dp
->d_name
[1] == '.' && dp
->d_name
[2] == '\0')
508 if (TSTINO(dp
->d_ino
, dumpinomap
)) {
509 ret
|= HASDUMPEDFILE
;
510 if (ret
& HASSUBDIRS
)
513 if (TSTINO(dp
->d_ino
, dumpdirmap
)) {
515 if (ret
& HASDUMPEDFILE
)
521 #endif /* __linux__ */
525 struct block_context
{
534 * Dump a block to the tape
537 dumponeblock(ext2_filsys fs
, blk_t
*blocknr
, int blockcnt
, void *private)
539 struct block_context
*p
;
542 if (blockcnt
< NDADDR
)
544 p
= (struct block_context
*)private;
545 for (i
= p
->next_block
; i
< blockcnt
; i
++) {
546 p
->buf
[p
->cnt
++] = 0;
547 if (p
->cnt
== p
->max
) {
548 blksout (p
->buf
, p
->cnt
, p
->ino
);
552 p
->buf
[p
->cnt
++] = *blocknr
;
553 if (p
->cnt
== p
->max
) {
554 blksout (p
->buf
, p
->cnt
, p
->ino
);
557 p
->next_block
= blockcnt
+ 1;
563 * Dump passes 3 and 4.
565 * Dump the contents of an inode to tape.
569 register struct dinode
*dp
;
575 struct old_bsd_inode obi
;
577 struct block_context bc
;
582 dumpmap(dumpinomap
, TS_BITS
, ino
);
584 CLRINO(ino
, dumpinomap
);
586 memset(&obi
, 0, sizeof(obi
));
587 obi
.di_mode
= dp
->di_mode
;
588 obi
.di_uid
= dp
->di_uid
;
589 obi
.di_gid
= dp
->di_gid
;
590 obi
.di_qsize
.v
= (u_quad_t
)dp
->di_size
;
591 obi
.di_atime
= dp
->di_atime
;
592 obi
.di_mtime
= dp
->di_mtime
;
593 obi
.di_ctime
= dp
->di_ctime
;
594 obi
.di_nlink
= dp
->di_nlink
;
595 obi
.di_blocks
= dp
->di_blocks
;
596 obi
.di_flags
= dp
->di_flags
;
597 obi
.di_gen
= dp
->di_gen
;
598 memmove(&obi
.di_db
, &dp
->di_db
, (NDADDR
+ NIADDR
) * sizeof(daddr_t
));
599 if (dp
->di_file_acl
|| dp
->di_dir_acl
)
600 warn("ACLs in inode #%d won't be dumped", ino
);
601 memmove(&spcl
.c_dinode
, &obi
, sizeof(obi
));
602 #else /* __linux__ */
604 #endif /* __linux__ */
605 spcl
.c_type
= TS_INODE
;
607 switch (dp
->di_mode
& S_IFMT
) {
617 msg("Warning: dumpino called on a directory (ino %d)\n", ino
);
623 * Check for short symbolic link.
626 if (dp
->di_size
> 0 &&
627 dp
->di_size
< EXT2_N_BLOCKS
* sizeof (daddr_t
)) {
631 memmove(buf
, dp
->di_db
, (u_long
)dp
->di_size
);
632 buf
[dp
->di_size
] = '\0';
636 #endif /* __linux__ */
638 if (dp
->di_size
> 0 &&
639 dp
->di_size
< sblock
->fs_maxsymlinklen
) {
643 memmove(buf
, dp
->di_shortlink
, (u_long
)dp
->di_size
);
644 buf
[dp
->di_size
] = '\0';
667 msg("Warning: undefined file type 0%o\n", dp
->di_mode
& IFMT
);
670 if (dp
->di_size
> NDADDR
* sblock
->fs_bsize
)
672 cnt
= NDADDR
* EXT2_FRAGS_PER_BLOCK(fs
->super
);
674 cnt
= NDADDR
* sblock
->fs_frag
;
677 cnt
= howmany(dp
->di_size
, sblock
->fs_fsize
);
678 blksout(&dp
->di_db
[0], cnt
, ino
);
679 if ((size
= ((int)dp
->di_size
) - NDADDR
* sblock
->fs_bsize
) <= 0)
682 bc
.max
= NINDIR(sblock
) * EXT2_FRAGS_PER_BLOCK(fs
->super
);
683 bc
.buf
= (int *)malloc (bc
.max
* sizeof (int));
686 bc
.next_block
= NDADDR
;
688 ext2fs_block_iterate (fs
, ino
, 0, NULL
, dumponeblock
, (void *)&bc
);
690 blksout (bc
.buf
, bc
.cnt
, bc
.ino
);
693 for (ind_level
= 0; ind_level
< NIADDR
; ind_level
++) {
694 dmpindir(ino
, dp
->di_ib
[ind_level
], ind_level
, &size
);
703 struct convert_dir_context
{
711 * This function converts an ext2fs directory entry to the BSD format.
713 * Basically, it adds a null-character at the end of the name, recomputes the
714 * size of the entry, and creates it in a temporary buffer
717 convert_dir(dirent
, offset
, blocksize
, buf
, private)
718 struct ext2_dir_entry
*dirent
;
724 struct convert_dir_context
*p
;
728 p
= (struct convert_dir_context
*)private;
730 reclen
= EXT2_DIR_REC_LEN(dirent
->name_len
+ 1);
731 if (((p
->offset
+ reclen
- 1) / p
->bs
) != (p
->offset
/ p
->bs
)) {
732 dp
= (struct direct
*)(p
->buf
+ p
->prev_offset
);
733 dp
->d_reclen
+= p
->bs
- (p
->offset
% p
->bs
);
734 p
->offset
+= p
->bs
- (p
->offset
% p
->bs
);
737 dp
= (struct direct
*)(p
->buf
+ p
->offset
);
738 dp
->d_ino
= dirent
->inode
;
739 dp
->d_reclen
= reclen
;
741 dp
->d_namlen
= dirent
->name_len
;
742 strncpy(dp
->d_name
, dirent
->name
, dirent
->name_len
);
743 dp
->d_name
[dp
->d_namlen
] = '\0';
744 p
->prev_offset
= p
->offset
;
753 * Dumps a directory to tape after converting it to the BSD format
757 register struct dinode
*dp
;
762 struct old_bsd_inode obi
;
763 struct convert_dir_context cdc
;
765 struct ext2_dir_entry
*de
;
770 dumpmap(dumpinomap
, TS_BITS
, ino
);
772 CLRINO(ino
, dumpinomap
);
775 * Convert the directory to the BSD format
777 /* Allocate a buffer for the conversion (twice the size of the
778 ext2fs directory to avoid problems ;-) */
779 cdc
.buf
= (char *)malloc(dp
->di_size
* 2 * sizeof(char));
781 err(1, "Cannot allocate buffer to convert directory #%ld\n",
785 cdc
.bs
= MIN(DIRBLKSIZ
, TP_BSIZE
);
786 /* Do the conversion */
787 retval
= ext2fs_dir_iterate(fs
, ino
, 0, NULL
, convert_dir
, (void *)&cdc
);
789 com_err(disk
, retval
, "while converting directory #%ld\n", ino
);
792 /* Fix the last entry */
793 if ((cdc
.offset
% cdc
.bs
) != 0) {
794 de
= (struct ext2_dir_entry
*)(cdc
.buf
+ cdc
.prev_offset
);
795 de
->rec_len
+= cdc
.bs
- (cdc
.offset
% cdc
.bs
);
796 cdc
.offset
+= cdc
.bs
- (cdc
.offset
% cdc
.bs
);
799 dir_size
= cdc
.offset
;
802 memset(&obi
, 0, sizeof(obi
));
803 obi
.di_mode
= dp
->di_mode
;
804 obi
.di_uid
= dp
->di_uid
;
805 obi
.di_gid
= dp
->di_gid
;
806 obi
.di_qsize
.v
= dir_size
; /* (u_quad_t)dp->di_size; */
807 obi
.di_atime
= dp
->di_atime
;
808 obi
.di_mtime
= dp
->di_mtime
;
809 obi
.di_ctime
= dp
->di_ctime
;
810 obi
.di_nlink
= dp
->di_nlink
;
811 obi
.di_blocks
= dp
->di_blocks
;
812 obi
.di_flags
= dp
->di_flags
;
813 obi
.di_gen
= dp
->di_gen
;
814 memmove(&obi
.di_db
, &dp
->di_db
, (NDADDR
+ NIADDR
) * sizeof(daddr_t
));
815 if (dp
->di_file_acl
|| dp
->di_dir_acl
)
816 warn("ACLs in inode #%d won't be dumped", ino
);
817 memmove(&spcl
.c_dinode
, &obi
, sizeof(obi
));
818 #else /* __linux__ */
820 #endif /* __linux__ */
821 spcl
.c_type
= TS_INODE
;
823 switch (dp
->di_mode
& S_IFMT
) {
834 msg("Warning: size of directory inode #%d is <= 0 (%d)!\n",
839 msg("Warning: dumpdirino called with file type 0%o (inode #%d)\n",
840 dp
->di_mode
& IFMT
, ino
);
843 for (size
= 0; size
< dir_size
; size
+= TP_BSIZE
) {
847 memmove(buf
, cdc
.buf
+ size
, TP_BSIZE
);
849 spcl
.c_type
= TS_ADDR
;
854 #endif /* __linux__ */
858 * Read indirect blocks, and pass the data blocks to be dumped.
861 dmpindir(ino
, blk
, ind_level
, size
)
868 daddr_t idblk
[MAXNINDIR
];
871 bread(fsbtodb(sblock
, blk
), (char *)idblk
, (int) sblock
->fs_bsize
);
873 memset(idblk
, 0, (int)sblock
->fs_bsize
);
874 if (ind_level
<= 0) {
875 if (*size
< NINDIR(sblock
) * sblock
->fs_bsize
)
876 cnt
= howmany(*size
, sblock
->fs_fsize
);
879 cnt
= NINDIR(sblock
) * EXT2_FRAGS_PER_BLOCK(fs
->super
);
881 cnt
= NINDIR(sblock
) * sblock
->fs_frag
;
883 *size
-= NINDIR(sblock
) * sblock
->fs_bsize
;
884 blksout(&idblk
[0], cnt
, ino
);
888 for (i
= 0; i
< NINDIR(sblock
); i
++) {
889 dmpindir(ino
, idblk
[i
], ind_level
, size
);
897 * Collect up the data into tape record sized buffers and output them.
900 blksout(blkp
, frags
, ino
)
905 register daddr_t
*bp
;
906 int i
, j
, count
, blks
, tbperdb
;
908 blks
= howmany(frags
* sblock
->fs_fsize
, TP_BSIZE
);
909 tbperdb
= sblock
->fs_bsize
>> tp_bshift
;
910 for (i
= 0; i
< blks
; i
+= TP_NINDIR
) {
911 if (i
+ TP_NINDIR
> blks
)
914 count
= i
+ TP_NINDIR
;
915 for (j
= i
; j
< count
; j
++)
916 if (blkp
[j
/ tbperdb
] != 0)
917 spcl
.c_addr
[j
- i
] = 1;
919 spcl
.c_addr
[j
- i
] = 0;
920 spcl
.c_count
= count
- i
;
922 bp
= &blkp
[i
/ tbperdb
];
923 for (j
= i
; j
< count
; j
+= tbperdb
, bp
++)
925 if (j
+ tbperdb
<= count
)
926 dumpblock(*bp
, (int)sblock
->fs_bsize
);
928 dumpblock(*bp
, (count
- j
) * TP_BSIZE
);
929 spcl
.c_type
= TS_ADDR
;
934 * Dump a map to the tape.
937 dumpmap(map
, type
, ino
)
946 spcl
.c_count
= howmany(mapsize
* sizeof(char), TP_BSIZE
);
948 for (i
= 0, cp
= map
; i
< spcl
.c_count
; i
++, cp
+= TP_BSIZE
)
953 * Write a header record to the dump tape.
960 register __s32 sum
, cnt
, *lp
;
962 register long sum
, cnt
, *lp
;
965 spcl
.c_inumber
= ino
;
966 spcl
.c_magic
= NFS_MAGIC
;
975 cnt
= sizeof(union u_spcl
) / (4 * sizeof(__s32
));
977 cnt
= sizeof(union u_spcl
) / (4 * sizeof(long));
985 spcl
.c_checksum
= CHECKSUM
- sum
;
986 writerec((char *)&spcl
, 1);
994 static struct dinode dinode
;
997 ext2fs_read_inode(fs
, inum
, (struct ext2_inode
*) &dinode
);
1000 #else /* __linux__ */
1005 static daddr_t minino
, maxino
;
1006 static struct dinode inoblock
[MAXINOPB
];
1009 if (inum
>= minino
&& inum
< maxino
)
1010 return (&inoblock
[inum
- minino
]);
1011 bread(fsbtodb(sblock
, ino_to_fsba(sblock
, inum
)), (char *)inoblock
,
1012 (int)sblock
->fs_bsize
);
1013 minino
= inum
- (inum
% INOPB(sblock
));
1014 maxino
= minino
+ INOPB(sblock
);
1015 return (&inoblock
[inum
- minino
]);
1017 #endif /* __linux__ */
1020 * Read a chunk of data from the disk.
1021 * Try to recover from hard errors by reading in sector sized pieces.
1022 * Error recovery is attempted at most BREADEMAX times before seeking
1023 * consent from the operator to continue.
1025 int breaderrors
= 0;
1026 #define BREADEMAX 32
1029 bread(blkno
, buf
, size
)
1039 if (ext2_llseek(diskfd
, ((ext2_loff_t
)blkno
<< dev_bshift
), 0) !=
1040 ((ext2_loff_t
)blkno
<< dev_bshift
))
1042 if ((int)lseek(diskfd
, ((off_t
)blkno
<< dev_bshift
), 0) == -1)
1044 msg("bread: lseek fails\n");
1045 if ((cnt
= read(diskfd
, buf
, size
)) == size
)
1047 if (blkno
+ (size
/ dev_bsize
) > fsbtodb(sblock
, sblock
->fs_size
)) {
1049 * Trying to read the final fragment.
1051 * NB - dump only works in TP_BSIZE blocks, hence
1052 * rounds `dev_bsize' fragments up to TP_BSIZE pieces.
1053 * It should be smarter about not actually trying to
1054 * read more than it can get, but for the time being
1055 * we punt and scale back the read only when it gets
1056 * us into trouble. (mkm 9/25/83)
1062 msg("read error from %s: %s: [block %d]: count=%d\n",
1063 disk
, strerror(errno
), blkno
, size
);
1065 msg("short read error from %s: [block %d]: count=%d, got=%d\n",
1066 disk
, blkno
, size
, cnt
);
1067 if (++breaderrors
> BREADEMAX
) {
1068 msg("More than %d block read errors from %d\n",
1070 broadcast("DUMP IS AILING!\n");
1071 msg("This is an unrecoverable error.\n");
1072 if (!query("Do you want to attempt to continue?")){
1079 * Zero buffer, then try to read each sector of buffer separately.
1081 memset(buf
, 0, size
);
1082 for (i
= 0; i
< size
; i
+= dev_bsize
, buf
+= dev_bsize
, blkno
++) {
1084 if (ext2_llseek(diskfd
, ((ext2_loff_t
)blkno
<< dev_bshift
), 0) !=
1085 ((ext2_loff_t
)blkno
<< dev_bshift
))
1087 if ((int)lseek(diskfd
, ((off_t
)blkno
<< dev_bshift
), 0) == -1)
1089 msg("bread: lseek2 fails!\n");
1090 if ((cnt
= read(diskfd
, buf
, (int)dev_bsize
)) == dev_bsize
)
1093 msg("read error from %s: %s: [sector %d]: count=%d\n",
1094 disk
, strerror(errno
), blkno
, dev_bsize
);
1097 msg("short read error from %s: [sector %d]: count=%d, got=%d\n",
1098 disk
, blkno
, dev_bsize
, cnt
);