Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame^] | 1 | From 3c0314e1820afc9a98e890cc5f7973c3c81877f8 Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Wed, 21 Dec 2022 18:23:03 -0800 |
| 4 | Subject: [PATCH] f2fs_io: Define _FILE_OFFSET_BITS=64 |
| 5 | |
| 6 | Remove _LARGEFILE64_SOURCE, this is redundant when _FILE_OFFSET_BITS=64 |
| 7 | additionally it fixes build with musl because the detection logic for |
| 8 | lseek64 fails because when using _LARGEFILE64_SOURCE musl also define's |
| 9 | lseek64 as an alias to lseek |
| 10 | |
| 11 | Upstream-Status: Submitted [https://lore.kernel.org/linux-f2fs-devel/20221222022830.976309-2-raj.khem@gmail.com/T/#u] |
| 12 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 13 | --- |
| 14 | lib/libf2fs_io.c | 4 +++- |
| 15 | tools/f2fs_io/f2fs_io.c | 4 ++-- |
| 16 | 2 files changed, 5 insertions(+), 3 deletions(-) |
| 17 | |
| 18 | --- a/lib/libf2fs_io.c |
| 19 | +++ b/lib/libf2fs_io.c |
| 20 | @@ -11,7 +11,9 @@ |
| 21 | * |
| 22 | * Dual licensed under the GPL or LGPL version 2 licenses. |
| 23 | */ |
| 24 | -#define _LARGEFILE64_SOURCE |
| 25 | +#ifndef _FILE_OFFSET_BITS |
| 26 | +#define _FILE_OFFSET_BITS 64 |
| 27 | +#endif |
| 28 | |
| 29 | #include <stdio.h> |
| 30 | #include <stdlib.h> |
| 31 | @@ -67,22 +69,13 @@ static int __get_device_fd(__u64 *offset |
| 32 | return -1; |
| 33 | } |
| 34 | |
| 35 | -#ifndef HAVE_LSEEK64 |
| 36 | -typedef off_t off64_t; |
| 37 | - |
| 38 | -static inline off64_t lseek64(int fd, __u64 offset, int set) |
| 39 | -{ |
| 40 | - return lseek(fd, offset, set); |
| 41 | -} |
| 42 | -#endif |
| 43 | - |
| 44 | /* ---------- dev_cache, Least Used First (LUF) policy ------------------- */ |
| 45 | /* |
| 46 | * Least used block will be the first victim to be replaced when max hash |
| 47 | * collision exceeds |
| 48 | */ |
| 49 | static bool *dcache_valid; /* is the cached block valid? */ |
| 50 | -static off64_t *dcache_blk; /* which block it cached */ |
| 51 | +static off_t *dcache_blk; /* which block it cached */ |
| 52 | static uint64_t *dcache_lastused; /* last used ticks for cache entries */ |
| 53 | static char *dcache_buf; /* cached block data */ |
| 54 | static uint64_t dcache_usetick; /* current use tick */ |
| 55 | @@ -172,7 +165,7 @@ static int dcache_alloc_all(long n) |
| 56 | { |
| 57 | if (n <= 0) |
| 58 | return -1; |
| 59 | - if ((dcache_blk = (off64_t *) malloc(sizeof(off64_t) * n)) == NULL |
| 60 | + if ((dcache_blk = (off_t *) malloc(sizeof(off_t) * n)) == NULL |
| 61 | || (dcache_lastused = (uint64_t *) |
| 62 | malloc(sizeof(uint64_t) * n)) == NULL |
| 63 | || (dcache_buf = (char *) malloc (F2FS_BLKSIZE * n)) == NULL |
| 64 | @@ -257,7 +250,7 @@ static inline long dcache_relocate(long |
| 65 | dcache_config.num_cache_entry; |
| 66 | } |
| 67 | |
| 68 | -static long dcache_find(off64_t blk) |
| 69 | +static long dcache_find(off_t blk) |
| 70 | { |
| 71 | register long n = dcache_config.num_cache_entry; |
| 72 | register unsigned m = dcache_config.max_hash_collision; |
| 73 | @@ -278,10 +271,10 @@ static long dcache_find(off64_t blk) |
| 74 | } |
| 75 | |
| 76 | /* Physical read into cache */ |
| 77 | -static int dcache_io_read(int fd, long entry, off64_t offset, off64_t blk) |
| 78 | +static int dcache_io_read(int fd, long entry, off_t offset, off_t blk) |
| 79 | { |
| 80 | - if (lseek64(fd, offset, SEEK_SET) < 0) { |
| 81 | - MSG(0, "\n lseek64 fail.\n"); |
| 82 | + if (lseek(fd, offset, SEEK_SET) < 0) { |
| 83 | + MSG(0, "\n lseek fail.\n"); |
| 84 | return -1; |
| 85 | } |
| 86 | if (read(fd, dcache_buf + entry * F2FS_BLKSIZE, F2FS_BLKSIZE) < 0) { |
| 87 | @@ -308,12 +301,12 @@ static int dcache_io_read(int fd, long e |
| 88 | * 1: cache not available (uninitialized) |
| 89 | * -1: error |
| 90 | */ |
| 91 | -static int dcache_update_rw(int fd, void *buf, off64_t offset, |
| 92 | +static int dcache_update_rw(int fd, void *buf, off_t offset, |
| 93 | size_t byte_count, bool is_write) |
| 94 | { |
| 95 | - off64_t blk; |
| 96 | + off_t blk; |
| 97 | int addr_in_blk; |
| 98 | - off64_t start; |
| 99 | + off_t start; |
| 100 | |
| 101 | if (!dcache_initialized) |
| 102 | dcache_init(); /* auto initialize */ |
| 103 | @@ -377,13 +370,13 @@ static int dcache_update_rw(int fd, void |
| 104 | * return value: 1: cache not available |
| 105 | * 0: success, -1: I/O error |
| 106 | */ |
| 107 | -int dcache_update_cache(int fd, void *buf, off64_t offset, size_t count) |
| 108 | +int dcache_update_cache(int fd, void *buf, off_t offset, size_t count) |
| 109 | { |
| 110 | return dcache_update_rw(fd, buf, offset, count, true); |
| 111 | } |
| 112 | |
| 113 | /* handles read into cache + read into buffer */ |
| 114 | -int dcache_read(int fd, void *buf, off64_t offset, size_t count) |
| 115 | +int dcache_read(int fd, void *buf, off_t offset, size_t count) |
| 116 | { |
| 117 | return dcache_update_rw(fd, buf, offset, count, false); |
| 118 | } |
| 119 | @@ -395,7 +388,7 @@ int dev_read_version(void *buf, __u64 of |
| 120 | { |
| 121 | if (c.sparse_mode) |
| 122 | return 0; |
| 123 | - if (lseek64(c.kd, (off64_t)offset, SEEK_SET) < 0) |
| 124 | + if (lseek(c.kd, (off_t)offset, SEEK_SET) < 0) |
| 125 | return -1; |
| 126 | if (read(c.kd, buf, len) < 0) |
| 127 | return -1; |
| 128 | @@ -537,10 +530,10 @@ int dev_read(void *buf, __u64 offset, si |
| 129 | |
| 130 | /* err = 1: cache not available, fall back to non-cache R/W */ |
| 131 | /* err = 0: success, err=-1: I/O error */ |
| 132 | - err = dcache_read(fd, buf, (off64_t)offset, len); |
| 133 | + err = dcache_read(fd, buf, (off_t)offset, len); |
| 134 | if (err <= 0) |
| 135 | return err; |
| 136 | - if (lseek64(fd, (off64_t)offset, SEEK_SET) < 0) |
| 137 | + if (lseek(fd, (off_t)offset, SEEK_SET) < 0) |
| 138 | return -1; |
| 139 | if (read(fd, buf, len) < 0) |
| 140 | return -1; |
| 141 | @@ -586,9 +579,9 @@ int dev_write(void *buf, __u64 offset, s |
| 142 | * dcache_update_cache() just update cache, won't do I/O. |
| 143 | * Thus even no error, we need normal non-cache I/O for actual write |
| 144 | */ |
| 145 | - if (dcache_update_cache(fd, buf, (off64_t)offset, len) < 0) |
| 146 | + if (dcache_update_cache(fd, buf, (off_t)offset, len) < 0) |
| 147 | return -1; |
| 148 | - if (lseek64(fd, (off64_t)offset, SEEK_SET) < 0) |
| 149 | + if (lseek(fd, (off_t)offset, SEEK_SET) < 0) |
| 150 | return -1; |
| 151 | if (write(fd, buf, len) < 0) |
| 152 | return -1; |
| 153 | @@ -602,7 +595,7 @@ int dev_write_block(void *buf, __u64 blk |
| 154 | |
| 155 | int dev_write_dump(void *buf, __u64 offset, size_t len) |
| 156 | { |
| 157 | - if (lseek64(c.dump_fd, (off64_t)offset, SEEK_SET) < 0) |
| 158 | + if (lseek(c.dump_fd, (off_t)offset, SEEK_SET) < 0) |
| 159 | return -1; |
| 160 | if (write(c.dump_fd, buf, len) < 0) |
| 161 | return -1; |
| 162 | @@ -627,7 +620,7 @@ int dev_fill(void *buf, __u64 offset, si |
| 163 | /* Only allow fill to zero */ |
| 164 | if (*((__u8*)buf)) |
| 165 | return -1; |
| 166 | - if (lseek64(fd, (off64_t)offset, SEEK_SET) < 0) |
| 167 | + if (lseek(fd, (off_t)offset, SEEK_SET) < 0) |
| 168 | return -1; |
| 169 | if (write(fd, buf, len) < 0) |
| 170 | return -1; |
| 171 | --- a/tools/f2fs_io/f2fs_io.c |
| 172 | +++ b/tools/f2fs_io/f2fs_io.c |
| 173 | @@ -12,8 +12,8 @@ |
| 174 | #ifndef _LARGEFILE_SOURCE |
| 175 | #define _LARGEFILE_SOURCE |
| 176 | #endif |
| 177 | -#ifndef _LARGEFILE64_SOURCE |
| 178 | -#define _LARGEFILE64_SOURCE |
| 179 | +#ifndef _FILE_OFFSET_BITS |
| 180 | +#define _FILE_OFFSET_BITS 64 |
| 181 | #endif |
| 182 | #ifndef O_LARGEFILE |
| 183 | #define O_LARGEFILE 0 |