2 * Copyright 2002-2013 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
6 * Ithamar R. Adema <ithamar@unet.nl>
7 * Stephan Aßmus <superstippi@gmx.de>
8 * Axel Dörfler, axeld@pinc-software.de.
9 * Bryce Groff <bgroff@hawaii.edu>
10 * Erik Jaesler <ejakowatz@users.sourceforge.net>
20 #include <Partition.h>
24 #undef B_TRANSLATION_CONTEXT
25 #define B_TRANSLATION_CONTEXT "Support"
28 static const int32 kMaxSliderLimit
= 0x7fffff80;
29 // this is the maximum value that BSlider seem to work with fine
33 dump_partition_info(const BPartition
* partition
)
36 printf("\tOffset(): %" B_PRIdOFF
"\n", partition
->Offset());
37 printf("\tSize(): %s\n", string_for_size(partition
->Size(), size
,
39 printf("\tContentSize(): %s\n", string_for_size(partition
->ContentSize(),
41 printf("\tBlockSize(): %" B_PRId32
"\n", partition
->BlockSize());
42 printf("\tIndex(): %" B_PRId32
"\n", partition
->Index());
43 printf("\tStatus(): %" B_PRId32
"\n\n", partition
->Status());
44 printf("\tContainsFileSystem(): %s\n",
45 partition
->ContainsFileSystem() ? "true" : "false");
46 printf("\tContainsPartitioningSystem(): %s\n\n",
47 partition
->ContainsPartitioningSystem() ? "true" : "false");
48 printf("\tIsDevice(): %s\n", partition
->IsDevice() ? "true" : "false");
49 printf("\tIsReadOnly(): %s\n", partition
->IsReadOnly() ? "true" : "false");
50 printf("\tIsMounted(): %s\n", partition
->IsMounted() ? "true" : "false");
51 printf("\tIsBusy(): %s\n\n", partition
->IsBusy() ? "true" : "false");
52 printf("\tFlags(): %" B_PRIx32
"\n\n", partition
->Flags());
53 printf("\tName(): %s\n", partition
->Name());
54 printf("\tContentName(): %s\n", partition
->ContentName());
55 printf("\tType(): %s\n", partition
->Type());
56 printf("\tContentType(): %s\n", partition
->ContentType());
57 printf("\tID(): %" B_PRIx32
"\n\n", partition
->ID());
62 is_valid_partitionable_space(size_t size
)
64 // TODO: remove this again, the DiskDeviceAPI should
65 // not even show these spaces to begin with
66 return size
>= 8 * 1024 * 1024;
70 // #pragma mark - SpaceIDMap
73 SpaceIDMap::SpaceIDMap()
75 HashMap
<HashString
, partition_id
>(),
81 SpaceIDMap::~SpaceIDMap()
87 SpaceIDMap::SpaceIDFor(partition_id parentID
, off_t spaceOffset
)
90 key
<< parentID
<< ':' << (uint64
)spaceOffset
;
92 if (ContainsKey(key
.String()))
93 return Get(key
.String());
95 partition_id newID
= fNextSpaceID
--;
96 Put(key
.String(), newID
);
105 SizeSlider::SizeSlider(const char* name
, const char* label
,
106 BMessage
* message
, off_t offset
, off_t size
, uint32 minGranularity
)
108 BSlider(name
, label
, message
, 0, kMaxSliderLimit
, B_HORIZONTAL
,
110 fStartOffset(offset
),
111 fEndOffset(offset
+ size
),
112 fMaxPartitionSize(size
),
113 fGranularity(minGranularity
)
115 rgb_color fillColor
= ui_color(B_CONTROL_HIGHLIGHT_COLOR
);
116 UseFillColor(true, &fillColor
);
118 // Lazy loop to get a power of two granularity
119 while (size
/ fGranularity
> kMaxSliderLimit
)
122 SetKeyIncrementValue(int32(1024 * 1024 * 1.0 * kMaxSliderLimit
123 / ((MaxPartitionSize() - 1) / fGranularity
) + 0.5));
128 snprintf(minString
, sizeof(minString
), B_TRANSLATE("Offset: %s"),
129 string_for_size(fStartOffset
, buffer
, sizeof(buffer
)));
130 snprintf(maxString
, sizeof(maxString
), B_TRANSLATE("End: %s"),
131 string_for_size(fEndOffset
, buffer
, sizeof(buffer
)));
132 SetLimitLabels(minString
, maxString
);
136 SizeSlider::~SizeSlider()
142 SizeSlider::SetValue(int32 value
)
144 BSlider::SetValue(value
);
146 fSize
= (off_t(1.0 * (MaxPartitionSize() - 1) * Value()
147 / kMaxSliderLimit
+ 0.5) / fGranularity
) * fGranularity
;
152 SizeSlider::UpdateText() const
154 return string_for_size(Size(), fStatusLabel
, sizeof(fStatusLabel
));
159 SizeSlider::Size() const
166 SizeSlider::SetSize(off_t size
)
171 SetValue(int32(1.0 * kMaxSliderLimit
/ fGranularity
* size
172 / ((MaxPartitionSize() - 1) / fGranularity
) + 0.5));
179 SizeSlider::Offset() const
181 // TODO: This should be the changed offset once a double
182 // headed slider is implemented.
188 SizeSlider::MaxPartitionSize() const
190 return fMaxPartitionSize
;