return r;
} else {
if (r >= 0) {
- set_error("Device already exists");
+ set_error("Device %s already exists.", options->name);
return -EEXIST;
}
if (r != -ENODEV)
int PBKDF2perSecond;
int keyIndex;
- if (!LUKS_device_ready(options->device, O_RDWR | O_EXCL)) {
- set_error("Can not access device");
- r = -ENOTBLK; goto out;
- }
+ if (!LUKS_device_ready(options->device, O_RDWR | O_EXCL))
+ return -ENOTBLK;
mk = LUKS_generate_masterkey(options->key_size);
if(NULL == mk) return -ENOMEM; // FIXME This may be misleading, since we don't know what went wrong
r = backend->status(0, &tmp, NULL);
if (r >= 0) {
- set_error("Device already exists");
+ set_error("Device %s already exists.", options->name);
return -EEXIST;
}
- if (!LUKS_device_ready(options->device, O_RDONLY | excl)) {
- set_error("Can not access device");
+ if (!LUKS_device_ready(options->device, O_RDONLY | excl))
return -ENOTBLK;
- }
if (get_device_infos(options->device, &infos) < 0) {
set_error("Can't get device information.\n");
unsigned int keyIndex;
const char *device = options->device;
int r;
-
- if (!LUKS_device_ready(options->device, O_RDWR)) {
- set_error("Can not access device");
- r = -ENOTBLK; goto out;
- }
+
+ if (!LUKS_device_ready(options->device, O_RDWR))
+ return -ENOTBLK;
r = LUKS_read_phdr(device, &hdr);
if(r < 0) return r;
int keyIndex;
int openedIndex;
int r;
- if (!LUKS_device_ready(options->device, O_RDWR)) {
- set_error("Can not access device");
- r = -ENOTBLK; goto out;
- }
+
+ if (!LUKS_device_ready(options->device, O_RDWR))
+ return -ENOTBLK;
if(supply_it) {
get_key("Enter LUKS passphrase to be deleted: ",&password,&passwordLen, 0, options->new_key_file, options->passphrase_fd, options->timeout, options->flags);
int LUKS_device_ready(const char *device, int mode)
{
- int devfd = open(device, mode | O_DIRECT | O_SYNC);
- if(devfd < 0) {
- set_error(_("Can't open device for %s%saccess: %s\n"), (mode & O_EXCL)?_("exclusive "):"", (mode & O_RDWR)?_("writable "):"read-only ", device);
- return 0;
- }
- close(devfd);
- return 1;
+ int devfd;
+ struct stat st;
+
+ if(stat(device, &st) < 0) {
+ set_error(_("Device %s doesn't exist or access denied."), device);
+ return 0;
+ }
+
+ devfd = open(device, mode | O_DIRECT | O_SYNC);
+ if(devfd < 0) {
+ set_error(_("Can't open device %s for %s%saccess."), device,
+ (mode & O_EXCL)?_("exclusive "):"",
+ (mode & O_RDWR)?_("writable "):"read-only ");
+ return 0;
+ }
+ close(devfd);
+
+ return 1;
}
// Local Variables: