summaryrefslogtreecommitdiffstats
path: root/compat
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2007-05-06 01:39:39 +0000
committerpjd <pjd@FreeBSD.org>2007-05-06 01:39:39 +0000
commit1effa32b6605b4852fd2e5c00bd93f04f0e3bf60 (patch)
tree155527b23b9a27cd3b08983c2dbd01ca5b09866d /compat
parenta360ad79b03fc86ad14ee529259ec67558935c3c (diff)
downloadFreeBSD-src-1effa32b6605b4852fd2e5c00bd93f04f0e3bf60.zip
FreeBSD-src-1effa32b6605b4852fd2e5c00bd93f04f0e3bf60.tar.gz
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.
Diffstat (limited to 'compat')
-rw-r--r--compat/opensolaris/include/devid.h27
-rw-r--r--compat/opensolaris/misc/deviceid.c119
2 files changed, 135 insertions, 11 deletions
diff --git a/compat/opensolaris/include/devid.h b/compat/opensolaris/include/devid.h
index 06839dd..6718ce2 100644
--- a/compat/opensolaris/include/devid.h
+++ b/compat/opensolaris/include/devid.h
@@ -27,23 +27,28 @@
#ifndef _OPENSOLARIS_DEVID_H_
#define _OPENSOLARIS_DEVID_H_
-#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/disk.h>
#include <stdlib.h>
-typedef int ddi_devid_t;
+typedef struct ddi_devid {
+ char devid[DISK_IDENT_SIZE];
+} ddi_devid_t;
typedef struct devid_nmlist {
- char *devname;
+ char devname[MAXPATHLEN];
dev_t dev;
} devid_nmlist_t;
-static inline int devid_str_decode(char *devidstr, ddi_devid_t *retdevid, char **retminor_name) { abort(); }
-static inline int devid_deviceid_to_nmlist(char *search_path, ddi_devid_t devid, char *minor_name, devid_nmlist_t **retlist) { abort(); }
-static inline void devid_str_free(char *str) { abort(); }
-static inline void devid_free(ddi_devid_t devid) { abort(); }
-static inline void devid_free_nmlist(devid_nmlist_t *list) { abort(); }
-static inline int devid_get(int fd, ddi_devid_t *retdevid) { return -1; }
-static inline int devid_get_minor_name(int fd, char **retminor_name) { abort(); }
-static inline char *devid_str_encode(ddi_devid_t devid, char *minor_name) { abort(); }
+int devid_str_decode(char *devidstr, ddi_devid_t *retdevid,
+ char **retminor_name);
+int devid_deviceid_to_nmlist(char *search_path, ddi_devid_t devid,
+ char *minor_name, devid_nmlist_t **retlist);
+void devid_str_free(char *str);
+void devid_free(ddi_devid_t devid);
+void devid_free_nmlist(devid_nmlist_t *list);
+int devid_get(int fd, ddi_devid_t *retdevid);
+int devid_get_minor_name(int fd, char **retminor_name);
+char *devid_str_encode(ddi_devid_t devid, char *minor_name);
#endif /* !_OPENSOLARIS_DEVID_H_ */
diff --git a/compat/opensolaris/misc/deviceid.c b/compat/opensolaris/misc/deviceid.c
new file mode 100644
index 0000000..f37b1d6
--- /dev/null
+++ b/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));
+}
OpenPOWER on IntegriCloud