e2fsprogs 16T fixes from upstream.

make package metadata refer to ext3 as well as ext2.
This commit is contained in:
Eric Sandeen 2006-09-27 19:26:10 +00:00
parent 2a76ca36e3
commit 3b7ddeed65
12 changed files with 2455 additions and 14 deletions

View File

@ -0,0 +1,168 @@
# HG changeset patch
# User tytso@mit.edu
# Date Tue Sep 12 14:56:17 2006 -0400
# Node ID 7e1e8751d2be27716166e88453b52273b7096039
# parent: 1aa8aca8acebca38b38ee003c17a045bc5fde185
Add checks to make sure inode counts don't overflow a 32-bit value
Signed-off-by: Eric Sandeen <esandeen@redhat.com>
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/ChangeLog
@@ -6,6 +6,10 @@
2006-08-30 Eric Sandeen <esandeen@redhat.com>
+ * unix.c (show_stats): use ext2_ino_t for inode containers.
+
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
* e2fsck.h (e2fsck): Use unsigned types for filesystem counters.
* emptydir.c (add_empty_dirblock):
* iscan.c (main):
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/unix.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/unix.c
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/unix.c
@@ -98,7 +98,7 @@ static void usage(e2fsck_t ctx)
static void show_stats(e2fsck_t ctx)
{
ext2_filsys fs = ctx->fs;
- __u32 inodes, inodes_used;
+ ext2_ino_t inodes, inodes_used;
blk_t blocks, blocks_used;
int dir_links;
int num_files, num_links;
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/ChangeLog
@@ -8,6 +8,11 @@
2006-08-30 Eric Sandeen <esandeen@redhat.com>
+ * initialize.c (ext2fs_initialize): Make sure inode count does
+ not overflow 32 bits.
+
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
* bmove.c (process_block):
* getsize.c (main):
* icount.c (ext2fs_create_icount2, insert_icount_el):
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/initialize.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/initialize.c
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/initialize.c
@@ -246,9 +246,8 @@ retry:
if (ipg > (unsigned) EXT2_MAX_INODES_PER_GROUP(super))
ipg = EXT2_MAX_INODES_PER_GROUP(super);
+ipg_retry:
super->s_inodes_per_group = ipg;
- if (super->s_inodes_count > ipg * fs->group_desc_count)
- super->s_inodes_count = ipg * fs->group_desc_count;
/*
* Make sure the number of inodes per group completely fills
@@ -276,6 +275,10 @@ retry:
/*
* adjust inode count to reflect the adjusted inodes_per_group
*/
+ if ((__u64)super->s_inodes_per_group * fs->group_desc_count > ~0U) {
+ ipg--;
+ goto ipg_retry;
+ }
super->s_inodes_count = super->s_inodes_per_group *
fs->group_desc_count;
super->s_free_inodes_count = super->s_inodes_count;
Index: e2fsprogs-1.39-my-patches-from-ted/misc/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/misc/ChangeLog
@@ -5,6 +5,10 @@
2006-08-30 Eric Sandeen <esandeen@redhat.com>
+ * mke2fs.c (PRS): Disallow > 2^32 inodes at mkfs time.
+
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
* dumpe2fs.c (list_bad_blocks):
* e2image.c (output_meta_data_blocks, write_raw_image_file):
* mke2fs.c (test_disk, handle_bad_blocks): Fix printf formats.
Index: e2fsprogs-1.39-my-patches-from-ted/misc/mke2fs.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/mke2fs.c
+++ e2fsprogs-1.39-my-patches-from-ted/misc/mke2fs.c
@@ -895,7 +895,7 @@ static void PRS(int argc, char *argv[])
double reserved_ratio = 5.0;
int sector_size = 0;
int show_version_only = 0;
- ext2_ino_t num_inodes = 0;
+ __u64 num_inodes = 0; /* u64 to catch too-large input */
errcode_t retval;
char * oldpath = getenv("PATH");
char * extended_opts = 0;
@@ -1430,6 +1430,21 @@ static void PRS(int argc, char *argv[])
fs_param.s_inode_size = inode_size;
}
+ /* Make sure number of inodes specified will fit in 32 bits */
+ if (num_inodes == 0) {
+ __u64 n;
+ n = (__u64) fs_param.s_blocks_count * blocksize / inode_ratio;
+ if (n > ~0U) {
+ com_err(program_name, 0,
+ _("too many inodes (%llu), raise inode ratio?"), n);
+ exit(1);
+ }
+ } else if (num_inodes > ~0U) {
+ com_err(program_name, 0,
+ _("too many inodes (%llu), specify < 2^32 inodes"),
+ (__u64)num_inodes);
+ exit(1);
+ }
/*
* Calculate number of inodes based on the inode ratio
*/
Index: e2fsprogs-1.39-my-patches-from-ted/resize/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/resize/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/resize/ChangeLog
@@ -1,5 +1,9 @@
2006-08-30 Eric Sandeen <esandeen@redhat.com>
+ * resize2fs.c (adjust_fs_info): Disallow > 2^32 indoes at resize time.
+
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
* online.c (online_resize_fs): Fix printf formats.
2006-08-30 Eric Sandeen <esandeen@redhat.com>
Index: e2fsprogs-1.39-my-patches-from-ted/resize/resize2fs.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/resize/resize2fs.c
+++ e2fsprogs-1.39-my-patches-from-ted/resize/resize2fs.c
@@ -186,6 +186,7 @@ errcode_t adjust_fs_info(ext2_filsys fs,
unsigned long i, j, old_desc_blocks, max_group;
unsigned int meta_bg, meta_bg_size;
int has_super;
+ __u64 new_inodes; /* u64 to check for overflow */
fs->super->s_blocks_count = new_size;
@@ -226,6 +227,12 @@ retry:
/*
* Adjust the number of inodes
*/
+ new_inodes =(__u64)fs->super->s_inodes_per_group * fs->group_desc_count;
+ if (new_inodes > ~0U) {
+ fprintf(stderr, _("inodes (%llu) must be less than %u"),
+ new_inodes, ~0U);
+ return EXT2_ET_TOO_MANY_INODES;
+ }
fs->super->s_inodes_count = fs->super->s_inodes_per_group *
fs->group_desc_count;

View File

@ -0,0 +1,216 @@
# HG changeset patch
# User tytso@mit.edu
# Date Wed Aug 30 03:08:13 2006 -0400
# Node ID 4a2b0d6c55fc3bea9e5bed4faa82845676f3be2b
# parent: 14e45223b10be14cc318f10b804a3fd535a86ad5
Fix potential 2**32-1 overflow by using e2p_percent()
Add a new functiom, e2p_percent(), which correct calculates the percentage
of a number based on a given percentage, without worrying about overflow
issues. This is used where we calculate the number of reserved blocks using
a percentage of the total number of blocks in a filesystem.
Based on patches from Eric Sandeen, but generalized to use this new function.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Eric Sandeen <esandeen@redhat.com>
Index: e2fsprogs-1.39-my-patches-from-ted/lib/e2p/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/e2p/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/lib/e2p/ChangeLog
@@ -1,3 +1,9 @@
+2006-08-30 Theodore Tso <tytso@mit.edu>
+
+ * percent.c (e2p_percent): Add a new function which accurate and
+ without risk of overflow calculates a percentage of a base
+ number.
+
2006-05-08 Theodore Tso <tytso@mit.edu>
* feature.c: Add support for EXT2_FEATURE_COMPAT_LAZY_BG feature.
Index: e2fsprogs-1.39-my-patches-from-ted/lib/e2p/Makefile.in
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/e2p/Makefile.in
+++ e2fsprogs-1.39-my-patches-from-ted/lib/e2p/Makefile.in
@@ -19,7 +19,7 @@ all:: e2p.pc
OBJS= feature.o fgetflags.o fsetflags.o fgetversion.o fsetversion.o \
getflags.o getversion.o hashstr.o iod.o ls.o mntopts.o \
parse_num.o pe.o pf.o ps.o setflags.o setversion.o uuid.o \
- ostype.o
+ ostype.o percent.o
SRCS= $(srcdir)/feature.c $(srcdir)/fgetflags.c \
$(srcdir)/fsetflags.c $(srcdir)/fgetversion.c \
@@ -28,7 +28,7 @@ SRCS= $(srcdir)/feature.c $(srcdir)/fge
$(srcdir)/ls.c $(srcdir)/mntopts.c $(srcdir)/parse_num.c \
$(srcdir)/pe.c $(srcdir)/pf.c $(srcdir)/ps.c \
$(srcdir)/setflags.c $(srcdir)/setversion.c $(srcdir)/uuid.c \
- $(srcdir)/ostype.c
+ $(srcdir)/ostype.c $(srcdir)/percent.o
HFILES= e2p.h
LIBRARY= libe2p
Index: e2fsprogs-1.39-my-patches-from-ted/lib/e2p/e2p.h
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/e2p/e2p.h
+++ e2fsprogs-1.39-my-patches-from-ted/lib/e2p/e2p.h
@@ -50,3 +50,5 @@ unsigned long parse_num_blocks(const cha
char *e2p_os2string(int os_type);
int e2p_string2os(char *str);
+
+unsigned int e2p_percent(int percent, unsigned int base);
Index: e2fsprogs-1.39-my-patches-from-ted/misc/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/misc/ChangeLog
@@ -1,5 +1,9 @@
2006-08-30 Theodore Tso <tytso@mit.edu>
+ * tune2fs.c (main), mke2fs.c (PRS): Use e2p_percent to properly
+ calculate the number of reserved blocks without worrying
+ about overflow.
+
* mke2fs.c (parse_extended_opts): Use ext2fs_div_ceil() instead of
a using an open-coded expression which was subject to
overflows.
Index: e2fsprogs-1.39-my-patches-from-ted/misc/mke2fs.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/mke2fs.c
+++ e2fsprogs-1.39-my-patches-from-ted/misc/mke2fs.c
@@ -1440,8 +1440,8 @@ static void PRS(int argc, char *argv[])
/*
* Calculate number of blocks to reserve
*/
- fs_param.s_r_blocks_count = (fs_param.s_blocks_count * reserved_ratio)
- / 100;
+ fs_param.s_r_blocks_count = e2p_percent(reserved_ratio,
+ fs_param.s_blocks_count);
}
int main (int argc, char *argv[])
Index: e2fsprogs-1.39-my-patches-from-ted/misc/tune2fs.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/tune2fs.c
+++ e2fsprogs-1.39-my-patches-from-ted/misc/tune2fs.c
@@ -823,7 +823,8 @@ int main (int argc, char ** argv)
printf (_("Setting interval between checks to %lu seconds\n"), interval);
}
if (m_flag) {
- sb->s_r_blocks_count = sb->s_blocks_count * reserved_ratio /100;
+ sb->s_r_blocks_count = e2p_percent(reserved_ratio,
+ sb->s_blocks_count);
ext2fs_mark_super_dirty(fs);
printf (_("Setting reserved blocks percentage to %g%% (%u blocks)\n"),
reserved_ratio, sb->s_r_blocks_count);
Index: e2fsprogs-1.39-my-patches-from-ted/resize/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/resize/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/resize/ChangeLog
@@ -1,5 +1,9 @@
2006-08-30 Theodore Tso <tytso@mit.edu>
+ * resize2fs.c (adjust_fs_info), online.c (online_resize_fs): Use
+ e2p_percent to properly calculate the number of reserved
+ blocks without worrying about overflow.
+
* resize2fs.c (ext2fs_calculate_summary_stats): Fix potential
overflow problems when the number of blocks is close to
2**31.
Index: e2fsprogs-1.39-my-patches-from-ted/resize/online.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/resize/online.c
+++ e2fsprogs-1.39-my-patches-from-ted/resize/online.c
@@ -107,7 +107,8 @@ errcode_t online_resize_fs(ext2_filsys f
sb->s_first_data_block -
(i * sb->s_blocks_per_group);
}
- input.reserved_blocks = input.blocks_count * r_frac / 100;
+ input.reserved_blocks = e2p_percent(r_frac,
+ input.blocks_count);
#if 0
printf("new block bitmap is at 0x%04x\n", input.block_bitmap);
Index: e2fsprogs-1.39-my-patches-from-ted/resize/resize2fs.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/resize/resize2fs.c
+++ e2fsprogs-1.39-my-patches-from-ted/resize/resize2fs.c
@@ -245,8 +245,8 @@ retry:
*/
blk = old_fs->super->s_r_blocks_count * 100 /
old_fs->super->s_blocks_count;
- fs->super->s_r_blocks_count = ((fs->super->s_blocks_count * blk)
- / 100);
+ fs->super->s_r_blocks_count = e2p_percent(blk,
+ fs->super->s_blocks_count);
/*
* Adjust the bitmaps for size
Index: e2fsprogs-1.39-my-patches-from-ted/lib/e2p/percent.c
===================================================================
--- /dev/null
+++ e2fsprogs-1.39-my-patches-from-ted/lib/e2p/percent.c
@@ -0,0 +1,62 @@
+/*
+ * percent.c - Take percentage of a number
+ *
+ * Copyright (C) 2006 Theodore Ts'o <tytso@mit.edu>
+ *
+ * This file can be redistributed under the terms of the GNU Library General
+ * Public License
+ */
+
+#include "e2p.h"
+
+#include <stdlib.h>
+
+/*
+ * We work really hard to calculate this accurately, while avoiding
+ * an overflow. "Is there a hyphen in anal-retentive?" :-)
+ */
+unsigned int e2p_percent(int percent, unsigned int base)
+{
+ unsigned int mask = ~((1 << (sizeof(unsigned int) - 1) * 8) - 1);
+
+ if (100 % percent == 0)
+ return base / (100 / percent);
+ if (mask & base)
+ return (base / 100) * percent;
+ return base * percent / 100;
+}
+
+#ifdef DEBUG
+#include <unistd.h>
+#include <stdio.h>
+
+main(int argc, char **argv)
+{
+ unsigned int base;
+ int percent;
+ char *p;
+ int log_block_size = 0;
+
+ if (argc != 3) {
+ fprintf(stderr, "Usage: %s percent base\n", argv[0]);
+ exit(1);
+ }
+
+ percent = strtoul(argv[1], &p, 0);
+ if (p[0] && p[1]) {
+ fprintf(stderr, "Bad percent: %s\n", argv[1]);
+ exit(1);
+ }
+
+ base = strtoul(argv[2], &p, 0);
+ if (p[0] && p[1]) {
+ fprintf(stderr, "Bad base: %s\n", argv[2]);
+ exit(1);
+ }
+
+ printf("%d percent of %u is %u.\n", percent, base,
+ e2p_percent(percent, base));
+
+ exit(0);
+}
+#endif

View File

@ -0,0 +1,132 @@
Return-Path: <linux-ext4-owner@vger.kernel.org>
Received: from pobox-2.corp.redhat.com ([unix socket])
by pobox-2.corp.redhat.com (Cyrus v2.2.12-Invoca-RPM-2.2.12-3.RHEL4.1) with LMTPA;
Wed, 20 Sep 2006 05:01:05 -0400
X-Sieve: CMU Sieve 2.2
Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254])
by pobox-2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id k8K915WI028994
for <esandeen@pobox-2.corp.redhat.com>; Wed, 20 Sep 2006 05:01:05 -0400
Received: from mx3.redhat.com (mx3.redhat.com [172.16.48.32])
by int-mx1.corp.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id k8K913p5009001;
Wed, 20 Sep 2006 05:01:03 -0400
Received: from vger.kernel.org (vger.kernel.org [209.132.176.167])
by mx3.redhat.com (8.13.1/8.13.1) with ESMTP id k8K8q7e4029305;
Wed, 20 Sep 2006 05:00:57 -0400
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
id S1750745AbWITI4c (ORCPT <rfc822;twoerner@redhat.com> + 3 others);
Wed, 20 Sep 2006 04:56:32 -0400
Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1750747AbWITI4c
(ORCPT <rfc822;linux-ext4-outgoing>);
Wed, 20 Sep 2006 04:56:32 -0400
Received: from ecfrec.frec.bull.fr ([129.183.4.8]:62635 "EHLO
ecfrec.frec.bull.fr") by vger.kernel.org with ESMTP
id S1750745AbWITI4a (ORCPT <rfc822;linux-ext4@vger.kernel.org>);
Wed, 20 Sep 2006 04:56:30 -0400
Received: from localhost (localhost [127.0.0.1])
by ecfrec.frec.bull.fr (Postfix) with ESMTP id 8B9F219D943
for <linux-ext4@vger.kernel.org>; Wed, 20 Sep 2006 10:56:28 +0200 (CEST)
Received: from ecfrec.frec.bull.fr ([127.0.0.1])
by localhost (ecfrec.frec.bull.fr [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id 22796-03 for <linux-ext4@vger.kernel.org>;
Wed, 20 Sep 2006 10:56:25 +0200 (CEST)
Received: from ecn002.frec.bull.fr (ecn002.frec.bull.fr [129.183.4.6])
by ecfrec.frec.bull.fr (Postfix) with ESMTP id 8D8AB19D94C
for <linux-ext4@vger.kernel.org>; Wed, 20 Sep 2006 10:56:09 +0200 (CEST)
Received: from openx1.frec.bull.fr ([129.183.10.3])
by ecn002.frec.bull.fr (Lotus Domino Release 5.0.12)
with ESMTP id 2006092011020109:122246 ;
Wed, 20 Sep 2006 11:02:01 +0200
Received: by openx1.frec.bull.fr (Postfix, from userid 15348)
id 7751E139B4; Wed, 20 Sep 2006 10:56:08 +0200 (CEST)
Date: Wed, 20 Sep 2006 10:56:08 +0200
From: Alexandre Ratchov <alexandre.ratchov@bull.net>
To: linux-ext4@vger.kernel.org
Cc: Jean-Pierre Dion <jean-pierre.dion@bull.net>
Subject: [patch] small fix for e2p_percent()
Message-ID: <20060920085608.GA18351@openx1.frec.bull.fr>
Mime-Version: 1.0
User-Agent: Mutt/1.4.1i
X-MIMETrack: Itemize by SMTP Server on ECN002/FR/BULL(Release 5.0.12 |February 13, 2003) at
20/09/2006 11:02:01,
Serialize by Router on ECN002/FR/BULL(Release 5.0.12 |February 13, 2003) at
20/09/2006 11:02:02,
Serialize complete at 20/09/2006 11:02:02
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
X-Virus-Scanned: by amavisd-new at frec.bull.fr
Sender: linux-ext4-owner@vger.kernel.org
Precedence: bulk
X-Mailing-List: linux-ext4@vger.kernel.org
X-RedHat-Spam-Score: 0
hello,
e2p_percent() doesn't work for zero percent (``mke2fs -m0'' gets killed with
SIGFPE).
is there a reason for not simply using 64 bit arithmetic? perhaps to avoid
overflows for 7e+9TB file-systems :-), or just for correctness...
So, here is the patch that fixes this. In order to avoid integer overflows,
we pick 16 more bits to store ``base'' and do the exact division on 48 bits.
Since ``100 * base'' always fits in 48 bits, there's never overflow. This
still work if we remplace 'unsigned int' by 'unsigned long long'.
cheers,
-- Alexandre
Signed-off-by: Alexandre Ratchov <alexandre.ratchov@bull.net>
Index: e2fsprogs-1.39-my-patches-from-ted/lib/e2p/percent.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/e2p/percent.c
+++ e2fsprogs-1.39-my-patches-from-ted/lib/e2p/percent.c
@@ -14,18 +14,41 @@
/*
* We work really hard to calculate this accurately, while avoiding
* an overflow. "Is there a hyphen in anal-retentive?" :-)
+ *
+ * -- "Yes there is, as in hair-splitting and nit-picking"
*/
unsigned int e2p_percent(int percent, unsigned int base)
{
- unsigned int mask = ~((1 << (sizeof(unsigned int) - 1) * 8) - 1);
+ unsigned hi, lo, q, r;
- if (100 % percent == 0)
- return base / (100 / percent);
- if (mask & base)
- return (base / 100) * percent;
- return base * percent / 100;
+ /*
+ * in order to avoid overflow we write 'base' as:
+ *
+ * base = hi * 2^16 + lo
+ *
+ * then we do all computations separately on 'hi' and 'lo'.
+ * By using the definition of division:
+ *
+ * precent * base = result * 100 + reminder
+ *
+ * (reminder < 100), we obtain the exact value of 'result'
+ * as follows:
+ */
+#define BITS 16
+#define MASK ((1 << BITS) - 1)
+
+ hi = percent * (base >> BITS);
+ lo = percent * (base & MASK);
+
+ q = ((hi / 100) << BITS) + lo / 100;
+ r = ((hi % 100) << BITS) + lo % 100;
+
+ return q + r / 100;
+#undef BITS
+#undef MASK
}
+
#ifdef DEBUG
#include <unistd.h>
#include <stdio.h>

View File

@ -0,0 +1,282 @@
# HG changeset patch
# User tytso@mit.edu
# Date Wed Aug 30 01:57:00 2006 -0400
# Node ID 59f8a8974d914231642239f176284d92dce0678d
# parent: c76ddbe4519a571de3868c2888d8bb99a559046f
Fix potential 2**32-1 overflow problems by ext2fs_div_ceil()
Add a new function, ext2fs_div_ceil(), which correctly calculates a division
of two unsigned integer where the result is always rounded up the next
largest integer. This is used everywhere where we might have
previously caused an overflow when the number of blocks
or inodes is too close to 2**32-1.
Based on patches from Eric Sandeen, but generalized to use this new function
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Eric Sandeen <esandeen@redhat.com>
Index: e2fsprogs-1.39-my-patches-from-ted/ext2ed/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/ext2ed/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/ext2ed/ChangeLog
@@ -1,3 +1,8 @@
+2006-08-30 Theodore Tso <tytso@mit.edu>
+
+ * init.c (div_ceil, set_file_system_info): Fix potential overflow
+ for really big filesystems.
+
2006-06-30 Theodore Ts'o <tytso@mit.edu>
* Release of E2fsprogs 1.38
Index: e2fsprogs-1.39-my-patches-from-ted/ext2ed/init.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/ext2ed/init.c
+++ e2fsprogs-1.39-my-patches-from-ted/ext2ed/init.c
@@ -370,6 +370,13 @@ void add_user_command (struct struct_com
ptr->callback [num]=callback;
}
+static unsigned int div_ceil(unsigned int a, unsigned int b)
+{
+ if (!a)
+ return 0;
+ return ((a - 1) / b) + 1;
+}
+
int set_file_system_info (void)
{
@@ -415,8 +422,8 @@ int set_file_system_info (void)
file_system_info.first_group_desc_offset=2*EXT2_MIN_BLOCK_SIZE;
else
file_system_info.first_group_desc_offset=file_system_info.block_size;
- file_system_info.groups_count=( sb->s_blocks_count-sb->s_first_data_block+sb->s_blocks_per_group-1) /
- sb->s_blocks_per_group;
+ file_system_info.groups_count = div_ceil(sb->s_blocks_count,
+ sb->s_blocks_per_group);
file_system_info.inodes_per_block=file_system_info.block_size/sizeof (struct ext2_inode);
file_system_info.blocks_per_group=sb->s_inodes_per_group/file_system_info.inodes_per_block;
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/ChangeLog
@@ -1,3 +1,14 @@
+2006-08-30 Theodore Tso <tytso@mit.edu>
+
+ * ext2fs.h (ext2fs_div_ceil): Add new function which safely
+ calculates an integer division where the result is always
+ rounded up while avoiding overflow errors.
+
+ * initialize.c (calc_reserved_gdt_blocks, ext2fs_initialize):
+ * openfs.c (ext2fs_open2): Use ext2fs_div_ceil() instead of a
+ using an open-coded expression which was subject to
+ overflows.
+
2006-05-21 Theodore Tso <tytso@mit.edu>
* openfs.c (ext2fs_open2): Fix type warning problem with sizeof()
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/ext2fs.h
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/ext2fs.h
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/ext2fs.h
@@ -969,6 +969,7 @@ extern int ext2fs_group_of_blk(ext2_fils
extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
struct ext2_inode *inode);
+extern unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b);
/*
* The actual inlined functions definitions themselves...
@@ -1136,6 +1137,16 @@ _INLINE_ blk_t ext2fs_inode_data_blocks(
return inode->i_blocks -
(inode->i_file_acl ? fs->blocksize >> 9 : 0);
}
+
+/*
+ * This is an efficient, overflow safe way of calculating ceil((1.0 * a) / b)
+ */
+_INLINE_ unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b)
+{
+ if (!a)
+ return 0;
+ return ((a - 1) / b) + 1;
+}
#undef _INLINE_
#endif
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/initialize.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/initialize.c
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/initialize.c
@@ -77,8 +77,8 @@ static unsigned int calc_reserved_gdt_bl
*/
if (sb->s_blocks_count < max_blocks / 1024)
max_blocks = sb->s_blocks_count * 1024;
- rsv_groups = (max_blocks - sb->s_first_data_block + bpg - 1) / bpg;
- rsv_gdb = (rsv_groups + gdpb - 1) / gdpb - fs->desc_blocks;
+ rsv_groups = ext2fs_div_ceil(max_blocks - sb->s_first_data_block, bpg);
+ rsv_gdb = ext2fs_div_ceil(rsv_groups, gdpb) - fs->desc_blocks;
if (rsv_gdb > EXT2_ADDR_PER_BLOCK(sb))
rsv_gdb = EXT2_ADDR_PER_BLOCK(sb);
#ifdef RES_GDT_DEBUG
@@ -205,17 +205,15 @@ errcode_t ext2fs_initialize(const char *
}
retry:
- fs->group_desc_count = (super->s_blocks_count -
- super->s_first_data_block +
- EXT2_BLOCKS_PER_GROUP(super) - 1)
- / EXT2_BLOCKS_PER_GROUP(super);
+ fs->group_desc_count = ext2fs_div_ceil(super->s_blocks_count -
+ super->s_first_data_block,
+ EXT2_BLOCKS_PER_GROUP(super));
if (fs->group_desc_count == 0) {
retval = EXT2_ET_TOOSMALL;
goto cleanup;
}
- fs->desc_blocks = (fs->group_desc_count +
- EXT2_DESC_PER_BLOCK(super) - 1)
- / EXT2_DESC_PER_BLOCK(super);
+ fs->desc_blocks = ext2fs_div_ceil(fs->group_desc_count,
+ EXT2_DESC_PER_BLOCK(super));
i = fs->blocksize >= 4096 ? 1 : 4096 / fs->blocksize;
set_field(s_inodes_count, super->s_blocks_count / i);
@@ -233,8 +231,7 @@ retry:
* should be. But make sure that we don't allocate more than
* one bitmap's worth of inodes each group.
*/
- ipg = (super->s_inodes_count + fs->group_desc_count - 1) /
- fs->group_desc_count;
+ ipg = ext2fs_div_ceil(super->s_inodes_count, fs->group_desc_count);
if (ipg > fs->blocksize * 8) {
if (super->s_blocks_per_group >= 256) {
/* Try again with slightly different parameters */
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/openfs.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/openfs.c
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/openfs.c
@@ -258,12 +258,11 @@ errcode_t ext2fs_open2(const char *name,
retval = EXT2_ET_CORRUPT_SUPERBLOCK;
goto cleanup;
}
- fs->group_desc_count = (fs->super->s_blocks_count -
- fs->super->s_first_data_block +
- blocks_per_group - 1) / blocks_per_group;
- fs->desc_blocks = (fs->group_desc_count +
- EXT2_DESC_PER_BLOCK(fs->super) - 1)
- / EXT2_DESC_PER_BLOCK(fs->super);
+ fs->group_desc_count = ext2fs_div_ceil(fs->super->s_blocks_count -
+ fs->super->s_first_data_block,
+ blocks_per_group);
+ fs->desc_blocks = ext2fs_div_ceil(fs->group_desc_count,
+ EXT2_DESC_PER_BLOCK(fs->super));
retval = ext2fs_get_mem(fs->desc_blocks * fs->blocksize,
&fs->group_desc);
if (retval)
Index: e2fsprogs-1.39-my-patches-from-ted/misc/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/misc/ChangeLog
@@ -1,3 +1,12 @@
+2006-08-30 Theodore Tso <tytso@mit.edu>
+
+ * mke2fs.c (parse_extended_opts): Use ext2fs_div_ceil() instead of
+ a using an open-coded expression which was subject to
+ overflows.
+
+ * filefrag.c (div_ceil, frag_report): Fix potential overflow for
+ really big filesystems.
+
2006-05-29 Theodore Tso <tytso@mit.edu>
* filefrag.c: Add support for ancient Linux systems that do not
Index: e2fsprogs-1.39-my-patches-from-ted/misc/filefrag.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/filefrag.c
+++ e2fsprogs-1.39-my-patches-from-ted/misc/filefrag.c
@@ -47,6 +47,13 @@ int verbose = 0;
#define EXT3_EXTENTS_FL 0x00080000 /* Inode uses extents */
#define EXT3_IOC_GETFLAGS _IOR('f', 1, long)
+static unsigned int div_ceil(unsigned int a, unsigned int b)
+{
+ if (!a)
+ return 0;
+ return ((a - 1) / b) + 1;
+}
+
static unsigned long get_bmap(int fd, unsigned long block)
{
int ret;
@@ -105,7 +112,7 @@ static void frag_report(const char *file
if (verbose) {
printf("Filesystem type is: %x\n", fsinfo.f_type);
}
- cylgroups = (fsinfo.f_blocks + fsinfo.f_bsize*8-1) / fsinfo.f_bsize*8;
+ cylgroups = div_ceil(fsinfo.f_blocks, fsinfo.f_bsize*8);
if (verbose) {
printf("Filesystem cylinder groups is approximately %ld\n",
cylgroups);
Index: e2fsprogs-1.39-my-patches-from-ted/misc/mke2fs.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/mke2fs.c
+++ e2fsprogs-1.39-my-patches-from-ted/misc/mke2fs.c
@@ -819,12 +819,12 @@ static void parse_extended_opts(struct e
if (!bpg)
bpg = blocksize * 8;
gdpb = blocksize / sizeof(struct ext2_group_desc);
- group_desc_count = (param->s_blocks_count +
- bpg - 1) / bpg;
+ group_desc_count =
+ ext2fs_div_ceil(param->s_blocks_count, bpg);
desc_blocks = (group_desc_count +
gdpb - 1) / gdpb;
- rsv_groups = (resize + bpg - 1) / bpg;
- rsv_gdb = (rsv_groups + gdpb - 1) / gdpb -
+ rsv_groups = ext2fs_div_ceil(resize, bpg);
+ rsv_gdb = ext2fs_div_ceil(rsv_groups, gdpb) -
desc_blocks;
if (rsv_gdb > (int) EXT2_ADDR_PER_BLOCK(param))
rsv_gdb = EXT2_ADDR_PER_BLOCK(param);
Index: e2fsprogs-1.39-my-patches-from-ted/resize/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/resize/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/resize/ChangeLog
@@ -1,3 +1,9 @@
+2006-08-30 Theodore Tso <tytso@mit.edu>
+
+ * resize2fs.c (adjust_fs_info): Use ext2fs_div_ceil() instead of a
+ using an open-coded expression which was subject to
+ overflows.
+
2006-05-22 Theodore Tso <tytso@mit.edu>
* resize2fs.8.in: Fixed spelling mistake (Addresses Debian Bug:
Index: e2fsprogs-1.39-my-patches-from-ted/resize/resize2fs.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/resize/resize2fs.c
+++ e2fsprogs-1.39-my-patches-from-ted/resize/resize2fs.c
@@ -190,15 +190,13 @@ errcode_t adjust_fs_info(ext2_filsys fs,
fs->super->s_blocks_count = new_size;
retry:
- fs->group_desc_count = (fs->super->s_blocks_count -
- fs->super->s_first_data_block +
- EXT2_BLOCKS_PER_GROUP(fs->super) - 1)
- / EXT2_BLOCKS_PER_GROUP(fs->super);
+ fs->group_desc_count = ext2fs_div_ceil(fs->super->s_blocks_count -
+ fs->super->s_first_data_block,
+ EXT2_BLOCKS_PER_GROUP(fs->super));
if (fs->group_desc_count == 0)
return EXT2_ET_TOOSMALL;
- fs->desc_blocks = (fs->group_desc_count +
- EXT2_DESC_PER_BLOCK(fs->super) - 1)
- / EXT2_DESC_PER_BLOCK(fs->super);
+ fs->desc_blocks = ext2fs_div_ceil(fs->group_desc_count,
+ EXT2_DESC_PER_BLOCK(fs->super));
/*
* Overhead is the number of bookkeeping blocks per group. It

View File

@ -0,0 +1,151 @@
# HG changeset patch
# User tytso@mit.edu
# Date Wed Aug 30 02:16:55 2006 -0400
# Node ID 14e45223b10be14cc318f10b804a3fd535a86ad5
# parent: d609388faa895de79ff143e53f8ed04557048c42
Detect overflows in loop counters
For loops such as:
for (i=1; i <= fs->super->s_blocks_count; i++) {
<do_stuff>
}
if i is an int and s_blocks_count is (2^32-1), the condition is never false.
Change these loops to:
for (i=1; i <= fs->super->s_blocks_count && i > 0; i++) {
<do_stuff>
}
to stop the loop when we overflow i
Signed-off-by: Eric Sandeen <esandeen@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/ChangeLog
@@ -1,3 +1,9 @@
+2006-08-30 Theodore Tso <tytso@mit.edu>
+
+ * pass5.c (check_inode_bitmaps, check_inode_end, check_block_end):
+ * pass4.c (e2fsck_pass4): Fix potential overflow problems when the
+ number of blocks is close to 2**31.
+
2006-05-29 Theodore Tso <tytso@mit.edu>
* pass1b.c: Add missing semicolon when HAVE_INTPTR_T is not defined
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/pass4.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/pass4.c
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/pass4.c
@@ -110,8 +110,9 @@ void e2fsck_pass4(e2fsck_t ctx)
if (ctx->progress)
if ((ctx->progress)(ctx, 4, 0, maxgroup))
return;
-
- for (i=1; i <= fs->super->s_inodes_count; i++) {
+
+ /* Protect loop from wrap-around if s_inodes_count maxed */
+ for (i=1; i <= fs->super->s_inodes_count && i > 0; i++) {
if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
return;
if ((i % fs->super->s_inodes_per_group) == 0) {
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/pass5.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/pass5.c
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/pass5.c
@@ -370,7 +370,8 @@ redo_counts:
EXT2_BG_INODE_UNINIT))
skip_group++;
- for (i = 1; i <= fs->super->s_inodes_count; i++) {
+ /* Protect loop from wrap-around if inodes_count is maxed */
+ for (i = 1; i <= fs->super->s_inodes_count && i > 0; i++) {
actual = ext2fs_fast_test_inode_bitmap(ctx->inode_used_map, i);
if (skip_group)
bitmap = 0;
@@ -528,8 +529,9 @@ static void check_inode_end(e2fsck_t ctx
}
if (save_inodes_count == end)
return;
-
- for (i = save_inodes_count + 1; i <= end; i++) {
+
+ /* protect loop from wrap-around if end is maxed */
+ for (i = save_inodes_count + 1; i <= end && i > save_inodes_count; i++) {
if (!ext2fs_test_inode_bitmap(fs->inode_map, i)) {
if (fix_problem(ctx, PR_5_INODE_BMAP_PADDING, &pctx)) {
for (i = save_inodes_count + 1; i <= end; i++)
@@ -572,8 +574,9 @@ static void check_block_end(e2fsck_t ctx
}
if (save_blocks_count == end)
return;
-
- for (i = save_blocks_count + 1; i <= end; i++) {
+
+ /* Protect loop from wrap-around if end is maxed */
+ for (i = save_blocks_count + 1; i <= end && i > save_blocks_count; i++) {
if (!ext2fs_test_block_bitmap(fs->block_map, i)) {
if (fix_problem(ctx, PR_5_BLOCK_BMAP_PADDING, &pctx)) {
for (i = save_blocks_count + 1; i <= end; i++)
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/ChangeLog
@@ -1,5 +1,8 @@
2006-08-30 Theodore Tso <tytso@mit.edu>
+ * bitmaps.c (ext2fs_set_bitmap_padding): Fix potential overflow
+ problems when the number of blocks is close to 2**31.
+
* ext2fs.h (ext2fs_div_ceil): Add new function which safely
calculates an integer division where the result is always
rounded up while avoiding overflow errors.
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/bitmaps.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/bitmaps.c
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/bitmaps.c
@@ -102,7 +102,10 @@ void ext2fs_set_bitmap_padding(ext2fs_ge
{
__u32 i, j;
- for (i=map->end+1, j = i - map->start; i <= map->real_end; i++, j++)
+ /* Protect loop from wrap-around if map->real_end is maxed */
+ for (i=map->end+1, j = i - map->start;
+ i <= map->real_end && i > map->end;
+ i++, j++)
ext2fs_set_bit(j, map->bitmap);
return;
Index: e2fsprogs-1.39-my-patches-from-ted/resize/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/resize/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/resize/ChangeLog
@@ -1,5 +1,9 @@
2006-08-30 Theodore Tso <tytso@mit.edu>
+ * resize2fs.c (ext2fs_calculate_summary_stats): Fix potential
+ overflow problems when the number of blocks is close to
+ 2**31.
+
* resize2fs.c (adjust_fs_info): Use ext2fs_div_ceil() instead of a
using an open-coded expression which was subject to
overflows.
Index: e2fsprogs-1.39-my-patches-from-ted/resize/resize2fs.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/resize/resize2fs.c
+++ e2fsprogs-1.39-my-patches-from-ted/resize/resize2fs.c
@@ -1582,7 +1582,9 @@ static errcode_t ext2fs_calculate_summar
total_free = 0;
count = 0;
group = 0;
- for (ino = 1; ino <= fs->super->s_inodes_count; ino++) {
+
+ /* Protect loop from wrap-around if s_inodes_count maxed */
+ for (ino = 1; ino <= fs->super->s_inodes_count && ino > 0; ino++) {
if (!ext2fs_fast_test_inode_bitmap(fs->inode_map, ino)) {
group_free++;
total_free++;

View File

@ -0,0 +1,552 @@
# HG changeset patch
# User tytso@mit.edu
# Date Tue Sep 12 14:56:15 2006 -0400
# Node ID 4b504bc7413f5ef17f8b62f4b3479da6bfa83efb
# parent: 59bf36fb8344bb7a3971af7df22d41f8d8b14610
Fix signed vs unsigned printf format strings for block and inode numbers
There were still some %d's lurking when we print blocks & inodes; also
many of the counters in the e2fsck_struct were signed, and probably
need to be unsigned to avoid overflows.
Signed-off-by: Eric Sandeen <esandeen@redhat.com>
Index: e2fsprogs-1.39-my-patches-from-ted/debugfs/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/debugfs/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/debugfs/ChangeLog
@@ -1,3 +1,7 @@
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
+ * htree.c (htree_dump_int_node): Fix printf formats.
+
2006-05-29 Theodore Tso <tytso@mit.edu>
* util.c (reset_getopt): In order to support ancient Linux header
Index: e2fsprogs-1.39-my-patches-from-ted/debugfs/htree.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/debugfs/htree.c
+++ e2fsprogs-1.39-my-patches-from-ted/debugfs/htree.c
@@ -114,7 +114,7 @@ static void htree_dump_int_node(ext2_fil
for (i=0; i < limit.count; i++) {
hash = i ? ext2fs_le32_to_cpu(ent[i].hash) : 0;
- fprintf(pager, "Entry #%d: Hash 0x%08x%s, block %d\n", i,
+ fprintf(pager, "Entry #%d: Hash 0x%08x%s, block %u\n", i,
hash, (hash & 1) ? " (**)" : "",
ext2fs_le32_to_cpu(ent[i].block));
}
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/ChangeLog
@@ -1,5 +1,12 @@
2006-08-30 Eric Sandeen <esandeen@redhat.com>
+ * e2fsck.h (e2fsck): Use unsigned types for filesystem counters.
+ * emptydir.c (add_empty_dirblock):
+ * iscan.c (main):
+ * unix.c (show_stats, check_if_skip): Fix printf formats.
+
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
* pass1.c (handle_fs_bad_blocks): Remove unused variables.
2006-08-30 Eric Sandeen <esandeen@redhat.com>
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/e2fsck.h
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/e2fsck.h
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/e2fsck.h
@@ -306,24 +306,24 @@ struct e2fsck_struct {
char start_meta[2], stop_meta[2];
/* File counts */
- int fs_directory_count;
- int fs_regular_count;
- int fs_blockdev_count;
- int fs_chardev_count;
- int fs_links_count;
- int fs_symlinks_count;
- int fs_fast_symlinks_count;
- int fs_fifo_count;
- int fs_total_count;
- int fs_badblocks_count;
- int fs_sockets_count;
- int fs_ind_count;
- int fs_dind_count;
- int fs_tind_count;
- int fs_fragmented;
- int large_files;
- int fs_ext_attr_inodes;
- int fs_ext_attr_blocks;
+ __u32 fs_directory_count;
+ __u32 fs_regular_count;
+ __u32 fs_blockdev_count;
+ __u32 fs_chardev_count;
+ __u32 fs_links_count;
+ __u32 fs_symlinks_count;
+ __u32 fs_fast_symlinks_count;
+ __u32 fs_fifo_count;
+ __u32 fs_total_count;
+ __u32 fs_badblocks_count;
+ __u32 fs_sockets_count;
+ __u32 fs_ind_count;
+ __u32 fs_dind_count;
+ __u32 fs_tind_count;
+ __u32 fs_fragmented;
+ __u32 large_files;
+ __u32 fs_ext_attr_inodes;
+ __u32 fs_ext_attr_blocks;
time_t now;
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/emptydir.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/emptydir.c
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/emptydir.c
@@ -94,7 +94,7 @@ void add_empty_dirblock(empty_dir_info e
if (db->ino == 11)
return; /* Inode number 11 is usually lost+found */
- printf(_("Empty directory block %u (#%d) in inode %d\n"),
+ printf(_("Empty directory block %u (#%d) in inode %u\n"),
db->blk, db->blockcnt, db->ino);
ext2fs_mark_block_bitmap(edi->empty_dir_blocks, db->blk);
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/iscan.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/iscan.c
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/iscan.c
@@ -98,7 +98,7 @@ int main (int argc, char *argv[])
int exit_value = FSCK_OK;
ext2_filsys fs;
ext2_ino_t ino;
- int num_inodes = 0;
+ __u32 num_inodes = 0;
struct ext2_inode inode;
ext2_inode_scan scan;
@@ -135,7 +135,7 @@ int main (int argc, char *argv[])
}
print_resource_track(NULL, &global_rtrack);
- printf(_("%d inodes scanned.\n"), num_inodes);
+ printf(_("%u inodes scanned.\n"), num_inodes);
exit(0);
}
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/unix.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/unix.c
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/unix.c
@@ -98,7 +98,7 @@ static void usage(e2fsck_t ctx)
static void show_stats(e2fsck_t ctx)
{
ext2_filsys fs = ctx->fs;
- int inodes, inodes_used;
+ __u32 inodes, inodes_used;
blk_t blocks, blocks_used;
int dir_links;
int num_files, num_links;
@@ -118,49 +118,48 @@ static void show_stats(e2fsck_t ctx)
frag_percent = (frag_percent + 5) / 10;
if (!verbose) {
- printf(_("%s: %d/%d files (%0d.%d%% non-contiguous), %u/%u blocks\n"),
+ printf(_("%s: %u/%u files (%0d.%d%% non-contiguous), %u/%u blocks\n"),
ctx->device_name, inodes_used, inodes,
frag_percent / 10, frag_percent % 10,
blocks_used, blocks);
return;
}
- printf (P_("\n%8d inode used (%d%%)\n", "\n%8d inodes used (%d%%)\n",
- inodes_used), inodes_used, 100 * inodes_used / inodes);
- printf (P_("%8d non-contiguous inode (%0d.%d%%)\n",
- "%8d non-contiguous inodes (%0d.%d%%)\n",
+ printf (P_("\n%8u inode used (%2.2f%%)\n", "\n%8u inodes used (%2.2f%%)\n",
+ inodes_used), inodes_used, 100.0 * inodes_used / inodes);
+ printf (P_("%8u non-contiguous inode (%0d.%d%%)\n",
+ "%8u non-contiguous inodes (%0d.%d%%)\n",
ctx->fs_fragmented),
ctx->fs_fragmented, frag_percent / 10, frag_percent % 10);
- printf (_(" # of inodes with ind/dind/tind blocks: %d/%d/%d\n"),
+ printf (_(" # of inodes with ind/dind/tind blocks: %u/%u/%u\n"),
ctx->fs_ind_count, ctx->fs_dind_count, ctx->fs_tind_count);
- printf (P_("%8u block used (%d%%)\n", "%8u blocks used (%d%%)\n",
- blocks_used),
- blocks_used, (int) ((long long) 100 * blocks_used / blocks));
- printf (P_("%8d bad block\n", "%8d bad blocks\n",
+ printf (P_("%8u block used (%2.2f%%)\n", "%8u blocks used (%2.2f%%)\n",
+ blocks_used), blocks_used, 100.0 * blocks_used / blocks);
+ printf (P_("%8u bad block\n", "%8u bad blocks\n",
ctx->fs_badblocks_count), ctx->fs_badblocks_count);
- printf (P_("%8d large file\n", "%8d large files\n",
+ printf (P_("%8u large file\n", "%8u large files\n",
ctx->large_files), ctx->large_files);
- printf (P_("\n%8d regular file\n", "\n%8d regular files\n",
+ printf (P_("\n%8u regular file\n", "\n%8u regular files\n",
ctx->fs_regular_count), ctx->fs_regular_count);
- printf (P_("%8d directory\n", "%8d directories\n",
+ printf (P_("%8u directory\n", "%8u directories\n",
ctx->fs_directory_count), ctx->fs_directory_count);
- printf (P_("%8d character device file\n",
- "%8d character device files\n", ctx->fs_chardev_count),
+ printf (P_("%8u character device file\n",
+ "%8u character device files\n", ctx->fs_chardev_count),
ctx->fs_chardev_count);
- printf (P_("%8d block device file\n", "%8d block device files\n",
+ printf (P_("%8u block device file\n", "%8u block device files\n",
ctx->fs_blockdev_count), ctx->fs_blockdev_count);
- printf (P_("%8d fifo\n", "%8d fifos\n", ctx->fs_fifo_count),
+ printf (P_("%8u fifo\n", "%8u fifos\n", ctx->fs_fifo_count),
ctx->fs_fifo_count);
- printf (P_("%8d link\n", "%8d links\n",
+ printf (P_("%8u link\n", "%8u links\n",
ctx->fs_links_count - dir_links),
ctx->fs_links_count - dir_links);
- printf (P_("%8d symbolic link", "%8d symbolic links",
+ printf (P_("%8u symbolic link", "%8u symbolic links",
ctx->fs_symlinks_count), ctx->fs_symlinks_count);
- printf (P_(" (%d fast symbolic link)\n", " (%d fast symbolic links)\n",
+ printf (P_(" (%u fast symbolic link)\n", " (%u fast symbolic links)\n",
ctx->fs_fast_symlinks_count), ctx->fs_fast_symlinks_count);
- printf (P_("%8d socket\n", "%8d sockets\n", ctx->fs_sockets_count),
+ printf (P_("%8u socket\n", "%8u sockets\n", ctx->fs_sockets_count),
ctx->fs_sockets_count);
printf ("--------\n");
- printf (P_("%8d file\n", "%8d files\n",
+ printf (P_("%8u file\n", "%8u files\n",
ctx->fs_total_count - dir_links),
ctx->fs_total_count - dir_links);
}
@@ -300,7 +299,7 @@ static void check_if_skip(e2fsck_t ctx)
fputs(_(", check forced.\n"), stdout);
return;
}
- printf(_("%s: clean, %d/%d files, %u/%u blocks"), ctx->device_name,
+ printf(_("%s: clean, %u/%u files, %u/%u blocks"), ctx->device_name,
fs->super->s_inodes_count - fs->super->s_free_inodes_count,
fs->super->s_inodes_count,
fs->super->s_blocks_count - fs->super->s_free_blocks_count,
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/ChangeLog
@@ -1,5 +1,17 @@
2006-08-30 Eric Sandeen <esandeen@redhat.com>
+ * bmove.c (process_block):
+ * getsize.c (main):
+ * icount.c (ext2fs_create_icount2, insert_icount_el):
+ * tst_badblocks.c (print_list, validate_test_seq, do_test_seq):
+ * tst_badblocks.c (invalid_proc):
+ * tst_getsize.c (main):
+ * tst_iscan.c (check_map):
+ * unix_io.c (raw_read_blk, unix_read_blk):
+ * write_bb_file.c (ext2fs_write_bb_FILE): Fix printf formats.
+
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
* closefs.c (write_backup_super):
* initialize.c (ext2fs_initialize): Remove unused variables.
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/bmove.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/bmove.c
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/bmove.c
@@ -73,7 +73,7 @@ static int process_block(ext2_filsys fs,
ext2fs_mark_block_bitmap(pb->alloc_map, block);
ret = BLOCK_CHANGED;
if (pb->flags & EXT2_BMOVE_DEBUG)
- printf("ino=%ld, blockcnt=%lld, %d->%d\n", pb->ino,
+ printf("ino=%ld, blockcnt=%lld, %u->%u\n", pb->ino,
blockcnt, orig, block);
}
if (pb->add_dir) {
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/getsize.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/getsize.c
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/getsize.c
@@ -302,7 +302,7 @@ int main(int argc, char **argv)
"while calling ext2fs_get_device_size");
exit(1);
}
- printf("Device %s has %d 1k blocks.\n", argv[1], blocks);
+ printf("Device %s has %u 1k blocks.\n", argv[1], blocks);
exit(0);
}
#endif
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/icount.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/icount.c
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/icount.c
@@ -116,7 +116,7 @@ errcode_t ext2fs_create_icount2(ext2_fil
bytes = (size_t) (icount->size * sizeof(struct ext2_icount_el));
#if 0
- printf("Icount allocated %d entries, %d bytes.\n",
+ printf("Icount allocated %u entries, %d bytes.\n",
icount->size, bytes);
#endif
retval = ext2fs_get_mem(bytes, &icount->list);
@@ -176,7 +176,7 @@ static struct ext2_icount_el *insert_ico
if (new_size < (icount->size + 100))
new_size = icount->size + 100;
#if 0
- printf("Reallocating icount %d entries...\n", new_size);
+ printf("Reallocating icount %u entries...\n", new_size);
#endif
retval = ext2fs_resize_mem((size_t) icount->size *
sizeof(struct ext2_icount_el),
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/tst_badblocks.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/tst_badblocks.c
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/tst_badblocks.c
@@ -103,7 +103,7 @@ static void print_list(badblocks_list bb
}
ok = i = 1;
while (ext2fs_badblocks_list_iterate(iter, &blk)) {
- printf("%d ", blk);
+ printf("%u ", blk);
if (i++ != blk)
ok = 0;
}
@@ -130,7 +130,7 @@ static void validate_test_seq(badblocks_
ok = 0;
test_fail++;
}
- printf("\tblock %d is %s --- %s\n", vec[i],
+ printf("\tblock %u is %s --- %s\n", vec[i],
match ? "present" : "absent",
ok ? "OK" : "NOT OK");
}
@@ -145,7 +145,7 @@ static void do_test_seq(badblocks_list b
case ADD_BLK:
ext2fs_badblocks_list_add(bb, vec[i]);
match = ext2fs_badblocks_list_test(bb, vec[i]);
- printf("Adding block %d --- now %s\n", vec[i],
+ printf("Adding block %u --- now %s\n", vec[i],
match ? "present" : "absent");
if (!match) {
printf("FAILURE!\n");
@@ -155,7 +155,7 @@ static void do_test_seq(badblocks_list b
case DEL_BLK:
ext2fs_badblocks_list_del(bb, vec[i]);
match = ext2fs_badblocks_list_test(bb, vec[i]);
- printf("Removing block %d --- now %s\n", vec[i],
+ printf("Removing block %u --- now %s\n", vec[i],
ext2fs_badblocks_list_test(bb, vec[i]) ?
"present" : "absent");
if (match) {
@@ -209,7 +209,7 @@ static void invalid_proc(ext2_filsys fs,
printf("Expected invalid block\n");
test_expected_fail++;
} else {
- printf("Invalid block #: %d\n", blk);
+ printf("Invalid block #: %u\n", blk);
test_fail++;
}
}
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/tst_getsize.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/tst_getsize.c
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/tst_getsize.c
@@ -39,6 +39,6 @@ int main(int argc, const char *argv[])
com_err(argv[0], retval, "while getting device size");
exit(1);
}
- printf("%s is device has %d blocks.\n", argv[1], blocks);
+ printf("%s is device has %u blocks.\n", argv[1], blocks);
return 0;
}
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/tst_iscan.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/tst_iscan.c
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/tst_iscan.c
@@ -175,7 +175,7 @@ static void check_map(void)
for (i=0; test_vec[i]; i++) {
if (ext2fs_test_block_bitmap(touched_map, test_vec[i])) {
- printf("Bad block was touched --- %d\n", test_vec[i]);
+ printf("Bad block was touched --- %u\n", test_vec[i]);
failed++;
first_no_comma = 1;
}
@@ -199,7 +199,7 @@ static void check_map(void)
first = 0;
else
printf(", ");
- printf("%d", i);
+ printf("%u", i);
}
}
printf("\n");
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/unix_io.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/unix_io.c
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/unix_io.c
@@ -170,8 +170,8 @@ static errcode_t raw_read_blk(io_channel
size = (count < 0) ? -count : count * channel->block_size;
location = ((ext2_loff_t) block * channel->block_size) + data->offset;
#ifdef DEBUG
- printf("count=%d, size=%d, block=%d, blk_size=%d, location=%lx\n",
- count, size, block, channel->block_size, location);
+ printf("count=%d, size=%d, block=%lu, blk_size=%d, location=%llx\n",
+ count, size, block, channel->block_size, (long long)location);
#endif
if (ext2fs_llseek(data->dev, location, SEEK_SET) != location) {
retval = errno ? errno : EXT2_ET_LLSEEK_FAILED;
@@ -553,7 +553,7 @@ static errcode_t unix_read_blk(io_channe
/* If it's in the cache, use it! */
if ((cache = find_cached_block(data, block, &reuse[0]))) {
#ifdef DEBUG
- printf("Using cached block %d\n", block);
+ printf("Using cached block %lu\n", block);
#endif
memcpy(cp, cache->buf, channel->block_size);
count--;
@@ -569,7 +569,7 @@ static errcode_t unix_read_blk(io_channe
if (find_cached_block(data, block+i, &reuse[i]))
break;
#ifdef DEBUG
- printf("Reading %d blocks starting at %d\n", i, block);
+ printf("Reading %d blocks starting at %lu\n", i, block);
#endif
if ((retval = raw_read_blk(channel, data, block, i, cp)))
return retval;
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/write_bb_file.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/write_bb_file.c
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/write_bb_file.c
@@ -27,7 +27,7 @@ errcode_t ext2fs_write_bb_FILE(ext2_badb
return retval;
while (ext2fs_badblocks_list_iterate(bb_iter, &blk)) {
- fprintf(f, "%d\n", blk);
+ fprintf(f, "%u\n", blk);
}
ext2fs_badblocks_list_iterate_end(bb_iter);
return 0;
Index: e2fsprogs-1.39-my-patches-from-ted/misc/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/misc/ChangeLog
@@ -1,5 +1,11 @@
2006-08-30 Eric Sandeen <esandeen@redhat.com>
+ * dumpe2fs.c (list_bad_blocks):
+ * e2image.c (output_meta_data_blocks, write_raw_image_file):
+ * mke2fs.c (test_disk, handle_bad_blocks): Fix printf formats.
+
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
* e2image.c (mark_table_blocks): Remove unused first_block
incrementing from loop.
Index: e2fsprogs-1.39-my-patches-from-ted/misc/dumpe2fs.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/dumpe2fs.c
+++ e2fsprogs-1.39-my-patches-from-ted/misc/dumpe2fs.c
@@ -250,10 +250,10 @@ static void list_bad_blocks(ext2_filsys
return;
}
if (dump) {
- header = fmt = "%d\n";
+ header = fmt = "%u\n";
} else {
- header = _("Bad blocks: %d");
- fmt = ", %d";
+ header = _("Bad blocks: %u");
+ fmt = ", %u";
}
while (ext2fs_badblocks_list_iterate(bb_iter, &blk)) {
printf(header ? header : fmt, blk);
Index: e2fsprogs-1.39-my-patches-from-ted/misc/e2image.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/e2image.c
+++ e2fsprogs-1.39-my-patches-from-ted/misc/e2image.c
@@ -417,7 +417,7 @@ static void output_meta_data_blocks(ext2
retval = io_channel_read_blk(fs->io, blk, 1, buf);
if (retval) {
com_err(program_name, retval,
- "error reading block %d", blk);
+ "error reading block %u", blk);
}
if (scramble_block_map &&
ext2fs_test_block_bitmap(scramble_block_map, blk))
@@ -516,7 +516,7 @@ static void write_raw_image_file(ext2_fi
block_buf, process_dir_block, &pb);
if (retval) {
com_err(program_name, retval,
- "while iterating over inode %d",
+ "while iterating over inode %u",
ino);
exit(1);
}
@@ -529,7 +529,7 @@ static void write_raw_image_file(ext2_fi
process_file_block, &pb);
if (retval) {
com_err(program_name, retval,
- "while iterating over %d", ino);
+ "while iterating over inode %u", ino);
exit(1);
}
}
Index: e2fsprogs-1.39-my-patches-from-ted/misc/mke2fs.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/mke2fs.c
+++ e2fsprogs-1.39-my-patches-from-ted/misc/mke2fs.c
@@ -188,7 +188,7 @@ static void test_disk(ext2_filsys fs, ba
errcode_t retval;
char buf[1024];
- sprintf(buf, "badblocks -b %d -X %s%s%s %d", fs->blocksize,
+ sprintf(buf, "badblocks -b %d -X %s%s%s %u", fs->blocksize,
quiet ? "" : "-s ", (cflag > 1) ? "-w " : "",
fs->device_name, fs->super->s_blocks_count);
if (verbose)
@@ -232,7 +232,7 @@ static void handle_bad_blocks(ext2_filsy
if (ext2fs_badblocks_list_test(bb_list, i)) {
fprintf(stderr, _("Block %d in primary "
"superblock/group descriptor area bad.\n"), i);
- fprintf(stderr, _("Blocks %u through %d must be good "
+ fprintf(stderr, _("Blocks %u through %u must be good "
"in order to build a filesystem.\n"),
fs->super->s_first_data_block, must_be_good);
fputs(_("Aborting....\n"), stderr);
Index: e2fsprogs-1.39-my-patches-from-ted/resize/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/resize/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/resize/ChangeLog
@@ -1,5 +1,9 @@
2006-08-30 Eric Sandeen <esandeen@redhat.com>
+ * online.c (online_resize_fs): Fix printf formats.
+
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
* resize2fs.c (mark_table_blocks): Remove unused variable.
2006-08-30 Theodore Tso <tytso@mit.edu>
Index: e2fsprogs-1.39-my-patches-from-ted/resize/online.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/resize/online.c
+++ e2fsprogs-1.39-my-patches-from-ted/resize/online.c
@@ -74,7 +74,7 @@ errcode_t online_resize_fs(ext2_filsys f
if (retval)
return retval;
- printf(_("Performing an on-line resize of %s to %d (%dk) blocks.\n"),
+ printf(_("Performing an on-line resize of %s to %u (%dk) blocks.\n"),
fs->device_name, *new_size, fs->blocksize / 1024);
size = fs->group_desc_count * sb->s_blocks_per_group +
@@ -116,7 +116,7 @@ errcode_t online_resize_fs(ext2_filsys f
printf("new inode table is at 0x%04x-0x%04x\n",
input.inode_table,
input.inode_table + new_fs->inode_blocks_per_group-1);
- printf("new group has %d blocks\n", input.blocks_count);
+ printf("new group has %u blocks\n", input.blocks_count);
printf("new group will reserve %d blocks\n",
input.reserved_blocks);
printf("new group has %d free blocks\n",

View File

@ -0,0 +1,288 @@
# HG changeset patch
# User tytso@mit.edu
# Date Tue Sep 12 14:56:16 2006 -0400
# Node ID 1aa8aca8acebca38b38ee003c17a045bc5fde185
# parent: 4b504bc7413f5ef17f8b62f4b3479da6bfa83efb
Create new ext2fs library inlines: ext2fs_group_{first,last}_block()
Create new ext2fs library inline functions in order to calculate
the starting and ending blocks in a block group.
Signed-off-by: Eric Sandeen <esandeen@redhat.com>
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/ChangeLog
@@ -1,5 +1,11 @@
2006-08-30 Eric Sandeen <esandeen@redhat.com>
+ * pass1.c (new_table_block, handle_fs_bad_blocks):
+ * super.c (check_super_block):
+ Use new inlines to calculate group first & last blocks.
+
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
* e2fsck.h (e2fsck): Use unsigned types for filesystem counters.
* emptydir.c (add_empty_dirblock):
* iscan.c (main):
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/pass1.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/pass1.c
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/pass1.c
@@ -1890,6 +1890,7 @@ static void new_table_block(e2fsck_t ctx
{
ext2_filsys fs = ctx->fs;
blk_t old_block = *new_block;
+ blk_t last_block;
int i;
char *buf;
struct problem_context pctx;
@@ -1900,8 +1901,8 @@ static void new_table_block(e2fsck_t ctx
pctx.blk = old_block;
pctx.str = name;
- pctx.errcode = ext2fs_get_free_blocks(fs, first_block,
- first_block + fs->super->s_blocks_per_group,
+ last_block = ext2fs_group_last_block(fs, group);
+ pctx.errcode = ext2fs_get_free_blocks(fs, first_block, last_block,
num, ctx->block_found_map, new_block);
if (pctx.errcode) {
pctx.num = num;
@@ -1952,9 +1953,11 @@ static void handle_fs_bad_blocks(e2fsck_
{
ext2_filsys fs = ctx->fs;
dgrp_t i;
- int first_block = fs->super->s_first_data_block;
+ int first_block;
for (i = 0; i < fs->group_desc_count; i++) {
+ first_block = ext2fs_group_first_block(fs, i);
+
if (ctx->invalid_block_bitmap_flag[i]) {
new_table_block(ctx, first_block, i, _("block bitmap"),
1, &fs->group_desc[i].bg_block_bitmap);
@@ -1969,7 +1972,6 @@ static void handle_fs_bad_blocks(e2fsck_
&fs->group_desc[i].bg_inode_table);
ctx->flags |= E2F_FLAG_RESTART;
}
- first_block += fs->super->s_blocks_per_group;
}
ctx->invalid_bitmaps = 0;
}
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/super.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/super.c
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/super.c
@@ -569,11 +569,9 @@ void check_super_block(e2fsck_t ctx)
for (i = 0, gd=fs->group_desc; i < fs->group_desc_count; i++, gd++) {
pctx.group = i;
-
- if (i == fs->group_desc_count - 1)
- last_block = sb->s_blocks_count - 1;
- else
- last_block = first_block + blocks_per_group - 1;
+
+ first_block = ext2fs_group_first_block(fs, i);
+ last_block = ext2fs_group_last_block(fs, i);
if ((gd->bg_block_bitmap < first_block) ||
(gd->bg_block_bitmap > last_block)) {
@@ -608,7 +606,6 @@ void check_super_block(e2fsck_t ctx)
}
free_blocks += gd->bg_free_blocks_count;
free_inodes += gd->bg_free_inodes_count;
- first_block += sb->s_blocks_per_group;
if ((gd->bg_free_blocks_count > sb->s_blocks_per_group) ||
(gd->bg_free_inodes_count > sb->s_inodes_per_group) ||
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/ChangeLog
@@ -1,5 +1,13 @@
2006-08-30 Eric Sandeen <esandeen@redhat.com>
+ * alloc_tables.c (ext2fs_allocate_group_table):
+ * check_desc.c (ext2fs_check_desc):
+ Use new inlines to calculate group first & last blocks.
+ * ext2fs.h:
+ Create new inlines to calculate first/last group blocks.
+
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
* bmove.c (process_block):
* getsize.c (main):
* icount.c (ext2fs_create_icount2, insert_icount_el):
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/alloc_tables.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/alloc_tables.c
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/alloc_tables.c
@@ -34,12 +34,8 @@ errcode_t ext2fs_allocate_group_table(ex
blk_t group_blk, start_blk, last_blk, new_blk, blk;
int j;
- group_blk = fs->super->s_first_data_block +
- (group * fs->super->s_blocks_per_group);
-
- last_blk = group_blk + fs->super->s_blocks_per_group;
- if (last_blk >= fs->super->s_blocks_count)
- last_blk = fs->super->s_blocks_count - 1;
+ group_blk = ext2fs_group_first_block(fs, group);
+ last_blk = ext2fs_group_last_block(fs, group);
if (!bmap)
bmap = fs->block_map;
@@ -54,8 +50,8 @@ errcode_t ext2fs_allocate_group_table(ex
return retval;
start_blk += fs->inode_blocks_per_group;
start_blk += ((fs->stride * group) %
- (last_blk - start_blk));
- if (start_blk > last_blk)
+ (last_blk - start_blk + 1));
+ if (start_blk >= last_blk)
start_blk = group_blk;
} else
start_blk = group_blk;
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/check_desc.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/check_desc.c
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/check_desc.c
@@ -38,11 +38,9 @@ errcode_t ext2fs_check_desc(ext2_filsys
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
for (i = 0; i < fs->group_desc_count; i++) {
- if (i == fs->group_desc_count - 1)
- last_block = fs->super->s_blocks_count - 1;
- else
- last_block = first_block +
- fs->super->s_blocks_per_group - 1;
+ first_block = ext2fs_group_first_block(fs, i);
+ last_block = ext2fs_group_last_block(fs, i);
+
/*
* Check to make sure block bitmap for group is
* located within the group.
@@ -65,8 +63,6 @@ errcode_t ext2fs_check_desc(ext2_filsys
((fs->group_desc[i].bg_inode_table +
fs->inode_blocks_per_group) > last_block))
return EXT2_ET_GDESC_BAD_INODE_TABLE;
-
- first_block += fs->super->s_blocks_per_group;
}
return 0;
}
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/ext2fs.h
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/ext2fs.h
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/ext2fs.h
@@ -967,6 +967,8 @@ extern int ext2fs_test_ib_dirty(ext2_fil
extern int ext2fs_test_bb_dirty(ext2_filsys fs);
extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
+extern blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group);
+extern blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group);
extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
struct ext2_inode *inode);
extern unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b);
@@ -1131,6 +1133,26 @@ _INLINE_ int ext2fs_group_of_ino(ext2_fi
return (ino - 1) / fs->super->s_inodes_per_group;
}
+/*
+ * Return the first block (inclusive) in a group
+ */
+_INLINE_ blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group)
+{
+ return fs->super->s_first_data_block +
+ (group * fs->super->s_blocks_per_group);
+}
+
+/*
+ * Return the last block (inclusive) in a group
+ */
+_INLINE_ blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group)
+{
+ return (group == fs->group_desc_count - 1 ?
+ fs->super->s_blocks_count - 1 :
+ ext2fs_group_first_block(fs, group) +
+ (fs->super->s_blocks_per_group - 1));
+}
+
_INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
struct ext2_inode *inode)
{
Index: e2fsprogs-1.39-my-patches-from-ted/misc/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/misc/ChangeLog
@@ -1,5 +1,10 @@
2006-08-30 Eric Sandeen <esandeen@redhat.com>
+ * dumpe2fs.c (list_desc): Use new inlines to calculate group
+ first & last blocks.
+
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
* dumpe2fs.c (list_bad_blocks):
* e2image.c (output_meta_data_blocks, write_raw_image_file):
* mke2fs.c (test_disk, handle_bad_blocks): Fix printf formats.
Index: e2fsprogs-1.39-my-patches-from-ted/misc/dumpe2fs.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/dumpe2fs.c
+++ e2fsprogs-1.39-my-patches-from-ted/misc/dumpe2fs.c
@@ -153,13 +153,11 @@ static void list_desc (ext2_filsys fs)
else
old_desc_blocks = fs->desc_blocks;
for (i = 0; i < fs->group_desc_count; i++) {
+ first_block = ext2fs_group_first_block(fs, i);
+ last_block = ext2fs_group_last_block(fs, i);
+
ext2fs_super_and_bgd_loc(fs, i, &super_blk,
&old_desc_blk, &new_desc_blk, 0);
- if (i == fs->group_desc_count - 1)
- last_block = fs->super->s_blocks_count - 1;
- else
- last_block = first_block +
- fs->super->s_blocks_per_group - 1;
printf (_("Group %lu: (Blocks "), i);
print_range(first_block, last_block);
@@ -226,7 +224,6 @@ static void list_desc (ext2_filsys fs)
fputc('\n', stdout);
inode_bitmap += fs->super->s_inodes_per_group / 8;
}
- first_block += fs->super->s_blocks_per_group;
}
}
Index: e2fsprogs-1.39-my-patches-from-ted/tests/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/tests/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/tests/ChangeLog
@@ -1,3 +1,9 @@
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
+ * m_raid_opt/expect.1:
+ Change expected values for last group due to correctly
+ calculated last block when using strides.
+
2006-05-28 Theodore Tso <tytso@mit.edu>
* test_config: Unset all locale-related environment variables
Index: e2fsprogs-1.39-my-patches-from-ted/tests/m_raid_opt/expect.1
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/tests/m_raid_opt/expect.1
+++ e2fsprogs-1.39-my-patches-from-ted/tests/m_raid_opt/expect.1
@@ -944,8 +944,8 @@ Group 126: (Blocks 129025-130048)
Free inodes: 32257-32512
Group 127: (Blocks 130049-131071)
Group descriptor at 130049
- Block bitmap at 130744 (+695), Inode bitmap at 130745 (+696)
+ Block bitmap at 130743 (+694), Inode bitmap at 130744 (+695)
Inode table at 130050-130081 (+1)
988 free blocks, 256 free inodes, 0 directories
- Free blocks: 130082-130743, 130746-131071
+ Free blocks: 130082-130742, 130745-131071
Free inodes: 32513-32768

View File

@ -0,0 +1,319 @@
# HG changeset patch
# User tytso@mit.edu
# Date Tue Sep 12 14:55:22 2006 -0400
# Node ID 90cd01f7fcd6293846f0b3ca6ce2b007e3dd7d51
# parent: cb841a8195a7aa87e8d0c95686291e8fb53358df
Fix loops over group descriptors to prevent 2**32-1 block number overflows
For loops iterating over all group descriptors, consistently define
first_block and last_block in a way that they are inclusive of the
range, and do not overflow.
Previously on the last block group we did a test of <= first +
dec_blocks; this would actually wrap back to 0 for a total block count
of 2^32-1
Also add handling of last block group which may be smaller.
Signed-off-by: Eric Sandeen <esandeen@redhat.com>
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/ChangeLog
@@ -1,3 +1,11 @@
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
+ * pass1b.c (check_if_fs_block): Change block group loop to use
+ a common pattern of first_block/last_block, etc.
+
+ * super.c (check_super_block): Avoid overflows when iterating over
+ group descriptors on very large filesystems
+
2006-08-30 Theodore Tso <tytso@mit.edu>
* pass5.c (check_inode_bitmaps, check_inode_end, check_block_end):
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/pass1b.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/pass1b.c
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/pass1b.c
@@ -779,16 +779,16 @@ errout:
static int check_if_fs_block(e2fsck_t ctx, blk_t test_block)
{
ext2_filsys fs = ctx->fs;
- blk_t block;
+ blk_t first_block;
dgrp_t i;
- block = fs->super->s_first_data_block;
+ first_block = fs->super->s_first_data_block;
for (i = 0; i < fs->group_desc_count; i++) {
- /* Check superblocks/block group descriptros */
+ /* Check superblocks/block group descriptors */
if (ext2fs_bg_has_super(fs, i)) {
- if (test_block >= block &&
- (test_block <= block + fs->desc_blocks))
+ if (test_block >= first_block &&
+ (test_block <= first_block + fs->desc_blocks))
return 1;
}
@@ -804,7 +804,7 @@ static int check_if_fs_block(e2fsck_t ct
(test_block == fs->group_desc[i].bg_inode_bitmap))
return 1;
- block += fs->super->s_blocks_per_group;
+ first_block += fs->super->s_blocks_per_group;
}
return 0;
}
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/super.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/super.c
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/super.c
@@ -566,15 +566,17 @@ void check_super_block(e2fsck_t ctx)
* Verify the group descriptors....
*/
first_block = sb->s_first_data_block;
- last_block = first_block + blocks_per_group;
for (i = 0, gd=fs->group_desc; i < fs->group_desc_count; i++, gd++) {
pctx.group = i;
if (i == fs->group_desc_count - 1)
- last_block = sb->s_blocks_count;
+ last_block = sb->s_blocks_count - 1;
+ else
+ last_block = first_block + blocks_per_group - 1;
+
if ((gd->bg_block_bitmap < first_block) ||
- (gd->bg_block_bitmap >= last_block)) {
+ (gd->bg_block_bitmap > last_block)) {
pctx.blk = gd->bg_block_bitmap;
if (fix_problem(ctx, PR_0_BB_NOT_GROUP, &pctx))
gd->bg_block_bitmap = 0;
@@ -584,7 +586,7 @@ void check_super_block(e2fsck_t ctx)
ctx->invalid_bitmaps++;
}
if ((gd->bg_inode_bitmap < first_block) ||
- (gd->bg_inode_bitmap >= last_block)) {
+ (gd->bg_inode_bitmap > last_block)) {
pctx.blk = gd->bg_inode_bitmap;
if (fix_problem(ctx, PR_0_IB_NOT_GROUP, &pctx))
gd->bg_inode_bitmap = 0;
@@ -595,7 +597,7 @@ void check_super_block(e2fsck_t ctx)
}
if ((gd->bg_inode_table < first_block) ||
((gd->bg_inode_table +
- fs->inode_blocks_per_group - 1) >= last_block)) {
+ fs->inode_blocks_per_group - 1) > last_block)) {
pctx.blk = gd->bg_inode_table;
if (fix_problem(ctx, PR_0_ITABLE_NOT_GROUP, &pctx))
gd->bg_inode_table = 0;
@@ -607,7 +609,6 @@ void check_super_block(e2fsck_t ctx)
free_blocks += gd->bg_free_blocks_count;
free_inodes += gd->bg_free_inodes_count;
first_block += sb->s_blocks_per_group;
- last_block += sb->s_blocks_per_group;
if ((gd->bg_free_blocks_count > sb->s_blocks_per_group) ||
(gd->bg_free_inodes_count > sb->s_inodes_per_group) ||
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/ChangeLog
@@ -1,3 +1,8 @@
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
+ * check_desc.c (ext2fs_check_desc): avoid overflows when iterating
+ over group descriptors on very large filesystems.
+
2006-08-30 Theodore Tso <tytso@mit.edu>
* bitmaps.c (ext2fs_set_bitmap_padding): Fix potential overflow
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/check_desc.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/check_desc.c
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/check_desc.c
@@ -32,37 +32,41 @@
errcode_t ext2fs_check_desc(ext2_filsys fs)
{
dgrp_t i;
- blk_t block = fs->super->s_first_data_block;
- blk_t next;
+ blk_t first_block = fs->super->s_first_data_block;
+ blk_t last_block;
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
for (i = 0; i < fs->group_desc_count; i++) {
- next = block + fs->super->s_blocks_per_group;
+ if (i == fs->group_desc_count - 1)
+ last_block = fs->super->s_blocks_count - 1;
+ else
+ last_block = first_block +
+ fs->super->s_blocks_per_group - 1;
/*
* Check to make sure block bitmap for group is
* located within the group.
*/
- if (fs->group_desc[i].bg_block_bitmap < block ||
- fs->group_desc[i].bg_block_bitmap >= next)
+ if (fs->group_desc[i].bg_block_bitmap < first_block ||
+ fs->group_desc[i].bg_block_bitmap > last_block)
return EXT2_ET_GDESC_BAD_BLOCK_MAP;
/*
* Check to make sure inode bitmap for group is
* located within the group
*/
- if (fs->group_desc[i].bg_inode_bitmap < block ||
- fs->group_desc[i].bg_inode_bitmap >= next)
+ if (fs->group_desc[i].bg_inode_bitmap < first_block ||
+ fs->group_desc[i].bg_inode_bitmap > last_block)
return EXT2_ET_GDESC_BAD_INODE_MAP;
/*
* Check to make sure inode table for group is located
* within the group
*/
- if (fs->group_desc[i].bg_inode_table < block ||
+ if (fs->group_desc[i].bg_inode_table < first_block ||
((fs->group_desc[i].bg_inode_table +
- fs->inode_blocks_per_group) >= next))
+ fs->inode_blocks_per_group) > last_block))
return EXT2_ET_GDESC_BAD_INODE_TABLE;
- block = next;
+ first_block += fs->super->s_blocks_per_group;
}
return 0;
}
Index: e2fsprogs-1.39-my-patches-from-ted/misc/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/misc/ChangeLog
@@ -1,3 +1,12 @@
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
+ * dumpe2fs.c (list_desc, mark_table_blocks): Avoid overflows when
+ iterating over group descriptors on very large
+ filesystems.
+
+ * e2image.c (mark_table_blocks): Change block group loop to use a
+ common pattern of first_block/last_block, etc.
+
2006-08-30 Theodore Tso <tytso@mit.edu>
* tune2fs.c (main), mke2fs.c (PRS): Use e2p_percent to properly
Index: e2fsprogs-1.39-my-patches-from-ted/misc/dumpe2fs.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/dumpe2fs.c
+++ e2fsprogs-1.39-my-patches-from-ted/misc/dumpe2fs.c
@@ -130,7 +130,7 @@ static void list_desc (ext2_filsys fs)
{
unsigned long i;
long diff;
- blk_t group_blk, next_blk;
+ blk_t first_block, last_block;
blk_t super_blk, old_desc_blk, new_desc_blk;
char *block_bitmap=NULL, *inode_bitmap=NULL;
int inode_blocks_per_group, old_desc_blocks, reserved_gdt;
@@ -147,7 +147,7 @@ static void list_desc (ext2_filsys fs)
EXT2_BLOCK_SIZE(fs->super);
reserved_gdt = fs->super->s_reserved_gdt_blocks;
fputc('\n', stdout);
- group_blk = fs->super->s_first_data_block;
+ first_block = fs->super->s_first_data_block;
if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
old_desc_blocks = fs->super->s_first_meta_bg;
else
@@ -155,11 +155,14 @@ static void list_desc (ext2_filsys fs)
for (i = 0; i < fs->group_desc_count; i++) {
ext2fs_super_and_bgd_loc(fs, i, &super_blk,
&old_desc_blk, &new_desc_blk, 0);
- next_blk = group_blk + fs->super->s_blocks_per_group;
- if (next_blk > fs->super->s_blocks_count)
- next_blk = fs->super->s_blocks_count;
+ if (i == fs->group_desc_count - 1)
+ last_block = fs->super->s_blocks_count - 1;
+ else
+ last_block = first_block +
+ fs->super->s_blocks_per_group - 1;
+
printf (_("Group %lu: (Blocks "), i);
- print_range(group_blk, next_blk - 1);
+ print_range(first_block, last_block);
fputs(")", stdout);
print_bg_opts(fs, i);
has_super = ((i==0) || super_blk);
@@ -188,19 +191,19 @@ static void list_desc (ext2_filsys fs)
fputc('\n', stdout);
fputs(_(" Block bitmap at "), stdout);
print_number(fs->group_desc[i].bg_block_bitmap);
- diff = fs->group_desc[i].bg_block_bitmap - group_blk;
+ diff = fs->group_desc[i].bg_block_bitmap - first_block;
if (diff >= 0)
printf(" (+%ld)", diff);
fputs(_(", Inode bitmap at "), stdout);
print_number(fs->group_desc[i].bg_inode_bitmap);
- diff = fs->group_desc[i].bg_inode_bitmap - group_blk;
+ diff = fs->group_desc[i].bg_inode_bitmap - first_block;
if (diff >= 0)
printf(" (+%ld)", diff);
fputs(_("\n Inode table at "), stdout);
print_range(fs->group_desc[i].bg_inode_table,
fs->group_desc[i].bg_inode_table +
inode_blocks_per_group - 1);
- diff = fs->group_desc[i].bg_inode_table - group_blk;
+ diff = fs->group_desc[i].bg_inode_table - first_block;
if (diff > 0)
printf(" (+%ld)", diff);
printf (_("\n %d free blocks, %d free inodes, "
@@ -223,7 +226,7 @@ static void list_desc (ext2_filsys fs)
fputc('\n', stdout);
inode_bitmap += fs->super->s_inodes_per_group / 8;
}
- group_blk = next_blk;
+ first_block += fs->super->s_blocks_per_group;
}
}
Index: e2fsprogs-1.39-my-patches-from-ted/misc/e2image.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/e2image.c
+++ e2fsprogs-1.39-my-patches-from-ted/misc/e2image.c
@@ -244,21 +244,21 @@ static int process_file_block(ext2_filsy
static void mark_table_blocks(ext2_filsys fs)
{
- blk_t block, b;
+ blk_t first_block, b;
unsigned int i,j;
- block = fs->super->s_first_data_block;
+ first_block = fs->super->s_first_data_block;
/*
* Mark primary superblock
*/
- ext2fs_mark_block_bitmap(meta_block_map, block);
+ ext2fs_mark_block_bitmap(meta_block_map, first_block);
/*
* Mark the primary superblock descriptors
*/
for (j = 0; j < fs->desc_blocks; j++) {
ext2fs_mark_block_bitmap(meta_block_map,
- ext2fs_descriptor_block_loc(fs, block, j));
+ ext2fs_descriptor_block_loc(fs, first_block, j));
}
for (i = 0; i < fs->group_desc_count; i++) {
@@ -287,7 +287,7 @@ static void mark_table_blocks(ext2_filsy
ext2fs_mark_block_bitmap(meta_block_map,
fs->group_desc[i].bg_inode_bitmap);
}
- block += fs->super->s_blocks_per_group;
+ first_block += fs->super->s_blocks_per_group;
}
}

View File

@ -0,0 +1,16 @@
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/getsize.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/getsize.c
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/getsize.c
@@ -250,6 +250,11 @@ errcode_t ext2fs_get_device_size(const c
if (fstat(fd, &st) == 0)
#endif
if (S_ISREG(st.st_mode)) {
+ if ((sizeof(*retblocks) < sizeof(unsigned long long)) &&
+ ((st.st_size / blocksize) > 0xFFFFFFFF)) {
+ rc = EFBIG;
+ goto out;
+ }
*retblocks = st.st_size / blocksize;
goto out;
}

View File

@ -0,0 +1,106 @@
# HG changeset patch
# User tytso@mit.edu
# Date Tue Sep 12 14:56:18 2006 -0400
# Node ID 8be686f713b52a3fa0b5dab70980ea3ddbad27b5
# parent: 7e1e8751d2be27716166e88453b52273b7096039
Fix more rounding overflows for filesystems that have 2**32-1 blocks
Signed-off-by: Eric Sandeen <esandeen@redhat.com>
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/ChangeLog
@@ -1,5 +1,9 @@
2006-08-30 Eric Sandeen <esandeen@redhat.com>
+ * pass1.c (handle_bad_fs_blocks): use blk_t, not int for first_block.
+
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
* pass1.c (new_table_block, handle_fs_bad_blocks):
* super.c (check_super_block):
Use new inlines to calculate group first & last blocks.
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/pass1.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/pass1.c
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/pass1.c
@@ -1953,7 +1953,7 @@ static void handle_fs_bad_blocks(e2fsck_
{
ext2_filsys fs = ctx->fs;
dgrp_t i;
- int first_block;
+ blk_t first_block;
for (i = 0; i < fs->group_desc_count; i++) {
first_block = ext2fs_group_first_block(fs, i);
Index: e2fsprogs-1.39-my-patches-from-ted/misc/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/misc/ChangeLog
@@ -1,5 +1,9 @@
2006-08-30 Eric Sandeen <esandeen@redhat.com>
+ * mke2fs.c (PRS): Avoid overflow in megs calculation.
+
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
* dumpe2fs.c (list_desc): Use new inlines to calculate group
first & last blocks.
Index: e2fsprogs-1.39-my-patches-from-ted/misc/mke2fs.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/mke2fs.c
+++ e2fsprogs-1.39-my-patches-from-ted/misc/mke2fs.c
@@ -1261,7 +1261,7 @@ static void PRS(int argc, char *argv[])
}
if (!fs_type) {
- int megs = fs_param.s_blocks_count *
+ int megs = (__u64)fs_param.s_blocks_count *
(EXT2_BLOCK_SIZE(&fs_param) / 1024) / 1024;
if (megs <= 3)
Index: e2fsprogs-1.39-my-patches-from-ted/resize/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/resize/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/resize/ChangeLog
@@ -1,5 +1,11 @@
2006-08-30 Eric Sandeen <esandeen@redhat.com>
+ * online.c (online_resize_fs): use div_ceil for r_frac calculation.
+ * resize2fs.c (adjust_fs_info): avoid overflow in blk calculation
+ when figuring new reserved blocks count.
+
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
* resize2fs.c (adjust_fs_info): Disallow > 2^32 indoes at resize time.
2006-08-30 Eric Sandeen <esandeen@redhat.com>
Index: e2fsprogs-1.39-my-patches-from-ted/resize/online.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/resize/online.c
+++ e2fsprogs-1.39-my-patches-from-ted/resize/online.c
@@ -59,8 +59,7 @@ errcode_t online_resize_fs(ext2_filsys f
exit(1);
}
- r_frac = ((100 * sb->s_r_blocks_count) + sb->s_blocks_count-1) /
- sb->s_blocks_count;
+ r_frac = ext2fs_div_ceil(100 * sb->s_r_blocks_count, sb->s_blocks_count);
retval = ext2fs_read_bitmaps(fs);
if (retval)
Index: e2fsprogs-1.39-my-patches-from-ted/resize/resize2fs.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/resize/resize2fs.c
+++ e2fsprogs-1.39-my-patches-from-ted/resize/resize2fs.c
@@ -250,7 +250,7 @@ retry:
/*
* Adjust the number of reserved blocks
*/
- blk = old_fs->super->s_r_blocks_count * 100 /
+ blk = (__u64)old_fs->super->s_r_blocks_count * 100 /
old_fs->super->s_blocks_count;
fs->super->s_r_blocks_count = e2p_percent(blk,
fs->super->s_blocks_count);

View File

@ -0,0 +1,182 @@
# HG changeset patch
# User tytso@mit.edu
# Date Tue Sep 12 14:56:12 2006 -0400
# Node ID 59bf36fb8344bb7a3971af7df22d41f8d8b14610
# parent: 90cd01f7fcd6293846f0b3ca6ce2b007e3dd7d51
Remove unused variables
Signed-off-by: Eric Sandeen <esandeen@redhat.com>
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/ChangeLog
@@ -1,5 +1,9 @@
2006-08-30 Eric Sandeen <esandeen@redhat.com>
+ * pass1.c (handle_fs_bad_blocks): Remove unused variables.
+
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
* pass1b.c (check_if_fs_block): Change block group loop to use
a common pattern of first_block/last_block, etc.
Index: e2fsprogs-1.39-my-patches-from-ted/e2fsck/pass1.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/e2fsck/pass1.c
+++ e2fsprogs-1.39-my-patches-from-ted/e2fsck/pass1.c
@@ -1981,14 +1981,13 @@ static void handle_fs_bad_blocks(e2fsck_
static void mark_table_blocks(e2fsck_t ctx)
{
ext2_filsys fs = ctx->fs;
- blk_t block, b;
+ blk_t b;
dgrp_t i;
int j;
struct problem_context pctx;
clear_problem_context(&pctx);
- block = fs->super->s_first_data_block;
for (i = 0; i < fs->group_desc_count; i++) {
pctx.group = i;
@@ -2049,7 +2048,6 @@ static void mark_table_blocks(e2fsck_t c
fs->group_desc[i].bg_inode_bitmap);
}
}
- block += fs->super->s_blocks_per_group;
}
}
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/ChangeLog
@@ -1,5 +1,10 @@
2006-08-30 Eric Sandeen <esandeen@redhat.com>
+ * closefs.c (write_backup_super):
+ * initialize.c (ext2fs_initialize): Remove unused variables.
+
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
* check_desc.c (ext2fs_check_desc): avoid overflows when iterating
over group descriptors on very large filesystems.
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/closefs.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/closefs.c
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/closefs.c
@@ -206,7 +206,6 @@ static errcode_t write_backup_super(ext2
errcode_t ext2fs_flush(ext2_filsys fs)
{
dgrp_t i,j;
- blk_t group_block;
errcode_t retval;
unsigned long fs_state;
struct ext2_super_block *super_shadow = 0;
@@ -275,7 +274,6 @@ errcode_t ext2fs_flush(ext2_filsys fs)
* Write out the master group descriptors, and the backup
* superblocks and group descriptors.
*/
- group_block = fs->super->s_first_data_block;
group_ptr = (char *) group_shadow;
if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
old_desc_blocks = fs->super->s_first_meta_bg;
Index: e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/initialize.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/lib/ext2fs/initialize.c
+++ e2fsprogs-1.39-my-patches-from-ted/lib/ext2fs/initialize.c
@@ -99,7 +99,6 @@ errcode_t ext2fs_initialize(const char *
int frags_per_block;
unsigned int rem;
unsigned int overhead = 0;
- blk_t group_block;
unsigned int ipg;
dgrp_t i;
blk_t numblocks;
@@ -360,7 +359,6 @@ retry:
* inode table have not been allocated (and in fact won't be
* by this routine), they are accounted for nevertheless.
*/
- group_block = super->s_first_data_block;
super->s_free_blocks_count = 0;
for (i = 0; i < fs->group_desc_count; i++) {
numblocks = ext2fs_reserve_super_and_bgd(fs, i, fs->block_map);
@@ -370,8 +368,6 @@ retry:
fs->group_desc[i].bg_free_inodes_count =
fs->super->s_inodes_per_group;
fs->group_desc[i].bg_used_dirs_count = 0;
-
- group_block += super->s_blocks_per_group;
}
ext2fs_mark_super_dirty(fs);
Index: e2fsprogs-1.39-my-patches-from-ted/misc/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/misc/ChangeLog
@@ -1,5 +1,10 @@
2006-08-30 Eric Sandeen <esandeen@redhat.com>
+ * e2image.c (mark_table_blocks): Remove unused first_block
+ incrementing from loop.
+
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
* dumpe2fs.c (list_desc, mark_table_blocks): Avoid overflows when
iterating over group descriptors on very large
filesystems.
Index: e2fsprogs-1.39-my-patches-from-ted/misc/e2image.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/misc/e2image.c
+++ e2fsprogs-1.39-my-patches-from-ted/misc/e2image.c
@@ -287,7 +287,6 @@ static void mark_table_blocks(ext2_filsy
ext2fs_mark_block_bitmap(meta_block_map,
fs->group_desc[i].bg_inode_bitmap);
}
- first_block += fs->super->s_blocks_per_group;
}
}
Index: e2fsprogs-1.39-my-patches-from-ted/resize/ChangeLog
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/resize/ChangeLog
+++ e2fsprogs-1.39-my-patches-from-ted/resize/ChangeLog
@@ -1,3 +1,7 @@
+2006-08-30 Eric Sandeen <esandeen@redhat.com>
+
+ * resize2fs.c (mark_table_blocks): Remove unused variable.
+
2006-08-30 Theodore Tso <tytso@mit.edu>
* resize2fs.c (adjust_fs_info), online.c (online_resize_fs): Use
Index: e2fsprogs-1.39-my-patches-from-ted/resize/resize2fs.c
===================================================================
--- e2fsprogs-1.39-my-patches-from-ted.orig/resize/resize2fs.c
+++ e2fsprogs-1.39-my-patches-from-ted/resize/resize2fs.c
@@ -536,14 +536,13 @@ errout:
static errcode_t mark_table_blocks(ext2_filsys fs,
ext2fs_block_bitmap bmap)
{
- blk_t block, b;
+ blk_t b;
unsigned int j;
dgrp_t i;
unsigned long meta_bg_size;
unsigned int old_desc_blocks;
meta_bg_size = (fs->blocksize / sizeof (struct ext2_group_desc));
- block = fs->super->s_first_data_block;
if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
old_desc_blocks = fs->super->s_first_meta_bg;
else
@@ -571,7 +570,6 @@ static errcode_t mark_table_blocks(ext2_
*/
ext2fs_mark_block_bitmap(bmap,
fs->group_desc[i].bg_inode_bitmap);
- block += fs->super->s_blocks_per_group;
}
return 0;
}

View File

@ -1,10 +1,10 @@
%define _root_sbindir /sbin
%define _root_libdir /%{_lib}
Summary: Utilities for managing the second extended (ext2) filesystem.
Summary: Utilities for managing the second and third extended (ext2/ext3) filesystems
Name: e2fsprogs
Version: 1.39
Release: 6
Release: 7
License: GPL
Group: System Environment/Base
Source: ftp://download.sourceforge.net/pub/sourceforge/e2fsprogs/e2fsprogs-%{version}.tar.gz
@ -18,6 +18,17 @@ Patch38: e2fsprogs-1.39-blkid-devname.patch
Patch39: e2fsprogs-1.39-multilib.patch
Patch40: e2fsprogs-1.39-leak.patch
Patch41: e2fsprogs-1.39-blkid-fatlabel.patch
Patch50: e2fsprogs-1.39-ext2fs_div_ceil.patch
Patch51: e2fsprogs-1.39-fix-loop-wraps.patch
Patch52: e2fsprogs-1.39-e2p_percent.patch
Patch53: e2fsprogs-1.39-group_desc_loops.patch
Patch54: e2fsprogs-1.39-unused_group_blocks.patch
Patch55: e2fsprogs-1.39-fix_formats.patch
Patch56: e2fsprogs-1.39-group_block_inlines.patch
Patch57: e2fsprogs-1.39-32_bit_inodes.patch
Patch58: e2fsprogs-1.39-more_rounding_overflows.patch
Patch59: e2fsprogs-1.39-large_file_size.patch
Patch60: e2fsprogs-1.39-e2p_percent_div.patch
Url: http://e2fsprogs.sourceforge.net/
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Requires: e2fsprogs-libs = %{version}-%{release}, device-mapper
@ -28,19 +39,20 @@ BuildRequires: device-mapper >= 1.02.02-3
%description
The e2fsprogs package contains a number of utilities for creating,
checking, modifying, and correcting any inconsistencies in second
extended (ext2) filesystems. E2fsprogs contains e2fsck (used to
repair filesystem inconsistencies after an unclean shutdown), mke2fs
(used to initialize a partition to contain an empty ext2 filesystem),
debugfs (used to examine the internal structure of a filesystem, to
manually repair a corrupted filesystem, or to create test cases for
e2fsck), tune2fs (used to modify filesystem parameters), and most of
the other core ext2fs filesystem utilities.
and third extended (ext2/ext3) filesystems. E2fsprogs contains
e2fsck (used to repair filesystem inconsistencies after an unclean
shutdown), mke2fs (used to initialize a partition to contain an
empty ext2 filesystem), debugfs (used to examine the internal
structure of a filesystem, to manually repair a corrupted
filesystem, or to create test cases for e2fsck), tune2fs (used to
modify filesystem parameters), and most of the other core ext2fs
filesystem utilities.
You should install the e2fsprogs package if you need to manage the
performance of an ext2 filesystem.
performance of an ext2 and/or ext3 filesystem.
%package libs
Summary: Ext2 filesystem-specific static libraries and headers.
Summary: Ext2/3 filesystem-specific static libraries and headers
Group: Development/Libraries
Prereq: /sbin/ldconfig
@ -48,16 +60,17 @@ Prereq: /sbin/ldconfig
E2fsprogs-lib contains the libraries of the e2fsprogs package.
%package devel
Summary: Ext2 filesystem-specific static libraries and headers.
Summary: Ext2/3 filesystem-specific static libraries and headers
Group: Development/Libraries
Requires: e2fsprogs-libs = %{version}-%{release}
Prereq: /sbin/install-info
%description devel
E2fsprogs-devel contains the libraries and header files needed to
develop second extended (ext2) filesystem-specific programs.
develop second and third extended (ext2/ext3) filesystem-specific
programs.
You should install e2fsprogs-devel if you want to develop ext2
You should install e2fsprogs-devel if you want to develop ext2/ext3
filesystem-specific programs. If you install e2fsprogs-devel, you'll
also want to install e2fsprogs.
@ -83,6 +96,18 @@ also want to install e2fsprogs.
%patch40 -p1 -b .leak
# Fix poblem with empty FAT label.
%patch41 -p1 -b .fatlabel
# 32-bit 16T fixups
%patch50 -p1 -b .ext2fs_div_ceil
%patch51 -p1 -b .fix-loop-wraps
%patch52 -p1 -b .e2p_percent
%patch53 -p1 -b .group_desc_loops
%patch54 -p1 -b .unused_group_blocks
%patch55 -p1 -b .fix_formats
%patch56 -p1 -b .group_block_inlines
%patch57 -p1 -b .32_bit_inodes
%patch58 -p1 -b .more_rounding_overflows
%patch59 -p1 -b .large_file_size
%patch60 -p1 -b .e2p_percent_div
%build
aclocal
@ -234,6 +259,10 @@ exit 0
%{_mandir}/man3/uuid_unparse.3*
%changelog
* Wed Sep 20 2006 Jarod Wilson <jwilson@redhat.com> - 1.39-7
- 32-bit 16T fixups from esandeen (#202807)
- Update summaries and descriptions
* Sun Sep 17 2006 Karel Zak <kzak@redhat.com> - 1.39-6
- Fix problem with empty FAT label (#206656)