aboutsummaryrefslogtreecommitdiff
path: root/cddl/compat/opensolaris/misc
diff options
context:
space:
mode:
authorPawel Jakub Dawidek <pjd@FreeBSD.org>2007-05-06 01:39:39 +0000
committerPawel Jakub Dawidek <pjd@FreeBSD.org>2007-05-06 01:39:39 +0000
commit7baf73a6c28bec6aec5d1e6ff656f7e527a6c8bc (patch)
tree155527b23b9a27cd3b08983c2dbd01ca5b09866d /cddl/compat/opensolaris/misc
parentfab3f4465e807dea84f8c8200b6e384766ae0422 (diff)
downloadsrc-7baf73a6c28bec6aec5d1e6ff656f7e527a6c8bc.tar.gz
src-7baf73a6c28bec6aec5d1e6ff656f7e527a6c8bc.zip
Use provider's ident to handle situations when disks are moved around
and show up with different names: first try to open provider using remembered name and compare its ident, if equal, this is our provider, if not equal or there is no provider with such name, find provider with remembered ident and don't care about the name.
Notes
Notes: svn path=/head/; revision=169303
Diffstat (limited to 'cddl/compat/opensolaris/misc')
-rw-r--r--cddl/compat/opensolaris/misc/deviceid.c119
1 files changed, 119 insertions, 0 deletions
diff --git a/cddl/compat/opensolaris/misc/deviceid.c b/cddl/compat/opensolaris/misc/deviceid.c
new file mode 100644
index 000000000000..f37b1d6d3563
--- /dev/null
+++ b/cddl/compat/opensolaris/misc/deviceid.c
@@ -0,0 +1,119 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@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
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS 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 AUTHORS 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <libgeom.h>
+#include <devid.h>
+
+int
+devid_str_decode(char *devidstr, ddi_devid_t *retdevid, char **retminor_name)
+{
+
+ if (strlcpy(retdevid->devid, devidstr, sizeof(retdevid->devid)) >=
+ sizeof(retdevid->devid)) {
+ return (EINVAL);
+ }
+ *retminor_name = strdup("");
+ if (*retminor_name == NULL);
+ return (ENOMEM);
+ return (0);
+}
+
+int
+devid_deviceid_to_nmlist(char *search_path, ddi_devid_t devid, char *minor_name,
+ devid_nmlist_t **retlist)
+{
+ char path[MAXPATHLEN];
+ char *dst;
+
+ if (g_get_name(devid.devid, path, sizeof(path)) == -1)
+ return (errno);
+ *retlist = malloc(sizeof(**retlist));
+ if (*retlist == NULL)
+ return (ENOMEM);
+ if (strlcpy((*retlist)[0].devname, path,
+ sizeof((*retlist)[0].devname)) >= sizeof((*retlist)[0].devname)) {
+ free(*retlist);
+ return (ENAMETOOLONG);
+ }
+ return (0);
+}
+
+void
+devid_str_free(char *str)
+{
+
+ free(str);
+}
+
+void
+devid_free(ddi_devid_t devid)
+{
+ /* Do nothing. */
+}
+
+void
+devid_free_nmlist(devid_nmlist_t *list)
+{
+
+ free(list);
+}
+
+int
+devid_get(int fd, ddi_devid_t *retdevid)
+{
+
+ if (ioctl(fd, DIOCGIDENT, retdevid->devid) == -1)
+ return (errno);
+ if (retdevid->devid[0] == '\0')
+ return (ENOENT);
+ return (0);
+}
+
+int
+devid_get_minor_name(int fd, char **retminor_name)
+{
+
+ *retminor_name = strdup("");
+ if (*retminor_name == NULL)
+ return (ENOMEM);
+ return (0);
+}
+
+char *
+devid_str_encode(ddi_devid_t devid, char *minor_name)
+{
+
+ return (strdup(devid.devid));
+}