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; };