summaryrefslogtreecommitdiff
path: root/sysutils/ntfsprogs/patches/patch-ae
blob: 0626e861ab258499a784c3fd22e98adb9cb794cb (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
$NetBSD: patch-ae,v 1.2 2005/03/15 20:24:30 rillig Exp $

--- libntfs/device.c.orig	Sat Sep  4 12:16:32 2004
+++ libntfs/device.c	Sat Mar 12 10:14:34 2005
@@ -37,6 +37,8 @@
 #	include <linux/hdreg.h>
 #endif
 
+#include "compat.h"
+
 #include "types.h"
 #include "mst.h"
 #include "debug.h"
@@ -52,6 +54,10 @@
 #define HDIO_GETGEO	0x0301	/* Get device geometry. */
 #endif
 
+#if defined(__NetBSD__)
+#include <sys/disklabel.h> /* XXX autoconf this ? */
+#endif
+
 /**
  * ntfs_device_alloc - allocate an ntfs device structure and pre-initialize it
  * name:	name of the device (must be present)
@@ -498,6 +504,23 @@ s64 ntfs_device_size_get(struct ntfs_dev
 					(unsigned long)this_floppy.size,
 					(unsigned long)this_floppy.size);
 			return (s64)this_floppy.size * 512 / block_size;
+		}
+	}
+#endif
+#ifdef DIOCGPART
+	{
+		struct stat st;
+		if (dev->d_ops->stat(dev, &st) >= 0) {
+			struct disklabel disklabel;
+			int secsize;
+			s64 psize;
+			if (dev->d_ops->ioctl(dev, DIOCGDINFO, &disklabel) >= 0) {
+				secsize = disklabel.d_secsize;
+				psize = disklabel.d_partitions[DISKPART(st.st_rdev)].p_size;
+				Dprintf("DIOCGPART nr %d byte blocks = %lld (0x%llx)\n",
+						secsize, psize, psize);
+				return psize * secsize / block_size;
+			}
 		}
 	}
 #endif