my_bool check_drop(uint audit_class,MYSQL* mysql,char* table) { char* pfile,*pdate; char sql[FN_LEN] = {0}; if(!mysql || !table) return FALSE; my_snprintf(sql,FN_LEN,"DROP TABLE %s", table); pdate = get_current_datetime(audit_datetime); if(audit_class == 2) { opt_audit_class = 2; if(!execute_no_query(mysql,sql)) return FALSE; pfile = get_audit_file_name(audit_name,FILE_NAME_LEN); return check_file_result(pfile,pdate,AUDIT_CREATE_NAME.str,mysql->host,mysql->user,sql); } else{ opt_audit_class = 4; if(!execute_no_query(mysql,sql)) return FALSE; pfile = get_audit_table_name(audit_name,FILE_NAME_LEN); return check_table_result(pfile,pdate,"command",AUDIT_CREATE_NAME.str,"host",mysql->host,"user",mysql->user,"query",sql); } }
int mount_fs() { FRESULT err; filesystem_info fatfs_info; FATFS_LinkDriver(&SFLASHDISK_Driver, SFLASHPath); err = f_mount(&SFLASHFatFs, (TCHAR const *)SFLASHPath, 0); check_file_result(err, "Fail to mount filesystem."); fatfs_info = fatfs_get_info((uint8_t *)SFLASHPath); if (fatfs_info.total_space == 0) { helper_log("Filesystem total space is %d, need format", fatfs_info.total_space); helper_log("Start formatting filesystem..."); err = f_mkfs((TCHAR const *)SFLASHPath, 0, _MAX_SS); check_file_result(err, "Fail to format filesystem."); fatfs_info = fatfs_get_info((uint8_t *)SFLASHPath); } helper_log("filesystem total space is %dKB, free space is %dKB", fatfs_info.total_space, fatfs_info.free_space); is_fs_mounted = true; return FR_OK; }
int save_file(char *filename, const char *input) { FRESULT err; uint32_t byteswritten; ensure_fs_mounted(); err = f_open(&SFLASHFile, filename, FA_CREATE_ALWAYS | FA_WRITE); check_file_result(err, "Fail to open file: %s, err: %d", filename, err); err = f_write(&SFLASHFile, input, strlen(input), (void *)&byteswritten); if ((byteswritten == 0) || (err != FR_OK)) { helper_log("Fail to write file, error %d", err); f_close(&SFLASHFile); return err; } helper_log("fatfs write file, name:%s, data:%s", filename, input); err = f_close(&SFLASHFile); check_file_result(err, "Fail to close file: %s", filename); return err; }
int read_file(char *filename, char *output, size_t output_len) { FRESULT err; uint32_t bytesread; ensure_fs_mounted(); err = f_open(&SFLASHFile, filename, FA_READ); check_file_result(err, "Fail to open file: %s", filename); err = f_read(&SFLASHFile, output, output_len, (void *)&bytesread); if ((bytesread == 0) || (err != FR_OK)) { helper_log("fatfs read error %d", err); f_close(&SFLASHFile); return err; } helper_log("fatfs read file, name:%s, data:%s", filename, output); err = f_close(&SFLASHFile); check_file_result(err, "Fail to close file: %s", filename); return err; }