mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-06 00:10:04 +01:00
Add interrupt safe read_lseek_blockwise function.
This commit is contained in:
committed by
Milan Broz
parent
3e653ace3e
commit
7fc006b63b
@@ -103,6 +103,7 @@ ssize_t read_buffer(int fd, void *buf, size_t count);
|
|||||||
ssize_t write_blockwise(int fd, int bsize, void *buf, size_t count);
|
ssize_t write_blockwise(int fd, int bsize, void *buf, size_t count);
|
||||||
ssize_t read_blockwise(int fd, int bsize, void *_buf, size_t count);
|
ssize_t read_blockwise(int fd, int bsize, void *_buf, size_t count);
|
||||||
ssize_t write_lseek_blockwise(int fd, int bsize, char *buf, size_t count, off_t offset);
|
ssize_t write_lseek_blockwise(int fd, int bsize, char *buf, size_t count, off_t offset);
|
||||||
|
ssize_t read_lseek_blockwise(int fd, int bsize, char *buf, size_t count, off_t offset);
|
||||||
|
|
||||||
unsigned crypt_getpagesize(void);
|
unsigned crypt_getpagesize(void);
|
||||||
int init_crypto(struct crypt_device *ctx);
|
int init_crypto(struct crypt_device *ctx);
|
||||||
|
|||||||
46
lib/utils.c
46
lib/utils.c
@@ -273,6 +273,52 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssize_t read_lseek_blockwise(int fd, int bsize, char *buf, size_t count, off_t offset)
|
||||||
|
{
|
||||||
|
char *frontPadBuf;
|
||||||
|
void *frontPadBuf_base = NULL;
|
||||||
|
int r, frontHang;
|
||||||
|
size_t innerCount = 0;
|
||||||
|
ssize_t ret = -1;
|
||||||
|
|
||||||
|
if (fd == -1 || !buf || bsize <= 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
frontHang = offset % bsize;
|
||||||
|
|
||||||
|
if (lseek(fd, offset - frontHang, SEEK_SET) < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if (frontHang) {
|
||||||
|
frontPadBuf = aligned_malloc(&frontPadBuf_base,
|
||||||
|
bsize, get_alignment(fd));
|
||||||
|
|
||||||
|
if (!frontPadBuf)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
r = read_buffer(fd, frontPadBuf, bsize);
|
||||||
|
if (r < 0 || r != bsize)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
innerCount = bsize - frontHang;
|
||||||
|
if (innerCount > count)
|
||||||
|
innerCount = count;
|
||||||
|
|
||||||
|
memcpy(buf, frontPadBuf + frontHang, innerCount);
|
||||||
|
|
||||||
|
buf += innerCount;
|
||||||
|
count -= innerCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = read_blockwise(fd, bsize, buf, count);
|
||||||
|
if (ret >= 0)
|
||||||
|
ret += innerCount;
|
||||||
|
out:
|
||||||
|
free(frontPadBuf_base);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* MEMLOCK */
|
/* MEMLOCK */
|
||||||
#define DEFAULT_PROCESS_PRIORITY -18
|
#define DEFAULT_PROCESS_PRIORITY -18
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user