BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / bootmanager / BootDrive.cpp
blob977a7bd2337c3776d6bfabab349166b1937a2258
1 /*
2 * Copyright 2011, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "BootDrive.h"
9 #include <DiskDevice.h>
10 #include <DiskDeviceRoster.h>
11 #include <Volume.h>
12 #include <VolumeRoster.h>
15 BootDrive::BootDrive(const char* path)
17 fPath(path)
22 BootDrive::~BootDrive()
27 BootMenu*
28 BootDrive::InstalledMenu(const BootMenuList& menus) const
30 for (int32 i = 0; i < menus.CountItems(); i++) {
31 BootMenu* menu = menus.ItemAt(i);
32 if (menu->IsInstalled(*this))
33 return menu;
35 return NULL;
39 status_t
40 BootDrive::CanMenuBeInstalled(const BootMenuList& menus) const
42 status_t status = B_ERROR;
44 for (int32 i = 0; i < menus.CountItems(); i++) {
45 status = menus.ItemAt(i)->CanBeInstalled(*this);
46 if (status == B_OK)
47 return status;
49 return status;
53 /*! Adds all boot menus from the list \a from that support the drive to \a to.
55 void
56 BootDrive::AddSupportedMenus(const BootMenuList& from, BootMenuList& to)
58 for (int32 i = 0; i < from.CountItems(); i++) {
59 BootMenu* menu = from.ItemAt(i);
60 if (menu->CanBeInstalled(*this))
61 to.AddItem(menu);
66 const char*
67 BootDrive::Path() const
69 return fPath.Path();
73 bool
74 BootDrive::IsBootDrive() const
76 BVolumeRoster volumeRoster;
77 BVolume volume;
78 if (volumeRoster.GetBootVolume(&volume) != B_OK)
79 return false;
81 BDiskDeviceRoster roster;
82 BDiskDevice device;
83 if (roster.FindPartitionByVolume(volume, &device, NULL) == B_OK) {
84 BPath path;
85 if (device.GetPath(&path) == B_OK && path == fPath)
86 return true;
89 return false;
93 status_t
94 BootDrive::GetDiskDevice(BDiskDevice& device) const
96 BDiskDeviceRoster roster;
97 return roster.GetDeviceForPath(fPath.Path(), &device);