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 /examples | |
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
Diffstat (limited to 'examples')
-rw-r--r-- | examples/sg_tst_excl.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
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)); |