summaryrefslogtreecommitdiffstats
path: root/meta/recipes-extended/mdadm/files/0001-restripe.c-Use-_FILE_OFFSET_BITS-to-enable-largefile.patch
blob: 13435ee418fe402679a063007b28e121b1144510 (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
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
From aa86de05cd6a75222b38e0789ac96fe00f705430 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Thu, 10 Nov 2022 12:31:22 -0800
Subject: [PATCH] restripe.c: Use _FILE_OFFSET_BITS to enable largefile support

Instead of using the lseek64 and friends, its better to enable it via
the feature macro _FILE_OFFSET_BITS = 64 and let the C library deal with
the width of types

Upstream-Status: Submitted [https://lore.kernel.org/linux-raid/20221110225546.337164-1-raj.khem@gmail.com/]
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 raid6check.c | 11 +++++++----
 restripe.c   | 13 ++++++++-----
 swap_super.c | 13 +++++++------
 3 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/raid6check.c b/raid6check.c
index 9947776..8e7f142 100644
--- a/raid6check.c
+++ b/raid6check.c
@@ -22,6 +22,9 @@
  *    Based on "restripe.c" from "mdadm" codebase
  */
 
+/* Enable largefile support */
+#define _FILE_OFFSET_BITS 64
+
 #include "mdadm.h"
 #include <stdint.h>
 #include <sys/mman.h>
@@ -284,9 +287,9 @@ int manual_repair(int chunk_size, int syndrome_disks,
 	}
 
 	int write_res1, write_res2;
-	off64_t seek_res;
+	off_t seek_res;
 
-	seek_res = lseek64(source[fd1],
+	seek_res = lseek(source[fd1],
 			   offsets[fd1] + start * chunk_size, SEEK_SET);
 	if (seek_res < 0) {
 		fprintf(stderr, "lseek failed for failed_disk1\n");
@@ -294,7 +297,7 @@ int manual_repair(int chunk_size, int syndrome_disks,
 	}
 	write_res1 = write(source[fd1], blocks[failed_slot1], chunk_size);
 
-	seek_res = lseek64(source[fd2],
+	seek_res = lseek(source[fd2],
 			   offsets[fd2] + start * chunk_size, SEEK_SET);
 	if (seek_res < 0) {
 		fprintf(stderr, "lseek failed for failed_disk2\n");
@@ -379,7 +382,7 @@ int check_stripes(struct mdinfo *info, int *source, unsigned long long *offsets,
 			goto exitCheck;
 		}
 		for (i = 0 ; i < raid_disks ; i++) {
-			off64_t seek_res = lseek64(source[i], offsets[i] + start * chunk_size,
+			off_t seek_res = lseek(source[i], offsets[i] + start * chunk_size,
 						   SEEK_SET);
 			if (seek_res < 0) {
 				fprintf(stderr, "lseek to source %d failed\n", i);
diff --git a/restripe.c b/restripe.c
index a7a7229..1c03577 100644
--- a/restripe.c
+++ b/restripe.c
@@ -22,6 +22,9 @@
  *    Email: <neilb@suse.de>
  */
 
+/* Enable largefile support */
+#define _FILE_OFFSET_BITS 64
+
 #include "mdadm.h"
 #include <stdint.h>
 
@@ -581,7 +584,7 @@ int save_stripes(int *source, unsigned long long *offsets,
 				       raid_disks, level, layout);
 			if (dnum < 0) abort();
 			if (source[dnum] < 0 ||
-			    lseek64(source[dnum],
+			    lseek(source[dnum],
 				    offsets[dnum] + offset, 0) < 0 ||
 			    read(source[dnum], buf+disk * chunk_size,
 				 chunk_size) != chunk_size) {
@@ -754,8 +757,8 @@ int restore_stripes(int *dest, unsigned long long *offsets,
 					   raid_disks, level, layout);
 			if (src_buf == NULL) {
 				/* read from file */
-				if (lseek64(source, read_offset, 0) !=
-					 (off64_t)read_offset) {
+				if (lseek(source, read_offset, 0) !=
+					 (off_t)read_offset) {
 					rv = -1;
 					goto abort;
 				}
@@ -816,7 +819,7 @@ int restore_stripes(int *dest, unsigned long long *offsets,
 		}
 		for (i=0; i < raid_disks ; i++)
 			if (dest[i] >= 0) {
-				if (lseek64(dest[i],
+				if (lseek(dest[i],
 					 offsets[i]+offset, 0) < 0) {
 					rv = -1;
 					goto abort;
@@ -866,7 +869,7 @@ int test_stripes(int *source, unsigned long long *offsets,
 		int disk;
 
 		for (i = 0 ; i < raid_disks ; i++) {
-			if ((lseek64(source[i], offsets[i]+start, 0) < 0) ||
+			if ((lseek(source[i], offsets[i]+start, 0) < 0) ||
 			    (read(source[i], stripes[i], chunk_size) !=
 			     chunk_size)) {
 				free(q);
diff --git a/swap_super.c b/swap_super.c
index b6db574..18c89e2 100644
--- a/swap_super.c
+++ b/swap_super.c
@@ -1,3 +1,6 @@
+/* Enable largefile support */
+#define _FILE_OFFSET_BITS 64
+
 #include <unistd.h>
 #include <stdlib.h>
 #include <fcntl.h>
@@ -16,8 +19,6 @@
 
 #define MD_NEW_SIZE_SECTORS(x)		((x & ~(MD_RESERVED_SECTORS - 1)) - MD_RESERVED_SECTORS)
 
-extern long long lseek64(int, long long, int);
-
 int main(int argc, char *argv[])
 {
 	int fd, i;
@@ -38,8 +39,8 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 	offset = MD_NEW_SIZE_SECTORS(size) * 512LL;
-	if (lseek64(fd, offset, 0) < 0LL) {
-		perror("lseek64");
+	if (lseek(fd, offset, 0) < 0LL) {
+		perror("lseek");
 		exit(1);
 	}
 	if (read(fd, super, 4096) != 4096) {
@@ -68,8 +69,8 @@ int main(int argc, char *argv[])
 		super[32*4+10*4 +i] = t;
 	}
 
-	if (lseek64(fd, offset, 0) < 0LL) {
-		perror("lseek64");
+	if (lseek(fd, offset, 0) < 0LL) {
+		perror("lseek");
 		exit(1);
 	}
 	if (write(fd, super, 4096) != 4096) {