summaryrefslogtreecommitdiff
path: root/lib/util/sys_rw.c
diff options
context:
space:
mode:
authorRalph Boehme <slow@samba.org>2021-06-22 18:58:21 +0200
committerJeremy Allison <jra@samba.org>2021-10-08 19:28:32 +0000
commit2f523a03f5061feb68c614f39ae0061748c2d9b3 (patch)
treed072321b72adb55d6a32a4353d1b77476c7ab8cf /lib/util/sys_rw.c
parent8fa7848b4a002900e0c3384d2e0d41ea0fdf6ea9 (diff)
downloadsamba-2f523a03f5061feb68c614f39ae0061748c2d9b3.tar.gz
lib: add sys_block_align[_truncate]()
This implements MS-FSA algorithms BlockAlign() and BlockAlignTruncate(). Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib/util/sys_rw.c')
-rw-r--r--lib/util/sys_rw.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/util/sys_rw.c b/lib/util/sys_rw.c
index 02aaa871a39..d25a42b7082 100644
--- a/lib/util/sys_rw.c
+++ b/lib/util/sys_rw.c
@@ -23,6 +23,7 @@
#include "replace.h"
#include "system/filesys.h"
#include "lib/util/sys_rw.h"
+#include <assert.h>
bool sys_valid_io_range(off_t offset, size_t length)
{
@@ -73,6 +74,20 @@ bool sys_io_ranges_overlap(size_t c1, off_t o1,
}
}
+off_t sys_block_align_truncate(off_t len, off_t align)
+{
+ assert(align > 1);
+ assert(((align - 1) & align) == 0);
+ return len & (~align + 1);
+}
+
+off_t sys_block_align(off_t len, off_t align)
+{
+ assert(align > 1);
+ assert(((align - 1) & align) == 0);
+ return (len + (align - 1)) & ~(align - 1);
+}
+
/*******************************************************************
A read wrapper that will deal with EINTR/EWOULDBLOCK
********************************************************************/