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