Use /dev/loop-control if possible (kernel 3.1).

git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@605 36d66b0a-2a48-0410-832c-cd162a569da5
This commit is contained in:
Milan Broz
2011-08-22 22:33:24 +00:00
parent 1954792876
commit f3ed801e8b
3 changed files with 9 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
2011-08-22 Milan Broz <mbroz@redhat.com> 2011-08-22 Milan Broz <mbroz@redhat.com>
* Add more paranoid checks for LUKS header and keyslot attributes. * Add more paranoid checks for LUKS header and keyslot attributes.
* Fix crypt_load to properly check device size. * Fix crypt_load to properly check device size.
* Use new /dev/loop-control (kernel 3.1) if possible.
2011-07-25 Milan Broz <mbroz@redhat.com> 2011-07-25 Milan Broz <mbroz@redhat.com>
* Remove hash/hmac restart from crypto backend and make it part of hash/hmac final. * Remove hash/hmac restart from crypto backend and make it part of hash/hmac final.

View File

@@ -29,11 +29,7 @@
#include "utils_loop.h" #include "utils_loop.h"
#ifndef LOOP_CTL_GET_FREE static char *crypt_loop_get_device_old(void)
#define LOOP_CTL_GET_FREE 0x4C82
#endif
char *crypt_loop_get_device(void)
{ {
char dev[20]; char dev[20];
int i, loop_fd; int i, loop_fd;
@@ -60,8 +56,6 @@ char *crypt_loop_get_device(void)
return NULL; return NULL;
} }
/* loop-control not yet upstream */
#if 0
char *crypt_loop_get_device(void) char *crypt_loop_get_device(void)
{ {
char dev[64]; char dev[64];
@@ -70,7 +64,7 @@ char *crypt_loop_get_device(void)
loop_fd = open("/dev/loop-control", O_RDONLY); loop_fd = open("/dev/loop-control", O_RDONLY);
if (loop_fd < 0) if (loop_fd < 0)
return NULL; return crypt_loop_get_device_old();
i = ioctl(loop_fd, LOOP_CTL_GET_FREE); i = ioctl(loop_fd, LOOP_CTL_GET_FREE);
if (i < 0) { if (i < 0) {
@@ -79,14 +73,14 @@ char *crypt_loop_get_device(void)
} }
close(loop_fd); close(loop_fd);
snprintf(dev, "/dev/loop%d", i, sizeof(dev)); if (sprintf(dev, "/dev/loop%d", i) < 0)
return NULL;
if (stat(dev, &st) || !S_ISBLK(st.st_mode)) if (stat(dev, &st) || !S_ISBLK(st.st_mode))
return NULL; return NULL;
return strdup(dev); return strdup(dev);
} }
#endif
int crypt_loop_attach(const char *loop, const char *file, int offset, int crypt_loop_attach(const char *loop, const char *file, int offset,
int autoclear, int *readonly) int autoclear, int *readonly)

View File

@@ -9,6 +9,10 @@
#define LO_FLAGS_AUTOCLEAR 4 #define LO_FLAGS_AUTOCLEAR 4
#endif #endif
#ifndef LOOP_CTL_GET_FREE
#define LOOP_CTL_GET_FREE 0x4C82
#endif
char *crypt_loop_get_device(void); char *crypt_loop_get_device(void);
char *crypt_loop_backing_file(const char *loop); char *crypt_loop_backing_file(const char *loop);
int crypt_loop_device(const char *loop); int crypt_loop_device(const char *loop);