Input parameter handling for sg_wr_mode fails...
Opened this issue · 3 comments
Hello,
I updated to the latest version of sg3_utils and noticed that some of my test scripts didn't work anymore. After a quick study, I noticed that the sg_wr_mode input parameters are not handled right. Seems that after the latest changes, calling build_mode_page has been moved out from the while clause that's parsing the input parameters. When the build_mode_page is now called, optarg parameter is already NULL. Following changes fixed that for me (-c and -C parameters) but I'm not sure if there's more cases that needs to be updated/fixed.
BR, Affe
@@ -378,8 +378,10 @@ main(int argc, char * argv[])
pr2serr("Cannot have both --contents= and --cfile= options\n");
return SG_LIB_SYNTAX_ERROR;
}
-
if( cfile_arg )
-
contents_arg = cfile_arg; memset(read_in, 0, read_in_sz);
-
if ((ret = build_mode_page(optarg, !! cfile_arg, do_raw, read_in,
-
if ((ret = build_mode_page(contents_arg, !! cfile_arg, do_raw, read_in, &read_in_len, read_in_sz))) { pr2serr("bad argument to '%s'\n", cfile_arg ? "--cfile=" : "--contents=");
I tend to use the sdparm utility instead of sg_wr_mode. The existing code probably worked as long as -c or -C was the last option. Anyway svn rev 1048 now mirrored here should fix it. Could you test it? And if you have a general test script (or just a hex file for input) could you send it to me and I can put it in the inhex directory?
Hi Doug,
And thanks for the quick reply.
I can confirm that the parameter handling now works.
Placing the -c/-C option as a last one didn't make any difference because when the while loop for scanning the parameters is done (no more arguments found), the optarg content is returned as NULL.
Unfortunately, I can't provide any general test script for this. I have several scripts for multiple internal test cases and this was just one that started failing. I did used sdparm to do a one off test to verify that the functionality of the device was OK but since I'm mostly using these sg_utils for range of tests, I thought that it would be great to have this still fixed. I like the approach you have in here, easy to track down what is the problem, in case there is one :)
Thanks for the good job!
Affe
Inspired by this bug fix, I added a --mfile=MF option so that the mask data could also be placed in a separate file (svn rev: 1049]. Then in the inhex directory the wr_mode_cont.hex and wr_mode_mask.hex files have been added. Now those files can be used together with the Linux scsi_debug driver to turn off and on the WCE bit. (i.e. Write Cache Enable).