summaryrefslogtreecommitdiff
path: root/sysutils/wipe/patches/patch-ah
blob: 2943598290a507873bd5c7edad6794c54fad05c0 (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
$NetBSD: patch-ah,v 1.3 2013/06/17 06:09:06 dholland Exp $

- Don't declare own errno.
- DragonFly BSD's partinfo is not the standard BSD partinfo.
- NetBSD no longer supports the partinfo ioctl. Use the
  available alternatives, which is kind of messy.

--- blkdev.c.orig	2003-08-03 23:07:29.000000000 +0000
+++ blkdev.c
@@ -44,10 +44,20 @@
 # endif
 #endif
 
+#if defined(__DragonFly__)
+# include <sys/diskslice.h>
+# define BSD_BLKDEV
+#elif defined(__NetBSD__)
+# include <sys/disklabel.h>
+# include <sys/disk.h>
+# include <sys/param.h> /* for DEV_BSIZE, XXX */
+# define BSD_BLKDEV
+#else
 #ifdef HAVE_SYS_DISKLABEL_H
 # include <sys/disklabel.h>
 # define BSD_BLKDEV
 #endif
+#endif
 
 #ifndef LINUX_BLKDEV
 # ifndef BSD_BLKDEV
@@ -63,7 +73,6 @@
 #include "wipe.h"
 #include "blkdev.h"
 
-extern int errno;
 extern int exit_code;
 extern char *argvzero;
 extern struct opt_s options;
@@ -128,7 +137,13 @@ public int destroy_blkdev(struct file_s 
   int code;
 
 #ifdef BSD_BLKDEV
+#ifdef DIOCGPART
   struct partinfo pinfo;
+#else
+  struct disklabel lab;
+  struct dkwedge_info dkw;
+  int use_dkw;
+#endif
 #endif
 
 #ifdef NO_BLKDEV
@@ -160,12 +175,26 @@ public int destroy_blkdev(struct file_s 
     }
 
 #ifdef BSD_BLKDEV
+# ifdef DIOCGPART
   if (ioctl(f->fd, DIOCGPART, &pinfo))
     {
       fprintf(stderr, "\r%s: ioctl failed, can't get disklabel for `%s': %s\n",
 	      argvzero, f->name, strerror(errno));
       exit_code = errno; return FAILED;
     }
+# else
+  if (ioctl(f->fd, DIOCGDINFO, &lab) == 0) {
+     use_dkw = 0;
+  }
+  else if (ioctl(f->fd, DIOCGWEDGEINFO, &dkw) == 0) {
+     use_dkw = 1;
+  }
+  else {
+     fprintf(stderr, "\r%s: ioctl failed, can't get disklabel for `%s': %s\n",
+	     argvzero, f->name, strerror(errno));
+     exit_code = errno; return FAILED;
+  }
+# endif
 #endif
 
   if (options.sectors == 0)
@@ -182,15 +211,35 @@ public int destroy_blkdev(struct file_s 
       options.sectors = tmp;
 #endif
 
-#ifdef BSD_BLKDEV
+#if defined(BSD_BLKDEV)
+# if defined(__DragonFly__)
+      options.sectors = pinfo.media_blocks;
+# else
+#  if defined(DIOCGPART)
       options.sectors = pinfo.part->p_size;
+#  else
+      options.sectors = use_dkw ?
+	 dkw.dkw_size : lab.d_partitions[DISKPART(f->st.st_rdev)].p_size;
+#  endif
+# endif
 #endif
     }
 
   if (options.sector_size == 0)
     {
-#ifdef BSD_BLKDEV
+#if defined(__DragonFly__)
+      options.sector_size = pinfo.media_blocks;
+#elif defined(BSD_BLKDEV)
+# if defined(DIOCGPART)
       options.sector_size = pinfo.disklab->d_secsize;
+# else
+      /*
+       * XXX: we ought to use DIOCGDISKINFO to get the sector size,
+       * but that requires proplib and probably 500+ lines of code.
+       * So punt and use DEV_BSIZE...
+       */
+      options.sector_size = use_dkw ? DEV_BSIZE : lab.d_secsize;
+# endif
 #else
       options.sector_size = SECTOR_SIZE;
 #endif