← Commit list

274a087cd

Denys Vlasenko
Denys Vlasenko
2026-09-26
SUCCESS Duration: 184s

Subject

*: users of get_volume_size_in_bytes() should open their file O_RDWR

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

libbb/get_volsize.c+1 -0
@@ -27,6 +27,7 @@ uoff_t FAST_FUNC get_volume_size_in_bytes(int fd,
// Seek past end fails on block devices but works on files!
if (lseek(fd, result - 1, SEEK_SET) != (off_t)-1) {
char dummy;
+//NB: here, fd needs a O_RDWR open, not O_WRONLY!
if (extend && safe_read(fd, &dummy, 1) != 1) {
// the file is shorter
xwrite(fd, "", 1); // grow it
util-linux/mkfs_ext2.c+1 -1
@@ -255,7 +255,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
argv += optind; // argv[0] -- device
// open the device, check the device is a block device
- xmove_fd(xopen(argv[0], O_WRONLY), fd);
+ xmove_fd(xopen(argv[0], O_RDWR), fd);
xfstat(fd, &st, argv[0]);
if (!S_ISBLK(st.st_mode) && !(option_mask32 & OPT_F))
bb_error_msg_and_die("%s: not a block device", argv[0]);
util-linux/mkfs_reiser.c+1 -1
@@ -168,7 +168,7 @@ int mkfs_reiser_main(int argc UNUSED_PARAM, char **argv)
argv += optind; // argv[0] -- device
// check the device is a block device
- fd = xopen(argv[0], O_WRONLY | O_EXCL);
+ fd = xopen(argv[0], O_RDWR | O_EXCL);
xfstat(fd, &st, argv[0]);
if (!S_ISBLK(st.st_mode) && !(option_mask32 & OPT_f))
bb_error_msg_and_die("%s: not a block device", argv[0]);
util-linux/mkswap.c+1 -1
@@ -121,7 +121,7 @@ int mkswap_main(int argc UNUSED_PARAM, char **argv)
getopt32(argv, "^" "L:" "\0" "-1"/*at least one arg*/, &label);
argv += optind;
- fd = xopen(argv[0], O_WRONLY);
+ fd = xopen(argv[0], O_RDWR);
/* Figure out how big the device is */
len = get_volume_size_in_bytes(fd, argv[1], 1024, /*extend:*/ 1);