Improve the Read-Only mounting suggestion for additional volumes.

* Following a suggestion by BGA, even non-boot Haiku volumes will get the
  read-only popup, although with less emphasis in the wording.
* BPartition does inherit the read-only flag from it's parent device when
  not yet mounted. This is now checked and at least prevents the read-only
  popup for volumes on read-only media. If I understood everything correctly,
  there is no easy way to tell if a file system supports writing.
* Updated indentation style in the header.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27343 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2008-09-06 08:02:59 +00:00
parent e53fa536eb
commit 19a1d666b3
2 changed files with 101 additions and 62 deletions
+62 -30
View File
@@ -182,8 +182,64 @@ AutoMounter::_MountVolumes(mount_mode normal, mount_mode removable,
} }
bool
AutoMounter::_SuggestMountFlags(const BPartition* partition,
uint32* _flags) const
{
uint32 mountFlags = 0;
bool askReadOnly = true;
bool isBFS = false;
if (partition->ContentType() != NULL
&& strcmp(partition->ContentType(), kPartitionTypeBFS) == 0) {
#if 0
askReadOnly = false;
#endif
isBFS = true;
}
if (partition->IsReadOnly())
askReadOnly = false;
if (askReadOnly) {
// Suggest to the user to mount read-only until Haiku is more mature.
// TODO: would be nice to skip this for file systems which don't have
// support for writing anyways.
BString string;
// TODO: Use distro name instead of "Haiku"...
if (!isBFS) {
string << "The file system on this volume is not the Haiku file "
"system. It is strongly suggested to mount it in read-only "
"mode. ";
} else {
string << "It is suggested to mount all additional Haiku volumes "
"in read-only mode. ";
}
string << "This will prevent unintentional data loss because of "
"errors in Haiku.";
BAlert* alert = new BAlert("Mount Warning", string.String(),
"Mount Read/Write", "Cancel", "Mount Read-only",
B_WIDTH_FROM_WIDEST, B_WARNING_ALERT);
int32 choice = alert->Go();
switch (choice) {
case 0:
break;
case 1:
return false;
case 2:
mountFlags |= B_MOUNT_READ_ONLY;
break;
}
}
*_flags = mountFlags;
return true;
}
void void
AutoMounter::_MountVolume(BMessage *message) AutoMounter::_MountVolume(const BMessage* message)
{ {
int32 id; int32 id;
if (message->FindInt32("id", &id) != B_OK) if (message->FindInt32("id", &id) != B_OK)
@@ -195,33 +251,9 @@ AutoMounter::_MountVolume(BMessage *message)
if (roster.GetPartitionWithID(id, &device, &partition) != B_OK) if (roster.GetPartitionWithID(id, &device, &partition) != B_OK)
return; return;
uint32 mountFlags = 0; uint32 mountFlags;
if (partition->ContentType() == NULL if (!_SuggestMountFlags(partition, &mountFlags))
|| strcmp(partition->ContentType(), kPartitionTypeBFS) != 0) { return;
// not a BFS volume, suggest to the user to mount read-only
// until Haiku is more mature.
// TODO: would be nice to skip this for file systems which don't have
// support for writing anyways.
BString string;
// TODO: Use distro name instead of "Haiku"...
string << "The file system on this volume is not the Haiku file "
"system. It is strongly suggested to mount it in read-only mode."
"This will prevent unintentional data loss because of errors "
"in Haiku.";
BAlert* alert = new BAlert("Mount Warning", string.String(),
"Mount Read/Write", "Cancel", "Mount Read-only",
B_WIDTH_FROM_WIDEST, B_WARNING_ALERT);
int32 choice = alert->Go();
switch (choice) {
case 0:
break;
case 1:
return;
case 2:
mountFlags |= B_MOUNT_READ_ONLY;
break;
}
}
status_t status = partition->Mount(NULL, mountFlags); status_t status = partition->Mount(NULL, mountFlags);
if (status < B_OK) { if (status < B_OK) {
@@ -237,7 +269,7 @@ AutoMounter::_SuggestForceUnmount(const char* name, status_t error)
{ {
BString text; BString text;
text << "Could not unmount disk \"" << name << "\":\n\t" << strerror(error); text << "Could not unmount disk \"" << name << "\":\n\t" << strerror(error);
text << "\n\nShould I force unmounting the disk?\n\n" text << "\n\nShould unmounting be forced?\n\n"
"Note: if an application is currently writing to the volume, unmounting" "Note: if an application is currently writing to the volume, unmounting"
" it now might result in loss of data.\n"; " it now might result in loss of data.\n";
@@ -510,7 +542,7 @@ AutoMounter::GetSettings(BMessage *message)
void void
AutoMounter::MessageReceived(BMessage *message) AutoMounter::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case kMsgInitialScan: case kMsgInitialScan:
+39 -32
View File
@@ -57,49 +57,56 @@ const uint32 kVolumeMounted = 'vmtd';
// #pragma mark - Haiku Disk Device API // #pragma mark - Haiku Disk Device API
class AutoMounter : public BLooper { class AutoMounter : public BLooper {
public: public:
AutoMounter(); AutoMounter();
virtual ~AutoMounter(); virtual ~AutoMounter();
virtual bool QuitRequested(); virtual bool QuitRequested();
void GetSettings(BMessage* message); void GetSettings(BMessage* message);
private: private:
enum mount_mode { enum mount_mode {
kNoVolumes, kNoVolumes,
kOnlyBFSVolumes, kOnlyBFSVolumes,
kAllVolumes, kAllVolumes,
kRestorePreviousVolumes kRestorePreviousVolumes
}; };
void _MountVolumes(mount_mode normal, mount_mode removable, bool _SuggestMountFlags(const BPartition* partition,
bool initialRescan); uint32* _flags) const;
void _MountVolume(BMessage* message); void _MountVolumes(mount_mode normal,
bool _SuggestForceUnmount(const char* name, status_t error); mount_mode removable, bool initialRescan);
void _ReportUnmountError(const char* name, status_t error); void _MountVolume(const BMessage* message);
void _UnmountAndEjectVolume(BPartition* partition, BPath& mountPoint, bool _SuggestForceUnmount(const char* name,
const char* name); status_t error);
void _UnmountAndEjectVolume(BMessage* message); void _ReportUnmountError(const char* name,
status_t error);
void _UnmountAndEjectVolume(BPartition* partition,
BPath& mountPoint, const char* name);
void _UnmountAndEjectVolume(BMessage* message);
void _FromMode(mount_mode mode, bool& all, bool& bfs, bool& restore); void _FromMode(mount_mode mode, bool& all,
mount_mode _ToMode(bool all, bool bfs, bool restore = false); bool& bfs, bool& restore);
void _UpdateSettingsFromMessage(BMessage* message); mount_mode _ToMode(bool all, bool bfs,
void _ReadSettings(); bool restore = false);
void _WriteSettings();
virtual void MessageReceived(BMessage* message); void _UpdateSettingsFromMessage(BMessage* message);
void _ReadSettings();
void _WriteSettings();
private: virtual void MessageReceived(BMessage* message);
mount_mode fNormalMode;
mount_mode fRemovableMode;
BFile fPrefsFile; private:
BMessage fSettings; mount_mode fNormalMode;
mount_mode fRemovableMode;
BFile fPrefsFile;
BMessage fSettings;
}; };
#else // !__HAIKU__ #else // !__HAIKU__
// #pragma mark - R5 DeviceMap API // #pragma mark - R5 DeviceMap API
const uint32 kSuspendAutomounter = 'amsp'; const uint32 kSuspendAutomounter = 'amsp';
const uint32 kResumeAutomounter = 'amsr'; const uint32 kResumeAutomounter = 'amsr';