bool Util::createPackage(std::string path, const char* appname, const char* appver, const char* appdesc, const char* appauthor) { // Open the new package. std::fstream * nfd = new std::fstream(path.c_str(), std::ios::out | std::ios::trunc | std::ios::in | std::ios::binary); if (!nfd->is_open()) { AppLib::Logging::showErrorW("Unable to open new package path for writing."); return false; } // Write out 1MB for the bootstrap area. #if OFFSET_BOOTSTRAP != 0 #error The createPackage() function is written under the assumption that the bootstrap #error offset is 0, hence the library will not operate correctly with a different offset. #endif for (int i = 0; i < LENGTH_BOOTSTRAP; i += 1) { nfd->write("\0", 1); } // Write out the INode lookup table. for (int i = 0; i < LENGTH_LOOKUP / 4; i += 1) { if (i == 0) { uint32_t pos = OFFSET_DATA; nfd->write(reinterpret_cast<char *>(&pos), 4); } else nfd->write("\0\0\0\0", 4); } // Now add the FSInfo inode at OFFSET_FSINFO. INode fsnode(0, "", INodeType::INT_FSINFO); fsnode.ver_major = LIBRARY_VERSION_MAJOR; fsnode.ver_minor = LIBRARY_VERSION_MINOR; fsnode.ver_revision = LIBRARY_VERSION_REVISION; fsnode.setAppName(appname); fsnode.setAppVersion(appver); fsnode.setAppDesc(appdesc); fsnode.setAppAuthor(appauthor); fsnode.pos_root = OFFSET_DATA; fsnode.pos_freelist = 0; // The first FreeList block will automatically be // created when the first block is freed. std::string fsnode_towrite = fsnode.getBinaryRepresentation(); nfd->write(fsnode_towrite.c_str(), fsnode_towrite.size()); for (int i = fsnode_towrite.size(); i < LENGTH_FSINFO; i += 1) { nfd->write("\0", 1); } time_t rtime; time(&rtime); // Now add the root inode at OFFSET_DATA. INode rnode(0, "", INodeType::INT_DIRECTORY); rnode.uid = 0; rnode.gid = 1000; rnode.mask = 0777; rnode.atime = rtime; rnode.mtime = rtime; rnode.ctime = rtime; rnode.parent = 0; rnode.children_count = 0; std::string rnode_towrite = rnode.getBinaryRepresentation(); nfd->write(rnode_towrite.c_str(), rnode_towrite.size()); for (int i = rnode_towrite.size(); i < BSIZE_FILE; i += 1) { nfd->write("\0", 1); } nfd->close(); delete nfd; return true; }
int main(int argc, char *argv[]) { if(argc != 3) { std::cerr << "Usage: " << argv[0] << " <input file> <max tree depth>\n"; return 1; } /* parse command line args */ std::istringstream nd(argv[2]); std::ifstream infile(argv[1]); int maxdepth; nd >> maxdepth; // check for errors if(!infile) { std::cerr << "Unable to open " << argv[1] << " for input.\n"; return 2; } if(maxdepth <=1) { std::cerr << "Max depth must be >1. Value received was " << maxdepth << "\n"; return 2; } Graph G; if(!read_graph_from_stream(infile,G)) { std::cerr << "Error reading input graph.\n"; return 3; } // output command line to stderr std::cerr << "Command line:\t"; for(int i=0;i<argc;++i) std::cerr << argv[i] << " "; std::cerr << "\n"; struct timeval t1,t2,t3,t4; gettimeofday(&t1,NULL); /* Compute transitive reduction of G */ Graph Greduce = G.treduce(); gettimeofday(&t2,NULL); /* parse the graph into a clan tree */ ClanTree ptree; Greduce.topological_sort(); gettimeofday(&t3,NULL); graph_parse(Greduce, NULL, ptree, 5); gettimeofday(&t4,NULL); // check integrity of both graphs. if(!G.integrity_check()) { std::cerr << "Integrity check failed for " << G << ".\n"; return 4; } else { std::cerr << "Integrity check passed for " << G << ".\n"; } if(!ptree.integrity_check()) { std::cerr << "Integrity check failed for " << ptree << ".\n"; return 4; } else { std::cerr << "Integrity check passed for parse tree: " << ptree << ".\n"; } #if 0 std::cerr << ptree.nodelist().size() << " Clans found (including singletons)\n"; for(ClanTree::nodelist_c_iter_t rnode(ptree.nodelist().begin()); rnode != ptree.nodelist().end(); ++rnode) { std::cerr << clan_abbrev(rnode->first,0) << "\taddr=" << &rnode->first; std::cerr << "\tG= " << rnode->first.graph(); std::cerr << "\n\tChild nodes:\n"; for(std::set<Clanid>::const_iterator ccln(rnode->second.successors.begin()); ccln != rnode->second.successors.end(); ++ccln) std::cerr << "\t" << clan_abbrev(*ccln,0) << "\tG= " << ccln->graph() << "\n"; } #endif /* Output the clan tree */ Clanid root(ptree.find_source_node()); ClanTree::nodelist_c_iter_t rnode(ptree.nodelist().find(root)); draw_clan_tree(std::cout, rnode, ptree, 0, maxdepth); double dt1 = (t2.tv_sec - t1.tv_sec) + 1.0e-6*(t2.tv_usec - t1.tv_usec); double dt2 = (t3.tv_sec - t2.tv_sec) + 1.0e-6*(t3.tv_usec - t2.tv_usec); double dt3 = (t4.tv_sec - t3.tv_sec) + 1.0e-6*(t4.tv_usec - t3.tv_usec); std::cerr << "\nTiming report:\n\ttransitive reduction:\t" << dt1 << " s\n"; std::cerr << "\tTopological sort:\t" << dt2 << " s\n"; std::cerr << "\tGraph parse:\t" << dt3 << " s\n"; return 0; }