mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-13 20:00:08 +01:00
Set block size for loop device if supported by kernel (4.13+).
This commit is contained in:
@@ -32,6 +32,9 @@
|
|||||||
#ifdef HAVE_SYS_SYSMACROS_H
|
#ifdef HAVE_SYS_SYSMACROS_H
|
||||||
# include <sys/sysmacros.h> /* for major, minor */
|
# include <sys/sysmacros.h> /* for major, minor */
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_SYS_STATVFS_H
|
||||||
|
# include <sys/statvfs.h>
|
||||||
|
#endif
|
||||||
#include <linux/loop.h>
|
#include <linux/loop.h>
|
||||||
|
|
||||||
#include "utils_loop.h"
|
#include "utils_loop.h"
|
||||||
@@ -50,6 +53,11 @@
|
|||||||
#define LOOP_SET_CAPACITY 0x4C07
|
#define LOOP_SET_CAPACITY 0x4C07
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef LO_FLAGS_BLOCKSIZE
|
||||||
|
#define LO_FLAGS_BLOCKSIZE 32
|
||||||
|
#define LO_INFO_BLOCKSIZE(l) (l)->lo_init[0]
|
||||||
|
#endif
|
||||||
|
|
||||||
static char *crypt_loop_get_device_old(void)
|
static char *crypt_loop_get_device_old(void)
|
||||||
{
|
{
|
||||||
char dev[20];
|
char dev[20];
|
||||||
@@ -100,6 +108,21 @@ static char *crypt_loop_get_device(void)
|
|||||||
return strdup(dev);
|
return strdup(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t crypt_loop_block_size_fd(int fd)
|
||||||
|
{
|
||||||
|
size_t bs = 512;
|
||||||
|
#ifdef HAVE_SYS_STATVFS_H
|
||||||
|
struct statvfs buf;
|
||||||
|
|
||||||
|
if (!fstatvfs(fd, &buf) && buf.f_bsize)
|
||||||
|
bs = (size_t)buf.f_bsize;
|
||||||
|
|
||||||
|
if (bs != 1024 && bs != 2048 && bs != 4096)
|
||||||
|
bs = 512;
|
||||||
|
#endif
|
||||||
|
return bs;
|
||||||
|
}
|
||||||
|
|
||||||
int crypt_loop_attach(char **loop, const char *file, int offset,
|
int crypt_loop_attach(char **loop, const char *file, int offset,
|
||||||
int autoclear, int *readonly)
|
int autoclear, int *readonly)
|
||||||
{
|
{
|
||||||
@@ -144,6 +167,9 @@ int crypt_loop_attach(char **loop, const char *file, int offset,
|
|||||||
if (autoclear)
|
if (autoclear)
|
||||||
lo64.lo_flags |= LO_FLAGS_AUTOCLEAR;
|
lo64.lo_flags |= LO_FLAGS_AUTOCLEAR;
|
||||||
|
|
||||||
|
LO_INFO_BLOCKSIZE(&lo64) = crypt_loop_block_size_fd(file_fd);
|
||||||
|
lo64.lo_flags |= LO_FLAGS_BLOCKSIZE;
|
||||||
|
|
||||||
if (ioctl(loop_fd, LOOP_SET_STATUS64, &lo64) < 0) {
|
if (ioctl(loop_fd, LOOP_SET_STATUS64, &lo64) < 0) {
|
||||||
(void)ioctl(loop_fd, LOOP_CLR_FD, 0);
|
(void)ioctl(loop_fd, LOOP_CLR_FD, 0);
|
||||||
goto out;
|
goto out;
|
||||||
|
|||||||
Reference in New Issue
Block a user