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