void ControlsView::VolumeTabView::AttachedToWindow() { // Populate the menu with the persistent volumes. fVolumeRoster = new BVolumeRoster(); BVolume tempVolume; while (fVolumeRoster->GetNextVolume(&tempVolume) == B_OK) { if (!tempVolume.IsPersistent()) continue; char name[B_PATH_NAME_LENGTH]; if (tempVolume.GetName(name) != B_OK) continue; if (strcmp(name, "system") == 0 || strcmp(name, "config") == 0) { // Don't include virtual volumes. continue; } BVolume* volume = new BVolume(tempVolume); VolumeView* volumeView = new VolumeView(name, volume); VolumeTab* volumeTab = new VolumeTab(volume); AddTab(volumeView, volumeTab); } // Begin watching mount and unmount events. fVolumeRoster->StartWatching(BMessenger(this)); }
bool BNavMenu::StartBuildingItemList() { BEntry entry; if (fNavDir.device < 0 || entry.SetTo(&fNavDir) != B_OK || !entry.Exists()) return false; fItemList = new BObjectList<BMenuItem>(50); fIteratingDesktop = false; BDirectory parent; status_t status = entry.GetParent(&parent); // if ref is the root item then build list of volume root dirs fFlags = uint8((fFlags & ~kVolumesOnly) | (status == B_ENTRY_NOT_FOUND ? kVolumesOnly : 0)); if (fFlags & kVolumesOnly) return true; Model startModel(&entry, true); if (startModel.InitCheck() != B_OK || !startModel.IsContainer()) return false; if (startModel.IsQuery()) fContainer = new QueryEntryListCollection(&startModel); else if (FSIsDeskDir(&entry)) { fIteratingDesktop = true; fContainer = DesktopPoseView::InitDesktopDirentIterator(0, startModel.EntryRef()); AddRootItemsIfNeeded(); } else if (FSIsTrashDir(&entry)) { // the trash window needs to display a union of all the // trash folders from all the mounted volumes BVolumeRoster volRoster; volRoster.Rewind(); BVolume volume; fContainer = new EntryIteratorList(); while (volRoster.GetNextVolume(&volume) == B_OK) { if (!volume.IsPersistent()) continue; BDirectory trashDir; if (FSGetTrashDir(&trashDir, volume.Device()) == B_OK) dynamic_cast<EntryIteratorList *>(fContainer)-> AddItem(new DirectoryEntryList(trashDir)); } } else fContainer = new DirectoryEntryList(*dynamic_cast<BDirectory *> (startModel.Node())); if (fContainer == NULL || fContainer->InitCheck() != B_OK) return false; fContainer->Rewind(); return true; }
status_t CDDBQuery::_OpenContentFile(const int32 &discID) { // Makes sure that the lookup has a valid file to work with for the CD // content. Returns true if there is an existing file, false if a lookup is // required. BFile file; BString predicate; predicate << "CD:key == " << discID; entry_ref ref; BVolumeRoster roster; BVolume volume; roster.Rewind(); while (roster.GetNextVolume(&volume) == B_OK) { if (volume.IsReadOnly() || !volume.IsPersistent() || !volume.KnowsAttr() || !volume.KnowsQuery()) continue; // make sure the volume we are looking at is indexed right fs_create_index(volume.Device(), "CD:key", B_INT32_TYPE, 0); BQuery query; query.SetVolume(&volume); query.SetPredicate(predicate.String()); if (query.Fetch() != B_OK) continue; if (query.GetNextRef(&ref) == B_OK) break; } status_t status = fCDData.Load(ref); if (status == B_NO_INIT) { // We receive this error when the Load() function couldn't load the // track times This just means that we get it from the SCSI data given // to us in SetToCD vector<CDAudioTime> times; GetTrackTimes(&fSCSIData,times); for (int32 i = 0; i < fCDData.CountTracks(); i++) { CDAudioTime *item = fCDData.TrackTimeAt(i); *item = times[i + 1] - times[i]; } status = B_OK; } return status; }
void TTracker::InstallIndices() { BVolumeRoster roster; BVolume volume; roster.Rewind(); while (roster.GetNextVolume(&volume) == B_OK) { if (volume.IsReadOnly() || !volume.IsPersistent() || !volume.KnowsAttr() || !volume.KnowsQuery()) continue; InstallIndices(volume.Device()); } }
void BSlowContextMenu::AddRootItemsIfNeeded() { BVolumeRoster roster; roster.Rewind(); BVolume volume; while (roster.GetNextVolume(&volume) == B_OK) { BDirectory root; BEntry entry; if (!volume.IsPersistent() || volume.GetRootDirectory(&root) != B_OK || root.GetEntry(&entry) != B_OK) continue; Model model(&entry); AddOneItem(&model); } }
void BTrashWatcher::WatchTrashDirs() { BVolumeRoster volRoster; volRoster.Rewind(); BVolume volume; while (volRoster.GetNextVolume(&volume) == B_OK) { if (volume.IsReadOnly() || !volume.IsPersistent()) continue; BDirectory trashDir; if (FSGetTrashDir(&trashDir, volume.Device()) == B_OK) { node_ref trash_node; trashDir.GetNodeRef(&trash_node); watch_node(&trash_node, B_WATCH_DIRECTORY, this); fTrashNodeList.AddItem(new node_ref(trash_node)); } } }
void BSlowContextMenu::BuildVolumeMenu() { BVolumeRoster roster; BVolume volume; roster.Rewind(); while (roster.GetNextVolume(&volume) == B_OK) { if (!volume.IsPersistent()) continue; BDirectory startDir; if (volume.GetRootDirectory(&startDir) == B_OK) { BEntry entry; startDir.GetEntry(&entry); Model *model = new Model(&entry); if (model->InitCheck() != B_OK) { delete model; continue; } BNavMenu *menu = new BNavMenu(model->Name(), fMessage.what, fMessenger, fParentWindow, fTypesList); menu->SetNavDir(model->EntryRef()); menu->InitTrackingHook(fTrackingHook.fTrackingHook, &(fTrackingHook.fTarget), fTrackingHook.fDragMessage); ASSERT(menu->Name()); ModelMenuItem *item = new ModelMenuItem(model, menu); BMessage *message = new BMessage(fMessage); message->AddRef("refs", model->EntryRef()); item->SetMessage(message); fItemList->AddItem(item); ASSERT(item->Label()); } } }
bool BTrashWatcher::CheckTrashDirs() { BVolumeRoster volRoster; volRoster.Rewind(); BVolume volume; while (volRoster.GetNextVolume(&volume) == B_OK) { if (volume.IsReadOnly() || !volume.IsPersistent()) continue; BDirectory trashDir; FSGetTrashDir(&trashDir, volume.Device()); trashDir.Rewind(); BEntry entry; if (trashDir.GetNextEntry(&entry) == B_OK) return true; } return false; }
status_t PackageView::_InstallTypeChanged(int32 index) { if (index < 0) return B_ERROR; // Clear the choice list for (int32 i = fDestination->CountItems() - 1; i >= 0; i--) { BMenuItem* item = fDestination->RemoveItem(i); delete item; } fCurrentType = index; pkg_profile* profile = fInfo.GetProfile(index); if (profile == NULL) return B_ERROR; BString typeDescription = profile->description; if (typeDescription.IsEmpty()) typeDescription = profile->name; fInstallTypeDescriptionView->SetText(typeDescription.String()); BPath path; BVolume volume; if (profile->path_type == P_INSTALL_PATH) { BMenuItem* item = NULL; if (find_directory(B_SYSTEM_NONPACKAGED_DIRECTORY, &path) == B_OK) { dev_t device = dev_for_path(path.Path()); if (volume.SetTo(device) == B_OK && !volume.IsReadOnly() && path.Append("apps") == B_OK) { item = _AddDestinationMenuItem(path.Path(), volume.FreeBytes(), path.Path()); } } if (item != NULL) { item->SetMarked(true); fCurrentPath.SetTo(path.Path()); fDestination->AddSeparatorItem(); } _AddMenuItem(B_TRANSLATE("Other" B_UTF8_ELLIPSIS), new BMessage(P_MSG_OPEN_PANEL), fDestination); fDestField->SetEnabled(true); } else if (profile->path_type == P_USER_PATH) { bool defaultPathSet = false; BVolumeRoster roster; while (roster.GetNextVolume(&volume) != B_BAD_VALUE) { BDirectory mountPoint; if (volume.IsReadOnly() || !volume.IsPersistent() || volume.GetRootDirectory(&mountPoint) != B_OK) { continue; } if (path.SetTo(&mountPoint, NULL) != B_OK) continue; char volumeName[B_FILE_NAME_LENGTH]; volume.GetName(volumeName); BMenuItem* item = _AddDestinationMenuItem(volumeName, volume.FreeBytes(), path.Path()); // The first volume becomes the default element if (!defaultPathSet) { item->SetMarked(true); fCurrentPath.SetTo(path.Path()); defaultPathSet = true; } } fDestField->SetEnabled(true); } else fDestField->SetEnabled(false); return B_OK; }
status_t ExtractQueryVolumes(BNode *node, vollist *volumes) { int32 length = 0; char *attr = ReadAttribute(*node, kTrackerQueryVolume, &length); BVolumeRoster roster; if (attr == NULL) { roster.Rewind(); BVolume vol; while (roster.GetNextVolume(&vol) == B_NO_ERROR) { if ((vol.IsPersistent() == true) && (vol.KnowsQuery() == true)) { volumes->push_back(vol); }; }; } else { BMessage msg; msg.Unflatten(attr); // !*YOINK*!d from that project... with the funny little doggie as a logo... // OpenTracker, that's it! time_t created; off_t capacity; for (int32 index = 0; msg.FindInt32("creationDate", index, &created) == B_OK; index++) { if ((msg.FindInt32("creationDate", index, &created) != B_OK) || (msg.FindInt64("capacity", index, &capacity) != B_OK)) return B_ERROR; BVolume volume; BString deviceName = ""; BString volumeName = ""; BString fshName = ""; if (msg.FindString("deviceName", &deviceName) == B_OK && msg.FindString("volumeName", &volumeName) == B_OK && msg.FindString("fshName", &fshName) == B_OK) { // New style volume identifiers: We have a couple of characteristics, // and compute a score from them. The volume with the greatest score // (if over a certain threshold) is the one we're looking for. We // pick the first volume, in case there is more than one with the // same score. int foundScore = -1; roster.Rewind(); char name[B_FILE_NAME_LENGTH]; while (roster.GetNextVolume(&volume) == B_OK) { if (volume.IsPersistent() && volume.KnowsQuery()) { // get creation time and fs_info BDirectory root; volume.GetRootDirectory(&root); time_t cmpCreated; fs_info info; if (root.GetCreationTime(&cmpCreated) == B_OK && fs_stat_dev(volume.Device(), &info) == 0) { // compute the score int score = 0; // creation time if (created == cmpCreated) score += 5; // capacity if (capacity == volume.Capacity()) score += 4; // device name if (deviceName == info.device_name) score += 3; // volume name if (volumeName == info.volume_name) score += 2; // fsh name if (fshName == info.fsh_name) score += 1; // check score if (score >= 9 && score > foundScore) { volume.GetName(name); volumes->push_back(volume); } } } } } else { // Old style volume identifiers: We have only creation time and // capacity. Both must match. roster.Rewind(); while (roster.GetNextVolume(&volume) == B_OK) if (volume.IsPersistent() && volume.KnowsQuery()) { BDirectory root; volume.GetRootDirectory(&root); time_t cmpCreated; root.GetCreationTime(&cmpCreated); if (created == cmpCreated && capacity == volume.Capacity()) { volumes->push_back(volume); } } } }; }; return B_OK; };
QueryEntryListCollection::QueryEntryListCollection(Model* model, BHandler* target, PoseList* oldPoseList) : fQueryListRep(new QueryListRep(new BObjectList<BQuery>(5, true))) { Rewind(); attr_info info; BQuery query; if (!model->Node()) { fStatus = B_ERROR; return; } // read the actual query string fStatus = model->Node()->GetAttrInfo(kAttrQueryString, &info); if (fStatus != B_OK) return; BString buffer; if (model->Node()->ReadAttr(kAttrQueryString, B_STRING_TYPE, 0, buffer.LockBuffer((int32)info.size), (size_t)info.size) != info.size) { fStatus = B_ERROR; return; } buffer.UnlockBuffer(); // read the extra options MoreOptionsStruct saveMoreOptions; if (ReadAttr(model->Node(), kAttrQueryMoreOptions, kAttrQueryMoreOptionsForeign, B_RAW_TYPE, 0, &saveMoreOptions, sizeof(MoreOptionsStruct), &MoreOptionsStruct::EndianSwap) != kReadAttrFailed) { fQueryListRep->fShowResultsFromTrash = saveMoreOptions.searchTrash; } fStatus = query.SetPredicate(buffer.String()); fQueryListRep->fOldPoseList = oldPoseList; fQueryListRep->fDynamicDateQuery = false; fQueryListRep->fRefreshEveryHour = false; fQueryListRep->fRefreshEveryMinute = false; if (model->Node()->ReadAttr(kAttrDynamicDateQuery, B_BOOL_TYPE, 0, &fQueryListRep->fDynamicDateQuery, sizeof(bool)) != sizeof(bool)) { fQueryListRep->fDynamicDateQuery = false; } if (fQueryListRep->fDynamicDateQuery) { // only refresh every minute on debug builds fQueryListRep->fRefreshEveryMinute = buffer.IFindFirst("second") != -1 || buffer.IFindFirst("minute") != -1; fQueryListRep->fRefreshEveryHour = fQueryListRep->fRefreshEveryMinute || buffer.IFindFirst("hour") != -1; #if !DEBUG // don't refresh every minute unless we are running debug build fQueryListRep->fRefreshEveryMinute = false; #endif } if (fStatus != B_OK) return; bool searchAllVolumes = true; status_t result = B_OK; // get volumes to perform query on if (model->Node()->GetAttrInfo(kAttrQueryVolume, &info) == B_OK) { char* buffer = NULL; if ((buffer = (char*)malloc((size_t)info.size)) != NULL && model->Node()->ReadAttr(kAttrQueryVolume, B_MESSAGE_TYPE, 0, buffer, (size_t)info.size) == info.size) { BMessage message; if (message.Unflatten(buffer) == B_OK) { for (int32 index = 0; ;index++) { ASSERT(index < 100); BVolume volume; // match a volume with the info embedded in // the message result = MatchArchivedVolume(&volume, &message, index); if (result == B_OK) { // start the query on this volume result = FetchOneQuery(&query, target, fQueryListRep->fQueryList, &volume); if (result != B_OK) continue; searchAllVolumes = false; } else if (result != B_DEV_BAD_DRIVE_NUM) { // if B_DEV_BAD_DRIVE_NUM, the volume just isn't // mounted this time around, keep looking for more // if other error, bail break; } } } } free(buffer); } if (searchAllVolumes) { // no specific volumes embedded in query, search everything BVolumeRoster roster; BVolume volume; roster.Rewind(); while (roster.GetNextVolume(&volume) == B_OK) if (volume.IsPersistent() && volume.KnowsQuery()) { result = FetchOneQuery(&query, target, fQueryListRep->fQueryList, &volume); if (result != B_OK) continue; } } fStatus = B_OK; return; }
status_t Settings::ReadSwapSettings() { void* settings = load_driver_settings(kVirtualMemorySettings); if (settings == NULL) return kErrorSettingsNotFound; CObjectDeleter<void, status_t> settingDeleter(settings, &unload_driver_settings); const char* enabled = get_driver_parameter(settings, "vm", NULL, NULL); const char* automatic = get_driver_parameter(settings, "swap_auto", NULL, NULL); const char* size = get_driver_parameter(settings, "swap_size", NULL, NULL); const char* volume = get_driver_parameter(settings, "swap_volume_name", NULL, NULL); const char* device = get_driver_parameter(settings, "swap_volume_device", NULL, NULL); const char* filesystem = get_driver_parameter(settings, "swap_volume_filesystem", NULL, NULL); const char* capacity = get_driver_parameter(settings, "swap_volume_capacity", NULL, NULL); if (enabled == NULL || automatic == NULL || size == NULL || device == NULL || volume == NULL || capacity == NULL || filesystem == NULL) return kErrorSettingsInvalid; off_t volCapacity = atoll(capacity); SetSwapEnabled(get_driver_boolean_parameter(settings, "vm", true, false)); SetSwapAutomatic(get_driver_boolean_parameter(settings, "swap_auto", true, false)); SetSwapSize(atoll(size)); int32 bestScore = -1; dev_t bestVol = -1; BVolume vol; fs_info volStat; BVolumeRoster roster; while (roster.GetNextVolume(&vol) == B_OK) { if (!vol.IsPersistent() || vol.IsReadOnly() || vol.IsRemovable() || vol.IsShared()) continue; if (fs_stat_dev(vol.Device(), &volStat) == 0) { int32 score = 0; if (strcmp(volume, volStat.volume_name) == 0) score += 4; if (strcmp(device, volStat.device_name) == 0) score += 3; if (volCapacity == volStat.total_blocks * volStat.block_size) score += 2; if (strcmp(filesystem, volStat.fsh_name) == 0) score += 1; if (score >= 4 && score > bestScore) { bestVol = vol.Device(); bestScore = score; } } } SetSwapVolume(bestVol); fInitialSettings = fCurrentSettings; if (bestVol < 0) return kErrorVolumeNotFound; return B_OK; }