+static int device_check_and_adjust(struct crypt_device *cd,
+ const char *device,
+ uint64_t *size, uint64_t *offset,
+ int *read_only)
+{
+ struct device_infos infos;
+
+ if (get_device_infos(device, &infos, cd) < 0) {
+ log_err(cd, _("Cannot get info about device %s.\n"), device);
+ return -ENOTBLK;
+ }
+
+ if (!*size) {
+ *size = infos.size;
+ if (!*size) {
+ log_err(cd, _("Device %s has zero size.\n"), device);
+ return -ENOTBLK;
+ }
+ if (*size <= *offset) {
+ log_err(cd, _("Device %s is too small.\n"), device);
+ return -EINVAL;
+ }
+ *size -= *offset;
+ }
+
+ if (infos.readonly)
+ *read_only = 1;
+
+ return 0;
+}
+