int main(int argc, char** argv) { if(argc < 9) { fprintf(stderr, "l_imageLoad_app received too few arguments\n" ); exit(RES_RES_INVALID_ARGS); } if(argc > 9) { fprintf(stderr, "l_imageLoad_app received too many arguments\n" ); exit(RES_RES_INVALID_ARGS); } UnixOpen(argv[1]); pid_t parentPid = getpid(); pid_t child = fork(); if (child < 0) { perror("fork failed while creating application process"); exit(RES_FORK_FAILED); } if (child) { // inside parent while(!AfterAttach()) { sleep(1); } UnixOpen(argv[2]); } if ( child == 0 ) { // inside child char attachPid[MAX_SIZE]; sprintf(attachPid, "%d", parentPid); execl(argv[3], argv[3], argv[4],argv[5],"-pid", attachPid, "-t", argv[6], argv[7], argv[8], NULL); perror("execl failed while trying to attach Pin to the application\n"); exit(RES_EXEC_FAILED); } return RES_SUCCESS; }
/// Read the index contained in the file f. This function always reads all /// bitvectors. int ibis::skive::read(const char* f) { std::string fnm; indexFileName(fnm, f); int fdes = UnixOpen(fnm.c_str(), OPEN_READONLY); if (fdes < 0) { LOGGER(ibis::gVerbose > 0) << "Warning -- skive[" << col->partition()->name() << '.' << col->name() << "]::read failed to open " << fnm; return -1; // can not do anything else } char header[8]; IBIS_BLOCK_GUARD(UnixClose, fdes); #if defined(_WIN32) && defined(_MSC_VER) (void)_setmode(fdes, _O_BINARY); #endif int ierr = UnixRead(fdes, static_cast<void*>(header), 8); if (ierr != 8) { LOGGER(ibis::gVerbose > 0) << "Warning -- skive[" << col->partition()->name() << '.' << col->name() << "]::read failed to read 8 bytes from " << fnm; return -2; } if (!(header[0] == '#' && header[1] == 'I' && header[2] == 'B' && header[3] == 'I' && header[4] == 'S' && (header[5] == static_cast<char>(ibis::index::SKIVE) || header[5] == static_cast<char>(ibis::index::SLICE)) && (header[6] == 8 || header[6] == 4) && header[7] == static_cast<char>(0))) { if (ibis::gVerbose > 0) { ibis::util::logger lg; lg() << "Warning -- skive[" << col->partition()->name() << '.' << col->name() << "]::read the header from " << fnm << " ("; printHeader(lg(), header); lg() << ") does not contain the expected values"; } return -3; } uint32_t dim[3]; // nrows, nobs, card size_t begin, end; clear(); // clear the current content ierr = UnixRead(fdes, static_cast<void*>(dim), 3*sizeof(uint32_t)); nrows = dim[0]; // read vals begin = 8*((3*sizeof(uint32_t) + 15) / 8); end = begin + dim[2] * sizeof(double); { array_t<double> dbl(fnm.c_str(), fdes, begin, end); vals.swap(dbl); } // read the offsets begin = end; end += header[6] * (dim[1] + 1); ierr = initOffsets(fdes, header[6], begin, dim[1]); if (ierr < 0) return ierr; // cnts begin = end; end += sizeof(uint32_t) * dim[2]; { array_t<uint32_t> szt(fnm.c_str(), fdes, begin, end); cnts.swap(szt); } ibis::fileManager::instance().recordPages(0, end); initBitmaps(fdes); activate(); return 0; } // ibis::skive::read
// the argument is the name of the directory or the file name int ibis::skive::write(const char* dt) const { if (vals.empty()) return -1; std::string fnm; indexFileName(fnm, dt); if (fnm.empty()) { return 0; } else if (0 != str && 0 != str->filename() && 0 == fnm.compare(str->filename())) { LOGGER(ibis::gVerbose > 0) << "Warning -- skive::write can not overwrite the index file \"" << fnm << "\" while it is used as a read-only file map"; return 0; } else if (fname != 0 && *fname != 0 && 0 == fnm.compare(fname)) { activate(); // read everything into memory fname = 0; // break the link with the named file } ibis::fileManager::instance().flushFile(fnm.c_str()); int fdes = UnixOpen(fnm.c_str(), OPEN_WRITENEW, OPEN_FILEMODE); if (fdes < 0) { ibis::fileManager::instance().flushFile(fnm.c_str()); fdes = UnixOpen(fnm.c_str(), OPEN_WRITENEW, OPEN_FILEMODE); if (fdes < 0) { LOGGER(ibis::gVerbose > 0) << "Warning -- skive[" << col->partition()->name() << '.' << col->name() << "]::write failed to open \"" << fnm << "\" for writing"; return -2; } } IBIS_BLOCK_GUARD(UnixClose, fdes); #if defined(_WIN32) && defined(_MSC_VER) (void)_setmode(fdes, _O_BINARY); #endif #ifdef FASTBIT_USE_LONG_OFFSETS const bool useoffset64 = true; #else const bool useoffset64 = (getSerialSize()+8 > 0x80000000UL); #endif char header[] = "#IBIS\11\0\0"; header[5] = (char)ibis::index::SKIVE; header[6] = (char)(useoffset64 ? 8 : 4); int ierr = UnixWrite(fdes, header, 8); if (ierr < 8) { LOGGER(ibis::gVerbose > 0) << "Warning -- skive[" << col->partition()->name() << "." << col->name() << "]::write(" << fnm << ") failed to write the 8-byte header, ierr = " << ierr; return -3; } if (useoffset64) ierr = write64(fdes); else ierr = write32(fdes); if (ierr >= 0) { #if defined(FASTBIT_SYNC_WRITE) #if _POSIX_FSYNC+0 > 0 (void) UnixFlush(fdes); // write to disk #elif defined(_WIN32) && defined(_MSC_VER) (void) _commit(fdes); #endif #endif LOGGER(ibis::gVerbose > 3) << "skive[" << col->partition()->name() << "." << col->name() << "]::write wrote " << bits.size() << " bitmap" << (bits.size()>1?"s":"") << " to file " << fnm; } return ierr; } // ibis::skive::write