void ModXReader::readActionGroup() { while (!atEnd()) { readNext(); if (isEndElement()) { break; } if (isStartElement()) { if (name() == "sql") { m_data->sqlDialect = ModXData::sqlDialects.key(attributes().value("dbms").toString(), ModXData::DialectSqlParser); m_data->sql << readElementText(); } else if (name() == "copy") { m_data->copyFiles = true; // Read <file> as unknown elements... readUnknownElement(); } else if (name() == "open") { QString file = attributes().value("src").toString(); m_data->actions[file] = readOpen(); } else if (name() == "diy-instructions") { QString lang = attributes().value("lang").toString(); m_data->diy[lang] = readElementText(); } else { readUnknownElement(); } } } }
/* * Initialize recycler dat for each samfsdump file. Generate the dat file * name and see if this file was created on a previous run of the recycler. */ void DatInit( CsdDir_t *csdDir) { int idx; struct stat sb; char *filename; CsdEntry_t *csdEntry; int fd; int rval; for (idx = 0; idx < csdDir->cd_count; idx++) { csdEntry = &csdDir->cd_entry[idx]; if (csdEntry->ce_skip == B_TRUE) { continue; } filename = csdEntry->ce_path; /* path to samfsdump file */ /* * Build path to recycler's dat file for the samfsdump file. */ SamMalloc(csdEntry->ce_datPath, sizeof (upath_t)); (void) snprintf(csdEntry->ce_datPath, sizeof (upath_t), "%s%s", filename, DAT_FILE_SUFFIX); if (stat(csdEntry->ce_datPath, &sb) == 0) { /* * Dat file exists. */ if (RegenDatfiles == B_TRUE) { Trace(TR_MISC, "Regenerating recycler dat file '%s'", csdEntry->ce_datPath); (void) unlink(csdEntry->ce_datPath); continue; } /* * Read and validate header. */ csdEntry->ce_exists = B_FALSE; fd = readOpen(csdEntry->ce_datPath); if (fd < 0) { Trace(TR_MISC, "Failed to open dat file '%s' errno: %d", csdEntry->ce_datPath, errno); continue; } rval = readHeader(fd, csdEntry->ce_datPath); if (rval == 0) { csdEntry->ce_exists = B_TRUE; } else { Trace(TR_MISC, "Invalid recycler dat file '%s'", csdEntry->ce_datPath); (void) unlink(csdEntry->ce_datPath); } (void) DatClose(fd); } /* * Allocate and initialize media table for samfsdump file. */ SamMalloc(csdEntry->ce_table, sizeof (MediaTable_t)); (void) memset(csdEntry->ce_table, 0, sizeof (MediaTable_t)); if (MediaInit(csdEntry->ce_table, csdEntry->ce_path) != 0) { Trace(TR_MISC, "Error: media table initialization failed"); return; } } }
/* * Accumulate media entries from recycler's dat file. */ int DatAccumulate( CsdEntry_t *csd) { size_t size; MediaTable_t *dat_table; MediaEntry_t *datfile_cache; MediaEntry_t *vsn; MediaEntry_t *datfile; /* vsn entry from dat file */ MediaEntry_t *dat; /* vsn entry in samfs dump's dat table */ size_t ngot; int i; int idx; int num_inodes; DatTable_t table; int rval; off_t pos; char *path; int fd; path = csd->ce_datPath; /* path to dat file */ fd = readOpen(path); /* open file descriptor for dat file */ if (fd < 0) { Trace(TR_MISC, "%s '%s', dat file open failed, errno= %d", errmsg1, path, errno); return (-1); } dat_table = csd->ce_table; /* media table generated for dat file */ /* * Need to search from the beginning. Rewind dat file and * the read header again. */ rval = readHeader(fd, path); if (rval != 0) { Trace(TR_MISC, "%s '%s', dat table header read failed", errmsg1, path); DatClose(fd); return (-1); } num_inodes = 0; /* * Read datfile table entries until we find the entry we are * currently processing. */ while (InfiniteLoop) { datfile_cache = NULL; ngot = read(fd, &table, sizeof (DatTable_t)); if (ngot != sizeof (DatTable_t)) { Trace(TR_MISC, "%s '%s', dat table read failed", errmsg1, path); DatClose(fd); return (-1); } if (table.dt_mapmin != dat_table->mt_mapmin) { continue; } if (table.dt_mapchunk != dat_table->mt_mapchunk) { Trace(TR_MISC, "%s '%s', map chunk does not match", errmsg1, path); DatClose(fd); return (-1); } pos = lseek(fd, 0, SEEK_CUR); Trace(TR_MISC, "[%s] Read dat entries 0x%lx " "count: %d seqnum candidates: %lld-%lld", dat_table->mt_name, pos, table.dt_count, table.dt_mapmin, table.dt_mapmin + table.dt_mapchunk - 1); size = table.dt_count * sizeof (MediaEntry_t); SamMalloc(datfile_cache, size); (void) memset(datfile_cache, 0, size); for (i = 0; i < table.dt_count; i++) { datfile = &datfile_cache[i]; ngot = read(fd, datfile, sizeof (MediaEntry_t)); if (ngot != sizeof (MediaEntry_t)) { Trace(TR_MISC, "%s '%s', header read error " "read: %d expected: %d, errno= %d", errmsg1, path, ngot, sizeof (MediaEntry_t), errno); num_inodes = -1; goto out; } if ((datfile->me_type == DT_DISK) && (datfile->me_mapsize != 0)) { SamMalloc(datfile->me_bitmap, datfile->me_mapsize); (void) memset(datfile->me_bitmap, 0, datfile->me_mapsize); ngot = read(fd, datfile->me_bitmap, datfile->me_mapsize); if (ngot != datfile->me_mapsize) { Trace(TR_MISC, "%s '%s', bitmap read error " "read: %d expected: %d, errno= %d", errmsg1, path, ngot, datfile->me_mapsize, errno); num_inodes = -1; goto out; } } vsn = MediaFind(&ArchMedia, datfile->me_type, datfile->me_name); if (vsn == NULL) { Trace(TR_MISC, "%s '%s', failed to find vsn %s.%s", errmsg1, path, sam_mediatoa(datfile->me_type), datfile->me_name); num_inodes = -1; goto out; } /* * For completeness, update in-memory's dat_table for * samfs dump file. This is not really necessary but * might be useful for debugging purposes. */ dat = NULL; if (dat_table != NULL) { dat = MediaFind(dat_table, datfile->me_type, datfile->me_name); if (dat == NULL) { Trace(TR_MISC, "Error failed to find vsn %s.%s", sam_mediatoa(datfile->me_type), datfile->me_name); num_inodes = -1; goto out; } } Trace(TR_SAMDEV, "[%s.%s] Accumulate dat active files: %d", sam_mediatoa(vsn->me_type), vsn->me_name, datfile->me_files); PthreadMutexLock(&vsn->me_mutex); vsn->me_files += datfile->me_files; PthreadMutexUnlock(&vsn->me_mutex); if (dat != NULL) { PthreadMutexLock(&dat->me_mutex); dat->me_files += datfile->me_files; PthreadMutexUnlock(&dat->me_mutex); } num_inodes += datfile->me_files; if ((datfile->me_type == DT_DISK) && (datfile->me_mapsize != 0)) { for (idx = 0; idx <= dat_table->mt_mapchunk; idx++) { /* FIXME */ if (BT_TEST(datfile->me_bitmap, idx) == 1) { PthreadMutexLock(&vsn->me_mutex); BT_SET(vsn->me_bitmap, idx); PthreadMutexUnlock(&vsn->me_mutex); if (dat != NULL) { PthreadMutexLock(&dat->me_mutex); BT_SET(dat->me_bitmap, idx); PthreadMutexUnlock(&dat->me_mutex); } } } } /* * Free memory allocated for bitmap read from disk. */ if (datfile->me_bitmap != NULL) { SamFree(datfile->me_bitmap); datfile->me_bitmap = NULL; } } break; } out: if (datfile_cache != NULL) { SamFree(datfile_cache); for (i = 0; i < table.dt_count; i++) { datfile = &datfile_cache[i]; if (datfile->me_bitmap != NULL) { SamFree(datfile->me_bitmap); datfile->me_bitmap = NULL; } } } DatClose(fd); return (num_inodes); }