Skip to content

Commit c9abbf6

Browse files
nekopsykosekdave
authored andcommitted
btrfs-progs: stop using legacy *64 interfaces
The *64 interfaces, such as fstat64, off64_t, etc, are legacy interfaces created at a time when 64-bit file support was still new. They are generally exposed when defining a macro named _LARGEFILE64_SOURCE, as e.g. the glibc docs[0] say. The modern way to utilise largefile support, is to continue to use the regular interfaces (off_t, fstat, ..), and define _FILE_OFFSET_BITS=64. We already use the autoconf macro AC_SYS_LARGEFILE[1] which arranges this and sets this macro for us. Therefore, we can utilise the non-64 names without fear of breaking on 32-bit systems. This fixes the build against musl libc, ever since musl dropped the *64 compat from interfaces by default[2] just for _GNU_SOURCE, unless _LARGEFILE64_SOURCE is defined. However, there are plans for a future removal of the whole *64 header API, and that workaround (adding another define) might cease to exist. So, rename all *64 API use to the regular non-suffixed names. For consistency, rename the internal functions that were *64 named (lstat64_path, ..) too. This should have no regressions on any platform. [0]: https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html#index-_005fLARGEFILE64_005fSOURCE [1]: https://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/System-Services.html [2]: bminor/musl@25e6fee Pull-request: #615 Signed-off-by: psykose <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 858a41e commit c9abbf6

File tree

8 files changed

+175
-175
lines changed

8 files changed

+175
-175
lines changed

cmds/rescue-chunk-recover.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ static int scan_one_device(void *dev_scan_struct)
754754
if (is_super_block_address(bytenr))
755755
bytenr += rc->sectorsize;
756756

757-
if (pread64(fd, buf->data, rc->nodesize, bytenr) <
757+
if (pread(fd, buf->data, rc->nodesize, bytenr) <
758758
rc->nodesize)
759759
break;
760760

@@ -1874,7 +1874,7 @@ static int check_one_csum(int fd, u64 start, u32 len, u32 tree_csum,
18741874
data = malloc(len);
18751875
if (!data)
18761876
return -1;
1877-
ret = pread64(fd, data, len, start);
1877+
ret = pread(fd, data, len, start);
18781878
if (ret < 0 || ret != len) {
18791879
ret = -1;
18801880
goto out;

image/main.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ static int flush_pending(struct metadump_struct *md, int done)
691691
if (start == BTRFS_SUPER_INFO_OFFSET) {
692692
int fd = get_dev_fd(md->root);
693693

694-
ret = pread64(fd, async->buffer, size, start);
694+
ret = pread(fd, async->buffer, size, start);
695695
if (ret < size) {
696696
free(async->buffer);
697697
free(async);
@@ -1366,7 +1366,7 @@ static void write_backup_supers(int fd, u8 *buf)
13661366
break;
13671367
btrfs_set_super_bytenr(super, bytenr);
13681368
csum_block(buf, BTRFS_SUPER_INFO_SIZE);
1369-
ret = pwrite64(fd, buf, BTRFS_SUPER_INFO_SIZE, bytenr);
1369+
ret = pwrite(fd, buf, BTRFS_SUPER_INFO_SIZE, bytenr);
13701370
if (ret < BTRFS_SUPER_INFO_SIZE) {
13711371
if (ret < 0)
13721372
error(
@@ -1487,12 +1487,12 @@ static int restore_one_work(struct mdrestore_struct *mdres,
14871487
else
14881488
bytenr = logical;
14891489

1490-
ret = pwrite64(outfd, buffer + offset, chunk_size, bytenr);
1490+
ret = pwrite(outfd, buffer + offset, chunk_size, bytenr);
14911491
if (ret != chunk_size)
14921492
goto write_error;
14931493

14941494
if (physical_dup)
1495-
ret = pwrite64(outfd, buffer + offset,
1495+
ret = pwrite(outfd, buffer + offset,
14961496
chunk_size, physical_dup);
14971497
if (ret != chunk_size)
14981498
goto write_error;
@@ -2451,7 +2451,7 @@ static int fixup_device_size(struct btrfs_trans_handle *trans,
24512451
}
24522452
if (S_ISREG(buf.st_mode)) {
24532453
/* Don't forget to enlarge the real file */
2454-
ret = ftruncate64(out_fd, dev_size);
2454+
ret = ftruncate(out_fd, dev_size);
24552455
if (ret < 0) {
24562456
error("failed to enlarge result image: %m");
24572457
return -errno;
@@ -2910,7 +2910,7 @@ static int restore_metadump(const char *input, FILE *out, int old_restore,
29102910
goto out;
29112911
}
29122912
if (S_ISREG(st.st_mode) && st.st_size < dev_size) {
2913-
ret = ftruncate64(fileno(out), dev_size);
2913+
ret = ftruncate(fileno(out), dev_size);
29142914
if (ret < 0) {
29152915
error(
29162916
"failed to enlarge result image file from %llu to %llu: %m",
@@ -3007,7 +3007,7 @@ static int update_disk_super_on_device(struct btrfs_fs_info *info,
30073007
memcpy(dev_item->fsid, fs_uuid, BTRFS_UUID_SIZE);
30083008
csum_block((u8 *)&disk_super, BTRFS_SUPER_INFO_SIZE);
30093009

3010-
ret = pwrite64(fp, &disk_super, BTRFS_SUPER_INFO_SIZE, BTRFS_SUPER_INFO_OFFSET);
3010+
ret = pwrite(fp, &disk_super, BTRFS_SUPER_INFO_SIZE, BTRFS_SUPER_INFO_OFFSET);
30113011
if (ret != BTRFS_SUPER_INFO_SIZE) {
30123012
if (ret < 0) {
30133013
errno = ret;

kernel-shared/zoned.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static int sb_write_pointer(int fd, struct blk_zone *zones, u64 *wp_ret)
194194
bytenr = ((zones[i].start + zones[i].len)
195195
<< SECTOR_SHIFT) - BTRFS_SUPER_INFO_SIZE;
196196

197-
ret = pread64(fd, buf[i], BTRFS_SUPER_INFO_SIZE, bytenr);
197+
ret = pread(fd, buf[i], BTRFS_SUPER_INFO_SIZE, bytenr);
198198
if (ret != BTRFS_SUPER_INFO_SIZE)
199199
return -EIO;
200200
super[i] = (struct btrfs_super_block *)&buf[i];
@@ -515,8 +515,8 @@ size_t btrfs_sb_io(int fd, void *buf, off_t offset, int rw)
515515
/* We can call pread/pwrite if 'fd' is non-zoned device/file */
516516
if (zone_size_sector == 0) {
517517
if (rw == READ)
518-
return pread64(fd, buf, count, offset);
519-
return pwrite64(fd, buf, count, offset);
518+
return pread(fd, buf, count, offset);
519+
return pwrite(fd, buf, count, offset);
520520
}
521521

522522
ASSERT(IS_ALIGNED(zone_size_sector, sb_size_sector));

kernel-shared/zoned.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ int btrfs_wipe_temporary_sb(struct btrfs_fs_devices *fs_devices);
150150
#else
151151

152152
#define sbread(fd, buf, offset) \
153-
pread64(fd, buf, BTRFS_SUPER_INFO_SIZE, offset)
153+
pread(fd, buf, BTRFS_SUPER_INFO_SIZE, offset)
154154
#define sbwrite(fd, buf, offset) \
155-
pwrite64(fd, buf, BTRFS_SUPER_INFO_SIZE, offset)
155+
pwrite(fd, buf, BTRFS_SUPER_INFO_SIZE, offset)
156156

157157
static inline int btrfs_reset_dev_zone(int fd, struct blk_zone *zone)
158158
{

mkfs/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,14 +461,14 @@ static int zero_output_file(int out_fd, u64 size)
461461
/* Only zero out the first 1M */
462462
loop_num = SZ_1M / SZ_4K;
463463
for (i = 0; i < loop_num; i++) {
464-
written = pwrite64(out_fd, buf, SZ_4K, location);
464+
written = pwrite(out_fd, buf, SZ_4K, location);
465465
if (written != SZ_4K)
466466
ret = -EIO;
467467
location += SZ_4K;
468468
}
469469

470470
/* Then enlarge the file to size */
471-
written = pwrite64(out_fd, buf, 1, size - 1);
471+
written = pwrite(out_fd, buf, 1, size - 1);
472472
if (written < 1)
473473
ret = -EIO;
474474
return ret;

mkfs/rootdir.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static int add_file_items(struct btrfs_trans_handle *trans,
340340
goto end;
341341
}
342342

343-
ret_read = pread64(fd, buffer, st->st_size, bytes_read);
343+
ret_read = pread(fd, buffer, st->st_size, bytes_read);
344344
if (ret_read == -1) {
345345
error("cannot read %s at offset %llu length %llu: %m",
346346
path_name, bytes_read, (unsigned long long)st->st_size);
@@ -386,7 +386,7 @@ static int add_file_items(struct btrfs_trans_handle *trans,
386386

387387
memset(eb->data, 0, sectorsize);
388388

389-
ret_read = pread64(fd, eb->data, sectorsize, file_pos +
389+
ret_read = pread(fd, eb->data, sectorsize, file_pos +
390390
bytes_read);
391391
if (ret_read == -1) {
392392
error("cannot read %s at offset %llu length %u: %m",
@@ -929,7 +929,7 @@ int btrfs_mkfs_shrink_fs(struct btrfs_fs_info *fs_info, u64 *new_size_ret,
929929
u64 new_size;
930930
struct btrfs_device *device;
931931
struct list_head *cur;
932-
struct stat64 file_stat;
932+
struct stat file_stat;
933933
int nr_devs = 0;
934934
int ret;
935935

@@ -963,14 +963,14 @@ int btrfs_mkfs_shrink_fs(struct btrfs_fs_info *fs_info, u64 *new_size_ret,
963963
*new_size_ret = new_size;
964964

965965
if (shrink_file_size) {
966-
ret = fstat64(device->fd, &file_stat);
966+
ret = fstat(device->fd, &file_stat);
967967
if (ret < 0) {
968968
error("failed to stat devid %llu: %m", device->devid);
969969
return ret;
970970
}
971971
if (!S_ISREG(file_stat.st_mode))
972972
return ret;
973-
ret = ftruncate64(device->fd, new_size);
973+
ret = ftruncate(device->fd, new_size);
974974
if (ret < 0) {
975975
error("failed to truncate device file of devid %llu: %m",
976976
device->devid);

0 commit comments

Comments
 (0)