//------------------------------------------------------------------------------------------------------------ // // 函数说明 // // // 参数说明 // // // 返回值 // // // 其他 // 无 // //------------------------------------------------------------------------------------------------------------ __s32 script_patch(char *script_name, void *script_buf, __s32 boot_script_type) { H_FILE script_file = NULL; int ret = -1; char *script_addr = NULL; int script_len; //打开脚本文件,打不开则失败 if(!script_name) { __wrn("the input script is empty\n"); return -1; } script_file = wBoot_fopen(script_name, "rb"); if(!script_file) { __wrn("unable to open script file %s\n", script_name); return -1; } //首先获取脚本的长度 script_len = wBoot_flen(script_file); //读出脚本所有的内容 script_addr = (char *)wBoot_malloc(script_len); if(!script_addr) { __wrn("unable to malloc memory for script\n"); goto _err_out; } wBoot_fread(script_addr, 1, script_len, script_file); wBoot_fclose(script_file); script_file = NULL; //解析脚本,根据脚本类型作区别 if(!boot_script_type) { ret = parser_script_os_sel(script_addr, script_len, script_buf); } if(ret) { __wrn("script is invalid\n"); } _err_out: //退出时候的处理 if(script_addr) { wBoot_free(script_addr); } if(script_file) { wBoot_fclose(script_file); script_file = NULL; } return ret; }
__s32 fetch_dynamic_data(char *buffer, int buffer_size) { int ret, i; H_FILE index_file = NULL; H_FILE data_file = NULL; int index_length; int data_length; char index_buffer[1024]; char *data_buffer; Dynamic_index *dindex; char data_file_name[32]; Dyamic_head *ddata; int index_number; char tmp_data_file_name[16]; ret = -1; // if(wBoot_fsmount('Z')) //其实是挂标准MBR的用户盘 // { // __inf("log error: cant find user disk\n"); // // return; // } //打开索引文件 index_file = wBoot_fopen("z:\\dynamic\\dindex.bin", "rb+"); if(!index_file) { sprite_wrn("dynamic data error: cant find dynamic data index file\n"); goto dynamic_data_err; } index_length = wBoot_flen(index_file); if(!index_length) { sprite_wrn("dynamic data error: dynamic data index file is bad\n"); goto dynamic_data_err; } //读出索引数据 memset(index_buffer, 0, 1024); wBoot_fread(index_buffer, 1, index_length, index_file); dindex = (Dynamic_index *)index_buffer; //校验索引数据 if(memcmp(dindex->magic, "dynamic", sizeof("dynamic"))) { sprite_wrn("dynamic data error: bad dynamic data index\n"); goto dynamic_data_err; } //生成数据文件名称 memset(data_file_name, 0, 32); strcpy(data_file_name, "z:\\dynamic\\"); while(dindex->used_count < dindex->total_count) { dindex->used_count ++; dindex->err_times ++; memset(tmp_data_file_name, 0, 16); strcpy(tmp_data_file_name, dindex->last_file); index_number = 0; for(i=1;(i<8) && (tmp_data_file_name[i] != '.');i++) { index_number = index_number * 10 + (tmp_data_file_name[i] - '0'); } //保存当前要查找的文件名 strcpy(data_file_name + sizeof("z:\\dynamic\\") - 1, dindex->last_file); //生成新的索引文件名称 index_number ++; for(i=7;i>0;i--) { tmp_data_file_name[i] = (index_number%10) + '0'; index_number /= 10; } //回写到索引文件中(缓存) strcpy(dindex->last_file, tmp_data_file_name); //打开数据文件 data_file = wBoot_fopen(data_file_name, "rb+"); if(!data_file) { //对应的数据文件不存在 sprite_wrn("dynamic data error: dynamic data file %s is not exist\n", data_file_name); data_file = NULL; continue; } data_length = wBoot_flen(data_file); if(!data_length) { sprite_wrn("dynamic data error: dynamic data file %s is bad\n", data_file_name); wBoot_fclose(data_file); data_file = NULL; continue; } data_buffer = wBoot_malloc(data_length); if(!data_buffer) { sprite_wrn("dynamic data error: not enough memory for dynamic data\n"); goto dynamic_data_err; } wBoot_fread(data_buffer, 1, data_length, data_file); //检查数据的校验和 // if(simple_check_data_valid(data_buffer, data_length)) // { // sprite_wrn("dynamic data error: dynamic data checksum error\n"); // wBoot_free(data_buffer); // data_buffer = NULL; // wBoot_fclose(data_file); // data_file = NULL; // // continue; // } ddata = (Dyamic_head *)data_buffer; if(ddata->used) //已经被使用过,切换下一个文件 { wBoot_free(data_buffer); data_buffer = NULL; wBoot_fclose(data_file); data_file = NULL; wBoot_fclose(data_file); } else { ddata->used = 1; //取出所有数据 dynamic_data_get(data_buffer, data_length, buffer, buffer_size); dindex->successed_times ++; dindex->err_times --; //保存回原文件 // simple_data_checksum(data_buffer, data_length); wBoot_fseek(data_file, 0, 0); wBoot_write(data_buffer, 1, data_length, data_file); wBoot_fclose(data_file); break; } } //修改索引文件 strcpy(dindex->last_file, tmp_data_file_name); wBoot_fseek(index_file, 0, 0); wBoot_write(index_buffer, 1, index_length, index_file); ret = 0; //完毕 dynamic_data_err: if(data_buffer) { wBoot_free(data_buffer); } if(data_file) { wBoot_fclose(data_file); } if(index_file) { wBoot_fclose(index_file); } return ret; }