summaryrefslogtreecommitdiff
path: root/sysutils/ntfsprogs/files/patch-libntfs-device.c
blob: 8e36e0f94cfa1d51dea787a484624d49903aa2d4 (plain) (blame)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
--- ./libntfs/device.c.orig	2007-09-26 22:28:34.000000000 +0400
+++ ./libntfs/device.c	2011-03-15 23:07:06.183948162 +0300
@@ -62,6 +62,9 @@
 #ifdef HAVE_LINUX_HDREG_H
 #include <linux/hdreg.h>
 #endif
+#ifdef __FreeBSD__
+#include <sys/disk.h>
+#endif
 
 #include "types.h"
 #include "mst.h"
@@ -599,6 +602,17 @@
 		}
 	}
 #endif
+#ifdef DIOCGMEDIASIZE 
+	{       off_t size;
+
+		if (dev->d_ops->ioctl(dev, DIOCGMEDIASIZE, &size) >= 0) {
+			ntfs_log_debug("DIOCGMEDIASIZE nr bytes = %llu (0x%llx)\n",
+					(unsigned long long)size,
+					(unsigned long long)size);
+			return (s64)size / block_size;
+		}
+	}
+#endif
 	/*
 	 * We couldn't figure it out by using a specialized ioctl,
 	 * so do binary search to find the size of the device.
@@ -627,8 +641,8 @@
  *
  * The following error codes are defined:
  *	EINVAL		Input parameter error
- *	EOPNOTSUPP	System does not support HDIO_GETGEO ioctl
- *	ENOTTY		@dev is a file or a device not supporting HDIO_GETGEO
+ *	EOPNOTSUPP	System does not support DIOCGFWSECTORS ioctl
+ *	ENOTTY		@dev is a file or a device not supporting DIOCGFWSECTORS
  */
 s64 ntfs_device_partition_start_sector_get(struct ntfs_device *dev)
 {
@@ -636,13 +650,13 @@
 		errno = EINVAL;
 		return -1;
 	}
-#ifdef HDIO_GETGEO
-	{	struct hd_geometry geo;
+#ifdef DIOCGFWSECTORS
+	{	u_int	start_sector = 0;
 
-		if (!dev->d_ops->ioctl(dev, HDIO_GETGEO, &geo)) {
-			ntfs_log_debug("HDIO_GETGEO start_sect = %lu (0x%lx)\n",
-					geo.start, geo.start);
-			return geo.start;
+		if (!dev->d_ops->ioctl(dev, DIOCGFWSECTORS, &start_sector)) {
+			ntfs_log_debug("DIOCGFWSECTORS start_sect = %lu (0x%lx)\n",
+					start_sector, start_sector);
+			return start_sector;
 		}
 	}
 #else
@@ -660,8 +674,8 @@
  *
  * The following error codes are defined:
  *	EINVAL		Input parameter error
- *	EOPNOTSUPP	System does not support HDIO_GETGEO ioctl
- *	ENOTTY		@dev is a file or a device not supporting HDIO_GETGEO
+ *	EOPNOTSUPP	System does not support DIOCGFWHEADS ioctl
+ *	ENOTTY		@dev is a file or a device not supporting DIOCGFWHEADS
  */
 int ntfs_device_heads_get(struct ntfs_device *dev)
 {
@@ -669,14 +683,13 @@
 		errno = EINVAL;
 		return -1;
 	}
-#ifdef HDIO_GETGEO
-	{	struct hd_geometry geo;
+#ifdef DIOCGFWHEADS
+	{	u_int	heads;
 
-		if (!dev->d_ops->ioctl(dev, HDIO_GETGEO, &geo)) {
-			ntfs_log_debug("HDIO_GETGEO heads = %u (0x%x)\n",
-					(unsigned)geo.heads,
-					(unsigned)geo.heads);
-			return geo.heads;
+		if (!dev->d_ops->ioctl(dev, DIOCGFWHEADS, &heads)) {
+			ntfs_log_debug("DIOCGFWHEADS heads = %u (0x%x)\n",
+					heads, heads);
+			return heads;
 		}
 	}
 #else
@@ -694,8 +707,8 @@
  *
  * The following error codes are defined:
  *	EINVAL		Input parameter error
- *	EOPNOTSUPP	System does not support HDIO_GETGEO ioctl
- *	ENOTTY		@dev is a file or a device not supporting HDIO_GETGEO
+ *	EOPNOTSUPP	System does not support DIOCGFWSECTORS ioctl
+ *	ENOTTY		@dev is a file or a device not supporting DIOCGFWSECTORS
  */
 int ntfs_device_sectors_per_track_get(struct ntfs_device *dev)
 {
@@ -703,14 +716,13 @@
 		errno = EINVAL;
 		return -1;
 	}
-#ifdef HDIO_GETGEO
-	{	struct hd_geometry geo;
+#ifdef DIOCGFWSECTORS
+	{	u_int	sptrack;
 
-		if (!dev->d_ops->ioctl(dev, HDIO_GETGEO, &geo)) {
-			ntfs_log_debug("HDIO_GETGEO sectors_per_track = %u (0x%x)\n",
-					(unsigned)geo.sectors,
-					(unsigned)geo.sectors);
-			return geo.sectors;
+		if (!dev->d_ops->ioctl(dev, DIOCGFWSECTORS, &sptrack)) {
+			ntfs_log_debug("DIOCGFWSECTORS sectors_per_track = %u (0x%x)\n",
+					sptrack, sptrack);
+			return sptrack;
 		}
 	}
 #else
@@ -728,8 +740,8 @@
  *
  * The following error codes are defined:
  *	EINVAL		Input parameter error
- *	EOPNOTSUPP	System does not support BLKSSZGET ioctl
- *	ENOTTY		@dev is a file or a device not supporting BLKSSZGET
+ *	EOPNOTSUPP	System does not support DIOCGSECTORSIZE ioctl
+ *	ENOTTY		@dev is a file or a device not supporting DIOCGSECTORSIZE
  */
 int ntfs_device_sector_size_get(struct ntfs_device *dev)
 {
@@ -737,13 +749,13 @@
 		errno = EINVAL;
 		return -1;
 	}
-#ifdef BLKSSZGET
+#ifdef	DIOCGSECTORSIZE
 	{
-		int sect_size = 0;
+		size_t sect_size = 0;
 
-		if (!dev->d_ops->ioctl(dev, BLKSSZGET, &sect_size)) {
-			ntfs_log_debug("BLKSSZGET sector size = %d bytes\n",
-					sect_size);
+		if (!dev->d_ops->ioctl(dev, DIOCGSECTORSIZE, &sect_size)) {
+			ntfs_log_debug("DIOCGSECTORSIZE sector size = %d bytes\n",
+				(int)sect_size);
 			return sect_size;
 		}
 	}