Commit 7fc006b6 authored by Ondrej Kozina's avatar Ondrej Kozina Committed by Milan Broz

Add interrupt safe read_lseek_blockwise function.

parent 3e653ace
...@@ -103,6 +103,7 @@ ssize_t read_buffer(int fd, void *buf, size_t count); ...@@ -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);
......
...@@ -273,6 +273,52 @@ out: ...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment