*
* Copyright (C) 2012, Red Hat, Inc. All rights reserved.
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
+ * This file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
char **uuid_string,
struct crypt_params_verity *params)
{
- const char *device = device_path(crypt_metadata_device(cd));
- int bsize = device_block_size(crypt_metadata_device(cd));
+ struct device *device = crypt_metadata_device(cd);
+ int bsize = device_block_size(device);
struct verity_sb sb = {};
ssize_t hdr_size = sizeof(struct verity_sb);
int devfd = 0, sb_version;
log_dbg("Reading VERITY header of size %u on device %s, offset %" PRIu64 ".",
- sizeof(struct verity_sb), device, sb_offset);
+ sizeof(struct verity_sb), device_path(device), sb_offset);
if (params->flags & CRYPT_VERITY_NO_HEADER) {
- log_err(cd, _("Verity device doesn't use on-disk header.\n"), device);
+ log_err(cd, _("Verity device doesn't use on-disk header.\n"),
+ device_path(device));
return -EINVAL;
}
return -EINVAL;
}
- devfd = open(device ,O_RDONLY | O_DIRECT);
+ devfd = device_open(device, O_RDONLY);
if(devfd == -1) {
- log_err(cd, _("Cannot open device %s.\n"), device);
+ log_err(cd, _("Cannot open device %s.\n"), device_path(device));
return -EINVAL;
}
close(devfd);
if (memcmp(sb.signature, VERITY_SIGNATURE, sizeof(sb.signature))) {
- log_err(cd, _("Device %s is not a valid VERITY device.\n"), device);
+ log_err(cd, _("Device %s is not a valid VERITY device.\n"),
+ device_path(device));
return -EINVAL;
}
const char *uuid_string,
struct crypt_params_verity *params)
{
- const char *device = device_path(crypt_metadata_device(cd));
- int bsize = device_block_size(crypt_metadata_device(cd));
+ struct device *device = crypt_metadata_device(cd);
+ int bsize = device_block_size(device);
struct verity_sb sb = {};
ssize_t hdr_size = sizeof(struct verity_sb);
uuid_t uuid;
int r, devfd = 0;
log_dbg("Updating VERITY header of size %u on device %s, offset %" PRIu64 ".",
- sizeof(struct verity_sb), device, sb_offset);
+ sizeof(struct verity_sb), device_path(device), sb_offset);
if (!uuid_string || uuid_parse(uuid_string, uuid) == -1) {
- log_err(cd, _("Wrong VERITY UUID format provided.\n"), device);
+ log_err(cd, _("Wrong VERITY UUID format provided.\n"),
+ device_path(device));
return -EINVAL;
}
if (params->flags & CRYPT_VERITY_NO_HEADER) {
- log_err(cd, _("Verity device doesn't use on-disk header.\n"), device);
+ log_err(cd, _("Verity device doesn't use on-disk header.\n"),
+ device_path(device));
return -EINVAL;
}
- devfd = open(device, O_RDWR | O_DIRECT);
+ devfd = device_open(device, O_RDWR);
if(devfd == -1) {
- log_err(cd, _("Cannot open device %s.\n"), device);
+ log_err(cd, _("Cannot open device %s.\n"), device_path(device));
return -EINVAL;
}
r = write_lseek_blockwise(devfd, bsize, (char*)&sb, hdr_size, sb_offset) < hdr_size ? -EIO : 0;
if (r)
- log_err(cd, _("Error during update of verity header on device %s.\n"), device);
+ log_err(cd, _("Error during update of verity header on device %s.\n"),
+ device_path(device));
close(devfd);
return r;
if (r)
return r;
- r = dm_create_device(name, CRYPT_VERITY, &dmd, 0);
- if (!r && !(dm_flags() & DM_VERITY_SUPPORTED)) {
+ r = dm_create_device(cd, name, CRYPT_VERITY, &dmd, 0);
+ if (r < 0 && !(dm_flags() & DM_VERITY_SUPPORTED)) {
log_err(cd, _("Kernel doesn't support dm-verity mapping.\n"));
return -ENOTSUP;
}
if (r < 0)
return r;
- r = dm_status_verity_ok(name);
+ r = dm_status_verity_ok(cd, name);
if (r < 0)
return r;