void Feeder::StartWatching() { BVolume *volume = new BVolume ; while (fVolumeRoster.GetNextVolume(volume) != B_BAD_VALUE) { if ((volume->IsRemovable() && !fMonitorRemovableDevices) || !volume->KnowsQuery()) continue ; AddQuery(volume) ; volume = new BVolume ; } fVolumeRoster.StartWatching(this) ; }
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; }