2 * Copyright 2011, Haiku Inc. All rights reserved.
3 * This file may be used under the terms of the MIT License.
15 # define TRACE(x...) dprintf("\33[34mbtrfs:\33[0m " x)
17 # define TRACE(x...) ;
19 # define FATAL(x...) dprintf("\33[34mbtrfs:\33[0m " x)
22 Chunk::Chunk(btrfs_chunk
* chunk
, fsblock_t offset
)
27 fChunkOffset
= offset
;
28 fChunk
= (btrfs_chunk
*)malloc(sizeof(btrfs_chunk
)
29 + chunk
->StripeCount() * sizeof(btrfs_stripe
));
31 fInitStatus
= B_NO_MEMORY
;
35 memcpy(fChunk
, chunk
, sizeof(btrfs_chunk
)
36 + chunk
->StripeCount() * sizeof(btrfs_stripe
));
38 TRACE("chunk[0] length %" B_PRIu64
" owner %" B_PRIu64
" stripe_length %"
39 B_PRIu64
" type %" B_PRIu64
" stripe_count %u sub_stripes %u "
40 "sector_size %" B_PRIu32
"\n", chunk
->Length(), chunk
->Owner(),
41 chunk
->StripeLength(), chunk
->Type(), chunk
->StripeCount(),
42 chunk
->SubStripes(), chunk
->SectorSize());
43 for (int32 i
= 0; i
< chunk
->StripeCount(); i
++) {
44 TRACE("chunk.stripe[%" B_PRId32
"].physical %" B_PRId64
" deviceid %"
45 B_PRId64
"\n", i
, chunk
->stripes
[i
].Offset(),
46 chunk
->stripes
[i
].DeviceID());
60 return sizeof(btrfs_chunk
)
61 + fChunk
->StripeCount() * sizeof(btrfs_stripe
);
66 Chunk::FindBlock(off_t logical
, off_t
& physical
)
71 if (logical
< (off_t
)fChunkOffset
72 || logical
> (off_t
)(fChunkOffset
+ fChunk
->Length()))
76 physical
= logical
+ fChunk
->stripes
[0].Offset() - fChunkOffset
;