#include "system-recovery.h"
+static int loop_fd = -1;
+
+static int recovery_image_mounted;
static char recovery_image_path[PATH_MAX - FIELD_LENGTH];
+static unsigned long long total_image_size;
+
#ifdef LOG_FILE
/**
}
#endif
+static int release_recovery_image(void)
+{
+ int ret;
+
+ if (recovery_image_mounted) {
+ ret = umount(RECOVERY_IMAGE_MOUNTPOINT);
+ ASSERT_RETV(ret == 0, errno, "Failed to unmount recovery image (%d)", errno);
+ }
+
+ if (loop_fd >= 0) {
+ ret = ioctl(loop_fd, LOOP_CLR_FD, 0);
+ ASSERT_RETV(ret == 0, errno, "Failed to clear loop device (%d)", errno);
+ }
+
+ return SUCCEED;
+}
+
__attribute__((destructor)) static void __fini__(void)
{
int ret = SUCCEED;
if (ret != SUCCEED)
_W("Failed to write log file (%d)", ret);
#endif
-}
-static unsigned long long total_image_size;
+ ret = release_recovery_image();
+ if (ret != SUCCEED)
+ _W("Failed to release recovery image (%d)", ret);
+}
static int find_recovery_image(void)
{
int ret;
_CLEANUP_FD_ int loopctl_fd = -1;
- _CLEANUP_FD_ int loop_fd = -1;
_CLEANUP_FD_ int img_fd = -1;
int loop_idx;
char loop_device_path[32];
"squashfs", MS_RDONLY, NULL);
ASSERT_RETV(ret == 0, errno, "Failed to mount recovery image (%d)", errno);
+ recovery_image_mounted = 1;
return SUCCEED;
}