/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 2015 Nexenta Systems, Inc.
*/
/*
* This file contains all the functions that implement the following
* GRUB commands:
* kernel, kernel$, module, module$, findroot, bootfs
* Return 0 on success, errno on failure.
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <alloca.h>
#include <errno.h>
#include <strings.h>
#include <unistd.h>
#include <fcntl.h>
#if defined(__i386)
#include <sys/x86_archext.h>
#endif /* __i386 */
#include "libgrub_impl.h"
#if defined(__i386)
/*
* Return 1 if the system supports 64-bit mode, 0 if it doesn't,
* or -1 on failure.
*/
static int
cpuid_64bit_capable(void)
{
struct {
} cpuid_regs;
return (ret);
sizeof (cpuid_regs))
return (ret);
}
#endif /* __i386 */
/*
* Expand $ISAIDR
*/
#if !defined(__i386)
/* ARGSUSED */
#endif /* __i386 */
static size_t
{
#if defined(__i386)
if (cpuid_64bit_capable() == 1)
#endif /* __i386 */
var[0] = 0;
return (0);
}
/*
* Expand $ZFS-BOOTFS
*/
static size_t
{
int n;
} else {
var[0] = 0;
n = 0;
}
return (n);
}
/*
* Expand all the variables without appending them more than once.
*/
static int
{
int ret = 0;
break;
}
}
if (ret == 0)
return (ret);
}
/*
* Searches first occurence of boot-property 'bprop' in str.
* str supposed to be in format:
* " [-B prop=[value][,prop=[value]]...]
*/
static const char *
{
const char *s;
s = str;
s = str + 3;
/* empty -B option, skip it */
continue;
s += len;
do {
if (s[len] != '=')
break;
/* boot property we are looking for? */
return (s);
s += len;
/* skip boot property value */
/* skip quoted */
if (s[0] == '\"' || s[0] == '\'') {
/* unbalanced quotes */
return (s);
}
}
else
break;
}
/* no more boot properties */
if (s == NULL)
return (s);
/* no more boot properties in that -B block */
if (s[0] != ',')
break;
s += strspn(s, ",");
} while (s[0] != ' ' && s[0] != '\t');
}
return (NULL);
}
/*
* Add bootpath property to str if
* 1. zfs-bootfs property is set explicitly
* and
* 2. bootpath property is not set
*/
static int
{
size_t n;
char *buf;
const char *bfs;
/* zfs-bootfs is not specified, or bootpath is allready set */
return (0);
return (E2BIG);
return (0);
}
static int
{
int ret;
const char *zfn;
if (ret != 0)
barg->gb_walkret = 0;
else
return (barg->gb_walkret == 0);
}
static void
{
barg->gb_bootsign[0] = 0;
}
/* ARGSUSED */
int
{
return (0);
}
/* ARGSUSED */
int
{
return (EG_ROOTNOTSUPP);
return (EG_INVALIDLINE);
}
int
{
return (E2BIG);
return (0);
}
int
{
return (E2BIG);
return (0);
}
int
{
int ret;
return (E2BIG);
return (EINVAL);
return (ret);
return (ret);
return (ret);
}
int
{
int ret;
return (E2BIG);
(isadir))
return (EINVAL);
return (ret);
}
int
{
const char *sign;
if (sign[0] == '(') {
const char *pos;
++sign;
return (EG_FINDROOTFMT);
++pos;
return (EG_FINDROOTFMT);
++pos;
/*
* check the slice only when its presented
*/
if (pos[0] != ')') {
if (pos[0] != ',' ||
return (EG_FINDROOTFMT);
}
} else {
}
return (E2BIG);
return (grub_find_bootsign(barg));
}
int
{
char *gfs_devp;
/* Check if root is zfs */
return (EG_NOTZFS);
/*
* If the bootfs value is the same as the bootfs for the pool,
* do nothing.
*/
return (0);
return (E2BIG);
/* check if specified bootfs belongs to the root pool */
ZFS_TYPE_FILESYSTEM)) == NULL)
return (EG_OPENZFS);
if (barg->gb_walkret == 0)
return (barg->gb_walkret);
}