zfsboot: cstyle cleanup

No functional changes intended.

Sponsored by:	Netflix, Klara Inc.
This commit is contained in:
Toomas Soome 2020-06-14 20:57:24 +00:00
parent 16f224b5f8
commit dfdeb45425

View File

@ -162,7 +162,8 @@ struct zfsdsk {
* Read from a dnode (which must be from a ZPL filesystem).
*/
static int
zfs_read(spa_t *spa, const dnode_phys_t *dnode, off_t *offp, void *start, size_t size)
zfs_read(spa_t *spa, const dnode_phys_t *dnode, off_t *offp, void *start,
size_t size)
{
const znode_phys_t *zp = (const znode_phys_t *) dnode->dn_bonus;
size_t n;
@ -198,10 +199,10 @@ vdev_read(void *xvdev, void *priv, off_t off, void *buf, size_t bytes)
daddr_t lba, alignlba;
off_t diff;
unsigned int nb, alignnb;
struct zfsdsk *zdsk = (struct zfsdsk *) priv;
struct zfsdsk *zdsk = priv;
if ((off & (DEV_BSIZE - 1)) || (bytes & (DEV_BSIZE - 1)))
return -1;
return (-1);
p = buf;
lba = off / DEV_BSIZE;
@ -242,12 +243,13 @@ vdev_read(void *xvdev, void *priv, off_t off, void *buf, size_t bytes)
}
if (drvread(&zdsk->dsk, dmadat->rdbuf, alignlba, alignnb))
return -1;
return (-1);
#ifdef LOADER_GELI_SUPPORT
/* decrypt */
if (zdsk->gdev != NULL) {
if (geli_read(zdsk->gdev, ((alignlba - zdsk->dsk.start) *
DEV_BSIZE), dmadat->rdbuf, alignnb * DEV_BSIZE))
if (geli_read(zdsk->gdev,
((alignlba - zdsk->dsk.start) * DEV_BSIZE),
dmadat->rdbuf, alignnb * DEV_BSIZE))
return (-1);
}
#endif
@ -260,13 +262,13 @@ vdev_read(void *xvdev, void *priv, off_t off, void *buf, size_t bytes)
diff = 0;
}
return 0;
return (0);
}
/* Match the signature exactly due to signature madness */
static int
vdev_read2(vdev_t *vdev, void *priv, off_t off, void *buf, size_t bytes)
{
return vdev_read(vdev, priv, off, buf, bytes);
return (vdev_read(vdev, priv, off, buf, bytes));
}
@ -276,10 +278,10 @@ vdev_write(vdev_t *vdev, void *priv, off_t off, void *buf, size_t bytes)
char *p;
daddr_t lba;
unsigned int nb;
struct zfsdsk *zdsk = (struct zfsdsk *) priv;
struct zfsdsk *zdsk = priv;
if ((off & (DEV_BSIZE - 1)) || (bytes & (DEV_BSIZE - 1)))
return -1;
return (-1);
p = buf;
lba = off / DEV_BSIZE;
@ -290,13 +292,13 @@ vdev_write(vdev_t *vdev, void *priv, off_t off, void *buf, size_t bytes)
nb = READ_BUF_SIZE / DEV_BSIZE;
memcpy(dmadat->rdbuf, p, nb * DEV_BSIZE);
if (drvwrite(&zdsk->dsk, dmadat->rdbuf, lba, nb))
return -1;
return (-1);
p += nb * DEV_BSIZE;
lba += nb;
bytes -= nb * DEV_BSIZE;
}
return 0;
return (0);
}
static int
@ -304,9 +306,9 @@ xfsread(const dnode_phys_t *dnode, off_t *offp, void *buf, size_t nbyte)
{
if ((size_t)zfs_read(spa, dnode, offp, buf, nbyte) != nbyte) {
printf("Invalid format\n");
return -1;
return (-1);
}
return 0;
return (0);
}
/*
@ -389,7 +391,8 @@ bios_getmem(void)
(smap.length >= (512 * 1024)))
bios_basemem = smap.length;
/* look for the first segment in 'extended' memory */
if ((smap.type == SMAP_TYPE_MEMORY) && (smap.base == 0x100000)) {
if ((smap.type == SMAP_TYPE_MEMORY) &&
(smap.base == 0x100000)) {
bios_extmem = smap.length;
}
@ -402,7 +405,8 @@ bios_getmem(void)
size = smap.length;
/*
* If this segment crosses the 4GB boundary, truncate it.
* If this segment crosses the 4GB boundary,
* truncate it.
*/
if (smap.base + size > 0x100000000ull)
size = 0x100000000ull - smap.base;
@ -423,14 +427,18 @@ bios_getmem(void)
bios_basemem = (v86.eax & 0xffff) * 1024;
}
/* Fall back through several compatibility functions for extended memory */
/*
* Fall back through several compatibility functions for extended
* memory.
*/
if (bios_extmem == 0) {
v86.ctl = V86_FLAGS;
v86.addr = 0x15; /* int 0x15 function 0xe801 */
v86.eax = 0xe801;
v86int();
if (!V86_CY(v86.efl)) {
bios_extmem = ((v86.ecx & 0xffff) + ((v86.edx & 0xffff) * 64)) * 1024;
bios_extmem = ((v86.ecx & 0xffff) +
((v86.edx & 0xffff) * 64)) * 1024;
}
}
if (bios_extmem == 0) {
@ -658,29 +666,38 @@ probe_drive(struct zfsdsk *zdsk)
if (memcmp(&ent->ent_type, &freebsd_zfs_uuid,
sizeof(uuid_t)) == 0) {
zdsk->dsk.start = ent->ent_lba_start;
zdsk->dsk.size = ent->ent_lba_end - ent->ent_lba_start + 1;
zdsk->dsk.size =
ent->ent_lba_end - ent->ent_lba_start + 1;
zdsk->dsk.slice = part + 1;
zdsk->dsk.part = 255;
if (vdev_probe(vdev_read2, zdsk, NULL) == 0) {
/*
* This slice had a vdev. We need a new dsk
* structure now since the vdev now owns this one.
* This slice had a vdev. We need a new
* dsk structure now since the vdev now
* owns this one.
*/
zdsk = copy_dsk(zdsk);
}
#ifdef LOADER_GELI_SUPPORT
else if ((zdsk->gdev = geli_taste(vdev_read, zdsk,
ent->ent_lba_end - ent->ent_lba_start, "disk%up%u:",
zdsk->dsk.unit, zdsk->dsk.slice)) != NULL) {
else if ((zdsk->gdev = geli_taste(vdev_read,
zdsk, ent->ent_lba_end - ent->ent_lba_start,
"disk%up%u:", zdsk->dsk.unit,
zdsk->dsk.slice)) != NULL) {
if (geli_havekey(zdsk->gdev) == 0 ||
geli_passphrase(zdsk->gdev, gelipw) == 0) {
geli_passphrase(zdsk->gdev, gelipw)
== 0) {
/*
* This slice has GELI, check it for ZFS.
* This slice has GELI,
* check it for ZFS.
*/
if (vdev_probe(vdev_read2, zdsk, NULL) == 0) {
if (vdev_probe(vdev_read2,
zdsk, NULL) == 0) {
/*
* This slice had a vdev. We need a new dsk
* structure now since the vdev now owns this one.
* This slice had a
* vdev. We need a new
* dsk structure now
* since the vdev now
* owns this one.
*/
zdsk = copy_dsk(zdsk);
}
@ -710,8 +727,8 @@ trymbr:
zdsk = copy_dsk(zdsk);
}
#ifdef LOADER_GELI_SUPPORT
else if ((zdsk->gdev = geli_taste(vdev_read, zdsk, dp[i].dp_size -
dp[i].dp_start, "disk%us%u:")) != NULL) {
else if ((zdsk->gdev = geli_taste(vdev_read, zdsk,
dp[i].dp_size - dp[i].dp_start, "disk%us%u:")) != NULL) {
if (geli_havekey(zdsk->gdev) == 0 ||
geli_passphrase(zdsk->gdev, gelipw) == 0) {
/*
@ -719,8 +736,9 @@ trymbr:
*/
if (vdev_probe(vdev_read2, zdsk, NULL) == 0) {
/*
* This slice had a vdev. We need a new dsk
* structure now since the vdev now owns this one.
* This slice had a vdev. We need a new
* dsk structure now since the vdev now
* owns this one.
*/
zdsk = copy_dsk(zdsk);
}
@ -833,18 +851,20 @@ main(void)
if (rc == 0) {
if (*cmd) {
/*
* We could find an old-style ZFS Boot Block header here.
* Simply ignore it.
* We could find an old-style ZFS Boot Block header
* here. Simply ignore it.
*/
if (*(uint64_t *)cmd != 0x2f5b007b10c) {
/*
* Note that parse() is destructive to cmd[] and we also want
* to honor RBX_QUIET option that could be present in cmd[].
* Note that parse() is destructive to cmd[]
* and we also want to honor RBX_QUIET option
* that could be present in cmd[].
*/
nextboot = 1;
memcpy(cmddup, cmd, sizeof(cmd));
if (parse_cmd()) {
printf("failed to parse pad2 area of primary vdev\n");
printf("failed to parse pad2 area of "
"primary vdev\n");
reboot();
}
if (!OPT_CHECK(RBX_QUIET))
@ -870,8 +890,9 @@ main(void)
if (*cmd) {
/*
* Note that parse_cmd() is destructive to cmd[] and we also want
* to honor RBX_QUIET option that could be present in cmd[].
* Note that parse_cmd() is destructive to cmd[] and we also
* want to honor RBX_QUIET option that could be present in
* cmd[].
*/
memcpy(cmddup, cmd, sizeof(cmd));
if (parse_cmd())
@ -888,9 +909,9 @@ main(void)
if (autoboot && !*kname) {
/*
* Iterate through the list of loader and kernel paths, trying to load.
* If interrupted by a keypress, or in case of failure, drop the user
* to the boot2 prompt.
* Iterate through the list of loader and kernel paths,
* trying to load. If interrupted by a keypress, or in case of
* failure, drop the user to the boot2 prompt.
*/
for (i = 0; i < nitems(loadpath); i++) {
memcpy(kname, loadpath[i].p, loadpath[i].len);
@ -1023,7 +1044,8 @@ load(void)
if (xfsread(&dn, &off, &es, sizeof(es)))
return;
for (i = 0; i < 2; i++) {
memcpy(p, &es[i].sh_size, sizeof(es[i].sh_size));
memcpy(p, &es[i].sh_size,
sizeof(es[i].sh_size));
p += sizeof(es[i].sh_size);
off = es[i].sh_offset;
if (xfsread(&dn, &off, p, es[i].sh_size))
@ -1048,9 +1070,10 @@ load(void)
else
printf("failed to detect primary vdev\n");
/*
* Note that the zfsargs struct is passed by value, not by pointer. Code in
* btxldr.S copies the values from the entry stack to a fixed location
* within loader(8) at startup due to the presence of KARGS_FLAGS_EXTARG.
* Note that the zfsargs struct is passed by value, not by pointer.
* Code in btxldr.S copies the values from the entry stack to a fixed
* location within loader(8) at startup due to the presence of
* KARGS_FLAGS_EXTARG.
*/
__exec((caddr_t)addr, RB_BOOTINFO | (opts & RBX_MASK),
bootdev,
@ -1074,23 +1097,23 @@ zfs_mount_ds(char *dsname)
newspa = spa_find_by_name(dsname);
if (newspa == NULL) {
printf("\nCan't find ZFS pool %s\n", dsname);
return -1;
return (-1);
}
if (zfs_spa_init(newspa))
return -1;
return (-1);
newroot = 0;
if (q) {
if (zfs_lookup_dataset(newspa, q, &newroot)) {
printf("\nCan't find dataset %s in ZFS pool %s\n",
q, newspa->spa_name);
return -1;
return (-1);
}
}
if (zfs_mount(newspa, newroot, &zfsmount)) {
printf("\nCan't mount ZFS dataset\n");
return -1;
return (-1);
}
spa = newspa;
return (0);
@ -1107,7 +1130,8 @@ parse_cmd(void)
while ((c = *arg++)) {
if (c == ' ' || c == '\t' || c == '\n')
continue;
for (p = arg; *p && *p != '\n' && *p != ' ' && *p != '\t'; p++);
for (p = arg; *p && *p != '\n' && *p != ' ' && *p != '\t'; p++)
;
ep = p;
if (*p)
*p++ = 0;
@ -1117,24 +1141,29 @@ parse_cmd(void)
if (*(uint8_t *)PTOV(0x496) & 0x10) {
cp = "yes";
} else {
opts |= OPT_SET(RBX_DUAL) | OPT_SET(RBX_SERIAL);
opts |= OPT_SET(RBX_DUAL);
opts |= OPT_SET(RBX_SERIAL);
cp = "no";
}
printf("Keyboard: %s\n", cp);
continue;
} else if (c == 'S') {
j = 0;
while ((unsigned int)(i = *arg++ - '0') <= 9)
while ((unsigned int)
(i = *arg++ - '0') <= 9)
j = j * 10 + i;
if (j > 0 && i == -'0') {
comspeed = j;
break;
}
/* Fall through to error below ('S' not in optstr[]). */
/*
* Fall through to error below
* ('S' not in optstr[]).
*/
}
for (i = 0; c != optstr[i]; i++)
if (i == NOPT - 1)
return -1;
return (-1);
opts ^= OPT_SET(flags[i]);
}
ioctrl = OPT_CHECK(RBX_DUAL) ? (IO_SERIAL|IO_KEYBOARD) :
@ -1149,7 +1178,7 @@ parse_cmd(void)
if (zfs_lookup(&zfsmount, arg, &dn) == 0) {
zap_list(spa, &dn);
}
return -1;
return (-1);
} else {
arg--;
@ -1157,9 +1186,9 @@ parse_cmd(void)
* Report pool status if the comment is 'status'. Lets
* hope no-one wants to load /status as a kernel.
*/
if (!strcmp(arg, "status")) {
if (strcmp(arg, "status") == 0) {
spa_all_status();
return -1;
return (-1);
}
/*
@ -1175,16 +1204,16 @@ parse_cmd(void)
if (q) {
*q++ = '\0';
if (zfs_mount_ds(arg) != 0)
return -1;
return (-1);
arg = q;
}
if ((i = ep - arg)) {
if ((size_t)i >= sizeof(kname))
return -1;
return (-1);
memcpy(kname, arg, i + 1);
}
}
arg = p;
}
return 0;
return (0);
}