mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-13 20:00:08 +01:00
Slight code style improvements for blockwise functions.
This commit is contained in:
committed by
Milan Broz
parent
7fc006b63b
commit
091dfa0c26
@@ -101,7 +101,7 @@ uint64_t crypt_dev_partition_offset(const char *dev_path);
|
|||||||
ssize_t write_buffer(int fd, const void *buf, size_t count);
|
ssize_t write_buffer(int fd, const void *buf, size_t count);
|
||||||
ssize_t read_buffer(int fd, void *buf, size_t count);
|
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);
|
ssize_t read_lseek_blockwise(int fd, int bsize, char *buf, size_t count, off_t offset);
|
||||||
|
|
||||||
|
|||||||
17
lib/utils.c
17
lib/utils.c
@@ -56,13 +56,14 @@ static void *aligned_malloc(void **base, int size, int alignment)
|
|||||||
/* Credits go to Michal's padlock patches for this alignment code */
|
/* Credits go to Michal's padlock patches for this alignment code */
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
ptr = malloc(size + alignment);
|
ptr = malloc(size + alignment);
|
||||||
if(ptr == NULL) return NULL;
|
if (!ptr)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
*base = ptr;
|
*base = ptr;
|
||||||
if(alignment > 1 && ((long)ptr & (alignment - 1))) {
|
if (alignment > 1 && ((long)ptr & (alignment - 1)))
|
||||||
ptr += alignment - ((long)(ptr) & (alignment - 1));
|
ptr += alignment - ((long)(ptr) & (alignment - 1));
|
||||||
}
|
|
||||||
return ptr;
|
return ptr;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -171,7 +172,8 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t read_blockwise(int fd, int bsize, void *orig_buf, size_t count) {
|
ssize_t read_blockwise(int fd, int bsize, void *orig_buf, size_t count)
|
||||||
|
{
|
||||||
void *hangover_buf, *hangover_buf_base = NULL;
|
void *hangover_buf, *hangover_buf_base = NULL;
|
||||||
void *buf, *buf_base = NULL;
|
void *buf, *buf_base = NULL;
|
||||||
int r, alignment;
|
int r, alignment;
|
||||||
@@ -193,7 +195,7 @@ ssize_t read_blockwise(int fd, int bsize, void *orig_buf, size_t count) {
|
|||||||
buf = orig_buf;
|
buf = orig_buf;
|
||||||
|
|
||||||
r = read_buffer(fd, buf, solid);
|
r = read_buffer(fd, buf, solid);
|
||||||
if(r < 0 || r != (ssize_t)solid)
|
if (r < 0 || r != (ssize_t)solid)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (hangover) {
|
if (hangover) {
|
||||||
@@ -222,7 +224,8 @@ out:
|
|||||||
* is implicitly included in the read/write offset, which can not be set to non-aligned
|
* is implicitly included in the read/write offset, which can not be set to non-aligned
|
||||||
* boundaries. Hence, we combine llseek with write.
|
* boundaries. Hence, we combine llseek with write.
|
||||||
*/
|
*/
|
||||||
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)
|
||||||
|
{
|
||||||
char *frontPadBuf;
|
char *frontPadBuf;
|
||||||
void *frontPadBuf_base = NULL;
|
void *frontPadBuf_base = NULL;
|
||||||
int r, frontHang;
|
int r, frontHang;
|
||||||
|
|||||||
Reference in New Issue
Block a user