diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2013-10-30 21:59:34 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2013-10-30 21:59:34 +0000 |
commit | 1f2bee2e23c650c9f24aa747c6005ea71efc3e62 (patch) | |
tree | d6f16978b376094dd34de25e0bfbc91852c75a43 | |
parent | 1faf81fa5c7a0f623ca002e8f5bc65447fc8eda8 (diff) | |
download | sg3_utils-1f2bee2e23c650c9f24aa747c6005ea71efc3e62.tar.gz |
examples/sg_tst_excl: only accept char devices to stop sg write/read hurting block dev
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@526 6180dd3e-e324-4e3e-922d-17de1ae2f315
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | examples/sg_tst_excl.cpp | 14 |
2 files changed, 14 insertions, 2 deletions
@@ -2,7 +2,7 @@ Each utility has its own version number, date of last change and some description at the top of its ".c" file. All utilities in the main directory have their own "man" pages. There is also a sg3_utils man page. -Changelog for sg3_utils-1.38 [20131029] [svn: r525] +Changelog for sg3_utils-1.38 [20131030] [svn: r526] - sg_inq: add --block=0|1 option to control opens - sg_luns: guard against garbage response - sg_lib_data: sync asc/ascq codes with T10 dated 20131008 diff --git a/examples/sg_tst_excl.cpp b/examples/sg_tst_excl.cpp index ebcb5197..86c3266a 100644 --- a/examples/sg_tst_excl.cpp +++ b/examples/sg_tst_excl.cpp @@ -46,7 +46,7 @@ #include "sg_lib.h" #include "sg_io_linux.h" -static const char * version_str = "1.05 20131028"; +static const char * version_str = "1.06 20131030"; static const char * util_name = "sg_tst_excl"; /* This is a test program for checking O_EXCL on open() works. It uses @@ -540,7 +540,19 @@ main(int argc, char * argv[]) return 1; } try { + struct stat a_stat; + if (stat(dev_name, &a_stat) < 0) { + perror("stat() on dev_name failed"); + return 1; + } + if (! S_ISCHR(a_stat.st_mode)) { + fprintf(stderr, "%s should be a sg device which is a char " + "device. %s\n", dev_name, dev_name); + fprintf(stderr, "is not a char device and damage could be done " + "if it is a BLOCK\ndevice, exiting ...\n"); + return 1; + } if (! force) { res = do_inquiry_prod_id(dev_name, block, wait_ms, ebusy_count, b, sizeof(b)); |