2 * Copyright (c) 2010 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 struct recover_dict
*next
;
39 struct recover_dict
*parent
;
48 #define DICTF_MADEDIR 0x01
49 #define DICTF_MADEFILE 0x02
50 #define DICTF_PARENT 0x04 /* parent attached for real */
51 #define DICTF_TRAVERSED 0x80
53 static void recover_top(char *ptr
, hammer_off_t offset
);
54 static void recover_elm(hammer_btree_leaf_elm_t leaf
);
55 static struct recover_dict
*get_dict(int64_t obj_id
, uint16_t pfs_id
);
56 static char *recover_path(struct recover_dict
*dict
);
57 static void sanitize_string(char *str
);
58 static hammer_off_t
scan_raw_limit(void);
59 static void scan_bigblocks(int target_zone
);
60 static void free_bigblocks(void);
61 static void add_bigblock_entry(hammer_off_t offset
);
62 static int test_bigblock_entry(hammer_off_t offset
);
64 static const char *TargetDir
;
65 static int CachedFd
= -1;
66 static char *CachedPath
;
68 typedef struct bigblock
{
69 RB_ENTRY(bigblock
) entry
;
70 hammer_off_t phys_offset
; /* zone-2 */
74 bigblock_cmp(bigblock_t b1
, bigblock_t b2
)
76 if (b1
->phys_offset
< b2
->phys_offset
)
78 if (b1
->phys_offset
> b2
->phys_offset
)
83 RB_HEAD(bigblock_rb_tree
, bigblock
) ZoneTree
= RB_INITIALIZER(&ZoneTree
);
84 RB_PROTOTYPE2(bigblock_rb_tree
, bigblock
, entry
, bigblock_cmp
, hammer_off_t
);
85 RB_GENERATE2(bigblock_rb_tree
, bigblock
, entry
, bigblock_cmp
, hammer_off_t
,
89 * XXX There is a hidden bug here while iterating zone-2 offset as
90 * shown in an example below.
92 * If a volume was once used as HAMMER filesystem which consists of
93 * multiple volumes whose usage has reached beyond the first volume,
94 * and then later re-formatted only using 1 volume, hammer recover is
95 * likely to hit assertion in get_buffer() due to having access to
96 * invalid volume (vol1,2,...) from old filesystem data.
98 * To avoid this, now the command only scans upto the last big-block
99 * that's actually used for filesystem data or meta-data at the moment,
100 * if all layer1/2 entries have correct CRC values. This also avoids
101 * recovery of irrelevant files from old filesystem.
103 * |-----vol0-----|-----vol1-----|-----vol2-----| old filesystem
104 * <-----------------------> used by old filesystem
106 * |-----vol0-----| new filesystem
107 * <-----> used by new filesystem
108 * <-------> unused, invalid data from old filesystem
109 * <-> B-Tree nodes likely to point to vol1
113 hammer_cmd_recover(char **av
, int ac
)
115 struct buffer_info
*data_buffer
;
116 struct volume_info
*volume
;
119 hammer_off_t off_end
;
120 hammer_off_t raw_limit
= 0;
121 hammer_off_t zone_limit
= 0;
124 int target_zone
= HAMMER_ZONE_BTREE_INDEX
;
129 fprintf(stderr
, "hammer recover <target_dir> [full|quick]\n");
135 if (!strcmp(av
[1], "full"))
137 if (!strcmp(av
[1], "quick"))
140 assert(!full
|| !quick
);
142 if (mkdir(TargetDir
, 0777) == -1) {
143 if (errno
!= EEXIST
) {
149 printf("Running %sraw scan of HAMMER image, recovering to %s\n",
150 full
? "full " : quick
? "quick " : "",
154 raw_limit
= scan_raw_limit();
156 raw_limit
+= HAMMER_BIGBLOCK_SIZE
;
157 assert(hammer_is_zone_raw_buffer(raw_limit
));
162 scan_bigblocks(target_zone
);
163 if (!RB_EMPTY(&ZoneTree
)) {
164 printf("Found zone-%d big-blocks at\n", target_zone
);
165 RB_FOREACH(b
, bigblock_rb_tree
, &ZoneTree
)
166 printf("%016jx\n", b
->phys_offset
);
168 b
= RB_MAX(bigblock_rb_tree
, &ZoneTree
);
169 zone_limit
= b
->phys_offset
+ HAMMER_BIGBLOCK_SIZE
;
170 assert(hammer_is_zone_raw_buffer(zone_limit
));
174 if (raw_limit
|| zone_limit
) {
175 #define _fmt "Scanning zone-%d big-blocks till %016jx"
176 if (!raw_limit
) /* unlikely */
177 printf(_fmt
" ???", target_zone
, zone_limit
);
178 else if (!zone_limit
)
179 printf(_fmt
, HAMMER_ZONE_RAW_BUFFER_INDEX
, raw_limit
);
180 else if (raw_limit
>= zone_limit
)
181 printf(_fmt
, target_zone
, zone_limit
);
183 printf(_fmt
" ???", HAMMER_ZONE_RAW_BUFFER_INDEX
, raw_limit
);
188 for (i
= 0; i
< HAMMER_MAX_VOLUMES
; i
++) {
189 volume
= get_volume(i
);
193 printf("Scanning volume %d size %s\n",
194 volume
->vol_no
, sizetostr(volume
->size
));
195 off
= HAMMER_ENCODE_RAW_BUFFER(volume
->vol_no
, 0);
196 off_end
= off
+ HAMMER_VOL_BUF_SIZE(volume
->ondisk
);
198 while (off
< off_end
) {
200 if (off
>= raw_limit
) {
201 printf("Done %016jx\n", (uintmax_t)off
);
206 if (off
>= zone_limit
) {
207 printf("Done %016jx\n", (uintmax_t)off
);
210 if (!test_bigblock_entry(off
)) {
211 off
= HAMMER_ZONE_LAYER2_NEXT_OFFSET(off
);
216 ptr
= get_buffer_data(off
, &data_buffer
, 0);
218 recover_top(ptr
, off
);
219 off
+= HAMMER_BUFSIZE
;
223 rel_buffer(data_buffer
);
236 print_node(hammer_node_ondisk_t node
, hammer_off_t offset
)
238 char buf
[HAMMER_BTREE_LEAF_ELMS
+ 1];
239 int maxcount
= hammer_node_max_elements(node
->type
);
242 for (i
= 0; i
< node
->count
&& i
< maxcount
; ++i
)
243 buf
[i
] = hammer_elm_btype(&node
->elms
[i
]);
246 printf("%016jx %c %d %s\n", offset
, node
->type
, node
->count
, buf
);
250 * Top level recovery processor. Assume the data is a B-Tree node.
251 * If the CRC is good we attempt to process the node, building the
252 * object space and creating the dictionary as we go.
255 recover_top(char *ptr
, hammer_off_t offset
)
257 hammer_node_ondisk_t node
;
258 hammer_btree_elm_t elm
;
263 for (node
= (void *)ptr
; (char *)node
< ptr
+ HAMMER_BUFSIZE
; ++node
) {
264 isnode
= hammer_crc_test_btree(node
);
265 maxcount
= hammer_node_max_elements(node
->type
);
269 print_node(node
, offset
);
270 else if (DebugOpt
> 1)
271 printf("%016jx -\n", offset
);
273 offset
+= sizeof(*node
);
275 if (isnode
&& node
->type
== HAMMER_BTREE_TYPE_LEAF
) {
276 for (i
= 0; i
< node
->count
&& i
< maxcount
; ++i
) {
277 elm
= &node
->elms
[i
];
278 if (elm
->base
.btype
== HAMMER_BTREE_TYPE_RECORD
)
279 recover_elm(&elm
->leaf
);
286 recover_elm(hammer_btree_leaf_elm_t leaf
)
288 struct buffer_info
*data_buffer
= NULL
;
289 struct recover_dict
*dict
;
290 struct recover_dict
*dict2
;
291 hammer_data_ondisk_t ondisk
;
292 hammer_off_t data_offset
;
306 * Ignore deleted records
310 if ((data_offset
= leaf
->data_offset
) != 0)
311 ondisk
= get_buffer_data(data_offset
, &data_buffer
, 0);
317 len
= leaf
->data_len
;
318 chunk
= HAMMER_BUFSIZE
- ((int)data_offset
& HAMMER_BUFMASK
);
322 if (len
< 0 || len
> HAMMER_XBUFSIZE
|| len
> chunk
)
325 pfs_id
= lo_to_pfs(leaf
->base
.localization
);
328 * Note that meaning of leaf->base.obj_id differs depending
329 * on record type. For a direntry, leaf->base.obj_id points
330 * to its parent inode that this entry is a part of, but not
331 * its corresponding inode.
333 dict
= get_dict(leaf
->base
.obj_id
, pfs_id
);
335 switch(leaf
->base
.rec_type
) {
336 case HAMMER_RECTYPE_INODE
:
338 * We found an inode which also tells us where the file
339 * or directory is in the directory hierarchy.
342 printf("inode %016jx:%05d found\n",
343 (uintmax_t)leaf
->base
.obj_id
, pfs_id
);
345 path1
= recover_path(dict
);
348 * Attach the inode to its parent. This isn't strictly
349 * necessary because the information is also in the
350 * directory entries, but if we do not find the directory
351 * entry this ensures that the files will still be
352 * reasonably well organized in their proper directories.
354 if ((dict
->flags
& DICTF_PARENT
) == 0 &&
355 dict
->obj_id
!= HAMMER_OBJID_ROOT
&&
356 ondisk
->inode
.parent_obj_id
!= 0) {
357 dict
->flags
|= DICTF_PARENT
;
358 dict
->parent
= get_dict(ondisk
->inode
.parent_obj_id
,
361 (dict
->parent
->flags
& DICTF_MADEDIR
) == 0) {
362 dict
->parent
->flags
|= DICTF_MADEDIR
;
363 path2
= recover_path(dict
->parent
);
364 printf("mkdir %s\n", path2
);
370 if (dict
->obj_type
== 0)
371 dict
->obj_type
= ondisk
->inode
.obj_type
;
372 dict
->size
= ondisk
->inode
.size
;
373 path2
= recover_path(dict
);
375 if (lstat(path1
, &st
) == 0) {
376 if (ondisk
->inode
.obj_type
== HAMMER_OBJTYPE_REGFILE
) {
377 truncate(path1
, dict
->size
);
378 /* chmod(path1, 0666); */
380 if (strcmp(path1
, path2
)) {
381 printf("Rename %s -> %s\n", path1
, path2
);
382 rename(path1
, path2
);
384 } else if (ondisk
->inode
.obj_type
== HAMMER_OBJTYPE_REGFILE
) {
385 printf("mkinode (file) %s\n", path2
);
386 fd
= open(path2
, O_RDWR
|O_CREAT
, 0666);
389 } else if (ondisk
->inode
.obj_type
== HAMMER_OBJTYPE_DIRECTORY
) {
390 printf("mkinode (dir) %s\n", path2
);
392 dict
->flags
|= DICTF_MADEDIR
;
397 case HAMMER_RECTYPE_DATA
:
401 if (leaf
->base
.obj_id
== 0)
404 printf("inode %016jx:%05d data %016jx,%d\n",
405 (uintmax_t)leaf
->base
.obj_id
,
407 (uintmax_t)leaf
->base
.key
- len
,
412 * Update the dictionary entry
414 if (dict
->obj_type
== 0)
415 dict
->obj_type
= HAMMER_OBJTYPE_REGFILE
;
418 * If the parent directory has not been created we
419 * have to create it (typically a PFS%05d)
422 (dict
->parent
->flags
& DICTF_MADEDIR
) == 0) {
423 dict
->parent
->flags
|= DICTF_MADEDIR
;
424 path2
= recover_path(dict
->parent
);
425 printf("mkdir %s\n", path2
);
432 * Create the file if necessary, report file creations
434 path1
= recover_path(dict
);
435 if (CachedPath
&& strcmp(CachedPath
, path1
) == 0) {
438 fd
= open(path1
, O_CREAT
|O_RDWR
, 0666);
441 printf("Unable to create %s: %s\n",
442 path1
, strerror(errno
));
446 if ((dict
->flags
& DICTF_MADEFILE
) == 0) {
447 dict
->flags
|= DICTF_MADEFILE
;
448 printf("mkfile %s\n", path1
);
452 * And write the record. A HAMMER data block is aligned
453 * and may contain trailing zeros after the file EOF. The
454 * inode record is required to get the actual file size.
456 * However, when the inode record is not available
457 * we can do a sparse write and that will get it right
458 * most of the time even if the inode record is never
461 file_offset
= (int64_t)leaf
->base
.key
- len
;
462 lseek(fd
, (off_t
)file_offset
, SEEK_SET
);
464 if (dict
->size
== -1) {
465 for (zfill
= chunk
- 1; zfill
>= 0; --zfill
) {
466 if (((char *)ondisk
)[zfill
])
475 write(fd
, ondisk
, zfill
);
477 lseek(fd
, chunk
- zfill
, SEEK_CUR
);
480 data_offset
+= chunk
;
481 file_offset
+= chunk
;
482 ondisk
= get_buffer_data(data_offset
, &data_buffer
, 0);
485 chunk
= HAMMER_BUFSIZE
-
486 ((int)data_offset
& HAMMER_BUFMASK
);
490 if (dict
->size
>= 0 && file_offset
> dict
->size
) {
491 ftruncate(fd
, dict
->size
);
492 /* fchmod(fd, 0666); */
495 if (fd
== CachedFd
) {
497 } else if (CachedPath
) {
507 case HAMMER_RECTYPE_DIRENTRY
:
508 nlen
= len
- HAMMER_ENTRY_NAME_OFF
;
509 if ((int)nlen
< 0) /* illegal length */
511 if (ondisk
->entry
.obj_id
== 0 ||
512 ondisk
->entry
.obj_id
== HAMMER_OBJID_ROOT
)
514 name
= malloc(nlen
+ 1);
515 bcopy(ondisk
->entry
.name
, name
, nlen
);
517 sanitize_string(name
);
520 printf("dir %016jx:%05d entry %016jx \"%s\"\n",
521 (uintmax_t)leaf
->base
.obj_id
,
523 (uintmax_t)ondisk
->entry
.obj_id
,
528 * We can't deal with hardlinks so if the object already
529 * has a name assigned to it we just keep using that name.
531 dict2
= get_dict(ondisk
->entry
.obj_id
, pfs_id
);
532 path1
= recover_path(dict2
);
534 if (dict2
->name
== NULL
)
540 * Attach dict2 to its directory (dict), create the
541 * directory (dict) if necessary. We must ensure
542 * that the directory entry exists in order to be
543 * able to properly rename() the file without creating
544 * a namespace conflict.
546 if ((dict2
->flags
& DICTF_PARENT
) == 0) {
547 dict2
->flags
|= DICTF_PARENT
;
548 dict2
->parent
= dict
;
549 if ((dict
->flags
& DICTF_MADEDIR
) == 0) {
550 dict
->flags
|= DICTF_MADEDIR
;
551 path2
= recover_path(dict
);
552 printf("mkdir %s\n", path2
);
558 path2
= recover_path(dict2
);
559 if (strcmp(path1
, path2
) != 0 && lstat(path1
, &st
) == 0) {
560 printf("Rename %s -> %s\n", path1
, path2
);
561 rename(path1
, path2
);
568 * Ignore any other record types
573 rel_buffer(data_buffer
);
576 #define RD_HSIZE 32768
577 #define RD_HMASK (RD_HSIZE - 1)
579 struct recover_dict
*RDHash
[RD_HSIZE
];
582 struct recover_dict
*
583 get_dict(int64_t obj_id
, uint16_t pfs_id
)
585 struct recover_dict
*dict
;
591 i
= crc32(&obj_id
, sizeof(obj_id
)) & RD_HMASK
;
592 for (dict
= RDHash
[i
]; dict
; dict
= dict
->next
) {
593 if (dict
->obj_id
== obj_id
&&
594 dict
->pfs_id
== pfs_id
) {
599 dict
= malloc(sizeof(*dict
));
600 bzero(dict
, sizeof(*dict
));
601 dict
->obj_id
= obj_id
;
602 dict
->pfs_id
= pfs_id
;
603 dict
->next
= RDHash
[i
];
608 * Always connect dangling dictionary entries to object 1
609 * (the root of the PFS).
611 * DICTF_PARENT will not be set until we know what the
612 * real parent directory object is.
614 if (dict
->obj_id
!= HAMMER_OBJID_ROOT
)
615 dict
->parent
= get_dict(HAMMER_OBJID_ROOT
, pfs_id
);
621 enum { PI_FIGURE
, PI_LOAD
} state
;
628 static void recover_path_helper(struct recover_dict
*, struct path_info
*);
632 recover_path(struct recover_dict
*dict
)
634 struct path_info info
;
636 /* Find info.len first */
637 bzero(&info
, sizeof(info
));
638 info
.state
= PI_FIGURE
;
639 recover_path_helper(dict
, &info
);
641 /* Fill in the path */
642 info
.pfs_id
= dict
->pfs_id
;
643 info
.base
= malloc(info
.len
);
644 info
.next
= info
.base
;
645 info
.state
= PI_LOAD
;
646 recover_path_helper(dict
, &info
);
648 /* Return the path */
652 #define STRLEN_OBJID 22 /* "obj_0x%016jx" */
653 #define STRLEN_PFSID 8 /* "PFS%05d" */
657 recover_path_helper(struct recover_dict
*dict
, struct path_info
*info
)
660 * Calculate path element length
662 dict
->flags
|= DICTF_TRAVERSED
;
664 switch(info
->state
) {
666 if (dict
->obj_id
== HAMMER_OBJID_ROOT
)
667 info
->len
+= STRLEN_PFSID
;
669 info
->len
+= strlen(dict
->name
);
671 info
->len
+= STRLEN_OBJID
;
675 (dict
->parent
->flags
& DICTF_TRAVERSED
) == 0) {
676 recover_path_helper(dict
->parent
, info
);
678 info
->len
+= strlen(TargetDir
) + 1;
683 (dict
->parent
->flags
& DICTF_TRAVERSED
) == 0) {
684 recover_path_helper(dict
->parent
, info
);
686 strcpy(info
->next
, TargetDir
);
687 info
->next
+= strlen(info
->next
);
691 if (dict
->obj_id
== HAMMER_OBJID_ROOT
) {
692 snprintf(info
->next
, STRLEN_PFSID
+ 1,
693 "PFS%05d", info
->pfs_id
);
694 } else if (dict
->name
) {
695 strcpy(info
->next
, dict
->name
);
697 snprintf(info
->next
, STRLEN_OBJID
+ 1,
698 "obj_0x%016jx", (uintmax_t)dict
->obj_id
);
700 info
->next
+= strlen(info
->next
);
703 dict
->flags
&= ~DICTF_TRAVERSED
;
708 sanitize_string(char *str
)
721 struct volume_info
*vol
;
722 hammer_blockmap_t rootmap
;
723 hammer_blockmap_layer1_t layer1
;
724 hammer_blockmap_layer2_t layer2
;
725 struct buffer_info
*buffer1
= NULL
;
726 struct buffer_info
*buffer2
= NULL
;
727 hammer_off_t layer1_offset
;
728 hammer_off_t layer2_offset
;
729 hammer_off_t phys_offset
;
730 hammer_off_t block_offset
;
731 hammer_off_t offset
= 0;
732 int zone
= HAMMER_ZONE_FREEMAP_INDEX
;
734 vol
= get_root_volume();
735 rootmap
= &vol
->ondisk
->vol0_blockmap
[zone
];
736 assert(rootmap
->phys_offset
!= 0);
738 for (phys_offset
= HAMMER_ZONE_ENCODE(zone
, 0);
739 phys_offset
< HAMMER_ZONE_ENCODE(zone
, HAMMER_OFF_LONG_MASK
);
740 phys_offset
+= HAMMER_BLOCKMAP_LAYER2
) {
744 layer1_offset
= rootmap
->phys_offset
+
745 HAMMER_BLOCKMAP_LAYER1_OFFSET(phys_offset
);
746 layer1
= get_buffer_data(layer1_offset
, &buffer1
, 0);
748 if (!hammer_crc_test_layer1(layer1
)) {
749 offset
= 0; /* failed */
752 if (layer1
->phys_offset
== HAMMER_BLOCKMAP_UNAVAIL
)
755 for (block_offset
= 0;
756 block_offset
< HAMMER_BLOCKMAP_LAYER2
;
757 block_offset
+= HAMMER_BIGBLOCK_SIZE
) {
759 * Dive layer 2, each entry represents a big-block.
761 layer2_offset
= layer1
->phys_offset
+
762 HAMMER_BLOCKMAP_LAYER2_OFFSET(block_offset
);
763 layer2
= get_buffer_data(layer2_offset
, &buffer2
, 0);
765 if (!hammer_crc_test_layer2(layer2
)) {
766 offset
= 0; /* failed */
769 if (layer2
->zone
== HAMMER_ZONE_UNAVAIL_INDEX
) {
771 } else if (layer2
->zone
&& layer2
->zone
!= zone
) {
772 offset
= phys_offset
+ block_offset
;
780 return(hammer_xlate_to_zone2(offset
));
785 scan_bigblocks(int target_zone
)
787 struct volume_info
*vol
;
788 hammer_blockmap_t rootmap
;
789 hammer_blockmap_layer1_t layer1
;
790 hammer_blockmap_layer2_t layer2
;
791 struct buffer_info
*buffer1
= NULL
;
792 struct buffer_info
*buffer2
= NULL
;
793 hammer_off_t layer1_offset
;
794 hammer_off_t layer2_offset
;
795 hammer_off_t phys_offset
;
796 hammer_off_t block_offset
;
797 hammer_off_t offset
= 0;
798 int zone
= HAMMER_ZONE_FREEMAP_INDEX
;
800 vol
= get_root_volume();
801 rootmap
= &vol
->ondisk
->vol0_blockmap
[zone
];
802 assert(rootmap
->phys_offset
!= 0);
804 for (phys_offset
= HAMMER_ZONE_ENCODE(zone
, 0);
805 phys_offset
< HAMMER_ZONE_ENCODE(zone
, HAMMER_OFF_LONG_MASK
);
806 phys_offset
+= HAMMER_BLOCKMAP_LAYER2
) {
810 layer1_offset
= rootmap
->phys_offset
+
811 HAMMER_BLOCKMAP_LAYER1_OFFSET(phys_offset
);
812 layer1
= get_buffer_data(layer1_offset
, &buffer1
, 0);
815 if (!hammer_crc_test_layer1(layer1)) {
818 if (layer1
->phys_offset
== HAMMER_BLOCKMAP_UNAVAIL
)
821 for (block_offset
= 0;
822 block_offset
< HAMMER_BLOCKMAP_LAYER2
;
823 block_offset
+= HAMMER_BIGBLOCK_SIZE
) {
824 offset
= phys_offset
+ block_offset
;
826 * Dive layer 2, each entry represents a big-block.
828 layer2_offset
= layer1
->phys_offset
+
829 HAMMER_BLOCKMAP_LAYER2_OFFSET(block_offset
);
830 layer2
= get_buffer_data(layer2_offset
, &buffer2
, 0);
833 if (!hammer_crc_test_layer2(layer2)) {
836 if (layer2
->zone
== target_zone
) {
837 add_bigblock_entry(offset
);
838 } else if (layer2
->zone
== HAMMER_ZONE_UNAVAIL_INDEX
) {
853 while ((b
= RB_ROOT(&ZoneTree
)) != NULL
) {
854 RB_REMOVE(bigblock_rb_tree
, &ZoneTree
, b
);
857 assert(RB_EMPTY(&ZoneTree
));
862 add_bigblock_entry(hammer_off_t offset
)
866 b
= calloc(sizeof(*b
), 1);
867 b
->phys_offset
= hammer_xlate_to_zone2(offset
);
868 assert((b
->phys_offset
& HAMMER_BIGBLOCK_MASK64
) == 0);
870 RB_INSERT(bigblock_rb_tree
, &ZoneTree
, b
);
875 test_bigblock_entry(hammer_off_t offset
)
879 offset
= hammer_xlate_to_zone2(offset
);
880 offset
&= ~HAMMER_BIGBLOCK_MASK64
;
882 b
= RB_LOOKUP(bigblock_rb_tree
, &ZoneTree
, offset
);