"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/utils_loop.c" between
cryptsetup-2.3.6.tar.xz and cryptsetup-2.4.0.tar.xz

About: cryptsetup is a utility used to conveniently setup disk encryption based on the dm-crypt kernel module. These include plain dm-crypt volumes, LUKS volumes, loop-AES and TrueCrypt compatible format.

utils_loop.c  (cryptsetup-2.3.6.tar.xz):utils_loop.c  (cryptsetup-2.4.0.tar.xz)
skipping to change at line 31 skipping to change at line 31
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h>
#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
#include <linux/types.h>
#include <linux/loop.h> #include <linux/loop.h>
#include "utils_loop.h" #include "utils_loop.h"
#include "libcryptsetup_macros.h"
#define LOOP_DEV_MAJOR 7 #define LOOP_DEV_MAJOR 7
#ifndef LO_FLAGS_AUTOCLEAR #ifndef LO_FLAGS_AUTOCLEAR
#define LO_FLAGS_AUTOCLEAR 4 #define LO_FLAGS_AUTOCLEAR 4
#endif #endif
#ifndef LOOP_CTL_GET_FREE #ifndef LOOP_CTL_GET_FREE
#define LOOP_CTL_GET_FREE 0x4C82 #define LOOP_CTL_GET_FREE 0x4C82
#endif #endif
#ifndef LOOP_SET_CAPACITY #ifndef LOOP_SET_CAPACITY
#define LOOP_SET_CAPACITY 0x4C07 #define LOOP_SET_CAPACITY 0x4C07
#endif #endif
#ifndef LOOP_SET_BLOCK_SIZE
#define LOOP_SET_BLOCK_SIZE 0x4C09
#endif
#ifndef LOOP_CONFIGURE
#define LOOP_CONFIGURE 0x4C0A
struct loop_config {
__u32 fd;
__u32 block_size;
struct loop_info64 info;
__u64 __reserved[8];
};
#endif
static char *crypt_loop_get_device_old(void) static char *crypt_loop_get_device_old(void)
{ {
char dev[20]; char dev[20];
int i, loop_fd; int i, loop_fd;
struct loop_info64 lo64 = {0}; struct loop_info64 lo64 = {0};
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
sprintf(dev, "/dev/loop%d", i); sprintf(dev, "/dev/loop%d", i);
loop_fd = open(dev, O_RDONLY); loop_fd = open(dev, O_RDONLY);
skipping to change at line 104 skipping to change at line 119
if (sprintf(dev, "/dev/loop%d", i) < 0) if (sprintf(dev, "/dev/loop%d", i) < 0)
return NULL; 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);
} }
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, size_t blocksize)
{ {
struct loop_info64 lo64 = {0}; struct loop_config config = {0};
char *lo_file_name; char *lo_file_name;
int loop_fd = -1, file_fd = -1, r = 1; int loop_fd = -1, file_fd = -1, r = 1;
int fallback = 0;
*loop = NULL; *loop = NULL;
file_fd = open(file, (*readonly ? O_RDONLY : O_RDWR) | O_EXCL); file_fd = open(file, (*readonly ? O_RDONLY : O_RDWR) | O_EXCL);
if (file_fd < 0 && (errno == EROFS || errno == EACCES) && !*readonly) { if (file_fd < 0 && (errno == EROFS || errno == EACCES) && !*readonly) {
*readonly = 1; *readonly = 1;
file_fd = open(file, O_RDONLY | O_EXCL); file_fd = open(file, O_RDONLY | O_EXCL);
} }
if (file_fd < 0) if (file_fd < 0)
goto out; goto out;
while (loop_fd < 0) { config.fd = file_fd;
lo_file_name = (char*)config.info.lo_file_name;
lo_file_name[LO_NAME_SIZE-1] = '\0';
strncpy(lo_file_name, file, LO_NAME_SIZE-1);
config.info.lo_offset = offset;
if (autoclear)
config.info.lo_flags |= LO_FLAGS_AUTOCLEAR;
if (blocksize > SECTOR_SIZE)
config.block_size = blocksize;
while (loop_fd < 0) {
*loop = crypt_loop_get_device(); *loop = crypt_loop_get_device();
if (!*loop) if (!*loop)
goto out; goto out;
loop_fd = open(*loop, *readonly ? O_RDONLY : O_RDWR); loop_fd = open(*loop, *readonly ? O_RDONLY : O_RDWR);
if (loop_fd < 0) if (loop_fd < 0)
goto out; goto out;
if (ioctl(loop_fd, LOOP_CONFIGURE, &config) < 0) {
if (ioctl(loop_fd, LOOP_SET_FD, file_fd) < 0) { if (errno == EINVAL || errno == ENOTTY) {
free(*loop);
*loop = NULL;
close(loop_fd);
loop_fd = -1;
/* kernel doesn't support LOOP_CONFIGURE */
fallback = 1;
break;
}
if (errno != EBUSY) if (errno != EBUSY)
goto out; goto out;
free(*loop); free(*loop);
*loop = NULL; *loop = NULL;
close(loop_fd); close(loop_fd);
loop_fd = -1; loop_fd = -1;
} }
} }
lo_file_name = (char*)lo64.lo_file_name; if (fallback) {
lo_file_name[LO_NAME_SIZE-1] = '\0'; while (loop_fd < 0) {
strncpy(lo_file_name, file, LO_NAME_SIZE-1); *loop = crypt_loop_get_device();
lo64.lo_offset = offset; if (!*loop)
if (autoclear) goto out;
lo64.lo_flags |= LO_FLAGS_AUTOCLEAR;
if (ioctl(loop_fd, LOOP_SET_STATUS64, &lo64) < 0) { loop_fd = open(*loop, *readonly ? O_RDONLY : O_RDWR);
(void)ioctl(loop_fd, LOOP_CLR_FD, 0); if (loop_fd < 0)
goto out; goto out;
if (ioctl(loop_fd, LOOP_SET_FD, file_fd) < 0) {
if (errno != EBUSY)
goto out;
free(*loop);
*loop = NULL;
close(loop_fd);
loop_fd = -1;
}
}
if (blocksize > SECTOR_SIZE)
(void)ioctl(loop_fd, LOOP_SET_BLOCK_SIZE, (unsigned long)
blocksize);
if (ioctl(loop_fd, LOOP_SET_STATUS64, &config.info) < 0) {
(void)ioctl(loop_fd, LOOP_CLR_FD, 0);
goto out;
}
} }
/* Verify that autoclear is really set */ /* Verify that autoclear is really set */
if (autoclear) { if (autoclear) {
memset(&lo64, 0, sizeof(lo64)); memset(&config.info, 0, sizeof(config.info));
if (ioctl(loop_fd, LOOP_GET_STATUS64, &lo64) < 0 || if (ioctl(loop_fd, LOOP_GET_STATUS64, &config.info) < 0 ||
!(lo64.lo_flags & LO_FLAGS_AUTOCLEAR)) { !(config.info.lo_flags & LO_FLAGS_AUTOCLEAR)) {
(void)ioctl(loop_fd, LOOP_CLR_FD, 0); (void)ioctl(loop_fd, LOOP_CLR_FD, 0);
goto out; goto out;
} }
} }
r = 0; r = 0;
out: out:
if (r && loop_fd >= 0) if (r && loop_fd >= 0)
close(loop_fd); close(loop_fd);
if (file_fd >= 0) if (file_fd >= 0)
 End of changes. 12 change blocks. 
18 lines changed or deleted 73 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)