Some initial work on using the BDiskDevice APIs in DriveSetup.

Early stages, so not usable yet. WIP!



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18082 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ithamar R. Adema
2006-07-09 20:16:11 +00:00
parent f9d5f90ecc
commit a4706a8cea
7 changed files with 253 additions and 271 deletions
+2
View File
@@ -1,5 +1,7 @@
SubDir HAIKU_TOP src preferences drivesetup ; SubDir HAIKU_TOP src preferences drivesetup ;
UsePrivateHeaders interface storage shared ;
AddResources DriveSetup : DriveSetup.rdef ; AddResources DriveSetup : DriveSetup.rdef ;
Preference DriveSetup : main.cpp MainWindow.cpp PosSettings.cpp ; Preference DriveSetup : main.cpp MainWindow.cpp PosSettings.cpp ;
+191 -85
View File
@@ -5,19 +5,69 @@
* *
*/ */
#ifndef MAIN_WINDOW_H #include "MainWindow.h"
#include "MainWindow.h" #include "PosSettings.h"
#endif #include <interface/MenuItem.h>
#include <interface/MenuBar.h>
#include <interface/Menu.h>
#include <interface/ColumnListView.h>
#include <interface/ColumnTypes.h>
#include <app/Application.h>
#include <storage/DiskDeviceVisitor.h>
#include <storage/DiskDevice.h>
#include <storage/Partition.h>
#include <storage/Path.h>
class DriveVisitor : public BDiskDeviceVisitor
{
public:
DriveVisitor(MainWindow* win);
bool Visit(BDiskDevice *device);
bool Visit(BPartition *partition, int32 level);
private:
MainWindow* fDSWindow;
};
const char*
SizeAsString(off_t size, char *string)
{
double kb = size / 1024.0;
if (kb < 1.0) {
sprintf(string, "%Ld B", size);
return string;
}
float mb = kb / 1024.0;
if (mb < 1.0) {
sprintf(string, "%3.1f KB", kb);
return string;
}
float gb = mb / 1024.0;
if (gb < 1.0) {
sprintf(string, "%3.1f MB", mb);
return string;
}
float tb = gb / 1024.0;
if (tb < 1.0) {
sprintf(string, "%3.1f GB", gb);
return string;
}
sprintf(string, "%.1f TB", tb);
return string;
}
/** /**
* Constructor. * Constructor.
* @param frame The size to make the window. * @param frame The size to make the window.
*/ */
MainWindow::MainWindow(BRect frame, PosSettings *Settings) MainWindow::MainWindow(BRect frame, PosSettings *Settings)
:BWindow(frame, "DriveSetup", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE){ : BWindow(frame, "DriveSetup", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
{
BRect bRect; BRect bRect;
BMenu *menu; BMenu *menu;
BMenu *tmpMenu; BMenu *tmpMenu;
@@ -28,7 +78,7 @@ MainWindow::MainWindow(BRect frame, PosSettings *Settings)
bRect = Bounds(); bRect = Bounds();
bRect.bottom = 18.0; bRect.bottom = 18.0;
rootMenu = new BMenuBar(bRect, "root menu"); BMenuBar* rootMenu = new BMenuBar(bRect, "root menu");
//Setup Mount menu //Setup Mount menu
menu = new BMenu("Mount"); menu = new BMenu("Mount");
menu->AddItem(new BMenuItem("Mount All Partitions", new BMessage(MOUNT_MOUNT_ALL_MSG), 'M')); menu->AddItem(new BMenuItem("Mount All Partitions", new BMessage(MOUNT_MOUNT_ALL_MSG), 'M'));
@@ -44,31 +94,45 @@ MainWindow::MainWindow(BRect frame, PosSettings *Settings)
//Setup Setup menu //Setup Setup menu
menu = new BMenu("Setup"); menu = new BMenu("Setup");
menu->AddItem(new BMenuItem("Format", new BMessage(SETUP_FORMAT_MSG), 'F')); menu->AddItem(new BMenuItem("Format", new BMessage(SETUP_FORMAT_MSG), 'F'));
tmpMenu = new BMenu("Partition"); tmpMenu = new BMenu("Partition");
tmpMenu->AddItem(new BMenuItem("apple...", new BMessage(SETUP_PARTITION_APPLE_MSG))); menu->AddItem(tmpMenu);
tmpMenu->AddItem(new BMenuItem("intel...", new BMessage(SETUP_PARTITION_INTEL_MSG))); tmpMenu = new BMenu("Initialize");
menu->AddItem(tmpMenu); //add menu for formats
tmpMenu = new BMenu("Initialize"); menu->AddItem(tmpMenu);
//add menu for formats
menu->AddItem(tmpMenu);
rootMenu->AddItem(menu); rootMenu->AddItem(menu);
//Setup Options menu //Setup Options menu
menu = new BMenu("Options"); menu = new BMenu("Options");
menu->AddItem(new BMenuItem("Eject", new BMessage(OPTIONS_EJECT_MSG), 'E')); menu->AddItem(new BMenuItem("Eject", new BMessage(OPTIONS_EJECT_MSG), 'E'));
menu->AddItem(new BMenuItem("Surface Test", new BMessage(OPTIONS_SURFACE_TEST_MSG), 'T')); menu->AddItem(new BMenuItem("Surface Test", new BMessage(OPTIONS_SURFACE_TEST_MSG), 'T'));
rootMenu->AddItem(menu); rootMenu->AddItem(menu);
//Setup Rescan menu //Setup Rescan menu
menu = new BMenu("Rescan"); menu = new BMenu("Rescan");
menu->AddItem(new BMenuItem("IDE", new BMessage(RESCAN_IDE_MSG))); menu->AddItem(new BMenuItem("IDE", new BMessage(RESCAN_IDE_MSG)));
menu->AddItem(new BMenuItem("SCSI", new BMessage(RESCAN_SCSI_MSG))); menu->AddItem(new BMenuItem("SCSI", new BMessage(RESCAN_SCSI_MSG)));
rootMenu->AddItem(menu); rootMenu->AddItem(menu);
AddChild(rootMenu); AddChild(rootMenu);
BRect r(Bounds());
r.top = rootMenu->Frame().bottom +1;
fListView = new BColumnListView(r, "storagelist", B_FOLLOW_ALL, 0, B_PLAIN_BORDER, true);
fListView->AddColumn(new BStringColumn("Device", 100, 500, 50, 0), 1);
fListView->AddColumn(new BStringColumn("Map style", 100, 500, 50, 0), 2);
fListView->AddColumn(new BStringColumn("Partition Type", 100, 500, 50, 0), 3);
fListView->AddColumn(new BStringColumn("Filesystem", 100, 500, 50, 0), 4);
fListView->AddColumn(new BStringColumn("Volume Name", 100, 500, 50, 0), 5);
fListView->AddColumn(new BStringColumn("Mounted At", 100, 500, 50, 0), 6);
fListView->AddColumn(new BStringColumn("Size", 100, 500, 50, 0), 7);
AddChild(fListView);
// Now visit all disks in the system and show their contents
DriveVisitor driveVisitor(this);
BPartition *partition = NULL;
BDiskDevice device;
fDDRoster.VisitEachPartition(&driveVisitor, &device, &partition);
} }
/** /**
@@ -99,16 +163,6 @@ void MainWindow::MessageReceived(BMessage *message){
printf("SETUP_FORMAT_MSG\n"); printf("SETUP_FORMAT_MSG\n");
break; break;
case SETUP_PARTITION_APPLE_MSG:
printf("SETUP_PARTITION_APPLE_MSG\n");
break;
case SETUP_PARTITION_INTEL_MSG:
printf("SETUP_PARTITION_INTEL_MSG\n");
break;
case SETUP_INITIALIZE_MSG: case SETUP_INITIALIZE_MSG:
printf("SETUP_INITIALIZE_MSG\n"); printf("SETUP_INITIALIZE_MSG\n");
@@ -143,66 +197,118 @@ void MainWindow::MessageReceived(BMessage *message){
} }
/** /**
* Quits and Saves. * Quits and Saves settings.
* Sets the swap size and turns the virtual memory on by writing to the
* /boot/home/config/settings/kernel/drivers/virtual_memory file.
*/ */
bool MainWindow::QuitRequested(){ bool
MainWindow::QuitRequested()
be_app->PostMessage(B_QUIT_REQUESTED); {
return(true); bool accepted = BWindow::QuitRequested();
if (accepted) {
fSettings->SetWindowPosition(Frame());
be_app->PostMessage(B_QUIT_REQUESTED);
}
return accepted;
} }
void MainWindow::FrameMoved(BPoint origin) static void
{//MainWindow::FrameMoved dump_partition_info(BPartition* partition)
fSettings->SetWindowPosition(Frame()); {
}//MainWindow::FrameMoved printf("\tOffset(): %Ld\n", partition->Offset());
printf("\tSize(): %Ld\n", partition->Size());
printf("\tContentSize(): %Ld\n", partition->ContentSize());
printf("\tBlockSize(): %ld\n", partition->BlockSize());
printf("\tIndex(): %ld\n", partition->Index());
printf("\tStatus(): %ld\n\n", partition->Status());
printf("\tContainsFileSystem(): %s\n", partition->ContainsFileSystem() ? "true" : "false");
printf("\tContainsPartitioningSystem(): %s\n\n", partition->ContainsPartitioningSystem() ? "true" : "false");
printf("\tIsDevice(): %s\n", partition->IsDevice() ? "true" : "false");
printf("\tIsReadOnly(): %s\n", partition->IsReadOnly() ? "true" : "false");
printf("\tIsMounted(): %s\n", partition->IsMounted() ? "true" : "false");
printf("\tIsBusy(): %s\n\n", partition->IsBusy() ? "true" : "false");
printf("\tFlags(): %lx\n\n", partition->Flags());
printf("\tName(): %s\n", partition->Name());
printf("\tContentName(): %s\n", partition->ContentName());
printf("\tType(): %s\n", partition->Type());
printf("\tContentType(): %s\n", partition->ContentType());
printf("\tID(): %x\n\n", partition->ID());
}
void MainWindow::AddDeviceInfo(dev_info d){ void
MainWindow::AddDrive(BDiskDevice* device)
{
printf("AddDrive(%p)\n", device);
BMenuItem *tmp; BPath path;
int cnt; if (device->GetPath(&path) == B_OK) {
BRow* row = new BRow();
row->SetField(new BStringField(path.Path()), 1);
printf("Got %s\n", d.device); printf("\tPath=%s\n", path.Path());
cnt = 0;
while(cnt < d.numParts){
if(d.parts[cnt].mounted){
//Check to see if we have to get rid of the <empty> item
if(strcmp(rootMenu->SubmenuAt(1)->ItemAt(0)->Label(), "<empty>") == 0){
rootMenu->SubmenuAt(1)->RemoveItem((int32) 0);
}//if
//add to Unmount menu
tmp = new BMenuItem(d.parts[cnt].mount_pt, new BMessage(UNMOUNT_UNMOUNT_SELECTED_MSG));
if(strcmp(d.parts[cnt].mount_pt, "/boot") == 0){
tmp->SetEnabled(false);
}//if
rootMenu->SubmenuAt(1)->AddItem(tmp);
}//if
//add to Mount menu
//This label comes from the type mapping
tmp = new BMenuItem(d.parts[cnt].fs, new BMessage(MOUNT_MOUNT_SELECTED_MSG));
if(d.parts[cnt].mounted){
tmp->SetEnabled(false);
}//if
rootMenu->SubmenuAt(0)->AddItem(tmp);
cnt++;
}//while
//send to view
}//SetDeviceInfo if (device->ContainsPartitioningSystem()) {
row->SetField(new BStringField(device->Type()), 3);
}
char size[1024];
row->SetField(new BStringField(SizeAsString(device->Size(), size)), 7);
fListView->AddRow(row);
}
dump_partition_info(device);
}
void
MainWindow::AddPartition(BPartition *partition, int32 level)
{
printf("AddPartition(%p, %d)\n", partition, level);
BPath path;
if (partition->GetPath(&path) == B_OK) {
BRow* row = new BRow();
row->SetField(new BStringField(path.Path()), 1);
printf("\tPath=%s\n", path.Path());
if (partition->ContainsFileSystem()) {
row->SetField(new BStringField(partition->Type()), 3); // Partition Type
row->SetField(new BStringField(partition->ContentType()), 4); // Filesystem
row->SetField(new BStringField(partition->ContentName()), 5); // Volume Name
if (partition->GetMountPoint(&path) == B_OK)
row->SetField(new BStringField(path.Path()), 6);
}
char size[1024];
row->SetField(new BStringField(SizeAsString(partition->Size(), size)), 7);
fListView->AddRow(row);
}
dump_partition_info(partition);
}
DriveVisitor::DriveVisitor(MainWindow* win)
: fDSWindow(win)
{
}
bool
DriveVisitor::Visit(BDiskDevice* device)
{
if (fDSWindow != NULL)
fDSWindow->AddDrive(device);
return false; // Don't stop yet!
}
bool
DriveVisitor::Visit(BPartition* partition, int32 level)
{
if (fDSWindow != NULL)
fDSWindow->AddPartition(partition, level);
return false; // Don't stop yet!
}
+32 -65
View File
@@ -4,82 +4,49 @@
*/ */
#ifndef MAIN_WINDOW_H #ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H
#define MAIN_WINDOW_H
#define MOUNT_MOUNT_ALL_MSG 'mall'
#define MOUNT_MOUNT_SELECTED_MSG 'msel'
#define UNMOUNT_UNMOUNT_SELECTED_MSG 'usel'
#define SETUP_FORMAT_MSG 'sfor'
#define SETUP_PARTITION_APPLE_MSG 'spaa'
#define SETUP_PARTITION_INTEL_MSG 'spai'
#define SETUP_INITIALIZE_MSG 'sini'
#define OPTIONS_EJECT_MSG 'oeje'
#define OPTIONS_SURFACE_TEST_MSG 'osut'
#define RESCAN_IDE_MSG 'ride'
#define RESCAN_SCSI_MSG 'rscs'
#ifndef _APPLICATION_H
#include <Application.h> #define MOUNT_MOUNT_ALL_MSG 'mall'
#define MOUNT_MOUNT_SELECTED_MSG 'msel'
#endif #define UNMOUNT_UNMOUNT_SELECTED_MSG 'usel'
#ifndef _WINDOW_H #define SETUP_FORMAT_MSG 'sfor'
#define SETUP_PARTITION_SELECTED_MSG 'spsl'
#include <Window.h> #define SETUP_INITIALIZE_MSG 'sini'
#define OPTIONS_EJECT_MSG 'oeje'
#endif #define OPTIONS_SURFACE_TEST_MSG 'osut'
#ifndef _MENU_BAR_H #define RESCAN_IDE_MSG 'ride'
#define RESCAN_SCSI_MSG 'rscs'
#include <MenuBar.h>
#endif
#ifndef _MENU_ITEM_H
#include <MenuItem.h>
#endif
#ifndef _RECT_H
#include <Rect.h>
#endif
#ifndef _STDIO_H
#include <stdio.h>
#endif
#ifndef POS_SETTINGS_H
#include "PosSettings.h"
#endif #include <interface/Window.h>
#ifndef STRUCTS_H #include <storage/DiskDeviceRoster.h>
#include "structs.h" // Forward declarations
class PosSettings;
#endif class BPartition;
class BDiskDevice;
class BColumnListView;
/** /**
* The main window of the app. * The main window of the app.
* *
* Sets up and displays everything you need for the app. * Sets up and displays everything you need for the app.
*/ */
class MainWindow : public BWindow{
class MainWindow : public BWindow
{
private: private:
PosSettings* fSettings;
PosSettings *fSettings; BDiskDeviceRoster fDDRoster;
BMenuBar *rootMenu; BColumnListView* fListView;
public: public:
MainWindow(BRect frame, PosSettings *fSettings); MainWindow(BRect frame, PosSettings *fSettings);
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message); bool QuitRequested();
virtual void FrameMoved(BPoint origin); void MessageReceived(BMessage *message);
void AddDeviceInfo(dev_info d);
// These are public for visitor....
void AddPartition(BPartition* partition, int32 level);
void AddDrive(BDiskDevice* device);
}; };
#endif #endif
+15 -24
View File
@@ -16,15 +16,14 @@
#include <stdio.h> #include <stdio.h>
const char PosSettings::kVMSettingsFile[] = "DriveSetup_prefs"; const char PosSettings::kSettingsFile[] = "DriveSetup_prefs";
PosSettings::PosSettings() PosSettings::PosSettings()
{//VMSettings::VMSettings {
BPath path; BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) == B_OK) if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) == B_OK)
{ {
path.Append(kVMSettingsFile); path.Append(kSettingsFile);
BFile file(path.Path(), B_READ_ONLY); BFile file(path.Path(), B_READ_ONLY);
if (file.InitCheck() != B_OK) if (file.InitCheck() != B_OK)
be_app->PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED);
@@ -34,7 +33,7 @@ PosSettings::PosSettings()
if (file.Read(&brCorner, sizeof(BPoint)) != sizeof(BPoint)) if (file.Read(&brCorner, sizeof(BPoint)) != sizeof(BPoint))
be_app->PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED);
} }
printf("VM settings file read.\n"); printf("settings file read.\n");
printf("=========================\n"); printf("=========================\n");
printf("fcorner read in as "); printf("fcorner read in as ");
fcorner.PrintToStream(); fcorner.PrintToStream();
@@ -53,42 +52,34 @@ PosSettings::PosSettings()
return; return;
// If they are not, lets just stick the window in the middle // If they are not, lets just stick the window in the middle
// of the screen. // of the screen.
//I don't want to deal with this now - MSM fWindowFrame = screen.Frame();
fWindowFrame.left = (fWindowFrame.right-269) /2;
/*fWindowFrame = screen.Frame();
fWindowFrame.left = (fWindowFrame.right-269)/2;
fWindowFrame.right = fWindowFrame.left + 269; fWindowFrame.right = fWindowFrame.left + 269;
fWindowFrame.top = (fWindowFrame.bottom-172)/2; fWindowFrame.top = (fWindowFrame.bottom-172) /2;
fWindowFrame.bottom = fWindowFrame.top + 172; fWindowFrame.bottom = fWindowFrame.top + 172;
*/ }
}//VMSettings::VMSettings
PosSettings::~PosSettings() PosSettings::~PosSettings()
{//VMSettings::~VMSettings {
//printf("enter\n");
BPath path; BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) < B_OK) if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) < B_OK)
return; return;
//printf("find_directory\n");
path.Append(kVMSettingsFile); path.Append(kSettingsFile);
//printf("path.Append\n");
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE); BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE);
//printf("create file\n");
if (file.InitCheck() == B_OK) if (file.InitCheck() == B_OK)
{ {
//printf("in if statement\n");
file.Write(&fcorner, sizeof(BPoint)); file.Write(&fcorner, sizeof(BPoint));
file.Write(&brCorner, sizeof(BPoint)); file.Write(&brCorner, sizeof(BPoint));
} }
//printf("exit\n"); }
}//MouseSettings::~MouseSettings
void PosSettings::SetWindowPosition(BRect f) void PosSettings::SetWindowPosition(BRect f)
{//VMSettings::SetWindowFrame {
fcorner.x=f.left; fcorner.x=f.left;
fcorner.y=f.top; fcorner.y=f.top;
brCorner.x=f.right; brCorner.x=f.right;
brCorner.y=f.bottom; brCorner.y=f.bottom;
brCorner.PrintToStream(); brCorner.PrintToStream();
}//VMSettings::SetWindowFrame }
+1 -1
View File
@@ -12,7 +12,7 @@ public :
void SetWindowPosition(BRect); void SetWindowPosition(BRect);
private: private:
static const char kVMSettingsFile[]; static const char kSettingsFile[];
BRect fWindowFrame; BRect fWindowFrame;
BPoint fcorner; BPoint fcorner;
BPoint brCorner; BPoint brCorner;
+7 -71
View File
@@ -6,16 +6,10 @@
* *
*/ */
#ifndef MAIN_WINDOW_H #include "MainWindow.h"
#include "main.h"
#include "MainWindow.h" #include "PosSettings.h"
#endif
#ifndef MAIN_H
#include "main.h"
#endif
/** /**
* Main method. * Main method.
@@ -41,77 +35,19 @@ int main(int, char**){
* Provides a contstructor for the application. * Provides a contstructor for the application.
*/ */
DriveSetup::DriveSetup() DriveSetup::DriveSetup()
:BApplication("application/x-vnd.MSM-DriveSetupPrefPanel"){ : BApplication("application/x-vnd.MSM-DriveSetupPrefPanel")
{
fSettings = new PosSettings(); fSettings = new PosSettings();
/* /*
* The main interface window. * The main interface window.
*/ */
MainWindow *Main; MainWindow *Main = new MainWindow(fSettings->WindowPosition(), fSettings);
dev_info devs;
partition_info partitions[4];
Main = new MainWindow(fSettings->WindowPosition(), fSettings);
//This section is to set up defaults that I can use for testing.
//set up floppy drive
partitions[0].type = 11;
partitions[0].fs = "dos";
partitions[0].name = "";
partitions[0].mount_pt = "";
partitions[0].size = 1.4;
partitions[0].mounted = FALSE;
devs.device = "/dev/disk/floppy";
devs.map = 1;
devs.numParts = 1;
devs.parts = partitions;
Main->AddDeviceInfo(devs);
partitions[0].type = 11;
partitions[0].fs = "dos";
partitions[0].name = "winxp";
partitions[0].mount_pt = "/winxp";
partitions[0].size = 5600.0;
partitions[0].mounted = TRUE;
partitions[1].type = 12;
partitions[1].fs = "dos";
partitions[1].name = "windata";
partitions[1].mount_pt = "/windata";
partitions[1].size = 3600.0;
partitions[1].mounted = TRUE;
partitions[2].type = 235;
partitions[2].fs = "Be File System";
partitions[2].name = "BeOS";
partitions[2].mount_pt = "/boot";
partitions[2].size = 4900.0;
partitions[2].mounted = TRUE;
devs.device = "/dev/disk/ide/ata/0/master/0";
devs.map = 1;
devs.numParts = 3;
devs.parts = partitions;
Main->AddDeviceInfo(devs);
partitions[0].type = 11;
partitions[0].fs = "iso9660";
partitions[0].name = "";
partitions[0].mount_pt = "/OUTLAWSTAR_D1";
partitions[0].size = 2200.0;
partitions[0].mounted = TRUE;
devs.device = "/dev/disk/ide/atapi/1/master/0";
devs.map = 2;
devs.numParts = 1;
devs.parts = partitions;
Main->AddDeviceInfo(devs);
//End set up of defaults
Main->Show(); Main->Show();
} }
DriveSetup::~DriveSetup() DriveSetup::~DriveSetup()
{ {
delete fSettings; delete fSettings;
} }
+5 -25
View File
@@ -4,30 +4,11 @@
*/ */
#ifndef MAIN_H #ifndef MAIN_H
#define MAIN_H
#define MAIN_H #include <Application.h>
#ifndef _APPLICATION_H class PosSettings;
#include <Application.h>
#endif
#ifndef _STDIO_H
#include <stdio.h>
#endif
#ifndef POS_SETTINGS_H
#include "PosSettings.h"
#endif
#ifndef STRUCTS_H
#include "structs.h"
#endif
/** /**
@@ -35,8 +16,8 @@
* *
* Gets everything going. * Gets everything going.
*/ */
class DriveSetup : public BApplication{ class DriveSetup : public BApplication
{
public: public:
/** /**
@@ -47,7 +28,6 @@
private: private:
PosSettings *fSettings; PosSettings *fSettings;
}; };
#endif #endif