0001-f2fs-tools-convert-to-lseek-and-kill-lseek64.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. From b15b6cc56ac7764be17acbdbf96448f388992adc Mon Sep 17 00:00:00 2001
  2. From: Waldemar Brodkorb <wbx@openadk.org>
  3. Date: Wed, 23 Aug 2023 15:41:28 +0200
  4. Subject: [PATCH] f2fs-tools: convert to lseek() and kill lseek64
  5. This patch replaces lseek64 with lseek() having #define _FILE_OFFSET_BITS 64.
  6. Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
  7. Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
  8. Upstream: https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git/commit/?id=b15b6cc56ac7764be17acbdbf96448f388992adc
  9. ---
  10. configure.ac | 2 --
  11. fsck/Makefile.am | 2 +-
  12. include/android_config.h | 4 ----
  13. lib/Makefile.am | 2 +-
  14. lib/libf2fs.c | 3 ---
  15. lib/libf2fs_io.c | 47 +++++++++++++++------------------------
  16. lib/libf2fs_zoned.c | 1 -
  17. mkfs/Makefile.am | 4 ++--
  18. mkfs/f2fs_format.c | 2 --
  19. mkfs/f2fs_format_main.c | 2 --
  20. mkfs/f2fs_format_utils.c | 10 ---------
  21. mkfs/f2fs_format_utils.h | 2 --
  22. tools/Makefile.am | 2 +-
  23. tools/f2fs_io/Makefile.am | 2 +-
  24. tools/f2fs_io/f2fs_io.c | 6 -----
  25. tools/f2fs_io_parse.c | 1 -
  26. tools/f2fscrypt.c | 9 --------
  27. tools/fibmap.c | 7 ------
  28. 18 files changed, 24 insertions(+), 84 deletions(-)
  29. diff --git a/configure.ac b/configure.ac
  30. index efab8d8..123ddbb 100644
  31. --- a/configure.ac
  32. +++ b/configure.ac
  33. @@ -187,8 +187,6 @@ AC_CHECK_FUNCS_ONCE([
  34. getmntent
  35. getuid
  36. keyctl
  37. - llseek
  38. - lseek64
  39. memset
  40. setmntent
  41. clock_gettime
  42. diff --git a/fsck/Makefile.am b/fsck/Makefile.am
  43. index 579dd26..40d31b8 100644
  44. --- a/fsck/Makefile.am
  45. +++ b/fsck/Makefile.am
  46. @@ -1,7 +1,7 @@
  47. ## Makefile.am
  48. AM_CPPFLAGS = ${libuuid_CFLAGS} -I$(top_srcdir)/include
  49. -AM_CFLAGS = -Wall
  50. +AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64
  51. sbin_PROGRAMS = fsck.f2fs
  52. noinst_HEADERS = common.h dict.h dqblk_v2.h f2fs.h fsck.h node.h quotaio.h \
  53. quotaio_tree.h quotaio_v2.h xattr.h compress.h
  54. diff --git a/include/android_config.h b/include/android_config.h
  55. index 141fe06..da8abcb 100644
  56. --- a/include/android_config.h
  57. +++ b/include/android_config.h
  58. @@ -30,8 +30,6 @@
  59. #define HAVE_FSTAT 1
  60. #define HAVE_FSTAT64 1
  61. #define HAVE_GETMNTENT 1
  62. -#define HAVE_LLSEEK 1
  63. -#define HAVE_LSEEK64 1
  64. #define HAVE_MEMSET 1
  65. #define HAVE_SELINUX_ANDROID_H 1
  66. #define HAVE_SETMNTENT 1
  67. @@ -67,7 +65,6 @@
  68. #define HAVE_FSTAT 1
  69. #define HAVE_FSTAT64 1
  70. #define HAVE_GETMNTENT 1
  71. -#define HAVE_LLSEEK 1
  72. #define HAVE_MEMSET 1
  73. #define HAVE_SPARSE_SPARSE_H 1
  74. #define HAVE_LIBLZ4 1
  75. @@ -78,6 +75,5 @@
  76. #endif
  77. #if defined(_WIN32)
  78. -#define HAVE_LSEEK64
  79. #define HAVE_SPARSE_SPARSE_H 1
  80. #endif
  81. diff --git a/lib/Makefile.am b/lib/Makefile.am
  82. index 871d773..69d46f8 100644
  83. --- a/lib/Makefile.am
  84. +++ b/lib/Makefile.am
  85. @@ -3,7 +3,7 @@
  86. lib_LTLIBRARIES = libf2fs.la
  87. libf2fs_la_SOURCES = libf2fs.c libf2fs_io.c libf2fs_zoned.c nls_utf8.c
  88. -libf2fs_la_CFLAGS = -Wall
  89. +libf2fs_la_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64
  90. libf2fs_la_CPPFLAGS = -I$(top_srcdir)/include
  91. libf2fs_la_LDFLAGS = -version-info $(LIBF2FS_CURRENT):$(LIBF2FS_REVISION):$(LIBF2FS_AGE)
  92. diff --git a/lib/libf2fs.c b/lib/libf2fs.c
  93. index 577a7e8..c3d5744 100644
  94. --- a/lib/libf2fs.c
  95. +++ b/lib/libf2fs.c
  96. @@ -6,9 +6,6 @@
  97. *
  98. * Dual licensed under the GPL or LGPL version 2 licenses.
  99. */
  100. -#define _LARGEFILE64_SOURCE
  101. -#define _FILE_OFFSET_BITS 64
  102. -
  103. #include <f2fs_fs.h>
  104. #include <stdio.h>
  105. #include <stdlib.h>
  106. diff --git a/lib/libf2fs_io.c b/lib/libf2fs_io.c
  107. index 1a8167d..74e5f3a 100644
  108. --- a/lib/libf2fs_io.c
  109. +++ b/lib/libf2fs_io.c
  110. @@ -11,8 +11,6 @@
  111. *
  112. * Dual licensed under the GPL or LGPL version 2 licenses.
  113. */
  114. -#define _LARGEFILE64_SOURCE
  115. -
  116. #include <stdio.h>
  117. #include <stdlib.h>
  118. #include <string.h>
  119. @@ -67,22 +65,13 @@ static int __get_device_fd(__u64 *offset)
  120. return -1;
  121. }
  122. -#ifndef HAVE_LSEEK64
  123. -typedef off_t off64_t;
  124. -
  125. -static inline off64_t lseek64(int fd, __u64 offset, int set)
  126. -{
  127. - return lseek(fd, offset, set);
  128. -}
  129. -#endif
  130. -
  131. /* ---------- dev_cache, Least Used First (LUF) policy ------------------- */
  132. /*
  133. * Least used block will be the first victim to be replaced when max hash
  134. * collision exceeds
  135. */
  136. static bool *dcache_valid; /* is the cached block valid? */
  137. -static off64_t *dcache_blk; /* which block it cached */
  138. +static off_t *dcache_blk; /* which block it cached */
  139. static uint64_t *dcache_lastused; /* last used ticks for cache entries */
  140. static char *dcache_buf; /* cached block data */
  141. static uint64_t dcache_usetick; /* current use tick */
  142. @@ -172,7 +161,7 @@ static int dcache_alloc_all(long n)
  143. {
  144. if (n <= 0)
  145. return -1;
  146. - if ((dcache_blk = (off64_t *) malloc(sizeof(off64_t) * n)) == NULL
  147. + if ((dcache_blk = (off_t *) malloc(sizeof(off_t) * n)) == NULL
  148. || (dcache_lastused = (uint64_t *)
  149. malloc(sizeof(uint64_t) * n)) == NULL
  150. || (dcache_buf = (char *) malloc (F2FS_BLKSIZE * n)) == NULL
  151. @@ -257,7 +246,7 @@ static inline long dcache_relocate(long entry, int n)
  152. dcache_config.num_cache_entry;
  153. }
  154. -static long dcache_find(off64_t blk)
  155. +static long dcache_find(off_t blk)
  156. {
  157. register long n = dcache_config.num_cache_entry;
  158. register unsigned m = dcache_config.max_hash_collision;
  159. @@ -278,10 +267,10 @@ static long dcache_find(off64_t blk)
  160. }
  161. /* Physical read into cache */
  162. -static int dcache_io_read(int fd, long entry, off64_t offset, off64_t blk)
  163. +static int dcache_io_read(int fd, long entry, off_t offset, off_t blk)
  164. {
  165. - if (lseek64(fd, offset, SEEK_SET) < 0) {
  166. - MSG(0, "\n lseek64 fail.\n");
  167. + if (lseek(fd, offset, SEEK_SET) < 0) {
  168. + MSG(0, "\n lseek fail.\n");
  169. return -1;
  170. }
  171. if (read(fd, dcache_buf + entry * F2FS_BLKSIZE, F2FS_BLKSIZE) < 0) {
  172. @@ -308,12 +297,12 @@ static int dcache_io_read(int fd, long entry, off64_t offset, off64_t blk)
  173. * 1: cache not available (uninitialized)
  174. * -1: error
  175. */
  176. -static int dcache_update_rw(int fd, void *buf, off64_t offset,
  177. +static int dcache_update_rw(int fd, void *buf, off_t offset,
  178. size_t byte_count, bool is_write)
  179. {
  180. - off64_t blk;
  181. + off_t blk;
  182. int addr_in_blk;
  183. - off64_t start;
  184. + off_t start;
  185. if (!dcache_initialized)
  186. dcache_init(); /* auto initialize */
  187. @@ -377,13 +366,13 @@ static int dcache_update_rw(int fd, void *buf, off64_t offset,
  188. * return value: 1: cache not available
  189. * 0: success, -1: I/O error
  190. */
  191. -int dcache_update_cache(int fd, void *buf, off64_t offset, size_t count)
  192. +int dcache_update_cache(int fd, void *buf, off_t offset, size_t count)
  193. {
  194. return dcache_update_rw(fd, buf, offset, count, true);
  195. }
  196. /* handles read into cache + read into buffer */
  197. -int dcache_read(int fd, void *buf, off64_t offset, size_t count)
  198. +int dcache_read(int fd, void *buf, off_t offset, size_t count)
  199. {
  200. return dcache_update_rw(fd, buf, offset, count, false);
  201. }
  202. @@ -395,7 +384,7 @@ int dev_read_version(void *buf, __u64 offset, size_t len)
  203. {
  204. if (c.sparse_mode)
  205. return 0;
  206. - if (lseek64(c.kd, (off64_t)offset, SEEK_SET) < 0)
  207. + if (lseek(c.kd, (off_t)offset, SEEK_SET) < 0)
  208. return -1;
  209. if (read(c.kd, buf, len) < 0)
  210. return -1;
  211. @@ -534,10 +523,10 @@ int dev_read(void *buf, __u64 offset, size_t len)
  212. /* err = 1: cache not available, fall back to non-cache R/W */
  213. /* err = 0: success, err=-1: I/O error */
  214. - err = dcache_read(fd, buf, (off64_t)offset, len);
  215. + err = dcache_read(fd, buf, (off_t)offset, len);
  216. if (err <= 0)
  217. return err;
  218. - if (lseek64(fd, (off64_t)offset, SEEK_SET) < 0)
  219. + if (lseek(fd, (off_t)offset, SEEK_SET) < 0)
  220. return -1;
  221. if (read(fd, buf, len) < 0)
  222. return -1;
  223. @@ -580,9 +569,9 @@ int dev_write(void *buf, __u64 offset, size_t len)
  224. * dcache_update_cache() just update cache, won't do I/O.
  225. * Thus even no error, we need normal non-cache I/O for actual write
  226. */
  227. - if (dcache_update_cache(fd, buf, (off64_t)offset, len) < 0)
  228. + if (dcache_update_cache(fd, buf, (off_t)offset, len) < 0)
  229. return -1;
  230. - if (lseek64(fd, (off64_t)offset, SEEK_SET) < 0)
  231. + if (lseek(fd, (off_t)offset, SEEK_SET) < 0)
  232. return -1;
  233. if (write(fd, buf, len) < 0)
  234. return -1;
  235. @@ -596,7 +585,7 @@ int dev_write_block(void *buf, __u64 blk_addr)
  236. int dev_write_dump(void *buf, __u64 offset, size_t len)
  237. {
  238. - if (lseek64(c.dump_fd, (off64_t)offset, SEEK_SET) < 0)
  239. + if (lseek(c.dump_fd, (off_t)offset, SEEK_SET) < 0)
  240. return -1;
  241. if (write(c.dump_fd, buf, len) < 0)
  242. return -1;
  243. @@ -618,7 +607,7 @@ int dev_fill(void *buf, __u64 offset, size_t len)
  244. /* Only allow fill to zero */
  245. if (*((__u8*)buf))
  246. return -1;
  247. - if (lseek64(fd, (off64_t)offset, SEEK_SET) < 0)
  248. + if (lseek(fd, (off_t)offset, SEEK_SET) < 0)
  249. return -1;
  250. if (write(fd, buf, len) < 0)
  251. return -1;
  252. diff --git a/lib/libf2fs_zoned.c b/lib/libf2fs_zoned.c
  253. index a0dd8bd..2ab2497 100644
  254. --- a/lib/libf2fs_zoned.c
  255. +++ b/lib/libf2fs_zoned.c
  256. @@ -6,7 +6,6 @@
  257. *
  258. * Dual licensed under the GPL or LGPL version 2 licenses.
  259. */
  260. -#define _LARGEFILE64_SOURCE
  261. #include <f2fs_fs.h>
  262. #include <stdio.h>
  263. diff --git a/mkfs/Makefile.am b/mkfs/Makefile.am
  264. index af5b1c7..bfffd88 100644
  265. --- a/mkfs/Makefile.am
  266. +++ b/mkfs/Makefile.am
  267. @@ -1,7 +1,7 @@
  268. ## Makefile.am
  269. AM_CPPFLAGS = ${libuuid_CFLAGS} ${libblkid_CFLAGS} -I$(top_srcdir)/include
  270. -AM_CFLAGS = -Wall -DWITH_BLKDISCARD
  271. +AM_CFLAGS = -Wall -DWITH_BLKDISCARD -D_FILE_OFFSET_BITS=64
  272. sbin_PROGRAMS = mkfs.f2fs
  273. noinst_HEADERS = f2fs_format_utils.h
  274. include_HEADERS = $(top_srcdir)/include/f2fs_fs.h
  275. @@ -10,7 +10,7 @@ mkfs_f2fs_LDADD = ${libuuid_LIBS} ${libblkid_LIBS} $(top_builddir)/lib/libf2fs.l
  276. lib_LTLIBRARIES = libf2fs_format.la
  277. libf2fs_format_la_SOURCES = f2fs_format_main.c f2fs_format.c f2fs_format_utils.c
  278. -libf2fs_format_la_CFLAGS = -DWITH_BLKDISCARD
  279. +libf2fs_format_la_CFLAGS = -DWITH_BLKDISCARD -D_FILE_OFFSET_BITS=64
  280. libf2fs_format_la_LDFLAGS = ${libblkid_LIBS} ${libuuid_LIBS} -L$(top_builddir)/lib -lf2fs \
  281. -version-info $(FMT_CURRENT):$(FMT_REVISION):$(FMT_AGE)
  282. diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
  283. index 019fb3a..d937eda 100644
  284. --- a/mkfs/f2fs_format.c
  285. +++ b/mkfs/f2fs_format.c
  286. @@ -6,8 +6,6 @@
  287. *
  288. * Dual licensed under the GPL or LGPL version 2 licenses.
  289. */
  290. -#define _LARGEFILE64_SOURCE
  291. -
  292. #include <stdio.h>
  293. #include <stdlib.h>
  294. #include <fcntl.h>
  295. diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c
  296. index d8c9cea..08c1b25 100644
  297. --- a/mkfs/f2fs_format_main.c
  298. +++ b/mkfs/f2fs_format_main.c
  299. @@ -6,8 +6,6 @@
  300. *
  301. * Dual licensed under the GPL or LGPL version 2 licenses.
  302. */
  303. -#define _LARGEFILE64_SOURCE
  304. -
  305. #include <stdio.h>
  306. #include <stdlib.h>
  307. #include <fcntl.h>
  308. diff --git a/mkfs/f2fs_format_utils.c b/mkfs/f2fs_format_utils.c
  309. index 448fbaa..437f113 100644
  310. --- a/mkfs/f2fs_format_utils.c
  311. +++ b/mkfs/f2fs_format_utils.c
  312. @@ -6,20 +6,10 @@
  313. *
  314. * Dual licensed under the GPL or LGPL version 2 licenses.
  315. */
  316. -#ifndef _LARGEFILE_SOURCE
  317. -#define _LARGEFILE_SOURCE
  318. -#endif
  319. -#ifndef _LARGEFILE64_SOURCE
  320. -#define _LARGEFILE64_SOURCE
  321. -#endif
  322. #ifndef _GNU_SOURCE
  323. #define _GNU_SOURCE
  324. #endif
  325. -#ifndef _FILE_OFFSET_BITS
  326. -#define _FILE_OFFSET_BITS 64
  327. -#endif
  328. -
  329. #include <f2fs_fs.h>
  330. #include <stdio.h>
  331. diff --git a/mkfs/f2fs_format_utils.h b/mkfs/f2fs_format_utils.h
  332. index 807e7c3..6a7f687 100644
  333. --- a/mkfs/f2fs_format_utils.h
  334. +++ b/mkfs/f2fs_format_utils.h
  335. @@ -6,8 +6,6 @@
  336. *
  337. * Dual licensed under the GPL or LGPL version 2 licenses.
  338. */
  339. -#define _LARGEFILE64_SOURCE
  340. -
  341. #include "f2fs_fs.h"
  342. extern struct f2fs_configuration c;
  343. diff --git a/tools/Makefile.am b/tools/Makefile.am
  344. index 6b03814..7dfffb1 100644
  345. --- a/tools/Makefile.am
  346. +++ b/tools/Makefile.am
  347. @@ -1,7 +1,7 @@
  348. ## Makefile.am
  349. AM_CPPFLAGS = ${libuuid_CFLAGS} -I$(top_srcdir)/include
  350. -AM_CFLAGS = -Wall
  351. +AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64
  352. sbin_PROGRAMS =
  353. if !WINDOWS
  354. sbin_PROGRAMS += fibmap.f2fs parse.f2fs
  355. diff --git a/tools/f2fs_io/Makefile.am b/tools/f2fs_io/Makefile.am
  356. index bc4f9d0..f5227ce 100644
  357. --- a/tools/f2fs_io/Makefile.am
  358. +++ b/tools/f2fs_io/Makefile.am
  359. @@ -2,7 +2,7 @@
  360. if LINUX
  361. AM_CPPFLAGS = -I$(top_srcdir)/include
  362. -AM_CFLAGS = -Wall
  363. +AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64
  364. sbin_PROGRAMS = f2fs_io
  365. f2fs_io_SOURCES = f2fs_io.c
  366. endif
  367. diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
  368. index 771fd16..1f6549b 100644
  369. --- a/tools/f2fs_io/f2fs_io.c
  370. +++ b/tools/f2fs_io/f2fs_io.c
  371. @@ -9,12 +9,6 @@
  372. #ifndef _GNU_SOURCE
  373. #define _GNU_SOURCE
  374. #endif
  375. -#ifndef _LARGEFILE_SOURCE
  376. -#define _LARGEFILE_SOURCE
  377. -#endif
  378. -#ifndef _LARGEFILE64_SOURCE
  379. -#define _LARGEFILE64_SOURCE
  380. -#endif
  381. #ifndef O_LARGEFILE
  382. #define O_LARGEFILE 0
  383. #endif
  384. diff --git a/tools/f2fs_io_parse.c b/tools/f2fs_io_parse.c
  385. index 47f1194..c3c1005 100644
  386. --- a/tools/f2fs_io_parse.c
  387. +++ b/tools/f2fs_io_parse.c
  388. @@ -8,7 +8,6 @@
  389. * it under the terms of the GNU General Public License version 2 as
  390. * published by the Free Software Foundation.
  391. */
  392. -#define _LARGEFILE64_SOURCE
  393. #include <stdio.h>
  394. #include <stdlib.h>
  395. #include <unistd.h>
  396. diff --git a/tools/f2fscrypt.c b/tools/f2fscrypt.c
  397. index 8640ffa..d5222fb 100644
  398. --- a/tools/f2fscrypt.c
  399. +++ b/tools/f2fscrypt.c
  400. @@ -7,15 +7,6 @@
  401. * Authors: Michael Halcrow <mhalcrow@google.com>,
  402. * Ildar Muslukhov <ildarm@google.com>
  403. */
  404. -
  405. -#ifndef _LARGEFILE_SOURCE
  406. -#define _LARGEFILE_SOURCE
  407. -#endif
  408. -
  409. -#ifndef _LARGEFILE64_SOURCE
  410. -#define _LARGEFILE64_SOURCE
  411. -#endif
  412. -
  413. #ifndef _GNU_SOURCE
  414. #define _GNU_SOURCE
  415. #endif
  416. diff --git a/tools/fibmap.c b/tools/fibmap.c
  417. index bda8238..3acc77b 100644
  418. --- a/tools/fibmap.c
  419. +++ b/tools/fibmap.c
  420. @@ -1,13 +1,6 @@
  421. #if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__)
  422. #define _XOPEN_SOURCE 600
  423. #define _DARWIN_C_SOURCE
  424. -#define _FILE_OFFSET_BITS 64
  425. -#ifndef _LARGEFILE_SOURCE
  426. -#define _LARGEFILE_SOURCE
  427. -#endif
  428. -#ifndef _LARGEFILE64_SOURCE
  429. -#define _LARGEFILE64_SOURCE
  430. -#endif
  431. #ifndef _GNU_SOURCE
  432. #define _GNU_SOURCE
  433. #endif
  434. --
  435. 2.39.2