blob: 142ed355ef87724a97f0f2daa09b78d48101041c [file] [log] [blame]
Andrew Geissler517393d2023-01-13 08:55:19 -06001From 6b861a267a6ef6f60f6cc21e4c8e6d7cdd2451dc Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Thu, 10 Nov 2022 12:31:22 -0800
4Subject: [PATCH] restripe.c: Use _FILE_OFFSET_BITS to enable largefile support
5
6Instead of using the lseek64 and friends, its better to enable it via
7the feature macro _FILE_OFFSET_BITS = 64 and let the C library deal with
8the width of types
9
10Upstream-Status: Submitted [https://lore.kernel.org/linux-raid/20221110225546.337164-1-raj.khem@gmail.com/]
11Signed-off-by: Khem Raj <raj.khem@gmail.com>
12---
13 restripe.c | 13 ++++++++-----
14 1 file changed, 8 insertions(+), 5 deletions(-)
15
16--- a/restripe.c
17+++ b/restripe.c
18@@ -22,6 +22,9 @@
19 * Email: <neilb@suse.de>
20 */
21
22+/* Enable largefile support */
23+#define _FILE_OFFSET_BITS 64
24+
25 #include "mdadm.h"
26 #include <stdint.h>
27
28@@ -581,7 +584,7 @@ int save_stripes(int *source, unsigned l
29 raid_disks, level, layout);
30 if (dnum < 0) abort();
31 if (source[dnum] < 0 ||
32- lseek64(source[dnum],
33+ lseek(source[dnum],
34 offsets[dnum] + offset, 0) < 0 ||
35 read(source[dnum], buf+disk * chunk_size,
36 chunk_size) != chunk_size) {
37@@ -754,8 +757,8 @@ int restore_stripes(int *dest, unsigned
38 raid_disks, level, layout);
39 if (src_buf == NULL) {
40 /* read from file */
41- if (lseek64(source, read_offset, 0) !=
42- (off64_t)read_offset) {
43+ if (lseek(source, read_offset, 0) !=
44+ (off_t)read_offset) {
45 rv = -1;
46 goto abort;
47 }
48@@ -816,7 +819,7 @@ int restore_stripes(int *dest, unsigned
49 }
50 for (i=0; i < raid_disks ; i++)
51 if (dest[i] >= 0) {
52- if (lseek64(dest[i],
53+ if (lseek(dest[i],
54 offsets[i]+offset, 0) < 0) {
55 rv = -1;
56 goto abort;
57@@ -866,7 +869,7 @@ int test_stripes(int *source, unsigned l
58 int disk;
59
60 for (i = 0 ; i < raid_disks ; i++) {
61- if ((lseek64(source[i], offsets[i]+start, 0) < 0) ||
62+ if ((lseek(source[i], offsets[i]+start, 0) < 0) ||
63 (read(source[i], stripes[i], chunk_size) !=
64 chunk_size)) {
65 free(q);
66--- a/raid6check.c
67+++ b/raid6check.c
68@@ -22,6 +22,9 @@
69 * Based on "restripe.c" from "mdadm" codebase
70 */
71
72+/* Enable largefile support */
73+#define _FILE_OFFSET_BITS 64
74+
75 #include "mdadm.h"
76 #include <stdint.h>
77 #include <signal.h>
78@@ -279,9 +282,9 @@ int manual_repair(int chunk_size, int sy
79 }
80
81 int write_res1, write_res2;
82- off64_t seek_res;
83+ off_t seek_res;
84
85- seek_res = lseek64(source[fd1],
86+ seek_res = lseek(source[fd1],
87 offsets[fd1] + start * chunk_size, SEEK_SET);
88 if (seek_res < 0) {
89 fprintf(stderr, "lseek failed for failed_disk1\n");
90@@ -289,7 +292,7 @@ int manual_repair(int chunk_size, int sy
91 }
92 write_res1 = write(source[fd1], blocks[failed_slot1], chunk_size);
93
94- seek_res = lseek64(source[fd2],
95+ seek_res = lseek(source[fd2],
96 offsets[fd2] + start * chunk_size, SEEK_SET);
97 if (seek_res < 0) {
98 fprintf(stderr, "lseek failed for failed_disk2\n");
99@@ -374,7 +377,7 @@ int check_stripes(struct mdinfo *info, i
100 goto exitCheck;
101 }
102 for (i = 0 ; i < raid_disks ; i++) {
103- off64_t seek_res = lseek64(source[i], offsets[i] + start * chunk_size,
104+ off_t seek_res = lseek(source[i], offsets[i] + start * chunk_size,
105 SEEK_SET);
106 if (seek_res < 0) {
107 fprintf(stderr, "lseek to source %d failed\n", i);
108--- a/swap_super.c
109+++ b/swap_super.c
110@@ -1,3 +1,6 @@
111+/* Enable largefile support */
112+#define _FILE_OFFSET_BITS 64
113+
114 #include <unistd.h>
115 #include <stdlib.h>
116 #include <fcntl.h>
117@@ -16,8 +19,6 @@
118
119 #define MD_NEW_SIZE_SECTORS(x) ((x & ~(MD_RESERVED_SECTORS - 1)) - MD_RESERVED_SECTORS)
120
121-extern long long lseek64(int, long long, int);
122-
123 int main(int argc, char *argv[])
124 {
125 int fd, i;
126@@ -38,8 +39,8 @@ int main(int argc, char *argv[])
127 exit(1);
128 }
129 offset = MD_NEW_SIZE_SECTORS(size) * 512LL;
130- if (lseek64(fd, offset, 0) < 0LL) {
131- perror("lseek64");
132+ if (lseek(fd, offset, 0) < 0LL) {
133+ perror("lseek");
134 exit(1);
135 }
136 if (read(fd, super, 4096) != 4096) {
137@@ -68,8 +69,8 @@ int main(int argc, char *argv[])
138 super[32*4+10*4 +i] = t;
139 }
140
141- if (lseek64(fd, offset, 0) < 0LL) {
142- perror("lseek64");
143+ if (lseek(fd, offset, 0) < 0LL) {
144+ perror("lseek");
145 exit(1);
146 }
147 if (write(fd, super, 4096) != 4096) {