| @@ -1,55 +1,117 @@ | | | @@ -1,55 +1,117 @@ |
1 | $NetBSD: patch-ah,v 1.2 2013/06/17 05:37:22 dholland Exp $ | | 1 | $NetBSD: patch-ah,v 1.3 2013/06/17 06:09:06 dholland Exp $ |
2 | | | 2 | |
3 | - DragonFly BSD's partinfo is not the standard BSD partinfo. | | | |
4 | - Don't declare own errno. | | 3 | - Don't declare own errno. |
| | | 4 | - DragonFly BSD's partinfo is not the standard BSD partinfo. |
| | | 5 | - NetBSD no longer supports the partinfo ioctl. Use the |
| | | 6 | available alternatives, which is kind of messy. |
5 | | | 7 | |
6 | --- blkdev.c.orig 2003-08-03 23:07:29.000000000 +0000 | | 8 | --- blkdev.c.orig 2003-08-03 23:07:29.000000000 +0000 |
7 | +++ blkdev.c | | 9 | +++ blkdev.c |
8 | @@ -44,10 +44,15 @@ | | 10 | @@ -44,10 +44,20 @@ |
9 | # endif | | 11 | # endif |
10 | #endif | | 12 | #endif |
11 | | | 13 | |
12 | -#ifdef HAVE_SYS_DISKLABEL_H | | 14 | +#if defined(__DragonFly__) |
13 | +#ifdef __DragonFly__ | | | |
14 | +# include <sys/diskslice.h> | | 15 | +# include <sys/diskslice.h> |
15 | +# define BSD_BLKDEV | | 16 | +# define BSD_BLKDEV |
| | | 17 | +#elif defined(__NetBSD__) |
| | | 18 | +# include <sys/disklabel.h> |
| | | 19 | +# include <sys/disk.h> |
| | | 20 | +# include <sys/param.h> /* for DEV_BSIZE, XXX */ |
| | | 21 | +# define BSD_BLKDEV |
16 | +#else | | 22 | +#else |
17 | +#ifdef HAVE_SYS_DISKLABEL_H) | | 23 | #ifdef HAVE_SYS_DISKLABEL_H |
18 | # include <sys/disklabel.h> | | 24 | # include <sys/disklabel.h> |
19 | # define BSD_BLKDEV | | 25 | # define BSD_BLKDEV |
20 | #endif | | 26 | #endif |
21 | +#endif | | 27 | +#endif |
22 | | | 28 | |
23 | #ifndef LINUX_BLKDEV | | 29 | #ifndef LINUX_BLKDEV |
24 | # ifndef BSD_BLKDEV | | 30 | # ifndef BSD_BLKDEV |
25 | @@ -63,7 +68,6 @@ | | 31 | @@ -63,7 +73,6 @@ |
26 | #include "wipe.h" | | 32 | #include "wipe.h" |
27 | #include "blkdev.h" | | 33 | #include "blkdev.h" |
28 | | | 34 | |
29 | -extern int errno; | | 35 | -extern int errno; |
30 | extern int exit_code; | | 36 | extern int exit_code; |
31 | extern char *argvzero; | | 37 | extern char *argvzero; |
32 | extern struct opt_s options; | | 38 | extern struct opt_s options; |
33 | @@ -182,14 +186,20 @@ public int destroy_blkdev(struct file_s | | 39 | @@ -128,7 +137,13 @@ public int destroy_blkdev(struct file_s |
| | | 40 | int code; |
| | | 41 | |
| | | 42 | #ifdef BSD_BLKDEV |
| | | 43 | +#ifdef DIOCGPART |
| | | 44 | struct partinfo pinfo; |
| | | 45 | +#else |
| | | 46 | + struct disklabel lab; |
| | | 47 | + struct dkwedge_info dkw; |
| | | 48 | + int use_dkw; |
| | | 49 | +#endif |
| | | 50 | #endif |
| | | 51 | |
| | | 52 | #ifdef NO_BLKDEV |
| | | 53 | @@ -160,12 +175,26 @@ public int destroy_blkdev(struct file_s |
| | | 54 | } |
| | | 55 | |
| | | 56 | #ifdef BSD_BLKDEV |
| | | 57 | +# ifdef DIOCGPART |
| | | 58 | if (ioctl(f->fd, DIOCGPART, &pinfo)) |
| | | 59 | { |
| | | 60 | fprintf(stderr, "\r%s: ioctl failed, can't get disklabel for `%s': %s\n", |
| | | 61 | argvzero, f->name, strerror(errno)); |
| | | 62 | exit_code = errno; return FAILED; |
| | | 63 | } |
| | | 64 | +# else |
| | | 65 | + if (ioctl(f->fd, DIOCGDINFO, &lab) == 0) { |
| | | 66 | + use_dkw = 0; |
| | | 67 | + } |
| | | 68 | + else if (ioctl(f->fd, DIOCGWEDGEINFO, &dkw) == 0) { |
| | | 69 | + use_dkw = 1; |
| | | 70 | + } |
| | | 71 | + else { |
| | | 72 | + fprintf(stderr, "\r%s: ioctl failed, can't get disklabel for `%s': %s\n", |
| | | 73 | + argvzero, f->name, strerror(errno)); |
| | | 74 | + exit_code = errno; return FAILED; |
| | | 75 | + } |
| | | 76 | +# endif |
| | | 77 | #endif |
| | | 78 | |
| | | 79 | if (options.sectors == 0) |
| | | 80 | @@ -182,15 +211,35 @@ public int destroy_blkdev(struct file_s |
34 | options.sectors = tmp; | | 81 | options.sectors = tmp; |
35 | #endif | | 82 | #endif |
36 | | | 83 | |
37 | -#ifdef BSD_BLKDEV | | 84 | -#ifdef BSD_BLKDEV |
38 | +#if defined(BSD_BLKDEV) | | 85 | +#if defined(BSD_BLKDEV) |
39 | +# if defined(__DragonFly__) | | 86 | +# if defined(__DragonFly__) |
40 | + options.sectors = pinfo.media_blocks; | | 87 | + options.sectors = pinfo.media_blocks; |
41 | +# else | | 88 | +# else |
| | | 89 | +# if defined(DIOCGPART) |
42 | options.sectors = pinfo.part->p_size; | | 90 | options.sectors = pinfo.part->p_size; |
| | | 91 | +# else |
| | | 92 | + options.sectors = use_dkw ? |
| | | 93 | + dkw.dkw_size : lab.d_partitions[DISKPART(f->st.st_rdev)].p_size; |
| | | 94 | +# endif |
43 | +# endif | | 95 | +# endif |
44 | #endif | | 96 | #endif |
45 | } | | 97 | } |
46 | | | 98 | |
47 | if (options.sector_size == 0) | | 99 | if (options.sector_size == 0) |
48 | { | | 100 | { |
49 | -#ifdef BSD_BLKDEV | | 101 | -#ifdef BSD_BLKDEV |
50 | +#if defined(__DragonFly__) | | 102 | +#if defined(__DragonFly__) |
51 | + options.sector_size = pinfo.media_blocks; | | 103 | + options.sector_size = pinfo.media_blocks; |
52 | +#elif defined(BSD_BLKDEV) | | 104 | +#elif defined(BSD_BLKDEV) |
| | | 105 | +# if defined(DIOCGPART) |
53 | options.sector_size = pinfo.disklab->d_secsize; | | 106 | options.sector_size = pinfo.disklab->d_secsize; |
| | | 107 | +# else |
| | | 108 | + /* |
| | | 109 | + * XXX: we ought to use DIOCGDISKINFO to get the sector size, |
| | | 110 | + * but that requires proplib and probably 500+ lines of code. |
| | | 111 | + * So punt and use DEV_BSIZE... |
| | | 112 | + */ |
| | | 113 | + options.sector_size = use_dkw ? DEV_BSIZE : lab.d_secsize; |
| | | 114 | +# endif |
54 | #else | | 115 | #else |
55 | options.sector_size = SECTOR_SIZE; | | 116 | options.sector_size = SECTOR_SIZE; |
| | | 117 | #endif |