mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
Sync device using internal write enabled descriptor.
This commit is contained in:
committed by
Milan Broz
parent
ee57b865b0
commit
83c227d53c
@@ -129,7 +129,7 @@ int device_is_rotational(struct device *device);
|
||||
size_t device_alignment(struct device *device);
|
||||
int device_direct_io(const struct device *device);
|
||||
int device_fallocate(struct device *device, uint64_t size);
|
||||
void device_sync(struct crypt_device *cd, struct device *device, int devfd);
|
||||
void device_sync(struct crypt_device *cd, struct device *device);
|
||||
int device_check_size(struct crypt_device *cd,
|
||||
struct device *device,
|
||||
uint64_t req_offset, int falloc);
|
||||
|
||||
@@ -196,8 +196,7 @@ int LUKS_encrypt_to_storage(char *src, size_t srcLength,
|
||||
|
||||
r = 0;
|
||||
out:
|
||||
if (devfd >= 0)
|
||||
device_sync(ctx, device, devfd);
|
||||
device_sync(ctx, device);
|
||||
if (r)
|
||||
log_err(ctx, _("IO error while encrypting keyslot."));
|
||||
|
||||
|
||||
@@ -359,8 +359,7 @@ int LUKS_hdr_restore(
|
||||
/* Be sure to reload new data */
|
||||
r = LUKS_read_phdr(hdr, 1, 0, ctx);
|
||||
out:
|
||||
if (devfd >= 0)
|
||||
device_sync(ctx, device, devfd);
|
||||
device_sync(ctx, device);
|
||||
crypt_safe_free(buffer);
|
||||
return r;
|
||||
}
|
||||
@@ -661,7 +660,7 @@ int LUKS_write_phdr(struct luks_phdr *hdr,
|
||||
if (r)
|
||||
log_err(ctx, _("Error during update of LUKS header on device %s."), device_path(device));
|
||||
|
||||
device_sync(ctx, device, devfd);
|
||||
device_sync(ctx, device);
|
||||
|
||||
/* Re-read header from disk to be sure that in-memory and on-disk data are the same. */
|
||||
if (!r) {
|
||||
|
||||
@@ -345,7 +345,7 @@ static int hdr_write_disk(struct crypt_device *cd,
|
||||
LUKS2_HDR_BIN_LEN, offset) < (ssize_t)LUKS2_HDR_BIN_LEN)
|
||||
r = -EIO;
|
||||
|
||||
device_sync(cd, device, devfd);
|
||||
device_sync(cd, device);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@@ -1256,8 +1256,7 @@ out:
|
||||
crypt_memzero(&tmp_hdr, sizeof(tmp_hdr));
|
||||
crypt_safe_free(buffer);
|
||||
|
||||
if (devfd >= 0)
|
||||
device_sync(cd, device, devfd);
|
||||
device_sync(cd, device);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ static int luks2_encrypt_to_storage(char *src, size_t srcLength,
|
||||
else
|
||||
r = 0;
|
||||
|
||||
device_sync(cd, device, devfd);
|
||||
device_sync(cd, device);
|
||||
} else
|
||||
r = -EIO;
|
||||
|
||||
|
||||
@@ -465,7 +465,7 @@ static int move_keyslot_areas(struct crypt_device *cd, off_t offset_from,
|
||||
|
||||
r = 0;
|
||||
out:
|
||||
device_sync(cd, device, devfd);
|
||||
device_sync(cd, device);
|
||||
crypt_memzero(buf, buf_size);
|
||||
free(buf);
|
||||
|
||||
|
||||
@@ -240,11 +240,13 @@ static int _open_locked(struct crypt_device *cd, struct device *device, int flag
|
||||
|
||||
/*
|
||||
* Common wrapper for device sync.
|
||||
* FIXME: file descriptor will be in struct later.
|
||||
*/
|
||||
void device_sync(struct crypt_device *cd, struct device *device, int devfd)
|
||||
void device_sync(struct crypt_device *cd, struct device *device)
|
||||
{
|
||||
if (fsync(devfd) == -1)
|
||||
if (!device || device->dev_fd < 0)
|
||||
return;
|
||||
|
||||
if (fsync(device->dev_fd) == -1)
|
||||
log_dbg(cd, "Cannot sync device %s.", device_path(device));
|
||||
}
|
||||
|
||||
|
||||
@@ -215,7 +215,7 @@ int crypt_wipe_device(struct crypt_device *cd,
|
||||
}
|
||||
}
|
||||
|
||||
device_sync(cd, device, devfd);
|
||||
device_sync(cd, device);
|
||||
out:
|
||||
free(sf);
|
||||
return r;
|
||||
|
||||
@@ -199,7 +199,7 @@ int VERITY_write_sb(struct crypt_device *cd,
|
||||
log_err(cd, _("Error during update of verity header on device %s."),
|
||||
device_path(device));
|
||||
|
||||
device_sync(cd, device, devfd);
|
||||
device_sync(cd, device);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user