static void copy_indexes(dev_t from, dev_t to, bool verbose) { DIR *indexes = fs_open_index_dir(from); if (verbose) puts("Copying indexes:"); while (dirent *dirent = fs_read_index_dir(indexes)) { if (!strcmp(dirent->d_name, "name") || !strcmp(dirent->d_name, "size") || !strcmp(dirent->d_name, "last_modified")) continue; index_info info; if (fs_stat_index(from, dirent->d_name, &info) != 0) { fprintf(stderr, "%s: Skipped index \"%s\": %s\n", kProgramName, dirent->d_name, strerror(errno)); continue; } if (fs_create_index(to, dirent->d_name, info.type, 0) != 0) { if (errno == B_BAD_VALUE || errno == B_FILE_EXISTS) { // B_BAD_VALUE is what BeOS returns here... continue; } fprintf(stderr, "%s: Could not create index \"%s\": %s\n", kProgramName, dirent->d_name, strerror(errno)); } else if (verbose) printf("\t%s\n", dirent->d_name); } }
status_t TaskFS::SetUpMimeTyp(void) { status_t err; //set the MimeType BMimeType mime(TASK_MIMETYPE); //later do better check bool valid = mime.IsInstalled(); if (!valid) { mime.Install(); mime.SetShortDescription(B_TRANSLATE_CONTEXT("Tasks", "Short mimetype description")); mime.SetLongDescription(B_TRANSLATE_CONTEXT("Tasks", "Long mimetype description")); //get the icon from our Ressources BResources* res = BApplication::AppResources(); if (res != NULL){ size_t size; const void* data = res->LoadResource(B_VECTOR_ICON_TYPE, "TASK_ICON", &size); if (data!=NULL) mime.SetIcon(reinterpret_cast<const uint8*>(data), size); } mime.SetPreferredApp(APP_SIG); // add default task fields to meta-mime type BMessage fields; for (int32 i = 0; sDefaultAttributes[i].attribute; i++) { fields.AddString("attr:public_name", sDefaultAttributes[i].name); fields.AddString("attr:name", sDefaultAttributes[i].attribute); fields.AddInt32("attr:type", sDefaultAttributes[i].type); fields.AddString("attr:display_as", sDefaultAttributes[i].displayAs); fields.AddBool("attr:viewable", sDefaultAttributes[i].isPublic); fields.AddBool("attr:editable", sDefaultAttributes[i].editable); fields.AddInt32("attr:width", sDefaultAttributes[i].width); fields.AddInt32("attr:alignment", B_ALIGN_LEFT); fields.AddBool("attr:extra", false); } mime.SetAttrInfo(&fields); // create indices on all volumes for the found attributes. int32 count = 8; BVolumeRoster volumeRoster; BVolume volume; while (volumeRoster.GetNextVolume(&volume) == B_OK) { for (int32 i = 0; i < count; i++) { if (sDefaultAttributes[i].isPublic == true) fs_create_index(volume.Device(), sDefaultAttributes[i].attribute, sDefaultAttributes[i].type, 0); } } } else err = B_OK; return err; }
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; }
status_t WorkerThread::_MirrorIndices(const BPath& sourceDirectory, const BPath& targetDirectory) const { dev_t sourceDevice = dev_for_path(sourceDirectory.Path()); if (sourceDevice < 0) return (status_t)sourceDevice; dev_t targetDevice = dev_for_path(targetDirectory.Path()); if (targetDevice < 0) return (status_t)targetDevice; DIR* indices = fs_open_index_dir(sourceDevice); if (indices == NULL) { printf("%s: fs_open_index_dir(): (%d) %s\n", sourceDirectory.Path(), errno, strerror(errno)); // Opening the index directory will fail for example on ISO-Live // CDs. The default indices have already been created earlier, so // we simply bail. return B_OK; } while (dirent* index = fs_read_index_dir(indices)) { if (strcmp(index->d_name, "name") == 0 || strcmp(index->d_name, "size") == 0 || strcmp(index->d_name, "last_modified") == 0) { continue; } index_info info; if (fs_stat_index(sourceDevice, index->d_name, &info) != B_OK) { printf("Failed to mirror index %s: fs_stat_index(): (%d) %s\n", index->d_name, errno, strerror(errno)); continue; } uint32 flags = 0; // Flags are always 0 for the moment. if (fs_create_index(targetDevice, index->d_name, info.type, flags) != B_OK) { if (errno == B_FILE_EXISTS) continue; printf("Failed to mirror index %s: fs_create_index(): (%d) %s\n", index->d_name, errno, strerror(errno)); continue; } } fs_close_index_dir(indices); return B_OK; }
status_t WorkerThread::_CreateDefaultIndices(const BPath& targetDirectory) const { dev_t targetDevice = dev_for_path(targetDirectory.Path()); if (targetDevice < 0) return (status_t)targetDevice; struct IndexInfo { const char* name; uint32_t type; }; const IndexInfo defaultIndices[] = { { "BEOS:APP_SIG", B_STRING_TYPE }, { "BEOS:LOCALE_LANGUAGE", B_STRING_TYPE }, { "BEOS:LOCALE_SIGNATURE", B_STRING_TYPE }, { "_trk/qrylastchange", B_INT32_TYPE }, { "_trk/recentQuery", B_INT32_TYPE }, { "be:deskbar_item_status", B_STRING_TYPE } }; uint32 flags = 0; // Flags are always 0 for the moment. for (uint32 i = 0; i < sizeof(defaultIndices) / sizeof(IndexInfo); i++) { const IndexInfo& info = defaultIndices[i]; if (fs_create_index(targetDevice, info.name, info.type, flags) != B_OK) { if (errno == B_FILE_EXISTS) continue; printf("Failed to create index %s: fs_create_index(): (%d) %s\n", info.name, errno, strerror(errno)); return errno; } } return B_OK; }
void TTracker::InstallIndices(dev_t device) { status_t error = fs_create_index(device, kAttrQueryLastChange, B_INT32_TYPE, 0); error = fs_create_index(device, "_trk/recentQuery", B_INT32_TYPE, 0); }
int main(int argc, char **argv) { const char *indexTypeName = "string"; int indexType = B_STRING_TYPE; char *indexName = NULL; bool verbose = false; dev_t device = -1, copyFromDevice = -1; int c; while ((c = getopt_long(argc, argv, "d:ht:v", kLongOptions, NULL)) != -1) { switch (c) { case 0: break; case 'd': device = dev_for_path(optarg); if (device < 0) { fprintf(stderr, "%s: can't get information about volume: %s\n", kProgramName, optarg); return -1; } break; case 'f': copyFromDevice = dev_for_path(optarg); if (copyFromDevice < 0) { fprintf(stderr, "%s: can't get information about volume: %s\n", kProgramName, optarg); return -1; } break; case 'h': usage(0); break; case 't': indexTypeName = optarg; if (strncmp("int", optarg, 3) == 0) indexType = B_INT32_TYPE; else if (strncmp("llong", optarg, 5) == 0) indexType = B_INT64_TYPE; else if (strncmp("string", optarg, 6) == 0) indexType = B_STRING_TYPE; else if (strncmp("float", optarg, 5) == 0) indexType = B_FLOAT_TYPE; else if (strncmp("double", optarg, 6) == 0) indexType = B_DOUBLE_TYPE; else usage(1); break; case 'v': verbose = 1; break; default: usage(1); break; } } if (device == -1) { // Create the index on the volume of the current // directory if no volume was specified. device = dev_for_path("."); if (device < 0) { fprintf(stderr, "%s: can't get information about current volume\n", kProgramName); return -1; } } if (copyFromDevice != -1) { copy_indexes(copyFromDevice, device, verbose); return 0; } if (argc - optind == 1) { // last argument indexName = argv[optind]; } else usage(1); if (verbose) { /* Get the mount point of the specified volume. */ BVolume volume(device); BDirectory dir; volume.GetRootDirectory(&dir); BPath path(&dir, NULL); printf("Creating index \"%s\" of type %s on volume mounted at %s.\n", indexName, indexTypeName, path.Path()); } if (fs_create_index(device, indexName, indexType, 0) != 0) fprintf(stderr, "%s: Could not create index: %s\n", kProgramName, strerror(errno)); return 0; }