1*49c044abSAxel Dörfler /* 2*49c044abSAxel Dörfler * Copyright 2011, Axel Dörfler, axeld@pinc-software.de. 3*49c044abSAxel Dörfler * Distributed under the terms of the MIT License. 4*49c044abSAxel Dörfler */ 5*49c044abSAxel Dörfler 6*49c044abSAxel Dörfler 7*49c044abSAxel Dörfler #include "BootDrive.h" 8*49c044abSAxel Dörfler 9*49c044abSAxel Dörfler #include <DiskDevice.h> 10*49c044abSAxel Dörfler #include <DiskDeviceRoster.h> 11*49c044abSAxel Dörfler #include <Volume.h> 12*49c044abSAxel Dörfler #include <VolumeRoster.h> 13*49c044abSAxel Dörfler 14*49c044abSAxel Dörfler BootDrive(const char * path)15*49c044abSAxel DörflerBootDrive::BootDrive(const char* path) 16*49c044abSAxel Dörfler : 17*49c044abSAxel Dörfler fPath(path) 18*49c044abSAxel Dörfler { 19*49c044abSAxel Dörfler } 20*49c044abSAxel Dörfler 21*49c044abSAxel Dörfler ~BootDrive()22*49c044abSAxel DörflerBootDrive::~BootDrive() 23*49c044abSAxel Dörfler { 24*49c044abSAxel Dörfler } 25*49c044abSAxel Dörfler 26*49c044abSAxel Dörfler 27*49c044abSAxel Dörfler BootMenu* InstalledMenu(const BootMenuList & menus) const28*49c044abSAxel DörflerBootDrive::InstalledMenu(const BootMenuList& menus) const 29*49c044abSAxel Dörfler { 30*49c044abSAxel Dörfler for (int32 i = 0; i < menus.CountItems(); i++) { 31*49c044abSAxel Dörfler BootMenu* menu = menus.ItemAt(i); 32*49c044abSAxel Dörfler if (menu->IsInstalled(*this)) 33*49c044abSAxel Dörfler return menu; 34*49c044abSAxel Dörfler } 35*49c044abSAxel Dörfler return NULL; 36*49c044abSAxel Dörfler } 37*49c044abSAxel Dörfler 38*49c044abSAxel Dörfler 39*49c044abSAxel Dörfler status_t CanMenuBeInstalled(const BootMenuList & menus) const40*49c044abSAxel DörflerBootDrive::CanMenuBeInstalled(const BootMenuList& menus) const 41*49c044abSAxel Dörfler { 42*49c044abSAxel Dörfler status_t status = B_ERROR; 43*49c044abSAxel Dörfler 44*49c044abSAxel Dörfler for (int32 i = 0; i < menus.CountItems(); i++) { 45*49c044abSAxel Dörfler status = menus.ItemAt(i)->CanBeInstalled(*this); 46*49c044abSAxel Dörfler if (status == B_OK) 47*49c044abSAxel Dörfler return status; 48*49c044abSAxel Dörfler } 49*49c044abSAxel Dörfler return status; 50*49c044abSAxel Dörfler } 51*49c044abSAxel Dörfler 52*49c044abSAxel Dörfler 53*49c044abSAxel Dörfler /*! Adds all boot menus from the list \a from that support the drive to \a to. 54*49c044abSAxel Dörfler */ 55*49c044abSAxel Dörfler void AddSupportedMenus(const BootMenuList & from,BootMenuList & to)56*49c044abSAxel DörflerBootDrive::AddSupportedMenus(const BootMenuList& from, BootMenuList& to) 57*49c044abSAxel Dörfler { 58*49c044abSAxel Dörfler for (int32 i = 0; i < from.CountItems(); i++) { 59*49c044abSAxel Dörfler BootMenu* menu = from.ItemAt(i); 60*49c044abSAxel Dörfler if (menu->CanBeInstalled(*this)) 61*49c044abSAxel Dörfler to.AddItem(menu); 62*49c044abSAxel Dörfler } 63*49c044abSAxel Dörfler } 64*49c044abSAxel Dörfler 65*49c044abSAxel Dörfler 66*49c044abSAxel Dörfler const char* Path() const67*49c044abSAxel DörflerBootDrive::Path() const 68*49c044abSAxel Dörfler { 69*49c044abSAxel Dörfler return fPath.Path(); 70*49c044abSAxel Dörfler } 71*49c044abSAxel Dörfler 72*49c044abSAxel Dörfler 73*49c044abSAxel Dörfler bool IsBootDrive() const74*49c044abSAxel DörflerBootDrive::IsBootDrive() const 75*49c044abSAxel Dörfler { 76*49c044abSAxel Dörfler BVolumeRoster volumeRoster; 77*49c044abSAxel Dörfler BVolume volume; 78*49c044abSAxel Dörfler if (volumeRoster.GetBootVolume(&volume) != B_OK) 79*49c044abSAxel Dörfler return false; 80*49c044abSAxel Dörfler 81*49c044abSAxel Dörfler BDiskDeviceRoster roster; 82*49c044abSAxel Dörfler BDiskDevice device; 83*49c044abSAxel Dörfler if (roster.FindPartitionByVolume(volume, &device, NULL) == B_OK) { 84*49c044abSAxel Dörfler BPath path; 85*49c044abSAxel Dörfler if (device.GetPath(&path) == B_OK && path == fPath) 86*49c044abSAxel Dörfler return true; 87*49c044abSAxel Dörfler } 88*49c044abSAxel Dörfler 89*49c044abSAxel Dörfler return false; 90*49c044abSAxel Dörfler } 91*49c044abSAxel Dörfler 92*49c044abSAxel Dörfler 93*49c044abSAxel Dörfler status_t GetDiskDevice(BDiskDevice & device) const94*49c044abSAxel DörflerBootDrive::GetDiskDevice(BDiskDevice& device) const 95*49c044abSAxel Dörfler { 96*49c044abSAxel Dörfler BDiskDeviceRoster roster; 97*49c044abSAxel Dörfler return roster.GetDeviceForPath(fPath.Path(), &device); 98*49c044abSAxel Dörfler } 99