mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-15 12:50:06 +01:00
Ignore optimal-io if not aligned to minimal page size
This values is bogus on some systems and causes wrong alignment for data area. Just ignore it there. Fixes: #585.
This commit is contained in:
@@ -520,10 +520,16 @@ void device_topology_alignment(struct crypt_device *cd,
|
||||
|
||||
temp_alignment = (unsigned long)min_io_size;
|
||||
|
||||
/* Ignore bogus opt-io that could break alignment */
|
||||
/*
|
||||
* Ignore bogus opt-io that could break alignment.
|
||||
* Also real opt_io_size should be aligned to minimal page size (4k).
|
||||
* Some bogus USB enclosures reports wrong data here.
|
||||
*/
|
||||
if ((temp_alignment < (unsigned long)opt_io_size) &&
|
||||
!((unsigned long)opt_io_size % temp_alignment))
|
||||
!((unsigned long)opt_io_size % temp_alignment) && !MISALIGNED_4K(opt_io_size))
|
||||
temp_alignment = (unsigned long)opt_io_size;
|
||||
else if (opt_io_size)
|
||||
log_err(cd, "Ignoring bogus optimal-io size for data device (%u bytes).", opt_io_size);
|
||||
|
||||
/* If calculated alignment is multiple of default, keep default */
|
||||
if (temp_alignment && (default_alignment % temp_alignment))
|
||||
|
||||
@@ -100,7 +100,7 @@ format() # expected [forced] [encryption_sector_size]
|
||||
|
||||
if [ -z "$2" ] ; then
|
||||
echo -n "Formatting using topology info$_smsg..."
|
||||
echo $PWD1 | $CRYPTSETUP luksFormat $FAST_PBKDF --type luks2 $DEV -q -c aes-cbc-essiv:sha256 --sector-size $_sec_size >/dev/null || fail
|
||||
echo $PWD1 | $CRYPTSETUP luksFormat $FAST_PBKDF --type luks2 $DEV -q -c aes-cbc-essiv:sha256 --sector-size $_sec_size >/dev/null 2>&1 || fail
|
||||
else
|
||||
echo -n "Formatting using forced sector alignment $2$_smsg..."
|
||||
echo $PWD1 | $CRYPTSETUP luksFormat $FAST_PBKDF --type luks2 $DEV -q -c aes-cbc-essiv:sha256 --align-payload=$2 --sector-size $_sec_size >/dev/null || fail
|
||||
@@ -222,6 +222,31 @@ format $EXPCT $EXPCT s2048
|
||||
format $EXPCT $EXPCT s4096
|
||||
cleanup
|
||||
|
||||
echo "# Create drive with misaligned opt-io to page-size (some bad USB enclosures)"
|
||||
echo "# (logical_block_size=512, physical_block_size=512, alignment_offset=0, opt-io=33553920)"
|
||||
add_device dev_size_mb=32 sector_size=512 num_tgts=1 opt_blks=65535
|
||||
format $EXPCT
|
||||
format $EXPCT s1024
|
||||
format $EXPCT s2048
|
||||
format $EXPCT s4096
|
||||
format $EXPCT 1
|
||||
format $EXPCT 1 s1024
|
||||
format $EXPCT 1 s2048
|
||||
format $EXPCT 1 s4096
|
||||
format $EXPCT 8
|
||||
format $EXPCT 8 s1024
|
||||
format $EXPCT 8 s2048
|
||||
format $EXPCT 8 s4096
|
||||
format $((EXPCT+1)) $((EXPCT+1))
|
||||
format_fail $((EXPCT+1)) $((EXPCT+1)) s1024
|
||||
format_fail $((EXPCT+1)) $((EXPCT+1)) s2048
|
||||
format_fail $((EXPCT+1)) $((EXPCT+1)) s4096
|
||||
format $EXPCT $EXPCT
|
||||
format $EXPCT $EXPCT s1024
|
||||
format $EXPCT $EXPCT s2048
|
||||
format $EXPCT $EXPCT s4096
|
||||
cleanup
|
||||
|
||||
echo "# Create desktop-class 4K drive w/ 1-sector shift (original bug report)"
|
||||
echo "# (logical_block_size=512, physical_block_size=4096, alignment_offset=512)"
|
||||
add_device dev_size_mb=32 sector_size=512 physblk_exp=3 lowest_aligned=1 num_tgts=1
|
||||
|
||||
Reference in New Issue
Block a user