Skip to content

Commit

Permalink
btrfs-progs: stop using legacy *64 interfaces
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
nekopsykose authored and kdave committed Apr 25, 2023
1 parent 858a41e commit c9abbf6
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 175 deletions.
4 changes: 2 additions & 2 deletions cmds/rescue-chunk-recover.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ static int scan_one_device(void *dev_scan_struct)
if (is_super_block_address(bytenr))
bytenr += rc->sectorsize;

if (pread64(fd, buf->data, rc->nodesize, bytenr) <
if (pread(fd, buf->data, rc->nodesize, bytenr) <
rc->nodesize)
break;

Expand Down Expand Up @@ -1874,7 +1874,7 @@ static int check_one_csum(int fd, u64 start, u32 len, u32 tree_csum,
data = malloc(len);
if (!data)
return -1;
ret = pread64(fd, data, len, start);
ret = pread(fd, data, len, start);
if (ret < 0 || ret != len) {
ret = -1;
goto out;
Expand Down
14 changes: 7 additions & 7 deletions image/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ static int flush_pending(struct metadump_struct *md, int done)
if (start == BTRFS_SUPER_INFO_OFFSET) {
int fd = get_dev_fd(md->root);

ret = pread64(fd, async->buffer, size, start);
ret = pread(fd, async->buffer, size, start);
if (ret < size) {
free(async->buffer);
free(async);
Expand Down Expand Up @@ -1366,7 +1366,7 @@ static void write_backup_supers(int fd, u8 *buf)
break;
btrfs_set_super_bytenr(super, bytenr);
csum_block(buf, BTRFS_SUPER_INFO_SIZE);
ret = pwrite64(fd, buf, BTRFS_SUPER_INFO_SIZE, bytenr);
ret = pwrite(fd, buf, BTRFS_SUPER_INFO_SIZE, bytenr);
if (ret < BTRFS_SUPER_INFO_SIZE) {
if (ret < 0)
error(
Expand Down Expand Up @@ -1487,12 +1487,12 @@ static int restore_one_work(struct mdrestore_struct *mdres,
else
bytenr = logical;

ret = pwrite64(outfd, buffer + offset, chunk_size, bytenr);
ret = pwrite(outfd, buffer + offset, chunk_size, bytenr);
if (ret != chunk_size)
goto write_error;

if (physical_dup)
ret = pwrite64(outfd, buffer + offset,
ret = pwrite(outfd, buffer + offset,
chunk_size, physical_dup);
if (ret != chunk_size)
goto write_error;
Expand Down Expand Up @@ -2451,7 +2451,7 @@ static int fixup_device_size(struct btrfs_trans_handle *trans,
}
if (S_ISREG(buf.st_mode)) {
/* Don't forget to enlarge the real file */
ret = ftruncate64(out_fd, dev_size);
ret = ftruncate(out_fd, dev_size);
if (ret < 0) {
error("failed to enlarge result image: %m");
return -errno;
Expand Down Expand Up @@ -2910,7 +2910,7 @@ static int restore_metadump(const char *input, FILE *out, int old_restore,
goto out;
}
if (S_ISREG(st.st_mode) && st.st_size < dev_size) {
ret = ftruncate64(fileno(out), dev_size);
ret = ftruncate(fileno(out), dev_size);
if (ret < 0) {
error(
"failed to enlarge result image file from %llu to %llu: %m",
Expand Down Expand Up @@ -3007,7 +3007,7 @@ static int update_disk_super_on_device(struct btrfs_fs_info *info,
memcpy(dev_item->fsid, fs_uuid, BTRFS_UUID_SIZE);
csum_block((u8 *)&disk_super, BTRFS_SUPER_INFO_SIZE);

ret = pwrite64(fp, &disk_super, BTRFS_SUPER_INFO_SIZE, BTRFS_SUPER_INFO_OFFSET);
ret = pwrite(fp, &disk_super, BTRFS_SUPER_INFO_SIZE, BTRFS_SUPER_INFO_OFFSET);
if (ret != BTRFS_SUPER_INFO_SIZE) {
if (ret < 0) {
errno = ret;
Expand Down
6 changes: 3 additions & 3 deletions kernel-shared/zoned.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static int sb_write_pointer(int fd, struct blk_zone *zones, u64 *wp_ret)
bytenr = ((zones[i].start + zones[i].len)
<< SECTOR_SHIFT) - BTRFS_SUPER_INFO_SIZE;

ret = pread64(fd, buf[i], BTRFS_SUPER_INFO_SIZE, bytenr);
ret = pread(fd, buf[i], BTRFS_SUPER_INFO_SIZE, bytenr);
if (ret != BTRFS_SUPER_INFO_SIZE)
return -EIO;
super[i] = (struct btrfs_super_block *)&buf[i];
Expand Down Expand Up @@ -515,8 +515,8 @@ size_t btrfs_sb_io(int fd, void *buf, off_t offset, int rw)
/* We can call pread/pwrite if 'fd' is non-zoned device/file */
if (zone_size_sector == 0) {
if (rw == READ)
return pread64(fd, buf, count, offset);
return pwrite64(fd, buf, count, offset);
return pread(fd, buf, count, offset);
return pwrite(fd, buf, count, offset);
}

ASSERT(IS_ALIGNED(zone_size_sector, sb_size_sector));
Expand Down
4 changes: 2 additions & 2 deletions kernel-shared/zoned.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ int btrfs_wipe_temporary_sb(struct btrfs_fs_devices *fs_devices);
#else

#define sbread(fd, buf, offset) \
pread64(fd, buf, BTRFS_SUPER_INFO_SIZE, offset)
pread(fd, buf, BTRFS_SUPER_INFO_SIZE, offset)
#define sbwrite(fd, buf, offset) \
pwrite64(fd, buf, BTRFS_SUPER_INFO_SIZE, offset)
pwrite(fd, buf, BTRFS_SUPER_INFO_SIZE, offset)

static inline int btrfs_reset_dev_zone(int fd, struct blk_zone *zone)
{
Expand Down
4 changes: 2 additions & 2 deletions mkfs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,14 +461,14 @@ static int zero_output_file(int out_fd, u64 size)
/* Only zero out the first 1M */
loop_num = SZ_1M / SZ_4K;
for (i = 0; i < loop_num; i++) {
written = pwrite64(out_fd, buf, SZ_4K, location);
written = pwrite(out_fd, buf, SZ_4K, location);
if (written != SZ_4K)
ret = -EIO;
location += SZ_4K;
}

/* Then enlarge the file to size */
written = pwrite64(out_fd, buf, 1, size - 1);
written = pwrite(out_fd, buf, 1, size - 1);
if (written < 1)
ret = -EIO;
return ret;
Expand Down
10 changes: 5 additions & 5 deletions mkfs/rootdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ static int add_file_items(struct btrfs_trans_handle *trans,
goto end;
}

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

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

ret_read = pread64(fd, eb->data, sectorsize, file_pos +
ret_read = pread(fd, eb->data, sectorsize, file_pos +
bytes_read);
if (ret_read == -1) {
error("cannot read %s at offset %llu length %u: %m",
Expand Down Expand Up @@ -929,7 +929,7 @@ int btrfs_mkfs_shrink_fs(struct btrfs_fs_info *fs_info, u64 *new_size_ret,
u64 new_size;
struct btrfs_device *device;
struct list_head *cur;
struct stat64 file_stat;
struct stat file_stat;
int nr_devs = 0;
int ret;

Expand Down Expand Up @@ -963,14 +963,14 @@ int btrfs_mkfs_shrink_fs(struct btrfs_fs_info *fs_info, u64 *new_size_ret,
*new_size_ret = new_size;

if (shrink_file_size) {
ret = fstat64(device->fd, &file_stat);
ret = fstat(device->fd, &file_stat);
if (ret < 0) {
error("failed to stat devid %llu: %m", device->devid);
return ret;
}
if (!S_ISREG(file_stat.st_mode))
return ret;
ret = ftruncate64(device->fd, new_size);
ret = ftruncate(device->fd, new_size);
if (ret < 0) {
error("failed to truncate device file of devid %llu: %m",
device->devid);
Expand Down
Loading

0 comments on commit c9abbf6

Please sign in to comment.