- devfd = open(rc->device, O_RDWR | O_DIRECT);
- if (devfd == -1)
- return errno == EBUSY ? -EBUSY : -EINVAL;
+ devfd = open(rc->device, O_RDWR | O_EXCL | O_DIRECT);
+ if (devfd == -1) {
+ if (errno == EBUSY) {
+ log_err(_("Cannot exclusively open %s, device in use.\n"),
+ rc->device);
+ return -EBUSY;
+ }
+ log_err(_("Cannot open device %s\n"), rc->device);
+ return -EINVAL;
+ }
+
+ if (set_magic == CHECK_OPEN) {
+ r = 0;
+ goto out;
+ }