Index: sys/boot/i386/libi386/biosdisk.c =================================================================== --- sys/boot/i386/libi386/biosdisk.c (revision 298949) +++ sys/boot/i386/libi386/biosdisk.c (working copy) @@ -746,16 +746,15 @@ * sectors cannot be decrypted. Round the requested LBA down to * nearest multiple of DEV_GELIBOOT_BSIZE bytes. */ - alignlba = dblk & - ~(daddr_t)((DEV_GELIBOOT_BSIZE / BIOSDISK_SECSIZE) - 1); + alignlba = rounddown2(dblk, + DEV_GELIBOOT_BSIZE / BIOSDISK_SECSIZE); /* * Round number of blocks to read up to nearest multiple of * DEV_GELIBOOT_BSIZE */ - alignblks = blks + (dblk - alignlba) + - ((DEV_GELIBOOT_BSIZE / BIOSDISK_SECSIZE) - 1) & - ~(int)((DEV_GELIBOOT_BSIZE / BIOSDISK_SECSIZE) - 1); diff = (dblk - alignlba) * BIOSDISK_SECSIZE; + alignblks = roundup2(blks * BIOSDISK_SECSIZE + diff, + DEV_GELIBOOT_BSIZE) / BIOSDISK_SECSIZE; /* * Use a temporary buffer here because the buffer provided by * the caller may be too small. Index: sys/boot/i386/zfsboot/zfsboot.c =================================================================== --- sys/boot/i386/zfsboot/zfsboot.c (revision 298949) +++ sys/boot/i386/zfsboot/zfsboot.c (working copy) @@ -201,7 +201,7 @@ { char *p; daddr_t lba, alignlba; - off_t alignoff, diff; + off_t diff; unsigned int nb, alignnb; struct dsk *dsk = (struct dsk *) priv; @@ -211,11 +211,12 @@ p = buf; lba = off / DEV_BSIZE; lba += dsk->start; - /* Align reads to 4k else 4k sector GELIs will not decrypt. */ - alignoff = off & ~ (off_t)(DEV_GELIBOOT_BSIZE - 1); - /* Round LBA down to nearest multiple of DEV_GELIBOOT_BSIZE bytes. */ - alignlba = alignoff / DEV_BSIZE; /* + * Align reads to 4k else 4k sector GELIs will not decrypt. + * Round LBA down to nearest multiple of DEV_GELIBOOT_BSIZE bytes. + */ + alignlba = rounddown2(off, DEV_GELIBOOT_BSIZE) / DEV_BSIZE; + /* * The read must be aligned to DEV_GELIBOOT_BSIZE bytes relative to the * start of the GELI partition, not the start of the actual disk. */