2007-06-11 16:41:06

by Valerie Clement

[permalink] [raw]
Subject: [RFC][PATCH 4/12] convert some block types in e2fsprogs

Index: e2fsprogs-1.39-tyt3-v6/debugfs/logdump.c
===================================================================
--- e2fsprogs-1.39-tyt3-v6.orig/debugfs/logdump.c 2007-06-11 12:48:36.000000000 +0200
+++ e2fsprogs-1.39-tyt3-v6/debugfs/logdump.c 2007-06-11 12:48:47.000000000 +0200
@@ -36,11 +36,11 @@ extern char *optarg;

enum journal_location {JOURNAL_IS_INTERNAL, JOURNAL_IS_EXTERNAL};

-#define ANY_BLOCK ((unsigned int) -1)
+#define ANY_BLOCK ((blk_t) -1)

int dump_all, dump_contents, dump_descriptors;
-unsigned int block_to_dump, group_to_dump, bitmap_to_dump;
-unsigned int inode_block_to_dump, inode_offset_to_dump, bitmap_to_dump;
+blk_t block_to_dump, bitmap_to_dump, inode_block_to_dump;
+unsigned int group_to_dump, inode_offset_to_dump;
ext2_ino_t inode_to_dump;

struct journal_source
@@ -365,8 +365,8 @@ static void dump_journal(char *cmdname,
if (dump_all) {
fprintf(out_file, "\tuuid=%s\n", jsb_buffer);
fprintf(out_file, "\tblocksize=%d\n", blocksize);
- fprintf(out_file, "\tjournal data size %ld\n",
- (long) sb->s_blocks_count);
+ fprintf(out_file, "\tjournal data size %lu\n",
+ sb->s_blocks_count);
}
}

Index: e2fsprogs-1.39-tyt3-v6/debugfs/debugfs.c
===================================================================
--- e2fsprogs-1.39-tyt3-v6.orig/debugfs/debugfs.c 2007-06-11 12:48:36.000000000 +0200
+++ e2fsprogs-1.39-tyt3-v6/debugfs/debugfs.c 2007-06-11 12:48:47.000000000 +0200
@@ -43,7 +43,7 @@ ext2_filsys current_fs = NULL;
ext2_ino_t root, cwd;

static void open_filesystem(char *device, int open_flags, blk_t superblock,
- blk_t blocksize, int catastrophic,
+ int blocksize, int catastrophic,
char *data_filename)
{
int retval;
@@ -123,7 +123,7 @@ void do_open_filesys(int argc, char **ar
int c, err;
int catastrophic = 0;
blk_t superblock = 0;
- blk_t blocksize = 0;
+ int blocksize = 0;
int open_flags = EXT2_FLAG_SOFTSUPP_FEATURES;
char *data_filename = 0;

@@ -149,8 +149,7 @@ void do_open_filesys(int argc, char **ar
data_filename = optarg;
break;
case 'b':
- blocksize = parse_ulong(optarg, argv[0],
- "block size", &err);
+ blocksize = atoi(optarg);
if (err)
return;
break;
@@ -1892,7 +1891,7 @@ int main(int argc, char **argv)
int exit_status = 0;
char *cmd_file = 0;
blk_t superblock = 0;
- blk_t blocksize = 0;
+ int blocksize = 0;
int catastrophic = 0;
char *data_filename = 0;

@@ -1918,8 +1917,7 @@ int main(int argc, char **argv)
open_flags |= EXT2_FLAG_RW;
break;
case 'b':
- blocksize = parse_ulong(optarg, argv[0],
- "block size", 0);
+ blocksize = atoi(optarg);
break;
case 's':
superblock = parse_ulong(optarg, argv[0],
Index: e2fsprogs-1.39-tyt3-v6/lib/ext2fs/openfs.c
===================================================================
--- e2fsprogs-1.39-tyt3-v6.orig/lib/ext2fs/openfs.c 2007-06-11 12:48:36.000000000 +0200
+++ e2fsprogs-1.39-tyt3-v6/lib/ext2fs/openfs.c 2007-06-11 12:48:47.000000000 +0200
@@ -42,8 +42,7 @@ blk_t ext2fs_descriptor_block_loc(ext2_f
bg = EXT2_DESC_PER_BLOCK(fs->super) * i;
if (ext2fs_bg_has_super(fs, bg))
has_super = 1;
- ret_blk = (fs->super->s_first_data_block + has_super +
- (bg * fs->super->s_blocks_per_group));
+ ret_blk = ext2fs_group_first_block(fs, bg) + has_super;
/*
* If group_block is not the normal value, we're trying to use
* the backup group descriptors and superblock --- so use the
Index: e2fsprogs-1.39-tyt3-v6/lib/ext2fs/closefs.c
===================================================================
--- e2fsprogs-1.39-tyt3-v6.orig/lib/ext2fs/closefs.c 2007-06-11 12:48:36.000000000 +0200
+++ e2fsprogs-1.39-tyt3-v6/lib/ext2fs/closefs.c 2007-06-11 12:48:47.000000000 +0200
@@ -54,11 +54,10 @@ int ext2fs_super_and_bgd_loc(ext2_filsys
{
blk_t group_block, super_blk = 0, old_desc_blk = 0, new_desc_blk = 0;
unsigned int meta_bg, meta_bg_size;
- int numblocks, has_super;
- int old_desc_blocks;
+ blk_t numblocks, old_desc_blocks;
+ int has_super;

- group_block = fs->super->s_first_data_block +
- (group * fs->super->s_blocks_per_group);
+ group_block = ext2fs_group_first_block(fs, group);

if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
old_desc_blocks = fs->super->s_first_meta_bg;
Index: e2fsprogs-1.39-tyt3-v6/e2fsck/super.c
===================================================================
--- e2fsprogs-1.39-tyt3-v6.orig/e2fsck/super.c 2007-06-11 12:48:36.000000000 +0200
+++ e2fsprogs-1.39-tyt3-v6/e2fsck/super.c 2007-06-11 12:48:47.000000000 +0200
@@ -483,7 +483,8 @@ void check_super_block(e2fsck_t ctx)
dgrp_t i;
blk_t should_be;
struct problem_context pctx;
- __u32 free_blocks = 0, free_inodes = 0;
+ blk_t free_blocks = 0;
+ ino_t free_inodes = 0;

inodes_per_block = EXT2_INODES_PER_BLOCK(fs->super);
ipg_max = inodes_per_block * (blocks_per_group - 4);
Index: e2fsprogs-1.39-tyt3-v6/resize/resize2fs.c
===================================================================
--- e2fsprogs-1.39-tyt3-v6.orig/resize/resize2fs.c 2007-06-11 12:48:36.000000000 +0200
+++ e2fsprogs-1.39-tyt3-v6/resize/resize2fs.c 2007-06-11 12:48:47.000000000 +0200
@@ -1557,8 +1557,8 @@ static errcode_t ext2fs_calculate_summar
blk_t blk;
ext2_ino_t ino;
unsigned int group = 0;
- unsigned int count = 0;
- int total_free = 0;
+ blk_t count = 0;
+ blk_t total_free = 0;
int group_free = 0;

/*
Index: e2fsprogs-1.39-tyt3-v6/lib/e2p/e2p.h
===================================================================
--- e2fsprogs-1.39-tyt3-v6.orig/lib/e2p/e2p.h 2007-06-11 12:48:36.000000000 +0200
+++ e2fsprogs-1.39-tyt3-v6/lib/e2p/e2p.h 2007-06-11 12:48:47.000000000 +0200
@@ -51,4 +51,4 @@ 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);
+unsigned long e2p_percent(int percent, unsigned long base);
Index: e2fsprogs-1.39-tyt3-v6/lib/e2p/percent.c
===================================================================
--- e2fsprogs-1.39-tyt3-v6.orig/lib/e2p/percent.c 2007-06-11 12:48:36.000000000 +0200
+++ e2fsprogs-1.39-tyt3-v6/lib/e2p/percent.c 2007-06-11 12:48:47.000000000 +0200
@@ -15,7 +15,7 @@
* 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 long e2p_percent(int percent, unsigned long base)
{
unsigned int mask = ~((1 << (sizeof(unsigned int) - 1) * 8) - 1);

Index: e2fsprogs-1.39-tyt3-v6/lib/ext2fs/ext2fs.h
===================================================================
--- e2fsprogs-1.39-tyt3-v6.orig/lib/ext2fs/ext2fs.h 2007-06-11 12:48:36.000000000 +0200
+++ e2fsprogs-1.39-tyt3-v6/lib/ext2fs/ext2fs.h 2007-06-11 12:48:47.000000000 +0200
@@ -441,7 +441,7 @@ typedef struct ext2_icount *ext2_icount_
/*
* For ext2 compression support
*/
-#define EXT2FS_COMPRESSED_BLKADDR ((blk_t) 0xffffffff)
+#define EXT2FS_COMPRESSED_BLKADDR ((blk_t) -1)
#define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR)

/*
Index: e2fsprogs-1.39-tyt3-v6/lib/ext2fs/gen_bitmap.c
===================================================================
--- e2fsprogs-1.39-tyt3-v6.orig/lib/ext2fs/gen_bitmap.c 2007-06-11 12:48:36.000000000 +0200
+++ e2fsprogs-1.39-tyt3-v6/lib/ext2fs/gen_bitmap.c 2007-06-11 12:48:47.000000000 +0200
@@ -28,7 +28,7 @@
#include "ext2fs.h"

int ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap,
- __u32 bitno)
+ blk_t bitno)
{
if ((bitno < bitmap->start) || (bitno > bitmap->end)) {
ext2fs_warn_bitmap2(bitmap, EXT2FS_MARK_ERROR, bitno);
Index: e2fsprogs-1.39-tyt3-v6/lib/ext2fs/bitops.h
===================================================================
--- e2fsprogs-1.39-tyt3-v6.orig/lib/ext2fs/bitops.h 2007-06-11 12:48:36.000000000 +0200
+++ e2fsprogs-1.39-tyt3-v6/lib/ext2fs/bitops.h 2007-06-11 12:48:47.000000000 +0200
@@ -106,7 +106,7 @@ extern void ext2fs_set_bitmap_padding(ex

/* These two routines moved to gen_bitmap.c */
extern int ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap,
- __u32 bitno);
+ blk_t bitno);
extern int ext2fs_unmark_generic_bitmap(ext2fs_generic_bitmap bitmap,
blk_t bitno);
/*


Attachments:
04-clean-up-some-block-types (8.15 kB)

2007-06-11 21:00:00

by Jose R. Santos

[permalink] [raw]
Subject: Re: [RFC][PATCH 4/12] convert some block types in e2fsprogs

On Mon, 11 Jun 2007 18:42:28 +0200
Valerie Clement <[email protected]> wrote:

> This patch converts some int or unsigned int block number definitions
> to blk_t type. Most conversions are necessary for 64-bit porting.

What about unsigned long? There are various places where block is
represented by using unsigned long which is 32-bit when running 32 bit
binaries. Most PPC64 distributions compile their user-space tools in
32-bit binaries.

I wonder how badly it will break.

-JRS

2007-06-12 14:58:27

by Jose R. Santos

[permalink] [raw]
Subject: Re: [RFC][PATCH 4/12] convert some block types in e2fsprogs

On Mon, 11 Jun 2007 15:59:30 -0500
"Jose R. Santos" <[email protected]> wrote:

> On Mon, 11 Jun 2007 18:42:28 +0200
> Valerie Clement <[email protected]> wrote:
>
> > This patch converts some int or unsigned int block number definitions
> > to blk_t type. Most conversions are necessary for 64-bit porting.
>
> What about unsigned long? There are various places where block is
> represented by using unsigned long which is 32-bit when running 32 bit
> binaries. Most PPC64 distributions compile their user-space tools in
> 32-bit binaries.
>
> I wonder how badly it will break.

I found a PPC64 box to test this out and it seems to break pretty badly
when compiled in the default 32bit mode. Should ext2_get_device_size()
fail if the number of block is greater than 2**32 and the size of
unsigned long is 4? At least until it can be verified that this will
work under 32bit binaries since it could corrupt a filesystem to do
an fsck.

mke2fs 1.39-tyt3 (29-Apr-2007)

Warning:Filesystem greater than 2**32 blocks, 64-bit incompatible feature forced.

Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
4194304 inodes, 5 blocks
0 blocks (0.00%) reserved for the super user
First data block=1
524288 block groups
8192 blocks per group, 8192 fragments per group
8 inodes per group
Superblock backups stored on blocks:
267387660, 267387660, 267387660, 267387660, 267387660, 267387660, 267387660, 267387660, 267387660,
267387660, 267387660, 267387660, 267387660, 267387660, 267387660, 267387660,
267387660, 267387660, 267387660, 267387660, 267387660, 267387660,
267387660, 267387660, 267387660, 267387660

mke2fs: Could not allocate block in ext2 filesystem while trying to allocate filesystem tables


-JRS