For some reason there was an fstat() call here whose results was
entirely ignored. Let's remove it. Let's add a call to
fd_verify_regular() instead, because this is a code path for swap files,
hence let's make sure we actually operate on a file, and nothing else.
static int calculate_swap_file_offset(const SwapEntry *swap, uint64_t *ret_offset) {
_cleanup_close_ int fd = -EBADF;
_cleanup_free_ struct fiemap *fiemap = NULL;
- struct stat sb;
int r;
assert(swap);
if (fd < 0)
return log_debug_errno(errno, "Failed to open swap file %s to determine on-disk offset: %m", swap->device);
- if (fstat(fd, &sb) < 0)
- return log_debug_errno(errno, "Failed to stat %s: %m", swap->device);
+ r = fd_verify_regular(fd);
+ if (r < 0)
+ return log_debug_errno(r, "Selected swap file is not a regular file.");
r = fd_is_fs_type(fd, BTRFS_SUPER_MAGIC);
if (r < 0)