From: Theodore Ts'o Date: Tue, 13 Sep 2016 22:39:22 +0000 (-0400) Subject: libext2fs: force DIO alignment FreeBSD when operating on a block device X-Git-Tag: 1.43.4~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a68c6f1f071c2826e8ec6ceb810c98719a98717;p=thirdparty%2Fe2fsprogs.git libext2fs: force DIO alignment FreeBSD when operating on a block device FreeBSD (and possibly BSD systems) requires that reads and writes to block devices must be aligned, even when the O_DIRECT flag is not specified. Previously this was hard-coded to 512 bytes, but in order to properly handle Advanced Format HDD's, query the BSD kernel to determine the proper alignment to use. Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c index 27b6a9560..85ad4e39f 100644 --- a/lib/ext2fs/unix_io.c +++ b/lib/ext2fs/unix_io.c @@ -613,7 +613,7 @@ static errcode_t unix_open_channel(const char *name, int fd, } #endif -#if defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#if defined(__CYGWIN__) /* * Some operating systems require that the buffers be aligned, * regardless of O_DIRECT @@ -622,6 +622,14 @@ static errcode_t unix_open_channel(const char *name, int fd, io->align = 512; #endif +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + if (io->flags & CHANNEL_FLAGS_BLOCK_DEVICE) { + int dio_align = ext2fs_get_dio_alignment(fd); + + if (io->align < dio_align) + io->align = dio_align; + } +#endif if ((retval = alloc_cache(io, data))) goto cleanup;