int performFileAction(bool verbose, imago::Settings& vars, const std::string& imageName, const std::string& configName, const std::string& outputName) { logEnterFunction(); int result = 0; // ok mark imago::VirtualFS vfs; vars.general.StartTime = 0; // reset timelimit if (vars.general.ExtractCharactersOnly) { if (verbose) printf("Characters extraction from image '%s'\n", imageName.c_str()); } else { if (verbose) printf("Recognition of image '%s'\n", imageName.c_str()); } try { imago::Image image; if (vars.general.LogVFSEnabled) { imago::getLogExt().SetVirtualFS(vfs); } imago::ImageUtils::loadImageFromFile(image, imageName.c_str()); if (vars.general.ExtractCharactersOnly) { imago::Image out; imago::prefilterEntrypoint(vars, out, image); applyConfig(verbose, vars, configName); imago::ChemicalStructureRecognizer _csr; _csr.extractCharacters(vars, out); } else { RecognitionResult result = recognizeImage(verbose, vars, image, configName); imago::FileOutput fout(outputName.c_str()); fout.writeString(result.molecule.c_str()); if (imago::getLogExt().loggingEnabled()) { int molObj = indigoLoadMoleculeFromString(result.molecule.c_str()); if (molObj != -1) { indigoSetOption("render-output-format", "png"); indigoSetOption("render-background-color", "255, 255, 255"); std::string outputImg = imago::getLogExt().generateImageName(); indigoRenderToFile(molObj, outputImg.c_str()); imago::getLogExt().appendImageFile("Result image:", outputImg); indigoFree(molObj); } } } } catch (std::exception &e) { result = 2; // error mark puts(e.what()); } dumpVFS(vfs, "log_vfs.txt"); return result; }
long do_sys_open(int dfd, const char __user *filename, int flags, int mode) { struct open_flags op; int lookup = build_open_flags(flags, mode, &op); char *tmp = getname(filename); int fd = PTR_ERR(tmp); #ifdef CONFIG_STORAGE_LOGGER_ENABLE unsigned long long time1 = 0,time2 = 0; bool bwsdcard = false; bool internalFs = false; #endif if (!IS_ERR(tmp)) { #ifdef CONFIG_STORAGE_LOGGER_ENABLE if (unlikely(dumpVFS())) { if((!memcmp(tmp,"/mnt/sdcard",11))||(!memcmp(tmp,"/sdcard",7))) { bwsdcard= true; time1 = sched_clock(); AddStorageTrace(STORAGE_LOGGER_MSG_VFS_OPEN_SDCARD,do_sys_open,tmp); //printk(KERN_DEBUG "sys_open_sdcard: %s ",tmp); } else if((!memcmp(tmp,"/data",5))||(!memcmp(tmp,"/system",7))) { internalFs= true; time1 = sched_clock(); AddStorageTrace(STORAGE_LOGGER_MSG_VFS_OPEN_INTFS,do_sys_open,tmp); //printk(KERN_DEBUG "sys_open_intfs: %s ",tmp); } } #endif fd = get_unused_fd_flags(flags); if (fd >= 0) { struct file *f = do_filp_open(dfd, tmp, &op, lookup); if (IS_ERR(f)) { put_unused_fd(fd); fd = PTR_ERR(f); } else { fsnotify_open(f); fd_install(fd, f); } } #ifdef CONFIG_STORAGE_LOGGER_ENABLE if (unlikely(dumpVFS())) { if(bwsdcard) { bwsdcard=false; time2 = sched_clock(); if((time2 - time1) > (unsigned long long )30000000) { AddStorageTrace(STORAGE_LOGGER_MSG_VFS_OPEN_SDCARD_END,do_sys_open,tmp,(time2 - time1)); //printk(KERN_DEBUG "sys_open_end: %s, dt: %lld ",tmp, (time2 - time1)); } } else if(internalFs) { internalFs=false; time2 = sched_clock(); if((time2 - time1) > (unsigned long long )30000000) { AddStorageTrace(STORAGE_LOGGER_MSG_VFS_OPEN_INTFS_END,do_sys_open,tmp,(time2 - time1)); //printk(KERN_DEBUG "sys_open_end: %s, dt: %lld ",tmp, (time2 - time1)); } } } #endif putname(tmp); } return fd; }