* When inserting USB sticks, the read-only mount suggestion was completely
bypassed, same for invoking "Mount All". Now, the "initial scan" parameter is used to decide if the user should be alarmed. Basically, it means you get to decide for every mounted volume if you want it rather read-only. In the old code: - If you wanted a stick mounted read-only, you had to go to "Tracker Settings" and disabled auto-ejecting, unmount the stick, then re-mount to get it to ask you for read-only mounting. - But then, it would remember this setting, so when you unplugged the stick and then replugged it, it would mount it read-only again. This may be nice for later, but for now, I want to decide if I am willing to take the risk each time. * The new code also has the implication that when you plug a drive with more than one partition, you are being asked for each one. I extended the alert to also mention the partition name. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30716 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
05f452c37c
commit
3908951b11
@ -99,6 +99,70 @@ AutoMounter::~AutoMounter()
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
suggest_mount_flags(const BPartition* partition, uint32* _flags)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
BDiskSystem diskSystem;
|
||||
status_t status = partition->GetDiskSystem(&diskSystem);
|
||||
if (status == B_OK && !diskSystem.SupportsWriting())
|
||||
askReadOnly = false;
|
||||
|
||||
if (partition->IsReadOnly())
|
||||
askReadOnly = false;
|
||||
|
||||
if (askReadOnly) {
|
||||
// Suggest to the user to mount read-only until Haiku is more mature.
|
||||
BString string;
|
||||
string << "Mounting volume ";
|
||||
if (partition->ContentName() != NULL)
|
||||
string << "'" << partition->ContentName() << "'\n\n";
|
||||
else
|
||||
string << "<unnamed volume>\n\n";
|
||||
// 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);
|
||||
alert->SetShortcut(1, B_ESCAPE);
|
||||
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
|
||||
AutoMounter::_MountVolumes(mount_mode normal, mount_mode removable,
|
||||
bool initialRescan)
|
||||
@ -158,11 +222,18 @@ AutoMounter::_MountVolumes(mount_mode normal, mount_mode removable,
|
||||
}
|
||||
|
||||
uint32 mountFlags;
|
||||
BString mountFlagsKey(path.Path());
|
||||
mountFlagsKey << kMountFlagsKeyExtension;
|
||||
if (fPrevious.FindInt32(mountFlagsKey.String(),
|
||||
(int32*)&mountFlags) < B_OK) {
|
||||
mountFlags = 0;
|
||||
if (!fInitialRescan) {
|
||||
// Ask the user about mount flags if this is not the
|
||||
// initial scan.
|
||||
if (!suggest_mount_flags(partition, &mountFlags))
|
||||
return false;
|
||||
} else {
|
||||
BString mountFlagsKey(path.Path());
|
||||
mountFlagsKey << kMountFlagsKeyExtension;
|
||||
if (fPrevious.FindInt32(mountFlagsKey.String(),
|
||||
(int32*)&mountFlags) < B_OK) {
|
||||
mountFlags = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (partition->Mount(NULL, mountFlags) == B_OK
|
||||
@ -190,68 +261,6 @@ 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;
|
||||
}
|
||||
|
||||
BDiskSystem diskSystem;
|
||||
status_t status = partition->GetDiskSystem(&diskSystem);
|
||||
if (status == B_OK && !diskSystem.SupportsWriting())
|
||||
askReadOnly = false;
|
||||
|
||||
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);
|
||||
alert->SetShortcut(1, B_ESCAPE);
|
||||
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
|
||||
AutoMounter::_MountVolume(const BMessage* message)
|
||||
{
|
||||
@ -266,7 +275,7 @@ AutoMounter::_MountVolume(const BMessage* message)
|
||||
return;
|
||||
|
||||
uint32 mountFlags;
|
||||
if (!_SuggestMountFlags(partition, &mountFlags))
|
||||
if (!suggest_mount_flags(partition, &mountFlags))
|
||||
return;
|
||||
|
||||
status_t status = partition->Mount(NULL, mountFlags);
|
||||
@ -638,7 +647,8 @@ AutoMounter::MessageReceived(BMessage* message)
|
||||
break;
|
||||
|
||||
case B_DEVICE_UPDATE:
|
||||
message->PrintToStream();
|
||||
printf("B_DEVICE_UPDATE\n");
|
||||
message->PrintToStream();
|
||||
int32 event;
|
||||
if (message->FindInt32("event", &event) != B_OK
|
||||
|| (event != B_DEVICE_MEDIA_CHANGED
|
||||
|
@ -73,8 +73,6 @@ private:
|
||||
kRestorePreviousVolumes
|
||||
};
|
||||
|
||||
bool _SuggestMountFlags(const BPartition* partition,
|
||||
uint32* _flags) const;
|
||||
void _MountVolumes(mount_mode normal,
|
||||
mount_mode removable, bool initialRescan);
|
||||
void _MountVolume(const BMessage* message);
|
||||
|
Loading…
Reference in New Issue
Block a user