Add support for automatic loop device use (image infile etc).

git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@443 36d66b0a-2a48-0410-832c-cd162a569da5
This commit is contained in:
Milan Broz
2011-03-11 19:04:37 +00:00
parent b5a5564ac1
commit d9ba34693f
6 changed files with 205 additions and 17 deletions

View File

@@ -238,30 +238,33 @@ ssize_t write_lseek_blockwise(int fd, const char *buf, size_t count, off_t offse
int device_ready(struct crypt_device *cd, const char *device, int mode)
{
int devfd, r = 1;
int devfd, r = 0;
ssize_t s;
struct stat st;
char buf[512];
if(stat(device, &st) < 0) {
log_err(cd, _("Device %s doesn't exist or access denied.\n"), device);
return 0;
return -EINVAL;
}
if (!S_ISBLK(st.st_mode))
return -ENOTBLK;
log_dbg("Trying to open and read device %s.", device);
devfd = open(device, mode | O_DIRECT | O_SYNC);
if(devfd < 0) {
log_err(cd, _("Cannot open device %s for %s%s access.\n"), device,
(mode & O_EXCL) ? _("exclusive ") : "",
(mode & O_RDWR) ? _("writable") : _("read-only"));
return 0;
return -EINVAL;
}
/* Try to read first sector */
s = read_blockwise(devfd, buf, sizeof(buf));
if (s < 0 || s != sizeof(buf)) {
log_verbose(cd, _("Cannot read device %s.\n"), device);
r = 0;
r = -EIO;
}
memset(buf, 0, sizeof(buf));