summaryrefslogtreecommitdiff
path: root/devel/efivar/files/patch-src_gpt.c
blob: 87d6d523d72a129d54f1c17086e93f4984fffe07 (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
--- src/gpt.c.orig	2024-01-31 20:08:46 UTC
+++ src/gpt.c
@@ -16,6 +16,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#if defined(__FreeBSD__)
+#  include <sys/disk.h>
+#  undef LIST_HEAD
+#endif
+#include <sys/ioctl.h>
 #include <sys/mount.h>
 #include <sys/param.h>
 #include <sys/stat.h>
@@ -60,6 +65,7 @@ is_pmbr_valid(legacy_mbr *mbr)
 	return (magic && found);
 }
 
+#if defined(__linux__)
 /**
  * kernel_has_blkgetsize64()
  *
@@ -92,6 +98,7 @@ kernel_has_blkgetsize64(void)
 		return 0;
 	return 1;
 }
+#endif
 
 /************************************************************
  * _get_num_sectors
@@ -114,6 +121,8 @@ _get_num_sectors(int filedes)
 	unsigned long sectors=0;
 	uint64_t bytes=0;
 	int rc;
+
+#if defined(__linux__)
 	if (kernel_has_blkgetsize64()) {
 		rc = ioctl(filedes, BLKGETSIZE64, &bytes);
 		if (!rc)
@@ -125,6 +134,19 @@ _get_num_sectors(int filedes)
 		return 0;
 
 	return sectors;
+#elif defined(__FreeBSD__)
+	rc = ioctl(filedes, DIOCGMEDIASIZE, &bytes);
+	if (rc == -1)
+		return 0;
+
+	rc = ioctl(filedes, DIOCGSECTORSIZE, &sectors);
+	if (rc == -1)
+		return 0;
+
+	return bytes / sectors;
+#else
+	return 0;
+#endif
 }
 
 /************************************************************