1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | #include "Chunk.h" |
11 | |
12 | #include <stdlib.h> |
13 | #include <string.h> |
14 | |
15 | |
16 | |
17 | #ifdef TRACE_BTRFS |
18 | # define TRACE(x...); dprintf("\33[34mbtrfs:\33[0m " x) |
19 | #else |
20 | # define TRACE(x...); ; |
21 | #endif |
22 | # define FATAL(x...)dprintf("\33[34mbtrfs:\33[0m " x...) dprintf("\33[34mbtrfs:\33[0m " x) |
23 | |
24 | |
25 | Chunk::Chunk(struct btrfs_chunk* chunk, fsblock_t offset) |
26 | : |
27 | fChunk(NULL__null), |
28 | fInitStatus(B_OK((int)0)) |
29 | { |
30 | fChunkOffset = offset; |
31 | fChunk = (struct btrfs_chunk*)malloc(sizeof(struct btrfs_chunk) |
| 1 | Value assigned to field 'fChunk' | |
|
32 | + chunk->StripeCount() * sizeof(struct btrfs_stripe)); |
33 | if (fChunk == NULL__null) |
| 2 | | Assuming pointer value is null | |
|
| |
34 | fInitStatus = B_NO_MEMORY((-2147483647 - 1) + 0); |
35 | memcpy(fChunk, chunk, sizeof(struct btrfs_chunk) |
| 4 | | Null pointer argument in call to memory copy function |
|
36 | + chunk->StripeCount() * sizeof(struct btrfs_stripe)); |
37 | |
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());; |
47 | } |
48 | } |
49 | |
50 | |
51 | Chunk::~Chunk() |
52 | { |
53 | free(fChunk); |
54 | } |
55 | |
56 | |
57 | uint32 |
58 | Chunk::Size() const |
59 | { |
60 | return sizeof(struct btrfs_chunk) |
61 | + fChunk->StripeCount() * sizeof(struct btrfs_stripe); |
62 | } |
63 | |
64 | |
65 | status_t |
66 | Chunk::FindBlock(off_t logical, off_t &physical) |
67 | { |
68 | if (fChunk == NULL__null) |
69 | return B_NO_INIT((-2147483647 - 1) + 13); |
70 | |
71 | if (logical < (off_t)fChunkOffset |
72 | || logical > (off_t)(fChunkOffset + fChunk->Length())) |
73 | return B_BAD_VALUE((-2147483647 - 1) + 5); |
74 | |
75 | |
76 | physical = logical + fChunk->stripes[0].Offset() - fChunkOffset; |
77 | return B_OK((int)0); |
78 | } |
79 | |