int make_fs(const char *part_device, const char *fstype, unsigned int fsblocksize, unsigned int flags, const char *fslabel) { int i; char fsblock_size[14]; char *argv[12]; char ext_opts[1024]; uint64_t max_online_resize; const int lazy = !(flags & PLOOP_CREATE_NOLAZY); fsblocksize = fsblocksize != 0 ? fsblocksize : 4096; i = 0; argv[i++] = "mkfs"; argv[i++] = "-t"; argv[i++] = (char*)fstype; argv[i++] = "-j"; if (fslabel != NULL) { argv[i++] = "-L"; argv[i++] = (char*)fslabel; } snprintf(fsblock_size, sizeof(fsblock_size), "-b%u", fsblocksize); argv[i++] = fsblock_size; /* Reserve enough space so that the block group descriptor table can grow to 16T */ max_online_resize = PLOOP_MAX_FS_SIZE / fsblocksize; snprintf(ext_opts, sizeof(ext_opts), "-Elazy_itable_init=%d,resize=%" PRIu64, lazy, max_online_resize); argv[i++] = ext_opts; /* Set the journal size to 128M to allow online resize up to 16T * independly on the initial image size */ argv[i++] = "-Jsize=128"; argv[i++] = (char *)part_device; argv[i++] = NULL; if (run_prg(argv)) return SYSEXIT_MKFS; i = 0; argv[i++] = get_prog(tune2fs_progs); argv[i++] = "-ouser_xattr,acl"; argv[i++] = "-c0"; argv[i++] = "-i0"; argv[i++] = "-eremount-ro"; argv[i++] = (char *)part_device; argv[i++] = NULL; if (run_prg(argv)) return SYSEXIT_MKFS; return 0; }
int make_fs(const char *device, const char *fstype, unsigned int fsblocksize) { char part_device[64]; char fsblock_size[14]; char *argv[10]; char ext_opts[1024]; __u64 max_online_resize; fsblocksize = fsblocksize != 0 ? fsblocksize : 4096; if (get_partition_device_name(device, part_device, sizeof(part_device))) return SYSEXIT_MKFS; argv[0] = "mkfs"; argv[1] = "-t"; argv[2] = (char*)fstype; argv[3] = "-j"; snprintf(fsblock_size, sizeof(fsblock_size), "-b%u", fsblocksize); argv[4] = fsblock_size; /* Reserve enough space so that the block group descriptor table can grow to 16T * Note: the max_online_resize is __u32 in mkfs.ext4 */ max_online_resize = PLOOP_MAX_FS_SIZE / fsblocksize; if (max_online_resize > (__u32)~0) max_online_resize = (__u32)~0; snprintf(ext_opts, sizeof(ext_opts), "-Elazy_itable_init,resize=%llu", max_online_resize); argv[5] = ext_opts; /* Set the journal size to 128M to allow online resize up to 16T * independly on the initial image size */ argv[6] = "-Jsize=128"; argv[7] = "-i16384"; /* 1 inode per 16K disk space */ argv[8] = part_device; argv[9] = NULL; if (run_prg(argv)) return SYSEXIT_MKFS; argv[0] = get_prog(tune2fs_progs); argv[1] = "-ouser_xattr,acl"; argv[2] = "-c0"; argv[3] = "-i0"; argv[4] = "-eremount-ro"; argv[5] = part_device; argv[6] = NULL; if (run_prg(argv)) return SYSEXIT_MKFS; return 0; }
void prog_func(struct terminal *term, struct list_head *list, unsigned char *param, unsigned char *name) { unsigned char *prog, *cmd; if (!(prog = get_prog(list)) || !*prog) { msg_box(term, NULL, TEXT(T_NO_PROGRAM), AL_CENTER | AL_EXTD_TEXT, TEXT(T_NO_PROGRAM_SPECIFIED_FOR), " ", name, ".", NULL, NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC); return; } if ((cmd = subst_file(prog, param, 0))) { exec_on_terminal(term, cmd, "", 1); mem_free(cmd); } }
int resize_fs(const char *device, off_t size_sec) { char *argv[5]; char buf[22]; argv[0] = get_prog(resize2fs_progs); argv[1] = "-p"; argv[2] = (char *)device; if (size_sec) { // align size to 4K snprintf(buf, sizeof(buf), "%luk", (long)(size_sec >> 3 << 3) >> 1); argv[3] = buf; } else
void sccwriter::write_function_header( std::ostream& os, int index, int opts ) { //write the function header std::string fname; get_function_name( progNames[index], fname ); os << "Expr* " << fname.c_str() << "( "; CExpr* progvars = (CExpr*)get_prog( index )->kids[1]; int counter = 0; //write each argument while( progvars->kids[counter] ) { if( counter!=0 ) { os << ", "; } os << "Expr* "; write_variable( ((SymSExpr*)progvars->kids[counter])->s, os ); //add to vars if options are set to do so if( opts&opt_write_add_args ) { vars.push_back( ((SymSExpr*)progvars->kids[counter])->s ); } counter++; } os << " )"; if( opts&opt_write_call_debug ) { os << "{" << std::endl; indent( os, 1 ); os << "std::cout << \"Call function " << fname.c_str() << " with arguments \";" << std::endl; counter = 0; while( progvars->kids[counter] ) { if( counter!=0 ) { indent( os, 1 ); os << "std::cout << \", \";" << std::endl; } indent( os, 1 ); write_variable( ((SymSExpr*)progvars->kids[counter])->s, os ); os << "->print( std::cout );" << std::endl; counter++; } indent( os, 1 ); os << "std::cout << std::endl;" << std::endl; } }
void tune_fs(int balloonfd, const char *device, unsigned long long size_sec) { unsigned long long reserved_blocks; struct statfs fs; char *argv[5]; char buf[21]; int ret; if (fstatfs(balloonfd, &fs) != 0) { ploop_err(errno, "tune_fs: can't statfs %s", device); return; } reserved_blocks = size_sec / 100 * 5 * SECTOR_SIZE / fs.f_bsize; if (reserved_blocks == 0) { ploop_err(0, "Can't set reserved blocks for size %llu", size_sec); return; } /* First try to use kernel API, if available */ ret = ioctl(balloonfd, EXT4_IOC_SET_RSV_BLOCKS, &reserved_blocks); if (!ret) return; if (errno != ENOTTY) { ploop_err(errno, "Can't set reserved blocks to %llu", reserved_blocks); return; } /* Fallback to manual modification via tune2fs */ argv[0] = get_prog(tune2fs_progs); argv[1] = "-r"; snprintf(buf, sizeof(buf), "%llu", reserved_blocks); argv[2] = buf; argv[3] = (char *)device; argv[4] = NULL; run_prg(argv); }
void sccwriter::write_file() { static std::string filename( "scccode" ); //writer the h file std::fstream fsh; std::string fnameh( filename ); fnameh.append(".h"); fsh.open( fnameh.c_str(), std::ios::out ); //write the header in h fsh << "#ifndef SCC_CODE_H" << std::endl; fsh << "#define SCC_CODE_H" << std::endl << std::endl; //include necessary files in h file fsh << "#include \"check.h\"" << std::endl << std::endl; //write the init function fsh << "void init_compiled_scc();" << std::endl << std::endl; //write the entry function fsh << "Expr* run_compiled_scc( Expr* p, std::vector< Expr* >& args );" << std::endl << std::endl; //write the side condition code functions for( int n=0; n<(int)progs.size(); n++ ) { //write the header in the h file fsh << "inline "; write_function_header( fsh, n ); fsh << ";" << std::endl << std::endl; } fsh << "#endif" << std::endl << std::endl; fsh.close(); //writer the cpp code std::fstream fsc; std::string fnamec( filename ); fnamec.append(".cpp"); fsc.open( fnamec.c_str(), std::ios::out ); //include the h file in the cpp fsc << "#include \"scccode.h\"" << std::endl << std::endl; std::ostringstream fsc_funcs; //write the side condition code functions for( currProgram=0; currProgram<(int)progs.size(); currProgram++ ) { //reset naming counters vars.clear(); exprCount = 0; strCount = 0; argsCount = 0; rnumCount = 0; //for debugging std::cout << "program #" << currProgram << " " << progNames[currProgram].c_str() << std::endl; //write the function header write_function_header( fsc_funcs, currProgram, opt_write_add_args|options ); if( (options&opt_write_call_debug)==0 ) { fsc_funcs << "{" << std::endl; } //write the code //std::vector< std::string > cleanVec; //write_code( get_prog( n )->kids[2], fsc, 1, "return ", cleanVec ); //debug_write_code( progs[n].second->kids[2], fsc, 1 ); std::string expr; write_expr( get_prog( currProgram )->kids[2], fsc_funcs, 1, expr ); indent( fsc_funcs, 1 ); fsc_funcs << "return " << expr.c_str() << ";" << std::endl; fsc_funcs << "}" << std::endl << std::endl; } //write the predefined symbols necessary - symbols and progs for( int a=0; a<(int)globalSyms.size(); a++ ) { fsc << "Expr* e_" << globalSyms[a].c_str() << ";" << std::endl; } for( int a=0; a<(int)progs.size(); a++ ) { fsc << "Expr* e_" << progNames[a].c_str() << ";" << std::endl; } fsc << std::endl; //write the init function - initialize symbols and progs fsc << "void init_compiled_scc(){" << std::endl; for( int a=0; a<(int)globalSyms.size(); a++ ) { indent( fsc, 1 ); fsc << "e_" << globalSyms[a].c_str() << " = symbols->get(\"" << globalSyms[a].c_str() << "\").first;" << std::endl; } for( int a=0; a<(int)progs.size(); a++ ) { indent( fsc, 1 ); fsc << "e_" << progNames[a].c_str() << " = progs[\"" << progNames[a].c_str() << "\"];" << std::endl; } fsc << "}" << std::endl << std::endl; fsc << "Expr* run_compiled_scc( Expr* p, std::vector< Expr* >& args ){" << std::endl; //for( int n=0; n<(int)progs.size(); n++ ){ // indent( fsc, 1 ); // fsc << "static std::string s_" << progNames[n].c_str() << " = std::string( \"" << progNames[n].c_str() << "\" );" << std::endl; //} for( int n=0; n<(int)progs.size(); n++ ){ indent( fsc, 1 ); if( n!=0 ){ fsc << "}else "; } //for each function, test to see if the string matches the name of the function fsc << "if( p==e_" << progNames[n].c_str() << " ){" << std::endl; indent( fsc, 2 ); std::string fname; get_function_name( progNames[n], fname ); //map the function to the proper function fsc << "return " << fname.c_str() << "( "; //write the arguments to the function from args CExpr* progvars = (CExpr*)get_prog( n )->kids[1]; int counter = 0; bool firstTime = true; while( progvars->kids[counter] ) { if( !firstTime ) { fsc << ", "; } fsc << "args[" << counter << "]"; firstTime = false; counter++; } fsc << " );" << std::endl; } indent( fsc, 1 ); fsc << "}else{" << std::endl; indent( fsc, 2 ); //return null in the case the function could not be found fsc << "return NULL;" << std::endl; indent( fsc, 1 ); fsc << "}" << std::endl; fsc << "}" << std::endl << std::endl; fsc << fsc_funcs.str().c_str(); fsc.close(); }