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 */ 10 11 #include "Support.h" 12 13 #include <stdio.h> 14 15 #include <Partition.h> 16 #include <String.h> 17 18 19 const char* 20 string_for_size(off_t size, char *string) 21 { 22 double kb = size / 1024.0; 23 if (kb < 1.0) { 24 sprintf(string, "%Ld B", size); 25 return string; 26 } 27 float mb = kb / 1024.0; 28 if (mb < 1.0) { 29 sprintf(string, "%3.1f KB", kb); 30 return string; 31 } 32 float gb = mb / 1024.0; 33 if (gb < 1.0) { 34 sprintf(string, "%3.1f MB", mb); 35 return string; 36 } 37 float tb = gb / 1024.0; 38 if (tb < 1.0) { 39 sprintf(string, "%3.1f GB", gb); 40 return string; 41 } 42 sprintf(string, "%.1f TB", tb); 43 return string; 44 } 45 46 47 void 48 dump_partition_info(const BPartition* partition) 49 { 50 char size[1024]; 51 printf("\tOffset(): %Ld\n", partition->Offset()); 52 printf("\tSize(): %s\n", string_for_size(partition->Size(),size)); 53 printf("\tContentSize(): %s\n", string_for_size(partition->ContentSize(), 54 size)); 55 printf("\tBlockSize(): %ld\n", partition->BlockSize()); 56 printf("\tIndex(): %ld\n", partition->Index()); 57 printf("\tStatus(): %ld\n\n", partition->Status()); 58 printf("\tContainsFileSystem(): %s\n", 59 partition->ContainsFileSystem() ? "true" : "false"); 60 printf("\tContainsPartitioningSystem(): %s\n\n", 61 partition->ContainsPartitioningSystem() ? "true" : "false"); 62 printf("\tIsDevice(): %s\n", partition->IsDevice() ? "true" : "false"); 63 printf("\tIsReadOnly(): %s\n", partition->IsReadOnly() ? "true" : "false"); 64 printf("\tIsMounted(): %s\n", partition->IsMounted() ? "true" : "false"); 65 printf("\tIsBusy(): %s\n\n", partition->IsBusy() ? "true" : "false"); 66 printf("\tFlags(): %lx\n\n", partition->Flags()); 67 printf("\tName(): %s\n", partition->Name()); 68 printf("\tContentName(): %s\n", partition->ContentName()); 69 printf("\tType(): %s\n", partition->Type()); 70 printf("\tContentType(): %s\n", partition->ContentType()); 71 printf("\tID(): %lx\n\n", partition->ID()); 72 } 73 74 75 bool 76 is_valid_partitionable_space(size_t size) 77 { 78 // TODO: remove this again, the DiskDeviceAPI should 79 // not even show these spaces to begin with 80 return size >= 8 * 1024 * 1024; 81 } 82 83 84 // #pragma mark - SpaceIDMap 85 86 87 SpaceIDMap::SpaceIDMap() 88 : HashMap<HashString, partition_id>(), 89 fNextSpaceID(-2) 90 { 91 } 92 93 94 SpaceIDMap::~SpaceIDMap() 95 { 96 } 97 98 99 partition_id 100 SpaceIDMap::SpaceIDFor(partition_id parentID, off_t spaceOffset) 101 { 102 BString key; 103 key << parentID << ':' << (uint64)spaceOffset; 104 105 if (ContainsKey(key.String())) 106 return Get(key.String()); 107 108 partition_id newID = fNextSpaceID--; 109 Put(key.String(), newID); 110 111 return newID; 112 } 113 114