149c044abSAxel Dörfler/*
249c044abSAxel Dörfler * Copyright 2011, Axel D��rfler, axeld@pinc-software.de.
349c044abSAxel Dörfler * Distributed under the terms of the MIT License.
449c044abSAxel Dörfler */
549c044abSAxel Dörfler
649c044abSAxel Dörfler
749c044abSAxel Dörfler#include "BootDrive.h"
849c044abSAxel Dörfler
949c044abSAxel Dörfler#include <DiskDevice.h>
1049c044abSAxel Dörfler#include <DiskDeviceRoster.h>
1149c044abSAxel Dörfler#include <Volume.h>
1249c044abSAxel Dörfler#include <VolumeRoster.h>
1349c044abSAxel Dörfler
1449c044abSAxel Dörfler
1549c044abSAxel DörflerBootDrive::BootDrive(const char* path)
1649c044abSAxel Dörfler	:
1749c044abSAxel Dörfler	fPath(path)
1849c044abSAxel Dörfler{
1949c044abSAxel Dörfler}
2049c044abSAxel Dörfler
2149c044abSAxel Dörfler
2249c044abSAxel DörflerBootDrive::~BootDrive()
2349c044abSAxel Dörfler{
2449c044abSAxel Dörfler}
2549c044abSAxel Dörfler
2649c044abSAxel Dörfler
2749c044abSAxel DörflerBootMenu*
2849c044abSAxel DörflerBootDrive::InstalledMenu(const BootMenuList& menus) const
2949c044abSAxel Dörfler{
3049c044abSAxel Dörfler	for (int32 i = 0; i < menus.CountItems(); i++) {
3149c044abSAxel Dörfler		BootMenu* menu = menus.ItemAt(i);
3249c044abSAxel Dörfler		if (menu->IsInstalled(*this))
3349c044abSAxel Dörfler			return menu;
3449c044abSAxel Dörfler	}
3549c044abSAxel Dörfler	return NULL;
3649c044abSAxel Dörfler}
3749c044abSAxel Dörfler
3849c044abSAxel Dörfler
3949c044abSAxel Dörflerstatus_t
4049c044abSAxel DörflerBootDrive::CanMenuBeInstalled(const BootMenuList& menus) const
4149c044abSAxel Dörfler{
4249c044abSAxel Dörfler	status_t status = B_ERROR;
4349c044abSAxel Dörfler
4449c044abSAxel Dörfler	for (int32 i = 0; i < menus.CountItems(); i++) {
4549c044abSAxel Dörfler		status = menus.ItemAt(i)->CanBeInstalled(*this);
4649c044abSAxel Dörfler		if (status == B_OK)
4749c044abSAxel Dörfler			return status;
4849c044abSAxel Dörfler	}
4949c044abSAxel Dörfler	return status;
5049c044abSAxel Dörfler}
5149c044abSAxel Dörfler
5249c044abSAxel Dörfler
5349c044abSAxel Dörfler/*!	Adds all boot menus from the list \a from that support the drive to \a to.
5449c044abSAxel Dörfler*/
5549c044abSAxel Dörflervoid
5649c044abSAxel DörflerBootDrive::AddSupportedMenus(const BootMenuList& from, BootMenuList& to)
5749c044abSAxel Dörfler{
5849c044abSAxel Dörfler	for (int32 i = 0; i < from.CountItems(); i++) {
5949c044abSAxel Dörfler		BootMenu* menu = from.ItemAt(i);
6049c044abSAxel Dörfler		if (menu->CanBeInstalled(*this))
6149c044abSAxel Dörfler			to.AddItem(menu);
6249c044abSAxel Dörfler	}
6349c044abSAxel Dörfler}
6449c044abSAxel Dörfler
6549c044abSAxel Dörfler
6649c044abSAxel Dörflerconst char*
6749c044abSAxel DörflerBootDrive::Path() const
6849c044abSAxel Dörfler{
6949c044abSAxel Dörfler	return fPath.Path();
7049c044abSAxel Dörfler}
7149c044abSAxel Dörfler
7249c044abSAxel Dörfler
7349c044abSAxel Dörflerbool
7449c044abSAxel DörflerBootDrive::IsBootDrive() const
7549c044abSAxel Dörfler{
7649c044abSAxel Dörfler	BVolumeRoster volumeRoster;
7749c044abSAxel Dörfler	BVolume volume;
7849c044abSAxel Dörfler	if (volumeRoster.GetBootVolume(&volume) != B_OK)
7949c044abSAxel Dörfler		return false;
8049c044abSAxel Dörfler
8149c044abSAxel Dörfler	BDiskDeviceRoster roster;
8249c044abSAxel Dörfler	BDiskDevice device;
8349c044abSAxel Dörfler	if (roster.FindPartitionByVolume(volume, &device, NULL) == B_OK) {
8449c044abSAxel Dörfler		BPath path;
8549c044abSAxel Dörfler		if (device.GetPath(&path) == B_OK && path == fPath)
8649c044abSAxel Dörfler			return true;
8749c044abSAxel Dörfler	}
8849c044abSAxel Dörfler
8949c044abSAxel Dörfler	return false;
9049c044abSAxel Dörfler}
9149c044abSAxel Dörfler
9249c044abSAxel Dörfler
9349c044abSAxel Dörflerstatus_t
9449c044abSAxel DörflerBootDrive::GetDiskDevice(BDiskDevice& device) const
9549c044abSAxel Dörfler{
9649c044abSAxel Dörfler	BDiskDeviceRoster roster;
9749c044abSAxel Dörfler	return roster.GetDeviceForPath(fPath.Path(), &device);
9849c044abSAxel Dörfler}