Skip to contentSkip to conversation

Use pread/pwrite/ftruncate/stat instead of 64bit equivalents

PATCH In review Khem Raj 2 participants 2 messages Dec 15, 2022 – Dec 16, 2022 Btrfs file system

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/1 Use pread/pwrite/ftruncate/stat instead of 64bit equivalents

64bit functions are aliases to original functions when largefile feature is enabled via autoconf or right macro is passed on compiler cmdline

-D_FILE_OFFSET_BITS=64

---
 cmds/rescue-chunk-recover.c |   4 +-
 image/main.c                |  14 +--
 kernel-shared/zoned.c       |   6 +-
 kernel-shared/zoned.h       |   4 +-
 mkfs/main.c                 |   4 +-
 mkfs/rootdir.c              |  10 +-
 tests/fsstress.c            | 192 ++++++++++++++++++------------------
 tests/fssum.c               |   8 +-
 8 files changed, 121 insertions(+), 121 deletions(-)
cmds/rescue-chunk-recover.c +2 -2
index e8d4b28f..d597e8bd 100644
@@ -755,7 +755,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;
 
@@ -1875,7 +1875,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;
image/main.c +7 -7
index b1a0714a..e8acb4be 100644
@@ -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);
@@ -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(
@@ -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;
@@ -2454,7 +2454,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;
@@ -2913,7 +2913,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",
@@ -3010,7 +3010,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;
kernel-shared/zoned.c +3 -3
index a79fc6a5..88d53e37 100644
@@ -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];
@@ -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));
kernel-shared/zoned.h +2 -2
index cc0d6b6f..770f5889 100644
@@ -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)
 {
mkfs/main.c +2 -2
index df091b16..08faf730 100644
@@ -453,14 +453,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;
mkfs/rootdir.c +5 -5
index 2cf6eef9..1ddc1138 100644
@@ -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);
@@ -386,7 +386,7 @@ again:
 
 		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",
@@ -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;
 
@@ -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);
tests/fsstress.c +96 -96

606 lines not on this page · raw message

tests/fssum.c +4 -4
index 2cba1891..e35c0274 100644
@@ -519,9 +519,9 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in)
 	int excl;
 	sum_file_data_t sum_file_data = flags[FLAG_STRUCTURE] ?
 			sum_file_data_strict : sum_file_data_permissive;
-	struct stat64 dir_st;
+	struct stat dir_st;
 
-	if (fstat64(dirfd, &dir_st)) {
+	if (fstat(dirfd, &dir_st)) {
 		perror("fstat");
 		exit(-1);
 	}
@@ -552,7 +552,7 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in)
 	}
 	qsort(namelist, entries, sizeof(*namelist), namecmp);
 	for (i = 0; i < entries; ++i) {
-		struct stat64 st;
+		struct stat st;
 		sum_t cs;
 		sum_t meta;
 		char *path;
@@ -572,7 +572,7 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in)
 			perror("fchdir");
 			exit(-1);
 		}
-		ret = lstat64(namelist[i], &st);
+		ret = lstat(namelist[i], &st);
 		if (ret) {
 			fprintf(stderr, "stat failed for %s/%s: %m\n",
 				path_prefix, path);
Signature · 1 line
2.39.0
#1 lore raw
Quoted 2 lines · Khem Raj

64bit functions are aliases to original functions when largefile feature is enabled via autoconf or right macro is passed on compiler cmdline

I noticed that there's also lseek64, should this be also converted?