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 <tytso@mit.edu>
}
#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
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;