1/* 2 * Copyright 2002-2012 Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT license. 4 * 5 * Authors: 6 * Erik Jaesler <ejakowatz@users.sourceforge.net> 7 * Ithamar R. Adema <ithamar@unet.nl> 8 * Stephan Aßmus <superstippi@gmx.de> 9 * Bryce Groff <bgroff@hawaii.edu> 10 */ 11 12 13#include "Support.h" 14 15#include <stdio.h> 16 17#include <Catalog.h> 18#include <Locale.h> 19#include <Partition.h> 20#include <String.h> 21 22 23#undef B_TRANSLATION_CONTEXT 24#define B_TRANSLATION_CONTEXT "Support" 25 26 27void 28dump_partition_info(const BPartition* partition) 29{ 30 char size[1024]; 31 printf("\tOffset(): %" B_PRIdOFF "\n", partition->Offset()); 32 printf("\tSize(): %s\n", string_for_size(partition->Size(), size, 33 sizeof(size))); 34 printf("\tContentSize(): %s\n", string_for_size(partition->ContentSize(), 35 size, sizeof(size))); 36 printf("\tBlockSize(): %" B_PRId32 "\n", partition->BlockSize()); 37 printf("\tIndex(): %" B_PRId32 "\n", partition->Index()); 38 printf("\tStatus(): %" B_PRId32 "\n\n", partition->Status()); 39 printf("\tContainsFileSystem(): %s\n", 40 partition->ContainsFileSystem() ? "true" : "false"); 41 printf("\tContainsPartitioningSystem(): %s\n\n", 42 partition->ContainsPartitioningSystem() ? "true" : "false"); 43 printf("\tIsDevice(): %s\n", partition->IsDevice() ? "true" : "false"); 44 printf("\tIsReadOnly(): %s\n", partition->IsReadOnly() ? "true" : "false"); 45 printf("\tIsMounted(): %s\n", partition->IsMounted() ? "true" : "false"); 46 printf("\tIsBusy(): %s\n\n", partition->IsBusy() ? "true" : "false"); 47 printf("\tFlags(): %" B_PRIx32 "\n\n", partition->Flags()); 48 printf("\tName(): %s\n", partition->Name()); 49 printf("\tContentName(): %s\n", partition->ContentName()); 50 printf("\tType(): %s\n", partition->Type()); 51 printf("\tContentType(): %s\n", partition->ContentType()); 52 printf("\tID(): %" B_PRIx32 "\n\n", partition->ID()); 53} 54 55 56bool 57is_valid_partitionable_space(size_t size) 58{ 59 // TODO: remove this again, the DiskDeviceAPI should 60 // not even show these spaces to begin with 61 return size >= 8 * 1024 * 1024; 62} 63 64 65// #pragma mark - SpaceIDMap 66 67 68SpaceIDMap::SpaceIDMap() 69 : 70 HashMap<HashString, partition_id>(), 71 fNextSpaceID(-2) 72{ 73} 74 75 76SpaceIDMap::~SpaceIDMap() 77{ 78} 79 80 81partition_id 82SpaceIDMap::SpaceIDFor(partition_id parentID, off_t spaceOffset) 83{ 84 BString key; 85 key << parentID << ':' << (uint64)spaceOffset; 86 87 if (ContainsKey(key.String())) 88 return Get(key.String()); 89 90 partition_id newID = fNextSpaceID--; 91 Put(key.String(), newID); 92 93 return newID; 94} 95 96 97SizeSlider::SizeSlider(const char* name, const char* label, 98 BMessage* message, int32 minValue, int32 maxValue) 99 : 100 BSlider(name, label, message, minValue, maxValue, 101 B_HORIZONTAL, B_TRIANGLE_THUMB), 102 fStartOffset(minValue), 103 fEndOffset(maxValue), 104 fMaxPartitionSize(maxValue - minValue) 105{ 106 rgb_color fillColor = ui_color(B_CONTROL_HIGHLIGHT_COLOR); 107 UseFillColor(true, &fillColor); 108 char minString[64]; 109 char maxString[64]; 110 snprintf(minString, sizeof(minString), B_TRANSLATE("Offset: %ld MB"), 111 fStartOffset); 112 snprintf(maxString, sizeof(maxString), B_TRANSLATE("End: %ld MB"), 113 fEndOffset); 114 SetLimitLabels(minString, maxString); 115} 116 117 118SizeSlider::~SizeSlider() 119{ 120} 121 122 123const char* 124SizeSlider::UpdateText() const 125{ 126 // TODO: Perhaps replace with string_for_size, but it looks like 127 // Value() and fStartOffset are always in MiB. 128 snprintf(fStatusLabel, sizeof(fStatusLabel), B_TRANSLATE("%ld MiB"), 129 Value() - fStartOffset); 130 131 return fStatusLabel; 132} 133 134 135int32 136SizeSlider::Size() 137{ 138 return Value() - fStartOffset; 139} 140 141 142int32 143SizeSlider::Offset() 144{ 145 // TODO: This should be the changed offset once a double 146 // headed slider is implemented. 147 return fStartOffset; 148} 149 150int32 151SizeSlider::MaxPartitionSize() 152{ 153 return fMaxPartitionSize; 154} 155