Changeset View
Changeset View
Standalone View
Standalone View
sys/boot/i386/libi386/biosdisk.c
Show First 20 Lines • Show All 700 Lines • ▼ Show 20 Lines | /* hexdump(dest, (blks * BD(dev).bd_sectorsize)); */ | ||||
return(0); | return(0); | ||||
} | } | ||||
static int | static int | ||||
bd_read(struct disk_devdesc *dev, daddr_t dblk, int blks, caddr_t dest) | bd_read(struct disk_devdesc *dev, daddr_t dblk, int blks, caddr_t dest) | ||||
{ | { | ||||
#ifdef LOADER_GELI_SUPPORT | #ifdef LOADER_GELI_SUPPORT | ||||
struct dsk dskp; | struct dsk dskp; | ||||
off_t p_off; | off_t p_off, diff; | ||||
int err, n; | daddr_t alignlba; | ||||
int err, n, alignblks; | |||||
char *tmpbuf; | |||||
/* if we already know there is no GELI, skip the rest */ | /* if we already know there is no GELI, skip the rest */ | ||||
if (geli_status[dev->d_unit][dev->d_slice] != ISGELI_YES) | if (geli_status[dev->d_unit][dev->d_slice] != ISGELI_YES) | ||||
return (bd_io(dev, dblk, blks, dest, 0)); | return (bd_io(dev, dblk, blks, dest, 0)); | ||||
if (geli_status[dev->d_unit][dev->d_slice] == ISGELI_YES) { | if (geli_status[dev->d_unit][dev->d_slice] == ISGELI_YES) { | ||||
err = bd_io(dev, dblk, blks, dest, 0); | /* | ||||
* Align reads to DEV_GELIBOOT_BSIZE bytes because partial | |||||
* 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); | |||||
oshogbo: Style.
I would go with:
alignlba = dblk &
~(daddr_t)((DEV_GELIBOOT_BSIZE /… | |||||
/* | |||||
* 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); | |||||
Done Inline ActionsUp. oshogbo: Up. | |||||
diff = (dblk - alignlba) * BIOSDISK_SECSIZE; | |||||
/* | |||||
* Use a temporary buffer here because the buffer provided by | |||||
* the caller may be too small. | |||||
*/ | |||||
tmpbuf = alloca(alignblks * BIOSDISK_SECSIZE); | |||||
err = bd_io(dev, alignlba, alignblks, tmpbuf, 0); | |||||
if (err) | if (err) | ||||
return (err); | return (err); | ||||
dskp.drive = bd_unit2bios(dev->d_unit); | dskp.drive = bd_unit2bios(dev->d_unit); | ||||
dskp.type = dev->d_type; | dskp.type = dev->d_type; | ||||
dskp.unit = dev->d_unit; | dskp.unit = dev->d_unit; | ||||
dskp.slice = dev->d_slice; | dskp.slice = dev->d_slice; | ||||
dskp.part = dev->d_partition; | dskp.part = dev->d_partition; | ||||
dskp.start = dev->d_offset; | dskp.start = dev->d_offset; | ||||
/* GELI needs the offset relative to the partition start */ | /* GELI needs the offset relative to the partition start */ | ||||
p_off = dblk - dskp.start; | p_off = alignlba - dskp.start; | ||||
err = geli_read(&dskp, p_off * BIOSDISK_SECSIZE, dest, | err = geli_read(&dskp, p_off * BIOSDISK_SECSIZE, tmpbuf, | ||||
blks * BIOSDISK_SECSIZE); | alignblks * BIOSDISK_SECSIZE); | ||||
if (err) | if (err) | ||||
return (err); | return (err); | ||||
bcopy(tmpbuf + diff, dest, blks * BIOSDISK_SECSIZE); | |||||
return (0); | return (0); | ||||
} | } | ||||
#endif /* LOADER_GELI_SUPPORT */ | #endif /* LOADER_GELI_SUPPORT */ | ||||
return (bd_io(dev, dblk, blks, dest, 0)); | return (bd_io(dev, dblk, blks, dest, 0)); | ||||
} | } | ||||
static int | static int | ||||
▲ Show 20 Lines • Show All 113 Lines • Show Last 20 Lines |
Style.
I would go with:
alignlba = dblk &