entry.c revision 46a2abf27af40eda17a3f97e79eda1aef4e3c3c8
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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"
#include <fcntl.h>
#include <libdevinfo.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <libintl.h>
#include <locale.h>
#include "libdiskmgt.h"
#include "disks_private.h"
#include "partition.h"
extern char *getfullblkname();
extern dm_desc_type_t drive_assoc_types[];
extern dm_desc_type_t bus_assoc_types[];
extern dm_desc_type_t controller_assoc_types[];
extern dm_desc_type_t media_assoc_types[];
extern dm_desc_type_t slice_assoc_types[];
extern dm_desc_type_t partition_assoc_types[];
extern dm_desc_type_t path_assoc_types[];
extern dm_desc_type_t alias_assoc_types[];
void
{
return;
}
cache_wlock();
cache_unlock();
}
void
{
descriptor_t **dp;
int error;
return;
}
if (error != 0) {
return;
}
cache_wlock();
cache_unlock();
}
/*ARGSUSED*/
void
dm_free_name(char *name)
{
}
int *errp)
{
cache_wlock();
if (!cache_is_valid_desc(dp)) {
cache_unlock();
return (NULL);
}
/* verify that the descriptor is still valid */
cache_unlock();
return (NULL);
}
case DM_DRIVE:
break;
case DM_BUS:
break;
case DM_CONTROLLER:
break;
case DM_MEDIA:
break;
case DM_SLICE:
break;
case DM_PARTITION:
break;
case DM_PATH:
break;
case DM_ALIAS:
break;
default:
break;
}
cache_unlock();
}
{
switch (type) {
case DM_DRIVE:
return (drive_assoc_types);
case DM_BUS:
return (bus_assoc_types);
case DM_CONTROLLER:
return (controller_assoc_types);
case DM_MEDIA:
return (media_assoc_types);
case DM_SLICE:
return (slice_assoc_types);
case DM_PARTITION:
return (partition_assoc_types);
case DM_PATH:
return (path_assoc_types);
case DM_ALIAS:
return (alias_assoc_types);
}
return (NULL);
}
nvlist_t *
{
cache_rlock();
if (!cache_is_valid_desc(dp)) {
cache_unlock();
return (NULL);
}
/* verify that the descriptor is still valid */
cache_unlock();
return (NULL);
}
case DM_DRIVE:
break;
case DM_BUS:
break;
case DM_CONTROLLER:
break;
case DM_MEDIA:
break;
case DM_SLICE:
break;
case DM_PARTITION:
break;
case DM_PATH:
break;
case DM_ALIAS:
break;
default:
break;
}
cache_unlock();
return (attrs);
}
{
cache_wlock();
switch (desc_type) {
case DM_DRIVE:
break;
case DM_BUS:
break;
case DM_CONTROLLER:
errp);
break;
case DM_MEDIA:
break;
case DM_SLICE:
break;
case DM_PARTITION:
errp);
break;
case DM_PATH:
break;
case DM_ALIAS:
break;
default:
break;
}
cache_unlock();
return (desc);
}
{
cache_wlock();
switch (type) {
case DM_DRIVE:
break;
case DM_BUS:
break;
case DM_CONTROLLER:
break;
case DM_MEDIA:
break;
case DM_SLICE:
break;
case DM_PARTITION:
break;
case DM_PATH:
break;
case DM_ALIAS:
break;
default:
break;
}
cache_unlock();
}
char *
{
cache_rlock();
if (!cache_is_valid_desc(dp)) {
cache_unlock();
return (NULL);
}
/* verify that the descriptor is still valid */
cache_unlock();
return (NULL);
}
case DM_DRIVE:
break;
case DM_BUS:
break;
case DM_CONTROLLER:
break;
case DM_MEDIA:
break;
case DM_SLICE:
break;
case DM_PARTITION:
break;
case DM_PATH:
break;
case DM_ALIAS:
break;
}
cache_unlock();
*errp = 0;
return (NULL);
}
return (name);
}
return (NULL);
}
nvlist_t *
{
cache_rlock();
if (!cache_is_valid_desc(dp)) {
cache_unlock();
return (NULL);
}
/* verify that the descriptor is still valid */
cache_unlock();
return (NULL);
}
case DM_DRIVE:
break;
case DM_BUS:
break;
case DM_CONTROLLER:
break;
case DM_MEDIA:
break;
case DM_SLICE:
if (stat_type == DM_SLICE_STAT_USE) {
/*
* If NOINUSE_CHECK is set, we do not perform
* the in use checking if the user has set stat_type
* DM_SLICE_STAT_USE
*/
if (NOINUSE_SET) {
break;
}
}
break;
case DM_PARTITION:
break;
case DM_PATH:
break;
case DM_ALIAS:
break;
default:
break;
}
cache_unlock();
return (stats);
}
{
cache_rlock();
if (!cache_is_valid_desc(dp)) {
cache_unlock();
return (-1);
}
cache_unlock();
}
/*
* Returns, via slices paramater, a dm_descriptor_t list of
* slices for the named disk drive.
*/
void
{
*errp = 0;
return;
}
/*
* Errors must be handled by the caller. The dm_descriptor_t *
* values will be NULL if an error occured in these calls.
*/
}
}
}
}
/*
* Convenience function to get slice stats
*/
void
{
*errp = 0;
return;
}
/*
* Errors must be handled by the caller. The dm_descriptor_t *
* values will be NULL if an error occured in these calls.
*/
errp);
}
}
/*
* Checks for overlapping slices. If the given device is a slice, and it
* overlaps with any non-backup slice on the disk, return true with a detailed
* description similar to dm_inuse().
*/
int
{
int i = 0;
uint64_t start_block = 0;
uint64_t media_size = 0;
int ret = 0;
goto out;
/*
* Get the list of slices be fetching the associated media, and then all
* associated slices.
*/
goto out;
goto out;
goto out;
if (*errp != 0)
goto out;
goto out;
if (*errp != 0)
goto out;
if (*errp != 0)
goto out;
if (*errp != 0)
goto out;
for (i = 0; slices[i]; i ++) {
if (other_attrs == NULL)
continue;
if (*errp != 0)
goto out;
&other_start);
if (*errp) {
goto out;
}
&other_size);
if (*errp) {
ret = -1;
goto out;
}
&snum);
if (*errp) {
ret = -1;
goto out;
}
/*
* Check to see if there are > 2 overlapping regions
* on this media in the same region as this slice.
* This is done by assuming the following:
* Slice 2 is the backup slice if it is the size
* of the whole disk
* If slice 2 is the overlap and slice 2 is the size of
* the whole disk, continue. If another slice is found
* that overlaps with our slice, return it.
* There is the potential that there is more than one slice
* that our slice overlaps with, however, we only return
* the first overlapping slice we find.
*
*/
continue;
} else {
if (*errp != 0) {
ret = -1;
goto out;
}
ret = 1;
goto out;
}
} else if (other_start >= start_block &&
other_start <= end_block) {
continue;
} else {
if (*errp != 0) {
ret = -1;
goto out;
}
ret = 1;
goto out;
}
}
}
out:
if (media_attrs)
if (slice_attrs)
if (slices)
if (media)
if (slice)
return (ret);
}
/*
* Returns 'in use' details, if found, about a specific dev_name,
* based on the caller(who). It is important to note that it is possible
* for there to be more than one 'in use' statistic regarding a dev_name.
* The **msg parameter returns a list of 'in use' details. This message
* is formatted via gettext().
*/
int
{
int found = 0;
*errp = 0;
/*
* If the user doesn't want to do in use checking, return.
*/
if (NOINUSE_SET)
return (0);
/*
* If we cannot find the block name, we cannot check the device
* for in use statistics. So, return found, which is == 0.
*/
return (found);
}
/*
* If there is an error, but it isn't a no device found error
* return the error as recorded. Otherwise, with a full
* block name, we might not be able to get the slice
* associated, and will get an ENODEV error. For example,
* an SVM metadevice will return a value from getfullblkname()
* but libdiskmgt won't be able to find this device for
* statistics gathering. This is expected and we should not
* report errnoneous errors.
*/
if (*errp) {
*errp = 0;
}
}
return (found);
}
for (;;) {
/*
* End of the list found.
*/
break;
}
/*
* Otherwise, we check to see if this client(who) cares
* about this in use scenario
*/
/*
* If we error getting the string value continue on
* to the next pair(if there is one)
*/
continue;
}
continue;
}
switch (who) {
case DM_WHO_MKFS:
/*
* mkfs is not in use for these cases.
* All others are in use.
*/
break;
}
if (build_usage_string(dname,
if (*errp) {
goto out;
}
}
break;
case DM_WHO_SWAP:
/*
* Not in use for this.
*/
break;
}
if (build_usage_string(dname,
if (*errp) {
goto out;
}
}
break;
case DM_WHO_DUMP:
/*
* Not in use for this.
*/
break;
}
if (build_usage_string(dname,
if (*errp) {
goto out;
}
}
break;
case DM_WHO_FORMAT:
break;
if (build_usage_string(dname,
if (*errp) {
goto out;
}
}
break;
case DM_WHO_ZPOOL_FORCE:
break;
/* FALLTHROUGH */
case DM_WHO_ZPOOL:
if (build_usage_string(dname,
if (*errp)
goto out;
}
break;
default:
/*
* nothing found in use for this client
* of libdiskmgt. Default is 'not in use'.
*/
break;
}
}
out:
return (found);
}
void
{
return;
}
*usage_string = NULL;
"%s is currently used by swap. Please see swap(1M)."
"\n");
} else {
"%s is currently mounted on %s."
" Please see umount(1M).\n");
}
"Please remove this entry to use this device.\n");
"%s contains a %s filesystem.\n");
"%s contains an SVM %s. Please see "
"metadb(1M).\n");
} else {
"%s is part of SVM volume %s. "
"Please see metaclear(1M).\n");
}
"%s is part of VxVM volume %s.\n");
"%s is in use for live upgrade %s. Please see ludelete(1M)."
"\n");
"%s is in use by %s. Please see dumpadm(1M)."
"\n");
"%s is part of exported or potentially active ZFS pool %s. "
"Please see zpool(1M).\n");
"%s is part of active ZFS pool %s. Please see zpool(1M)."
"\n");
}
}
void
{
if (*errp == 0) {
}
}
descriptor_t **
{
return (NULL);
}
*errp = 0;
return (empty);
}
void
{
char *valp;
}
}
int
{
if (dm_debug) {
}
return (1);
} else {
return (0);
}
}
/* nm1 != NULL */
if (dm_debug) {
}
return (0);
}
return (1);
}
return (0);
}
/*ARGSUSED*/
static descriptor_t **
{
#ifdef _LP64
return ((descriptor_t **)descs);
#else
/* convert the 64 bit descriptors to 32 bit ptrs */
int cnt;
int i;
descriptor_t **da;
return (NULL);
}
for (i = 0; descs[i]; i++) {
}
*errp = 0;
return (da);
#endif
}
/*ARGSUSED*/
static dm_descriptor_t *
{
#ifdef _LP64
return ((dm_descriptor_t *)ptrs);
#else
/* convert the 32 bit ptrs to the 64 bit descriptors */
int cnt;
int i;
return (NULL);
}
return (NULL);
}
for (i = 0; ptrs[i]; i++) {
}
*errp = 0;
return (da);
#endif
}
/*
* Build the usage string for the in use data. Return the build string in
* the msg parameter. This function takes care of reallocing all the memory
* for this usage string. Usage string is returned already formatted for
* localization.
*/
static int
{
int len0;
int len1;
char *use;
char *p;
*errp = 0;
if (!use) {
return (-1);
}
if (*msg)
else
len0 = 0;
/* LINTED */
/*
* If multiple in use details they
* are listed 1 per line for ease of
* reading. dm_find_usage_string
* formats these appropriately.
*/
return (-1);
}
*msg = p;
/* LINTED */
(*found)++;
return (0);
}