libzfs_util.c revision 99653d4ee642c6528e88224f12409a5f23060994
/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Internal utility routines for the ZFS library.
*/
#include <errno.h>
#include <fcntl.h>
#include <libintl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <libzfs.h>
#include "libzfs_impl.h"
int
{
return (hdl->libzfs_error);
}
const char *
{
return (hdl->libzfs_action);
}
const char *
{
return (hdl->libzfs_desc);
switch (hdl->libzfs_error) {
case EZFS_NOMEM:
case EZFS_BADPROP:
case EZFS_PROPREADONLY:
case EZFS_PROPTYPE:
"datasets of this type"));
case EZFS_PROPNONINHERIT:
case EZFS_PROPSPACE:
case EZFS_BADTYPE:
"datasets of this type"));
case EZFS_BUSY:
case EZFS_EXISTS:
case EZFS_NOENT:
case EZFS_BADSTREAM:
case EZFS_DSREADONLY:
case EZFS_VOLTOOBIG:
"this system"));
case EZFS_VOLHASDATA:
case EZFS_INVALIDNAME:
case EZFS_BADRESTORE:
"destination"));
case EZFS_BADBACKUP:
case EZFS_BADTARGET:
case EZFS_NODEVICE:
case EZFS_BADDEV:
case EZFS_NOREPLICAS:
case EZFS_RESILVERING:
case EZFS_BADVERSION:
case EZFS_POOLUNAVAIL:
case EZFS_DEVOVERFLOW:
case EZFS_BADPATH:
case EZFS_CROSSTARGET:
"pools"));
case EZFS_ZONED:
case EZFS_MOUNTFAILED:
case EZFS_UMOUNTFAILED:
case EZFS_UNSHAREFAILED:
case EZFS_SHAREFAILED:
case EZFS_DEVLINKS:
case EZFS_PERM:
case EZFS_NOSPC:
case EZFS_IO:
case EZFS_INTR:
case EZFS_ISSPARE:
"spare"));
case EZFS_INVALCONFIG:
case EZFS_UNKNOWN:
default:
abort();
}
/* NOTREACHED */
}
/*PRINTFLIKE2*/
void
{
}
static void
{
if (hdl->libzfs_desc_active)
hdl->libzfs_desc_active = 0;
else
if (hdl->libzfs_printerr) {
if (error == EZFS_UNKNOWN) {
abort();
}
if (error == EZFS_NOMEM)
exit(1);
}
}
/*PRINTFLIKE3*/
int
{
return (-1);
}
static int
{
switch (error) {
case EPERM:
case EACCES:
return (-1);
case EIO:
return (-1);
case EINTR:
return (-1);
}
return (0);
}
/*PRINTFLIKE3*/
int
{
return (-1);
}
switch (error) {
case ENXIO:
break;
case ENOENT:
"dataset does not exist"));
break;
case ENOSPC:
case EDQUOT:
return (-1);
case EEXIST:
"dataset already exists"));
break;
case EBUSY:
"dataset is busy"));
break;
default:
break;
}
return (-1);
}
/*PRINTFLIKE3*/
int
{
return (-1);
}
switch (error) {
case ENODEV:
break;
case ENOENT:
break;
case EEXIST:
"pool already exists"));
break;
case EBUSY:
break;
case ENXIO:
"one or more devices is currently unavailable"));
break;
case ENAMETOOLONG:
break;
default:
}
return (-1);
}
/*
* Display an out of memory error message and abort the current program.
*/
int
{
}
/*
* A safe form of malloc() which will die if the allocation fails.
*/
void *
{
void *data;
return (data);
}
/*
* A safe form of strdup() which will die if the allocation fails.
*/
char *
{
char *ret;
return (ret);
}
/*
* Convert a number to an appropriately human-readable output.
*/
void
{
int index = 0;
char u;
while (n >= 1024) {
n /= 1024;
index++;
}
u = " KMGTPE"[index];
if (index == 0) {
/*
* If this is an even multiple of the base, always display
* without any decimal precision.
*/
} else {
/*
* We want to choose a precision that reflects the best choice
* for fitting in 5 characters. This can get rather tricky when
* we have numbers that are very close to an order of magnitude.
* For example, when displaying 10239 (which is really 9.999K),
* we want only a single place of precision for 10.0K. We could
* develop some complex heuristics for this, but it's much
* easier just to try each combination in turn.
*/
int i;
for (i = 2; i >= 0; i--) {
break;
}
}
}
void
{
}
libzfs_init(void)
{
return (NULL);
}
return (NULL);
}
return (NULL);
}
return (hdl);
}
void
{
if (hdl->libzfs_mnttab)
if (hdl->libzfs_sharetab)
}
{
}
{
}