1 /* 2 * Copyright 2002-2009 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 #include "Support.h" 13 14 #include <stdio.h> 15 16 #include <Catalog.h> 17 #include <Partition.h> 18 #include <String.h> 19 20 21 #define TR_CONTEXT "Support" 22 23 24 void 25 dump_partition_info(const BPartition* partition) 26 { 27 char size[1024]; 28 printf("\tOffset(): %Ld\n", partition->Offset()); 29 printf("\tSize(): %s\n", string_for_size(partition->Size(), size, 30 sizeof(size))); 31 printf("\tContentSize(): %s\n", string_for_size(partition->ContentSize(), 32 size, sizeof(size))); 33 printf("\tBlockSize(): %ld\n", partition->BlockSize()); 34 printf("\tIndex(): %ld\n", partition->Index()); 35 printf("\tStatus(): %ld\n\n", partition->Status()); 36 printf("\tContainsFileSystem(): %s\n", 37 partition->ContainsFileSystem() ? "true" : "false"); 38 printf("\tContainsPartitioningSystem(): %s\n\n", 39 partition->ContainsPartitioningSystem() ? "true" : "false"); 40 printf("\tIsDevice(): %s\n", partition->IsDevice() ? "true" : "false"); 41 printf("\tIsReadOnly(): %s\n", partition->IsReadOnly() ? "true" : "false"); 42 printf("\tIsMounted(): %s\n", partition->IsMounted() ? "true" : "false"); 43 printf("\tIsBusy(): %s\n\n", partition->IsBusy() ? "true" : "false"); 44 printf("\tFlags(): %lx\n\n", partition->Flags()); 45 printf("\tName(): %s\n", partition->Name()); 46 printf("\tContentName(): %s\n", partition->ContentName()); 47 printf("\tType(): %s\n", partition->Type()); 48 printf("\tContentType(): %s\n", partition->ContentType()); 49 printf("\tID(): %lx\n\n", partition->ID()); 50 } 51 52 53 bool 54 is_valid_partitionable_space(size_t size) 55 { 56 // TODO: remove this again, the DiskDeviceAPI should 57 // not even show these spaces to begin with 58 return size >= 8 * 1024 * 1024; 59 } 60 61 62 // #pragma mark - SpaceIDMap 63 64 65 SpaceIDMap::SpaceIDMap() 66 : 67 HashMap<HashString, partition_id>(), 68 fNextSpaceID(-2) 69 { 70 } 71 72 73 SpaceIDMap::~SpaceIDMap() 74 { 75 } 76 77 78 partition_id 79 SpaceIDMap::SpaceIDFor(partition_id parentID, off_t spaceOffset) 80 { 81 BString key; 82 key << parentID << ':' << (uint64)spaceOffset; 83 84 if (ContainsKey(key.String())) 85 return Get(key.String()); 86 87 partition_id newID = fNextSpaceID--; 88 Put(key.String(), newID); 89 90 return newID; 91 } 92 93 94 SizeSlider::SizeSlider(const char* name, const char* label, 95 BMessage* message, int32 minValue, int32 maxValue) 96 : 97 BSlider(name, label, message, minValue, maxValue, 98 B_HORIZONTAL, B_TRIANGLE_THUMB), 99 fStartOffset(minValue), 100 fEndOffset(maxValue) 101 { 102 SetBarColor((rgb_color){ 0, 80, 255, 255 }); 103 char minString[64]; 104 char maxString[64]; 105 snprintf(minString, sizeof(minString), TR("Offset: %ld MB"), 106 fStartOffset); 107 snprintf(maxString, sizeof(maxString), TR("End: %ld MB"), 108 fEndOffset); 109 SetLimitLabels(minString, maxString); 110 } 111 112 113 SizeSlider::~SizeSlider() 114 { 115 } 116 117 118 const char* 119 SizeSlider::UpdateText() const 120 { 121 // TODO: Perhaps replace with string_for_size, but it looks like 122 // Value() and fStartOffset are always in MiB. 123 snprintf(fStatusLabel, sizeof(fStatusLabel), TR("%ld MiB"), 124 Value() - fStartOffset); 125 126 return fStatusLabel; 127 } 128 129 130 int32 131 SizeSlider::Size() 132 { 133 return Value() - fStartOffset; 134 } 135 136 137 int32 138 SizeSlider::Offset() 139 { 140 // TODO: This should be the changed offset once a double 141 // headed slider is implemented. 142 return fStartOffset; 143 } 144