mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-13 20:00:08 +01:00
Add explicit device_close routine.
This commit is contained in:
@@ -109,6 +109,7 @@ const char *crypt_get_cipher_spec(struct crypt_device *cd);
|
|||||||
struct device;
|
struct device;
|
||||||
int device_alloc(struct crypt_device *cd, struct device **device, const char *path);
|
int device_alloc(struct crypt_device *cd, struct device **device, const char *path);
|
||||||
int device_alloc_no_check(struct device **device, const char *path);
|
int device_alloc_no_check(struct device **device, const char *path);
|
||||||
|
void device_close(struct crypt_device *cd, struct device *device);
|
||||||
void device_free(struct crypt_device *cd, struct device *device);
|
void device_free(struct crypt_device *cd, struct device *device);
|
||||||
const char *device_path(const struct device *device);
|
const char *device_path(const struct device *device);
|
||||||
const char *device_dm_name(const struct device *device);
|
const char *device_dm_name(const struct device *device);
|
||||||
|
|||||||
@@ -420,15 +420,7 @@ void device_free(struct crypt_device *cd, struct device *device)
|
|||||||
if (!device)
|
if (!device)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (device->ro_dev_fd != -1) {
|
device_close(cd, device);
|
||||||
log_dbg(cd, "Closed read only fd for %s.", device_path(device));
|
|
||||||
close(device->ro_dev_fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (device->dev_fd != -1) {
|
|
||||||
log_dbg(cd, "Closed read write fd for %s.", device_path(device));
|
|
||||||
close(device->dev_fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (device->dev_fd_excl != -1) {
|
if (device->dev_fd_excl != -1) {
|
||||||
log_dbg(cd, "Closed exclusive fd for %s.", device_path(device));
|
log_dbg(cd, "Closed exclusive fd for %s.", device_path(device));
|
||||||
@@ -978,3 +970,23 @@ bool device_is_locked(struct device *device)
|
|||||||
{
|
{
|
||||||
return device ? device_locked(device->lh) : 0;
|
return device ? device_locked(device->lh) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void device_close(struct crypt_device *cd, struct device *device)
|
||||||
|
{
|
||||||
|
if (!device)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (device->ro_dev_fd != -1) {
|
||||||
|
log_dbg(cd, "Closing read only fd for %s.", device_path(device));
|
||||||
|
if (close(device->ro_dev_fd))
|
||||||
|
log_dbg(cd, "Failed to close read only fd for %s.", device_path(device));
|
||||||
|
device->ro_dev_fd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (device->dev_fd != -1) {
|
||||||
|
log_dbg(cd, "Closing read write fd for %s.", device_path(device));
|
||||||
|
if (close(device->dev_fd))
|
||||||
|
log_dbg(cd, "Failed to close read write fd for %s.", device_path(device));
|
||||||
|
device->dev_fd = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user