aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2024-04-16 12:50:46 -0400
committerTheodore Ts'o <tytso@mit.edu>2024-04-16 12:50:46 -0400
commit187ba4f31537cf926cbd9849ee6848c9251ff8e5 (patch)
tree42d14fbd9e748f60e6f669153d24e7d0feb59c44
parentc6070404a2bed3ff675fc6500828ab6acee985f1 (diff)
parentef4e0825eee3d720a2df762249f0e80bb5f3ef3b (diff)
downloade2fsprogs-187ba4f31537cf926cbd9849ee6848c9251ff8e5.tar.gz
Merge branch 'maint' into next
-rw-r--r--.github/workflows/ci.yml1
-rw-r--r--lib/ext2fs/getsize.c31
-rw-r--r--lib/ext2fs/openfs.c3
-rw-r--r--lib/ext2fs/windows_io.c11
-rw-r--r--tests/f_desc_size_zero/expect.113
-rw-r--r--tests/f_desc_size_zero/image.gzbin0 -> 589 bytes
-rw-r--r--tests/f_desc_size_zero/name1
-rw-r--r--tests/f_desc_size_zero/script2
8 files changed, 29 insertions, 33 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 0c14250a4..da44fd078 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -120,7 +120,6 @@ jobs:
- run: make -j8 -C lib/support/ all V=1 CFLAGS_WARN="-Werror"
- run: make -j8 -C lib/e2p/ all V=1 CFLAGS_WARN="-Werror"
- run: make -j8 -C misc/ mke2fs V=1 CFLAGS_WARN="-Werror"
- - run: touch image.ext4
- run: misc/mke2fs.exe -T ext4 image.ext4 128M
- uses: actions/upload-artifact@v3
with:
diff --git a/lib/ext2fs/getsize.c b/lib/ext2fs/getsize.c
index bcf30208e..a02863443 100644
--- a/lib/ext2fs/getsize.c
+++ b/lib/ext2fs/getsize.c
@@ -71,12 +71,11 @@
#define HAVE_GET_FILE_SIZE_EX 1
#endif
-HANDLE windows_get_handle(io_channel channel);
-
errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
blk64_t *retblocks)
{
- HANDLE dev;
+ int fd;
+ HANDLE h;
PARTITION_INFORMATION pi;
DISK_GEOMETRY gi;
DWORD retbytes;
@@ -86,25 +85,18 @@ errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
DWORD filesize;
#endif /* HAVE_GET_FILE_SIZE_EX */
- io_channel data_io = 0;
- int retval;
-
- retval = windows_io_manager->open(file, 0, &data_io);
- if (retval)
- return retval;
-
- dev = windows_get_handle(data_io);
- if (dev == INVALID_HANDLE_VALUE)
- return EBADF;
-
- if (DeviceIoControl(dev, IOCTL_DISK_GET_PARTITION_INFO,
+ fd = ext2fs_open_file(file, O_RDONLY, 0);
+ if (fd < 0)
+ return errno;
+ h = (HANDLE)_get_osfhandle(fd);
+ if (DeviceIoControl(h, IOCTL_DISK_GET_PARTITION_INFO,
&pi, sizeof(PARTITION_INFORMATION),
&pi, sizeof(PARTITION_INFORMATION),
&retbytes, NULL)) {
*retblocks = pi.PartitionLength.QuadPart / blocksize;
- } else if (DeviceIoControl(dev, IOCTL_DISK_GET_DRIVE_GEOMETRY,
+ } else if (DeviceIoControl(h, IOCTL_DISK_GET_DRIVE_GEOMETRY,
&gi, sizeof(DISK_GEOMETRY),
&gi, sizeof(DISK_GEOMETRY),
&retbytes, NULL)) {
@@ -115,20 +107,19 @@ errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
gi.Cylinders.QuadPart / blocksize;
#ifdef HAVE_GET_FILE_SIZE_EX
- } else if (GetFileSizeEx(dev, &filesize)) {
+ } else if (GetFileSizeEx(h, &filesize)) {
*retblocks = filesize.QuadPart / blocksize;
}
#else
} else {
- filesize = GetFileSize(dev, NULL);
+ filesize = GetFileSize(h, NULL);
if (INVALID_FILE_SIZE != filesize) {
*retblocks = filesize / blocksize;
}
}
#endif /* HAVE_GET_FILE_SIZE_EX */
- windows_io_manager->close(data_io);
-
+ close(fd);
return 0;
}
diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
index c3611e0d8..eb44d5864 100644
--- a/lib/ext2fs/openfs.c
+++ b/lib/ext2fs/openfs.c
@@ -333,9 +333,10 @@ retry:
if (ext2fs_has_feature_64bit(fs->super)) {
unsigned desc_size = fs->super->s_desc_size;
- if (desc_size < EXT2_MIN_DESC_SIZE_64BIT ||
+ if (desc_size == 0 ||
(!(flags & EXT2_FLAG_IGNORE_SB_ERRORS) &&
((desc_size > EXT2_MAX_DESC_SIZE) ||
+ (desc_size < EXT2_MIN_DESC_SIZE_64BIT) ||
(desc_size & (desc_size - 1)) != 0))) {
retval = EXT2_ET_BAD_DESC_SIZE;
goto cleanup;
diff --git a/lib/ext2fs/windows_io.c b/lib/ext2fs/windows_io.c
index 83aea68b6..f01bbb6ad 100644
--- a/lib/ext2fs/windows_io.c
+++ b/lib/ext2fs/windows_io.c
@@ -857,17 +857,6 @@ static errcode_t windows_write_byte(io_channel channel, unsigned long offset,
return EXT2_ET_UNIMPLEMENTED;
}
-HANDLE windows_get_handle(io_channel channel)
-{
- struct windows_private_data *data;
-
- EXT2_CHECK_MAGIC_RETURN(channel, EXT2_ET_MAGIC_IO_CHANNEL, INVALID_HANDLE_VALUE);
- data = (struct windows_private_data *) channel->private_data;
- EXT2_CHECK_MAGIC_RETURN(data, EXT2_ET_MAGIC_WINDOWS_IO_CHANNEL, INVALID_HANDLE_VALUE);
-
- return data->handle;
-}
-
/*
* Flush data buffers to disk.
*/
diff --git a/tests/f_desc_size_zero/expect.1 b/tests/f_desc_size_zero/expect.1
new file mode 100644
index 000000000..acb752a75
--- /dev/null
+++ b/tests/f_desc_size_zero/expect.1
@@ -0,0 +1,13 @@
+../e2fsck/e2fsck: Block group descriptor size incorrect while trying to open test.img
+../e2fsck/e2fsck: Trying to load superblock despite errors...
+../e2fsck/e2fsck: Block group descriptor size incorrect while trying to open test.img
+
+The superblock could not be read or does not describe a valid ext2/ext3/ext4
+filesystem. If the device is valid and it really contains an ext2/ext3/ext4
+filesystem (and not swap or ufs or something else), then the superblock
+is corrupt, and you might try running e2fsck with an alternate superblock:
+ e2fsck -b 8193 <device>
+ or
+ e2fsck -b 32768 <device>
+
+Exit status is 8
diff --git a/tests/f_desc_size_zero/image.gz b/tests/f_desc_size_zero/image.gz
new file mode 100644
index 000000000..4e43c0c61
--- /dev/null
+++ b/tests/f_desc_size_zero/image.gz
Binary files differ
diff --git a/tests/f_desc_size_zero/name b/tests/f_desc_size_zero/name
new file mode 100644
index 000000000..e77bb11c2
--- /dev/null
+++ b/tests/f_desc_size_zero/name
@@ -0,0 +1 @@
+zero s_desc_size
diff --git a/tests/f_desc_size_zero/script b/tests/f_desc_size_zero/script
new file mode 100644
index 000000000..8ab2b9c61
--- /dev/null
+++ b/tests/f_desc_size_zero/script
@@ -0,0 +1,2 @@
+ONE_PASS_ONLY="true"
+. $cmd_dir/run_e2fsck