summaryrefslogtreecommitdiff
path: root/bootadm/debian/patches/bootadm-avoid-libadm.patch
blob: caa86e91463ff0d75ed9c3d5297f3a10db49c0db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
Index: bootadm/usr/src/cmd/boot/bootadm/Makefile
===================================================================
--- bootadm.orig/usr/src/cmd/boot/bootadm/Makefile	2013-01-12 18:30:39.777698514 +0400
+++ bootadm/usr/src/cmd/boot/bootadm/Makefile	2013-01-12 19:13:35.399844029 +0400
@@ -36,7 +36,7 @@
 .KEEP_STATE:
 
 LDLIBS_i386= -lfdisk
-LDLIBS +=	-lnvpair -lgen -ladm -lefi -lscf -lz $(LDLIBS_$(MACH))
+LDLIBS +=	-lnvpair -lgen -lefi -lscf -lz $(LDLIBS_$(MACH))
 
 # Writing into string literals is incorrect.  We need to match gcc's
 # behavior, which causes us to take SIGSEGV on such a write.
Index: bootadm/usr/src/cmd/boot/bootadm/bootadm.c
===================================================================
--- bootadm.orig/usr/src/cmd/boot/bootadm/bootadm.c	2013-01-12 18:30:40.181503527 +0400
+++ bootadm/usr/src/cmd/boot/bootadm/bootadm.c	2013-01-12 19:13:56.279332395 +0400
@@ -63,6 +63,7 @@
 #include <zlib.h>
 #include <sys/lockfs.h>
 #include <sys/filio.h>
+#include <sys/dkio.h>
 #ifdef i386
 #include <libfdisk.h>
 #endif
@@ -79,6 +80,87 @@
 #include <regex.h>
 #include <locale.h>
 
+/* From libadm.
+ * Read VTOC - return partition number.
+ */
+static int
+__read_vtoc(int fd, struct vtoc *vtoc)
+{
+    struct dk_cinfo     dki_info;
+
+    /*
+     * Read the vtoc.
+     */
+    if (ioctl(fd, DKIOCGVTOC, (caddr_t)vtoc) == -1) {
+        switch (errno) {
+        case EIO:
+            return (VT_EIO);
+        case EINVAL:
+            return (VT_EINVAL);
+        case ENOTSUP:
+            /* GPT labeled or disk > 1TB with no extvtoc support */
+            return (VT_ENOTSUP);
+        case EOVERFLOW:
+            return (VT_EOVERFLOW);
+        default:
+            return (VT_ERROR);
+        }
+    }
+
+    /*
+     * Sanity-check the vtoc.
+     */
+    if (vtoc->v_sanity != VTOC_SANE) {
+        return (VT_EINVAL);
+    }
+
+    /*
+     * Convert older-style vtoc's.
+     */
+    switch (vtoc->v_version) {
+    case 0:
+        /*
+         * No vtoc information.  Install default
+         * nparts/sectorsz and version.  We are
+         * assuming that the driver returns the
+         * current partition information correctly.
+         */
+
+        vtoc->v_version = V_VERSION;
+        if (vtoc->v_nparts == 0)
+            vtoc->v_nparts = V_NUMPAR;
+        if (vtoc->v_sectorsz == 0)
+            vtoc->v_sectorsz = DEV_BSIZE;
+
+        break;
+
+    case V_VERSION:
+        break;
+
+    default:
+        return (VT_EINVAL);
+    }
+
+    /*
+     * Return partition number for this file descriptor.
+     */
+    if (ioctl(fd, DKIOCINFO, (caddr_t)&dki_info) == -1) {
+        switch (errno) {
+        case EIO:
+            return (VT_EIO);
+        case EINVAL:
+            return (VT_EINVAL);
+        default:
+            return (VT_ERROR);
+        }
+    }
+    if (dki_info.dki_partition > V_NUMPAR) {
+        return (VT_EINVAL);
+    }
+    return ((int)dki_info.dki_partition);
+}
+
+
 #include "message.h"
 #include "bootadm.h"
 
@@ -6119,7 +6201,7 @@
 	}
 
 	e_flag = v_flag = 0;
-	retval = ((err = read_vtoc(fd, &vtoc)) >= 0) ? 0 : err;
+	retval = ((err = __read_vtoc(fd, &vtoc)) >= 0) ? 0 : err;
 	switch (retval) {
 		case VT_EIO:
 			BAM_DPRINTF((D_VTOC_READ_FAIL, fcn, s0path));