void AutoMounter::ReadyToRun() { // Do initial scan _MountVolumes(fNormalMode, fRemovableMode, true); BLaunchRoster().NotifyEvent(this, kInitialMountEvent); }
bool AutoMounter::_ScriptReceived(BMessage *message, int32 index, BMessage *specifier, int32 what, const char *property) { BMessage reply(B_REPLY); status_t err = B_BAD_SCRIPT_SYNTAX; switch (message->what) { case B_EXECUTE_PROPERTY: if (strcmp("InitialScan", property) == 0) { _MountVolumes(fNormalMode, fRemovableMode, true); err = reply.AddString("result", B_TRANSLATE("Previous volumes mounted.")); } break; } if (err == B_BAD_SCRIPT_SYNTAX) return false; if (err != B_OK) { reply.what = B_MESSAGE_NOT_UNDERSTOOD; reply.AddString("message", strerror(err)); } reply.AddInt32("error", err); message->SendReply(&reply); return true; }
void AutoMounter::MessageReceived(BMessage* message) { switch (message->what) { case kMountVolume: _MountVolume(message); break; case kUnmountVolume: _UnmountAndEjectVolume(message); break; case kSetAutomounterParams: { bool rescanNow = false; message->FindBool("rescanNow", &rescanNow); _UpdateSettingsFromMessage(message); _GetSettings(&fSettings); _WriteSettings(); if (rescanNow) _MountVolumes(fNormalMode, fRemovableMode); break; } case kGetAutomounterParams: { BMessage reply; _GetSettings(&reply); message->SendReply(&reply); break; } case kMountAllNow: _MountVolumes(kAllVolumes, kAllVolumes); break; case B_DEVICE_UPDATE: int32 event; if (message->FindInt32("event", &event) != B_OK || (event != B_DEVICE_MEDIA_CHANGED && event != B_DEVICE_ADDED)) break; partition_id deviceID; if (message->FindInt32("id", &deviceID) != B_OK) break; _MountVolumes(kNoVolumes, fRemovableMode, false, deviceID); break; #if 0 case B_NODE_MONITOR: { int32 opcode; if (message->FindInt32("opcode", &opcode) != B_OK) break; switch (opcode) { // The name of a mount point has changed case B_ENTRY_MOVED: { WRITELOG(("*** Received Mount Point Renamed Notification")); const char *newName; if (message->FindString("name", &newName) != B_OK) { WRITELOG(("ERROR: Couldn't find name field in update " "message")); PRINT_OBJECT(*message); break ; } // // When the node monitor reports a move, it gives the // parent device and inode that moved. The problem is // that the inode is the inode of root *in* the filesystem, // which is generally always the same number for every // filesystem of a type. // // What we'd really like is the device that the moved // volume is mounted on. Find this by using the // *new* name and directory, and then stat()ing that to // find the device. // dev_t parentDevice; if (message->FindInt32("device", &parentDevice) != B_OK) { WRITELOG(("ERROR: Couldn't find 'device' field in " "update message")); PRINT_OBJECT(*message); break; } ino_t toDirectory; if (message->FindInt64("to directory", &toDirectory) != B_OK) { WRITELOG(("ERROR: Couldn't find 'to directory' field " "in update message")); PRINT_OBJECT(*message); break; } entry_ref root_entry(parentDevice, toDirectory, newName); BNode entryNode(&root_entry); if (entryNode.InitCheck() != B_OK) { WRITELOG(("ERROR: Couldn't create mount point entry " "node: %s/n", strerror(entryNode.InitCheck()))); break; } node_ref mountPointNode; if (entryNode.GetNodeRef(&mountPointNode) != B_OK) { WRITELOG(("ERROR: Couldn't get node ref for new mount " "point")); break; } WRITELOG(("Attempt to rename device %li to %s", mountPointNode.device, newName)); Partition *partition = FindPartition(mountPointNode.device); if (partition != NULL) { WRITELOG(("Found device, changing name.")); BVolume mountVolume(partition->VolumeDeviceID()); BDirectory mountDir; mountVolume.GetRootDirectory(&mountDir); BPath dirPath(&mountDir, 0); partition->SetMountedAt(dirPath.Path()); partition->SetVolumeName(newName); break; } else { WRITELOG(("ERROR: Device %li does not appear to be " "present", mountPointNode.device)); } } } break; } #endif default: BLooper::MessageReceived(message); break; } }