Re: [dpdk-dev] [PATCH] app/procinfo: add device registers dump
From: Chengchang Tang <tangchengchang@huawei.com>
Date: 2021-07-19 07:00:26
On 2021/7/18 1:53, Stephen Hemminger wrote:
On Sun, 25 Apr 2021 21:02:22 +0800 "Min Hu (Connor)" [off-list ref] wrote:quoted
snprintf(file_name, MAX_FILE_NAME_SZ, "%s-port%u", + file_prefix, i); + fp_regs = fopen(file_name, "wb"); + if (fp_regs == NULL) { + printf("Error during opening '%s' for writing\n", + file_name); + } else { + if ((int)fwrite(buf_data, 1, buf_size, fp_regs) != + buf_size) + printf("Error during writing %s\n", + file_prefix); + else + printf("dump device (%s) regs successfully, " + "driver:%s version:0X%08X\n", + dev_info.device->name, + dev_info.driver_name, reg_info.version); + + fclose(fp_regs); +I don't like applications opening and writing an arbitrary file in the current directory. Any file should be an argument to the application and optional.
I think the use of the file here does not seem to be exactly the same as the behavior you object to. The directories of the file and its name prefix is passed by user. some suffixes has been added based on user's input. This is mainly considering the scenario where the user does not specify a device. If no device is specified, this command will dump regs for all devices, and their dumped files are distinguished by the suffixes. If the user is required to give a name to the dumped file of each device, the ease of use of this command may decreases
Also, since you are writing binary data, there is no point in using stdio here. .