/*-
* Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
* Copyright (c) 2012 Andrey V. Elsukov <ae@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
__FBSDID("$FreeBSD$");
#include <stand.h>
#include <stdarg.h>
#include <bootstrap.h>
#include <part.h>
#include "disk.h"
#ifdef DISK_DEBUG
#else
#endif
struct open_disk {
int rcnt;
};
struct print_args {
const char *prefix;
int verbose;
};
struct dentry {
int d_unit;
int d_slice;
int d_partition;
#ifdef DISK_DEBUG
#endif
};
static int
{
int rc;
continue;
#ifdef DISK_DEBUG
#endif
return (0);
}
}
return (rc);
}
static void
{
DEBUG("no memory");
return;
}
#ifdef DISK_DEBUG
#endif
}
#ifdef DISK_DEBUG
static int
{
}
return (CMD_OK);
}
#endif /* DISK_DEBUG */
/* Convert size to a human-readable number. */
static char *
{
char unit;
unit = 'K';
if (size >= 10485760000LL) {
size /= 1073741824;
unit = 'T';
} else if (size >= 10240000) {
size /= 1048576;
unit = 'G';
} else if (size >= 10000) {
size /= 1024;
unit = 'M';
}
return (buf);
}
static int
{
dev = (struct disk_devdesc *)d;
}
static int
{
int ret = 0;
od->sectorsize));
if (ret != 0)
return (ret);
/* Open slice with BSD or VTOC label */
return (ret);
}
return (ret);
}
int
{
/* Disk should be opened */
}
int
{
int ret;
return (ret);
}
int
{
int ret;
return (ret);
}
int
{
return (ENXIO);
}
int
{
rc = 0;
if ((flags & DISK_F_NOCACHE) == 0) {
if (rc == 0)
return (0);
}
/*
* While we are reading disk metadata, make sure we do it relative
* to the start of the disk
*/
/*
* This entire disk was already opened and there is no
* need to allocate new open_disk structure and open the
* main partition table.
*/
DEBUG("%s unit %d, slice %d, partition %d => %p (cached)",
goto opened;
} else {
DEBUG("no memory");
return (ENOMEM);
}
}
DEBUG("%s unit %d, slice %d, partition %d => %p",
/* Determine disk layout. */
ptblread);
DEBUG("Can't read partition table");
goto out;
}
rc = 0;
partition >= 0) {
/* It doesn't matter what value has d_slice */
if (rc == 0)
} else if (slice >= 0) {
/* Try to get information about partition */
if (slice == 0)
else
if (rc != 0) /* Partition doesn't exist */
goto out;
partition = 255;
goto out; /* Nothing more to do */
} else if (partition == 255) {
/*
* When we try to open GPT partition, but partition
* table isn't GPT, reset d_partition value to -1
* and try to autodetect appropriate value.
*/
partition = -1;
}
/*
* then try to read label, otherwise return the
* whole MBR slice.
*/
if (partition == -1 &&
goto out;
/* Try to read label */
goto out;
}
/*
* assume the 'a' partition. Otherwise just return the
* whole MBR slice, because it can contain ZFS.
*/
if (partition < 0) {
goto out;
partition = 0;
}
if (rc != 0)
goto out;
}
out:
if (rc != 0) {
}
} else {
if ((flags & DISK_F_NOCACHE) == 0)
/* Save the slice and partition number to the dev */
}
return (rc);
}
int
{
}
return (0);
}
void
{
#ifdef DISK_DEBUG
#endif
continue;
#ifdef DISK_DEBUG
#endif
}
}
}
char*
{
char *cp;
#ifdef LOADER_GPT_SUPPORT
return (buf);
} else
#endif
#ifdef LOADER_MBR_SUPPORT
#endif
}
if (dev->d_partition >= 0)
return (buf);
}
int
{
const char *np;
char *cp;
return (EUNIT);
#ifdef LOADER_GPT_SUPPORT
if (*cp == 'p') {
return (ESLICE);
/* we don't support nested partitions on GPT */
return (EINVAL);
partition = 255;
} else
#endif
#ifdef LOADER_MBR_SUPPORT
if (*cp == 's') {
return (ESLICE);
}
#endif
if (partition < 0)
return (EPART);
cp++;
}
} else
return (EINVAL);
return (EINVAL);
return (0);
}