summaryrefslogtreecommitdiff
path: root/usr/src/lib/libdiskmgt/common
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib/libdiskmgt/common')
-rw-r--r--usr/src/lib/libdiskmgt/common/disks_private.h8
-rw-r--r--usr/src/lib/libdiskmgt/common/drive.c96
-rw-r--r--usr/src/lib/libdiskmgt/common/findevs.c16
-rw-r--r--usr/src/lib/libdiskmgt/common/media.c120
-rw-r--r--usr/src/lib/libdiskmgt/common/partition.c90
-rw-r--r--usr/src/lib/libdiskmgt/common/slice.c493
6 files changed, 33 insertions, 790 deletions
diff --git a/usr/src/lib/libdiskmgt/common/disks_private.h b/usr/src/lib/libdiskmgt/common/disks_private.h
index 2d738dfcbf..0f782bc383 100644
--- a/usr/src/lib/libdiskmgt/common/disks_private.h
+++ b/usr/src/lib/libdiskmgt/common/disks_private.h
@@ -2,9 +2,8 @@
* 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.
+ * 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
* or http://www.opensolaris.org/os/licensing.
@@ -98,7 +97,6 @@ typedef struct disk {
char *device_id; /* string encoded device id */
ddi_devid_t devid; /* decoded device id */
char *kernel_name; /* handles drives w/ no devlinks */
- char *volm_path;
char *product_id;
char *vendor_id;
controller_t **controllers;
@@ -111,7 +109,6 @@ typedef struct disk {
int rpm;
int wide;
int cd_rom;
- int volm_path_set;
} disk_t;
typedef struct descriptor {
@@ -196,7 +193,6 @@ descriptor_t *media_get_descriptor_by_name(char *name, int *errp);
char *media_get_name(descriptor_t *desc);
nvlist_t *media_get_attributes(descriptor_t *desc, int *errp);
nvlist_t *media_get_stats(descriptor_t *desc, int stat_type, int *errp);
-int media_get_volm_path(disk_t *diskp, char *mediapath, int size);
int media_make_descriptors();
int media_read_info(int fd, struct dk_minfo *minfo);
int media_read_name(disk_t *dp, char *mname, int size);
diff --git a/usr/src/lib/libdiskmgt/common/drive.c b/usr/src/lib/libdiskmgt/common/drive.c
index b3f32c70d6..825348ce9f 100644
--- a/usr/src/lib/libdiskmgt/common/drive.c
+++ b/usr/src/lib/libdiskmgt/common/drive.c
@@ -2,9 +2,8 @@
* 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.
+ * 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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -626,99 +625,12 @@ drive_make_descriptors()
/*
* This function opens the disk generically (any slice).
- *
- * Opening the disk could fail because the disk is managed by the volume
- * manager. Handle this if that is the case. Note that the media APIs don't
- * always return a device. If the media has slices (e.g. a solaris install
- * CD-ROM) then media_findname(volname) returns a directory with per slice
- * devices underneath. We need to open one of those devices in this case.
*/
int
drive_open_disk(disk_t *diskp, char *opath, int len)
{
- char rmmedia_devpath[MAXPATHLEN];
-
- if (diskp->removable && media_get_volm_path(diskp, rmmedia_devpath,
- sizeof (rmmedia_devpath))) {
-
- int fd;
- struct stat buf;
-
- if (rmmedia_devpath[0] == 0) {
- /* removable but no media */
- return (-1);
- }
-
- if ((fd = open(rmmedia_devpath, O_RDONLY|O_NDELAY)) < 0) {
- return (-1);
- }
-
- if (fstat(fd, &buf) != 0) {
- (void) close(fd);
- return (-1);
- }
-
- if (S_ISCHR(buf.st_mode)) {
- /* opened, is device, so done */
- if (opath != NULL) {
- (void) strlcpy(opath, rmmedia_devpath, len);
- }
- return (fd);
-
- } else if (S_ISDIR(buf.st_mode)) {
- /* disk w/ slices so handle the directory */
- DIR *dirp;
- struct dirent *dentp;
- int dfd;
-
- /* each device file in the dir represents a slice */
-
- if ((dirp = fdopendir(fd)) == NULL) {
- (void) close(fd);
- return (-1);
- }
-
- while ((dentp = readdir(dirp)) != NULL) {
- char slice_path[MAXPATHLEN];
-
- if (libdiskmgt_str_eq(".", dentp->d_name) ||
- libdiskmgt_str_eq("..", dentp->d_name)) {
- continue;
- }
-
- (void) snprintf(slice_path, sizeof (slice_path), "%s/%s",
- rmmedia_devpath, dentp->d_name);
-
- if ((dfd = open(slice_path, O_RDONLY|O_NDELAY)) < 0) {
- continue;
- }
-
- if (fstat(dfd, &buf) == 0 && S_ISCHR(buf.st_mode)) {
- /* opened, is device, so done */
- (void) closedir(dirp);
- if (opath != NULL) {
- (void) strlcpy(opath, slice_path, len);
- }
- return (dfd);
- }
-
- /* not a device, keep looking */
- (void) close(dfd);
- }
-
- /* did not find a device under the rmmedia_path */
- (void) closedir(dirp);
- return (-1);
- }
-
- /* didn't find a device under volume management control */
- (void) close(fd);
- return (-1);
- }
-
/*
- * Not removable media under volume management control so just open the
- * first devpath.
+ * Just open the first devpath.
*/
if (diskp->aliases != NULL && diskp->aliases->devpaths != NULL) {
if (opath != NULL) {
diff --git a/usr/src/lib/libdiskmgt/common/findevs.c b/usr/src/lib/libdiskmgt/common/findevs.c
index 5a5bd4fc15..42d57d428a 100644
--- a/usr/src/lib/libdiskmgt/common/findevs.c
+++ b/usr/src/lib/libdiskmgt/common/findevs.c
@@ -2,9 +2,8 @@
* 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.
+ * 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
* or http://www.opensolaris.org/os/licensing.
@@ -977,15 +976,6 @@ create_disk(char *deviceid, char *kernel_name, struct search_args *args)
/* not a "CD-ROM" or Floppy */
diskp->removable = get_prop(REMOVABLE_PROP, args->node);
- if (diskp->removable == -1) {
- /*
- * This is a workaround. Hotpluggable devices don't export
- * a "removable-media" property, but they are treated as
- * removable media devices by vold to implement automount.
- * Once vold is EOL'ed, it should be removed.
- */
- diskp->removable = get_prop(HOTPLUGGABLE_PROP, args->node);
- }
if (diskp->removable == -1) {
diskp->removable = 0;
@@ -1026,8 +1016,6 @@ create_disk(char *deviceid, char *kernel_name, struct search_args *args)
diskp->drv_type = DM_DT_FIXED;
}
}
- diskp->volm_path_set = 0;
- diskp->volm_path = NULL;
diskp->next = args->disk_listp;
args->disk_listp = diskp;
diff --git a/usr/src/lib/libdiskmgt/common/media.c b/usr/src/lib/libdiskmgt/common/media.c
index ac29898ede..9f6ee99ff1 100644
--- a/usr/src/lib/libdiskmgt/common/media.c
+++ b/usr/src/lib/libdiskmgt/common/media.c
@@ -2,9 +2,8 @@
* 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.
+ * 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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -38,7 +37,6 @@
#include <sys/types.h>
#include <unistd.h>
#include <sys/vtoc.h>
-#include <volmgt.h>
#include <sys/efi_partition.h>
#include "libdiskmgt.h"
@@ -51,7 +49,7 @@
static descriptor_t **apply_filter(descriptor_t **media, int filter[],
int *errp);
static int get_attrs(disk_t *dp, int fd, nvlist_t *attrs);
-static int get_non_volm_name(disk_t *dp, char *mname, int size);
+static int get_rmm_name(disk_t *dp, char *mname, int size);
static int get_media_type(uint_t media_type);
static int desc_ok(descriptor_t *dp);
@@ -215,90 +213,6 @@ media_get_stats(descriptor_t *dp, int stat_type, int *errp)
return (NULL);
}
-/*
- * Get the removable media volume manager devpath for the disk. This is the
- * name we need to open that will work with vold.
- * Return 1 if under volm control, 0 if not under volm control.
- * The string in mediapath will be empty if the drive is under volm control
- * but there is no media loaded.
- */
-int
-media_get_volm_path(disk_t *diskp, char *mediapath, int size)
-{
- char vname[MAXPATHLEN];
- char *volname;
- char *media_name;
-
- if (!diskp->removable || !volmgt_running()) {
- return (0);
- }
-
- /*
- * The volume manager is running, so we have to check if this removable
- * drive is under volm control or not.
- */
-
- /*
- * We must check if this drive is under volume management control and
- * what devpath to use.
- * Note that we have to do this every time for drives that are not
- * under the control of the volume manager, since the volume manager
- * might have taken control since the last time we checked.
- */
- if (diskp->volm_path_set == 0) {
- alias_t *ap;
- slice_t *dp;
-
- if ((ap = diskp->aliases) == NULL) {
- return (0);
- }
-
- /* Check each devpath to see if it is under volm control. */
- dp = ap->devpaths;
- while (dp != NULL) {
- slice_rdsk2dsk(dp->devpath, vname, sizeof (vname));
- if (volmgt_inuse(vname)) {
- break;
- }
-
- dp = dp->next;
- }
-
- if (dp != NULL) {
- /* Volume manager is managing the devpath that dp points to. */
- diskp->volm_path = dp->devpath;
- diskp->volm_path_set = 1;
- }
- }
-
- if (diskp->volm_path_set == 0) {
- /* The volume manager is not managing any of the devpaths. */
- return (0);
- }
-
- if (dm_debug > 1) {
- (void) fprintf(stderr, "INFO: chk vol: %s\n", diskp->volm_path);
- }
-
- slice_rdsk2dsk(diskp->volm_path, vname, sizeof (vname));
- volname = volmgt_symname(vname);
- if (volname == NULL) {
- mediapath[0] = 0;
- return (1);
- }
-
- media_name = media_findname(volname);
- free(volname);
- if (media_name == NULL) {
- mediapath[0] = 0;
- return (1);
- }
-
- (void) strlcpy(mediapath, media_name, size);
- free(media_name);
- return (1);
-}
-
int
media_make_descriptors()
{
@@ -357,9 +271,6 @@ media_read_info(int fd, struct dk_minfo *minfo)
int
media_read_name(disk_t *dp, char *mname, int size)
{
- int under_volm;
- char rmmedia_devpath[MAXPATHLEN];
-
mname[0] = 0;
if (!dp->removable) {
@@ -371,24 +282,7 @@ media_read_name(disk_t *dp, char *mname, int size)
}
/* This is a removable media drive. */
-
- /* Get 1 if under volm control, 0 if not */
- under_volm = media_get_volm_path(dp, rmmedia_devpath,
- sizeof (rmmedia_devpath));
-
- if (under_volm) {
- /* under volm control */
- if (rmmedia_devpath[0] == 0) {
- /* no media */
- return (0);
- }
- (void) strlcpy(mname, rmmedia_devpath, size);
- return (1);
-
- } else {
- /* not under volm control */
- return (get_non_volm_name(dp, mname, size));
- }
+ return (get_rmm_name(dp, mname, size));
}
static descriptor_t **
@@ -636,10 +530,10 @@ get_media_type(uint_t media_type)
}
/*
- * This function handles removable media not under volume management.
+ * This function handles removable media.
*/
static int
-get_non_volm_name(disk_t *dp, char *mname, int size)
+get_rmm_name(disk_t *dp, char *mname, int size)
{
int loaded;
int fd;
diff --git a/usr/src/lib/libdiskmgt/common/partition.c b/usr/src/lib/libdiskmgt/common/partition.c
index 49fa757330..e1f29479b9 100644
--- a/usr/src/lib/libdiskmgt/common/partition.c
+++ b/usr/src/lib/libdiskmgt/common/partition.c
@@ -2,9 +2,8 @@
* 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.
+ * 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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -604,89 +603,8 @@ has_slices(descriptor_t *desc, int *errp)
static int
open_disk(disk_t *diskp, char *opath, int len)
{
- char rmmedia_devpath[MAXPATHLEN];
-
- if (diskp->removable && media_get_volm_path(diskp, rmmedia_devpath,
- sizeof (rmmedia_devpath))) {
-
- int fd;
- struct stat buf;
-
- if (rmmedia_devpath[0] == 0) {
- /* removable but no media */
- return (-1);
- }
-
- if ((fd = open(rmmedia_devpath, O_RDONLY|O_NDELAY)) < 0) {
- return (-1);
- }
-
- if (fstat(fd, &buf) != 0) {
- (void) close(fd);
- return (-1);
- }
-
- if (S_ISCHR(buf.st_mode)) {
- /* opened, is device, so done */
- if (opath != NULL) {
- (void) strlcpy(opath, rmmedia_devpath, len);
- }
- return (fd);
-
- } else if (S_ISDIR(buf.st_mode)) {
- /* disk w/ slices so handle the directory */
- DIR *dirp;
- struct dirent *dentp;
- int dfd;
-
- /* each device file in the dir represents a slice */
-
- if ((dirp = fdopendir(fd)) == NULL) {
- (void) close(fd);
- return (-1);
- }
-
- while ((dentp = readdir(dirp)) != NULL) {
- char slice_path[MAXPATHLEN];
-
- if (libdiskmgt_str_eq(".", dentp->d_name) ||
- libdiskmgt_str_eq("..", dentp->d_name)) {
- continue;
- }
-
- (void) snprintf(slice_path, sizeof (slice_path), "%s/%s",
- rmmedia_devpath, dentp->d_name);
-
- if ((dfd = open(slice_path, O_RDONLY|O_NDELAY)) < 0) {
- continue;
- }
-
- if (fstat(dfd, &buf) == 0 && S_ISCHR(buf.st_mode)) {
- /* opened, is device, so done */
- (void) closedir(dirp);
- if (opath != NULL) {
- (void) strlcpy(opath, slice_path, len);
- }
- return (dfd);
- }
-
- /* not a device, keep looking */
- (void) close(dfd);
- }
-
- /* did not find a device under the rmmedia_path */
- (void) closedir(dirp);
- return (-1);
- }
-
- /* didn't find a device under volume management control */
- (void) close(fd);
- return (-1);
- }
-
/*
- * Not removable media under volume management control so just open the
- * first devpath.
+ * Just open the first devpath.
*/
if (diskp->aliases != NULL && diskp->aliases->devpaths != NULL) {
#ifdef sparc
diff --git a/usr/src/lib/libdiskmgt/common/slice.c b/usr/src/lib/libdiskmgt/common/slice.c
index e94c443cfb..2e76e43671 100644
--- a/usr/src/lib/libdiskmgt/common/slice.c
+++ b/usr/src/lib/libdiskmgt/common/slice.c
@@ -2,9 +2,8 @@
* 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.
+ * 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
* or http://www.opensolaris.org/os/licensing.
@@ -73,17 +72,9 @@ static int desc_ok(descriptor_t *dp);
static void dsk2rdsk(char *dsk, char *rdsk, int size);
static int get_attrs(descriptor_t *dp, int fd, nvlist_t *attrs);
static descriptor_t **get_fixed_assocs(descriptor_t *desc, int *errp);
-static descriptor_t **get_removable_assocs(descriptor_t *desc, char *volm_path,
- int *errp);
static int get_slice_num(slice_t *devp);
static int match_fixed_name(disk_t *dp, char *name, int *errp);
-static int match_removable_name(disk_t *dp, char *name, int *errp);
static int make_fixed_descriptors(disk_t *dp);
-static int make_removable_descriptors(disk_t *dp);
-static int make_volm_dir_descriptors(disk_t *dp, int fd,
- char *volm_path);
-static int num_removable_slices(int fd, struct stat *bufp,
- char *volm_path);
descriptor_t **
slice_get_assoc_descriptors(descriptor_t *desc, dm_desc_type_t type,
@@ -114,35 +105,13 @@ slice_get_assoc_descriptors(descriptor_t *desc, dm_desc_type_t type,
descriptor_t **
slice_get_assocs(descriptor_t *desc, int *errp)
{
- int under_volm = 0;
- char volm_path[MAXPATHLEN];
-
/* Just check the first drive name. */
if (desc->p.disk->aliases == NULL) {
*errp = 0;
return (libdiskmgt_empty_desc_array(errp));
}
- if (desc->p.disk->removable) {
- if ((under_volm = media_get_volm_path(desc->p.disk, volm_path,
- sizeof (volm_path)))) {
- if (volm_path[0] == 0) {
- /* no media */
- *errp = 0;
- return (libdiskmgt_empty_desc_array(errp));
- }
- }
- }
-
- if (desc->p.disk->removable) {
- if (under_volm) {
- return (get_removable_assocs(desc, volm_path, errp));
- } else {
- return (get_fixed_assocs(desc, errp));
- }
- } else {
- return (get_fixed_assocs(desc, errp));
- }
+ return (get_fixed_assocs(desc, errp));
}
nvlist_t *
@@ -188,24 +157,21 @@ slice_get_descriptor_by_name(char *name, int *errp)
disk_t *dp;
for (dp = cache_get_disklist(); dp != NULL; dp = dp->next) {
- if (dp->removable) {
- found = match_removable_name(dp, name, errp);
- } else {
found = match_fixed_name(dp, name, errp);
- }
- if (found) {
- char mname[MAXPATHLEN];
+ if (found) {
+ char mname[MAXPATHLEN];
- if (*errp != 0) {
- return (NULL);
- }
+ if (*errp != 0) {
+ return (NULL);
+ }
- mname[0] = 0;
- (void) media_read_name(dp, mname, sizeof (mname));
+ mname[0] = 0;
+ (void) media_read_name(dp, mname, sizeof (mname));
- return (cache_get_desc(DM_SLICE, dp, name, mname, errp));
- }
+ return (cache_get_desc(DM_SLICE, dp, name, mname,
+ errp));
+ }
}
*errp = ENODEV;
@@ -310,11 +276,7 @@ slice_make_descriptors()
while (dp != NULL) {
int error;
- if (dp->removable) {
- error = make_removable_descriptors(dp);
- } else {
- error = make_fixed_descriptors(dp);
- }
+ error = make_fixed_descriptors(dp);
if (error != 0) {
return (error);
}
@@ -750,140 +712,6 @@ get_fixed_assocs(descriptor_t *desc, int *errp)
return (slices);
}
-/*
- * Called for loaded removable media under volume management control.
- */
-static descriptor_t **
-get_removable_assocs(descriptor_t *desc, char *volm_path, int *errp)
-{
- int pos;
- int fd;
- int cnt;
- struct stat buf;
- descriptor_t **slices;
- char *media_name = NULL;
- char devpath[MAXPATHLEN];
-
- /* get the media name from the descriptor */
- if (desc->type == DM_MEDIA) {
- media_name = desc->name;
- } else {
- /* must be a DM_PARTITION */
- media_name = desc->secondary_name;
- }
-
- /*
- * For removable media under volm control the volm_path will
- * either be a device (if the media is made up of a single slice) or
- * a directory (if the media has multiple slices) with the slices
- * as devices contained in the directory.
- */
-
- if ((fd = open(volm_path, O_RDONLY|O_NDELAY)) < 0 ||
- fstat(fd, &buf) != 0) {
- *errp = ENODEV;
- return (NULL);
- }
-
- cnt = num_removable_slices(fd, &buf, volm_path);
-
- /* allocate the array for the descriptors */
- slices = calloc(cnt + 1, sizeof (descriptor_t *));
- if (slices == NULL) {
- *errp = ENOMEM;
- return (NULL);
- }
-
- slice_rdsk2dsk(volm_path, devpath, sizeof (devpath));
-
- pos = 0;
- *errp = 0;
- if (S_ISCHR(buf.st_mode)) {
- struct dk_minfo minfo;
-
- /* Make sure media has readable label */
- if (media_read_info(fd, &minfo)) {
- int status;
- int data_format = FMT_UNKNOWN;
- struct vtoc vtoc;
- struct dk_gpt *efip;
-
- if ((status = read_vtoc(fd, &vtoc)) >= 0) {
- data_format = FMT_VTOC;
- } else if (status == VT_ENOTSUP &&
- efi_alloc_and_read(fd, &efip) >= 0) {
- data_format = FMT_EFI;
- }
-
- if (data_format != FMT_UNKNOWN) {
- /* has a readable label */
- slices[pos++] =
- cache_get_desc(DM_SLICE, desc->p.disk,
- devpath, media_name, errp);
- }
- }
- (void) close(fd);
- } else if (S_ISDIR(buf.st_mode)) {
- DIR *dirp;
- struct dirent *dentp;
-
- /* rewind, num_removable_slices already traversed */
- (void) lseek(fd, 0, SEEK_SET);
-
- if ((dirp = fdopendir(fd)) == NULL) {
- *errp = errno;
- (void) close(fd);
- return (NULL);
- }
-
- while ((dentp = readdir(dirp)) != NULL) {
- int dfd;
- int is_dev = 0;
- char slice_path[MAXPATHLEN];
-
- if (libdiskmgt_str_eq(".", dentp->d_name) ||
- libdiskmgt_str_eq("..", dentp->d_name)) {
- continue;
- }
-
- (void) snprintf(slice_path, sizeof (slice_path),
- "%s/%s", devpath, dentp->d_name);
-
- if ((dfd = open(slice_path, O_RDONLY|O_NDELAY)) >= 0) {
- struct stat buf;
-
- if (fstat(dfd, &buf) == 0 &&
- S_ISCHR(buf.st_mode)) {
- is_dev = 1;
- }
- (void) close(dfd);
- }
-
- if (!is_dev) {
- continue;
- }
-
- slices[pos++] = cache_get_desc(DM_SLICE, desc->p.disk,
- slice_path, media_name, errp);
- if (*errp != 0) {
- break;
- }
- }
- (void) closedir(dirp);
- } else {
- (void) close(fd);
- }
-
- slices[pos] = NULL;
-
- if (*errp != 0) {
- cache_free_descriptors(slices);
- return (NULL);
- }
-
- return (slices);
-}
-
static int
get_slice_num(slice_t *devp)
{
@@ -979,141 +807,6 @@ make_fixed_descriptors(disk_t *dp)
}
/*
- * For removable media under volm control we have to do some special handling.
- * We don't use the vtoc and /dev/dsk devpaths, since the slices are named
- * under the /vol fs.
- */
-static int
-make_removable_descriptors(disk_t *dp)
-{
- char volm_path[MAXPATHLEN];
- int error;
- int fd;
-
- /*
- * If this removable drive is not under volm control, just use
- * normal handling.
- */
- if (!media_get_volm_path(dp, volm_path, sizeof (volm_path))) {
- return (make_fixed_descriptors(dp));
- }
-
- if (volm_path[0] == 0) {
- /* no media */
- return (0);
- }
-
- /*
- * For removable media under volm control the rmmedia_devapth will
- * either be a device (if the media is made up of a single slice) or
- * a directory (if the media has multiple slices) with the slices
- * as devices contained in the directory.
- */
- error = 0;
- if ((fd = open(volm_path, O_RDONLY|O_NDELAY)) >= 0) {
- struct stat buf;
-
- if (fstat(fd, &buf) == 0) {
- if (S_ISCHR(buf.st_mode)) {
- int status;
- int data_format = FMT_UNKNOWN;
- struct dk_minfo minfo;
- int error;
- struct vtoc vtoc;
- struct dk_gpt *efip;
- char devpath[MAXPATHLEN];
-
- /* Make sure media has readable label */
- if (!media_read_info(fd, &minfo)) {
- /* no media */
- return (0);
- }
-
- if ((status = read_vtoc(fd, &vtoc)) >= 0) {
- data_format = FMT_VTOC;
- } else if (status == VT_ENOTSUP &&
- efi_alloc_and_read(fd, &efip) >= 0) {
- data_format = FMT_EFI;
- }
-
- if (data_format == FMT_UNKNOWN) {
- /* no readable label */
- return (0);
- }
-
- slice_rdsk2dsk(volm_path, devpath, sizeof (devpath));
- /* The media name is the volm_path in this case. */
- cache_load_desc(DM_SLICE, dp, devpath, volm_path, &error);
-
- } else if (S_ISDIR(buf.st_mode)) {
- /* each device file in the dir represents a slice */
- error = make_volm_dir_descriptors(dp, fd, volm_path);
- }
- }
- (void) close(fd);
- }
-
- return (error);
-}
-
-/*
- * This handles removable media with slices under volume management control.
- * In this case we have a dir which is the media name and each slice on the
- * media is a device file in this dir.
- */
-static int
-make_volm_dir_descriptors(disk_t *dp, int dirfd, char *volm_path)
-{
- int error;
- DIR *dirp;
- struct dirent *dentp;
- char devpath[MAXPATHLEN];
-
- dirfd = dup(dirfd);
- if (dirfd < 0)
- return (0);
- if ((dirp = fdopendir(dirfd)) == NULL) {
- (void) close(dirfd);
- return (0);
- }
-
- slice_rdsk2dsk(volm_path, devpath, sizeof (devpath));
-
- error = 0;
- while ((dentp = readdir(dirp)) != NULL) {
- int fd;
- char slice_path[MAXPATHLEN];
-
- if (libdiskmgt_str_eq(".", dentp->d_name) ||
- libdiskmgt_str_eq("..", dentp->d_name)) {
- continue;
- }
-
- (void) snprintf(slice_path, sizeof (slice_path), "%s/%s",
- devpath, dentp->d_name);
-
- if ((fd = open(slice_path, O_RDONLY|O_NDELAY)) >= 0) {
- struct stat buf;
-
- /* The media name is the volm_path in this case. */
- if (fstat(fd, &buf) == 0 && S_ISCHR(buf.st_mode)) {
- cache_load_desc(DM_SLICE, dp, slice_path,
- volm_path, &error);
- if (error != 0) {
- (void) close(fd);
- break;
- }
- }
-
- (void) close(fd);
- }
- }
- (void) closedir(dirp);
-
- return (error);
-}
-
-/*
* Just look for the name on the devpaths we have cached. Return 1 if we
* find the name and the size of that slice is non-zero.
*/
@@ -1206,161 +899,3 @@ match_fixed_name(disk_t *diskp, char *name, int *errp)
*errp = ENODEV;
return (1);
}
-
-static int
-match_removable_name(disk_t *diskp, char *name, int *errp)
-{
- char volm_path[MAXPATHLEN];
- int found;
- int fd;
- struct stat buf;
-
- /*
- * If this removable drive is not under volm control, just use
- * normal handling.
- */
- if (!media_get_volm_path(diskp, volm_path, sizeof (volm_path))) {
- return (match_fixed_name(diskp, name, errp));
- }
-
- if (volm_path[0] == 0) {
- /* no media */
- *errp = 0;
- return (0);
- }
-
- /*
- * For removable media under volm control the rmmedia_devapth will
- * either be a device (if the media is made up of a single slice) or
- * a directory (if the media has multiple slices) with the slices
- * as devices contained in the directory.
- */
-
- *errp = 0;
-
- if ((fd = open(volm_path, O_RDONLY|O_NDELAY)) == -1 ||
- fstat(fd, &buf) != 0) {
- return (0);
- }
-
- found = 0;
-
- if (S_ISCHR(buf.st_mode)) {
- char devpath[MAXPATHLEN];
-
- slice_rdsk2dsk(volm_path, devpath, sizeof (devpath));
- if (libdiskmgt_str_eq(name, devpath)) {
- found = 1;
- }
- (void) close(fd);
- return (found);
- } else if (S_ISDIR(buf.st_mode)) {
- /* each device file in the dir represents a slice */
- DIR *dirp;
- struct dirent *dentp;
- char devpath[MAXPATHLEN];
-
- if ((dirp = fdopendir(fd)) == NULL) {
- (void) close(fd);
- return (0);
- }
-
- slice_rdsk2dsk(volm_path, devpath, sizeof (devpath));
-
- while ((dentp = readdir(dirp)) != NULL) {
- char slice_path[MAXPATHLEN];
-
- if (libdiskmgt_str_eq(".", dentp->d_name) ||
- libdiskmgt_str_eq("..", dentp->d_name)) {
- continue;
- }
-
- (void) snprintf(slice_path, sizeof (slice_path),
- "%s/%s", devpath, dentp->d_name);
-
- if (libdiskmgt_str_eq(name, slice_path)) {
- /* found name, check device */
- int dfd;
- int is_dev = 0;
-
- dfd = open(slice_path, O_RDONLY|O_NDELAY);
- if (dfd >= 0) {
- struct stat buf;
-
- if (fstat(dfd, &buf) == 0 &&
- S_ISCHR(buf.st_mode)) {
- is_dev = 1;
- }
- (void) close(dfd);
- }
-
- /* we found the name */
- found = 1;
-
- if (!is_dev) {
- *errp = ENODEV;
- }
-
- break;
- }
- }
- (void) closedir(dirp);
- } else {
- (void) close(fd);
- }
-
- return (found);
-}
-
-static int
-num_removable_slices(int fd, struct stat *bufp, char *volm_path)
-{
- int cnt = 0;
-
- if (S_ISCHR(bufp->st_mode))
- return (1);
-
- if (S_ISDIR(bufp->st_mode)) {
- /* each device file in the dir represents a slice */
- DIR *dirp;
- struct dirent *dentp;
- char devpath[MAXPATHLEN];
-
- fd = dup(fd);
-
- if (fd < 0)
- return (0);
-
- if ((dirp = fdopendir(fd)) == NULL) {
- (void) close(fd);
- return (0);
- }
-
- slice_rdsk2dsk(volm_path, devpath, sizeof (devpath));
-
- while ((dentp = readdir(dirp)) != NULL) {
- int dfd;
- char slice_path[MAXPATHLEN];
-
- if (libdiskmgt_str_eq(".", dentp->d_name) ||
- libdiskmgt_str_eq("..", dentp->d_name)) {
- continue;
- }
-
- (void) snprintf(slice_path, sizeof (slice_path),
- "%s/%s", devpath, dentp->d_name);
-
- if ((dfd = open(slice_path, O_RDONLY|O_NDELAY)) >= 0) {
- struct stat buf;
-
- if (fstat(dfd, &buf) == 0 &&
- S_ISCHR(buf.st_mode)) {
- cnt++;
- }
- (void) close(dfd);
- }
- }
- (void) closedir(dirp);
- }
- return (cnt);
-}