Initial blk64_t capable API calls.
cover Initial blk64_t capable API calls.
The following series of patches implement API call needed to handle 64-bit block numbers. Im concentrating mainly in providing the API call first and if the interfaces are sane, we can go ahead and start using them in the rest of libext2fs and the user space programs.
It also introduces the changes needed in order to for mke2fs to support larger that 32-bit blocknr devices.
Bitmap dependencies are commented with "/* FIXME-64 */" to make them easy to find and replace with the new interface.
-JRS
PATCH 1/15 libext2fs: Add 64-bit support to the undo manager
From: Jose R. Santos <[email protected]>
libext2fs: Add 64-bit support to the undo manager
--
lib/ext2fs/undo_io.c | 55 +++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 45 insertions(+), 10 deletions(-)
lib/ext2fs/undo_io.c +45 -10
@@ -73,6 +73,10 @@ struct undo_private_data {static errcode_t undo_open (const char *name,int flags,io_channel *channel);static errcode_t undo_close (io_channel channel);static errcode_t undo_set_blksize (io_channel channel,int blksize); +static errcode_t undo_read_blk64 (io_channel channel,unsigned long long block, +int count,void *data); +static errcode_t undo_write_blk64 (io_channel channel,unsigned long long block, +int count,const void *data);static errcode_t undo_read_blk (io_channel channel,unsigned long block,int count,void *data); static errcode_t undo_write_blk(io_channel channel, unsigned long block,
@@ -82,6 +86,7 @@ static errcode_t undo_write_byte(io_channel channel, unsigned long offset, int size, const void *data);static errcode_t undo_set_option (io_channel channel,const char *option,const char *arg); +static errcode_t undo_get_stats (io_channel channel,io_stats *stats);static struct struct_io_manager struct_undo_manager = {EXT2_ET_MAGIC_IO_MANAGER ,
@@ -93,7 +98,10 @@ static struct struct_io_manager struct_undo_manager = { undo_write_blk, undo_flush, undo_write_byte, - undo_set_option + undo_set_option, + undo_get_stats, + undo_read_blk64, + undo_write_blk64, };io_manager undo_io_manager = &struct_undo_manager;
@@ -190,17 +198,17 @@ static errcode_t write_block_size(TDB_CONTEXT *tdb, int block_size) }static errcode_t undo_write_tdb (io_channel channel, -unsigned long block,int count) +unsigned long long block,int count) {int size, sz; -unsigned long block_num, backing_blk_num; +unsigned long long block_num, backing_blk_num;errcode_t retval =0 ;ext2_loff_t offset;struct undo_private_data *data;TDB_DATA tdb_key, tdb_data;unsigned char *read_ptr; -unsigned long end_block; +unsigned long long end_block; data = (struct undo_private_data *) channel->private_data;
@@ -266,7 +274,7 @@ static errcode_t undo_write_tdb(io_channel channel, sz = count / channel->block_size; else sz = -count; - retval =io_channel_read_blk (data->real, backing_blk_num, + retval =io_channel_read_blk64 (data->real, backing_blk_num, sz, read_ptr);if (retval) {if (retval !=EXT2_ET_SHORT_READ ) {
@@ -285,7 +293,7 @@ static errcode_t undo_write_tdb(io_channel channel, tdb_data.dptr = read_ptr + ((offset - data->offset) % channel->block_size);#ifdef DEBUG -printf ("Printing with key %ld data %x and size %d\n" , +printf ("Printing with key %lld data %x and size %d\n" , block_num, tdb_data.dptr, tdb_data.dsize);
@@ -455,7 +463,7 @@ static errcode_t undo_set_blksize(io_channel channel, int blksize)return retval; } -static errcode_t undo_read_blk (io_channel channel,unsigned long block, +static errcode_t undo_read_blk64 (io_channel channel,unsigned long long block,int count,void *buf) {errcode_t retval =0 ;
@@ -466,12 +474,18 @@ static errcode_t undo_read_blk(io_channel channel, unsigned long block,EXT2_CHECK_MAGIC (data,EXT2_ET_MAGIC_UNIX_IO_CHANNEL );if (data->real) - retval =io_channel_read_blk (data->real, block, count, buf); + retval =io_channel_read_blk64 (data->real, block, count, buf);return retval; } -static errcode_t undo_write_blk (io_channel channel,unsigned long block, +static errcode_t undo_read_blk (io_channel channel,unsigned long block, +int count,void *buf) +{ +return undo_read_blk64 (channel, block, count, buf); +} + +static errcode_t undo_write_blk64 (io_channel channel,unsigned long long block,int count,const void *buf) {struct undo_private_data *data;
@@ -487,11 +501,17 @@ static errcode_t undo_write_blk(io_channel channel, unsigned long block,if (retval)return retval;if (data->real) - retval =io_channel_write_blk (data->real, block, count, buf); + retval =io_channel_write_blk64 (data->real, block, count, buf);return retval; } +static errcode_t undo_write_blk (io_channel channel,unsigned long block, +int count,const void *buf) +{ +return undo_write_blk64 (channel, block, count, buf); +} +static errcode_t undo_write_byte (io_channel channel,unsigned long offset,int size,const void *buf) {
@@ -584,3 +604,18 @@ static errcode_t undo_set_option(io_channel channel, const char *option, }return retval; } + +static errcode_t undo_get_stats (io_channel channel,io_stats *stats) +{ +errcode_t retval; +struct undo_private_data *data; + +EXT2_CHECK_MAGIC (channel,EXT2_ET_MAGIC_IO_CHANNEL ); + data = (struct undo_private_data *) channel->private_data; +EXT2_CHECK_MAGIC (data,EXT2_ET_MAGIC_UNIX_IO_CHANNEL ); + +if (data->real) + retval = (data->real->manager->get_stats)(data->real, stats); + +return retval; +}
PATCH 2/15 Add ext2_off64_t type.
In reply to Jose R. SantosFrom: Jose R. Santos <[email protected]>
Add ext2_off64_t type.
The ext2_off_t is u32. Creating a new 64-bit ext2_off64_t for 64bit offsets.
--
lib/ext2fs/ext2fs.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
--
lib/ext2fs/ext2fs.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
lib/ext2fs/ext2fs.h +1 -0
@@ -68,6 +68,7 @@ typedef __u32 blk_t;typedef __u64 blk64_t ;typedef __u32 dgrp_t ;typedef __u32 ext2_off_t ; +typedef __u64 ext2_off64_t ;typedef __s64 e2_blkcnt_t ;typedef __u32 ext2_dirhash_t ;
PATCH 3/15 Add new blk64_t handling functions
In reply to Jose R. SantosFrom: Jose R. Santos <[email protected]>
Add new blk64_t handling functions
Add new blknum.c file which contains funtions to handle blk64_t and low/high values in super blocks and inodes.
--
lib/ext2fs/Makefile.in | 1 lib/ext2fs/blknum.c | 214 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/ext2fs/ext2fs.h | 33 +++++-- 3 files changed, 237 insertions(+), 11 deletions(-)
--
lib/ext2fs/Makefile.in | 1 lib/ext2fs/blknum.c | 244 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/ext2fs/ext2fs.h | 45 +++++++-- 3 files changed, 279 insertions(+), 11 deletions(-)
lib/ext2fs/Makefile.in +1 -0
@@ -26,6 +26,7 @@ OBJS= $(DEBUGFS_LIB_OBJS) $(RESIZE_LIB_OBJS) $(E2IMAGE_LIB_OBJS) \ bb_inode.o \ bitmaps.o \ bitops.o \ + blknum.o \ block.o \ bmap.o \ check_desc.o \
lib/ext2fs/blknum.c new file +244 -0
244 lines not on this page · raw message
lib/ext2fs/ext2fs.h +34 -11
75 lines not on this page · raw message
PATCH 4/15 Use blk64_t for blocks in struct ext2_file.
In reply to Jose R. SantosFrom: Jose R. Santos <[email protected]>
Use blk64_t for blocks in struct ext2_file.
The ext2_file structure is never exposed through the libext2fs API so it is safe to use 64-bit blocks for blockno and physclock without breaking the ABI.
--
lib/ext2fs/fileio.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
--
lib/ext2fs/fileio.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
lib/ext2fs/fileio.c +6 -6
@@ -25,8 +25,8 @@ struct ext2_file {struct ext2_inode inode;int flags;__u64 pos; -blk_t blockno; -blk_t physblock; +blk64_t blockno; +blk64_t physblock;char *buf; };
@@ -116,9 +116,9 @@ errcode_t ext2fs_file_flush(ext2_file_t file)* Allocate it. */ if (!file->physblock) { - retval =ext2fs_bmap (fs, file->ino, &file->inode, + retval =ext2fs_bmap2 (fs, file->ino, &file->inode,BMAP_BUFFER , file->ino ?BMAP_ALLOC :0 , - file->blockno, &file->physblock); + file->blockno,0 , &file->physblock);if (retval)return retval; }
@@ -168,8 +168,8 @@ static errcode_t load_buffer(ext2_file_t file, int dontfill)errcode_t retval;if (!(file->flags &EXT2_FILE_BUF_VALID )) { - retval =ext2fs_bmap (fs, file->ino, &file->inode, -BMAP_BUFFER ,0 , file->blockno, + retval =ext2fs_bmap2 (fs, file->ino, &file->inode, +BMAP_BUFFER ,0 , file->blockno,0 , &file->physblock);if (retval)return retval;
PATCH 5/15 Add 64-bit dirblock interface.
In reply to Jose R. SantosFrom: Jose R. Santos <[email protected]>
Add 64-bit dirblock interface.
Add new ext2fs_(read|write)_dir_block3() routines that take blk64_t as an input.
--
lib/ext2fs/dirblock.c | 23 +++++++++++++++++------ lib/ext2fs/ext2fs.h | 4 ++++ 2 files changed, 21 insertions(+), 6 deletions(-)
--
lib/ext2fs/dirblock.c | 23 +++++++++++++++++------ lib/ext2fs/ext2fs.h | 4 ++++ 2 files changed, 21 insertions(+), 6 deletions(-)
lib/ext2fs/dirblock.c +17 -6
@@ -19,7 +19,7 @@#include "ext2_fs.h" #include "ext2fs.h" -errcode_t ext2fs_read_dir_block2 (ext2_filsys fs,blk_t block, +errcode_t ext2fs_read_dir_block3 (ext2_filsys fs,blk64_t block, void *buf, int flags EXT2FS_ATTR((unused))) {errcode_t retval;
@@ -28,7 +28,7 @@ errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,unsigned int name_len, rec_len; - retval =io_channel_read_blk (fs->io, block,1 , buf); + retval =io_channel_read_blk64 (fs->io, block,1 , buf);if (retval)return retval;
@@ -58,14 +58,20 @@ errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,return retval; } +errcode_t ext2fs_read_dir_block2 (ext2_filsys fs,blk_t block, + void *buf, int flags EXT2FS_ATTR((unused))) +{ +return ext2fs_read_dir_block3 (fs, block, buf, flags); +} +errcode_t ext2fs_read_dir_block (ext2_filsys fs,blk_t block,void *buf) { -return ext2fs_read_dir_block2 (fs, block, buf,0 ); +return ext2fs_read_dir_block3 (fs, block, buf,0 ); } -errcode_t ext2fs_write_dir_block2 (ext2_filsys fs,blk_t block, +errcode_t ext2fs_write_dir_block3 (ext2_filsys fs,blk64_t block, void *inbuf, int flags EXT2FS_ATTR((unused))) {#ifdef WORDS_BIGENDIAN
@@ -95,7 +101,7 @@ errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,if (flags &EXT2_DIRBLOCK_V2_STRUCT ) dirent->name_len = ext2fs_swab16(dirent->name_len); } - retval =io_channel_write_blk (fs->io, block,1 , buf); + retval =io_channel_write_blk64 (fs->io, block,1 , buf);ext2fs_free_mem (&buf);return retval;#else
@@ -103,10 +109,15 @@ errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,#endif } +errcode_t ext2fs_write_dir_block2 (ext2_filsys fs,blk_t block, + void *inbuf, int flags EXT2FS_ATTR((unused))) +{ +return ext2fs_write_dir_block3 (fs, block, inbuf, flags); +}errcode_t ext2fs_write_dir_block (ext2_filsys fs,blk_t block,void *inbuf) { -return ext2fs_write_dir_block2 (fs, block, inbuf,0 ); +return ext2fs_write_dir_block3 (fs, block, inbuf,0 ); }
lib/ext2fs/ext2fs.h +4 -0
@@ -814,10 +814,14 @@ extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block, void *buf);extern errcode_t ext2fs_read_dir_block2 (ext2_filsys fs,blk_t block,void *buf,int flags); +extern errcode_t ext2fs_read_dir_block3 (ext2_filsys fs,blk64_t block, +void *buf,int flags);extern errcode_t ext2fs_write_dir_block (ext2_filsys fs,blk_t block,void *buf);extern errcode_t ext2fs_write_dir_block2 (ext2_filsys fs,blk_t block,void *buf,int flags); +extern errcode_t ext2fs_write_dir_block3 (ext2_filsys fs,blk64_t block, +void *buf,int flags);/* dirhash.c */ extern errcode_t ext2fs_dirhash(int version, const char *name, int len,
PATCH 6/15 Add 64-bit alloc_stats interface.
In reply to Jose R. SantosFrom: Jose R. Santos <[email protected]>
Add 64-bit alloc_stats interface.
Add new ext2fs_block_alloc_stats2() routine that takes blk64_t as an input.
--
lib/ext2fs/alloc_stats.c | 11 +++++++++-- lib/ext2fs/ext2fs.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-)
--
lib/ext2fs/alloc_stats.c | 13 ++++++++++--- lib/ext2fs/ext2fs.h | 1 + 2 files changed, 11 insertions(+), 3 deletions(-)
lib/ext2fs/alloc_stats.c +10 -3
@@ -54,25 +54,32 @@ void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse)ext2fs_inode_alloc_stats2 (fs, ino, inuse,0 ); } -void ext2fs_block_alloc_stats (ext2_filsys fs,blk_t blk,int inuse) +void ext2fs_block_alloc_stats2 (ext2_filsys fs,blk64_t blk,int inuse) { -int group =ext2fs_group_of_blk (fs, blk); +int group =ext2fs_group_of_blk2 (fs, blk);if (inuse >0 ) +/* FIXME-64 */ ext2fs_mark_block_bitmap (fs->block_map, blk);else +/* FIXME-64 */ ext2fs_unmark_block_bitmap (fs->block_map, blk); fs->group_desc[group].bg_free_blocks_count -= inuse; fs->group_desc[group].bg_flags &= ~EXT2_BG_BLOCK_UNINIT ;ext2fs_group_desc_csum_set (fs, group); - fs->super->s_free_blocks_count -= inuse; +ext2fs_free_blocks_count_add (fs->super, -inuse);ext2fs_mark_super_dirty (fs);ext2fs_mark_bb_dirty (fs);if (fs->block_alloc_stats) (fs->block_alloc_stats)(fs, (blk64_t ) blk, inuse); } +void ext2fs_block_alloc_stats (ext2_filsys fs,blk_t blk,int inuse) +{ +ext2fs_block_alloc_stats2 (fs, blk, inuse); +} + void ext2fs_set_block_alloc_stats_callback(ext2_filsys fs, void (*func)(ext2_filsys fs, blk64_t blk,
lib/ext2fs/ext2fs.h +1 -0
@@ -586,6 +586,7 @@ void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse);void ext2fs_inode_alloc_stats2 (ext2_filsys fs,ext2_ino_t ino,int inuse,int isdir);void ext2fs_block_alloc_stats (ext2_filsys fs,blk_t blk,int inuse); +void ext2fs_block_alloc_stats2 (ext2_filsys fs,blk64_t blk,int inuse);/* alloc_tables.c */ extern errcode_t ext2fs_allocate_tables (ext2_filsys fs);
PATCH 7/15 Add 64-bit alloc interface.
In reply to Jose R. SantosFrom: Jose R. Santos <[email protected]>
Add 64-bit alloc interface.
Add new ext2fs_new_block2(), ext2fs_get_free_blocks2() and ext2fs_alloc_block2() that take and return blk64_t.
--
lib/ext2fs/alloc.c | 70 ++++++++++++++++++++++++++++++++++++++------------- lib/ext2fs/ext2fs.h | 8 ++++++ 2 files changed, 60 insertions(+), 18 deletions(-)
lib/ext2fs/alloc.c +52 -18
@@ -73,10 +73,10 @@ errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir,* Stupid algorithm --- we now just search forward starting from the * goal. Should put in a smarter one someday.... */ -errcode_t ext2fs_new_block (ext2_filsys fs,blk_t goal, -ext2fs_block_bitmap map,blk_t *ret) +errcode_t ext2fs_new_block2 (ext2_filsys fs,blk64_t goal, +ext2fs_block_bitmap map,blk64_t *ret) { -blk_t i; +blk64_t i;EXT2_CHECK_MAGIC (fs,EXT2_ET_MAGIC_EXT2FS_FILSYS );
@@ -88,7 +88,8 @@ errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal, goal = fs->super->s_first_data_block; i = goal; do { - if (!ext2fs_fast_test_block_bitmap(map, i)) { + /* FIXME-64 */ + if (!ext2fs_fast_test_block_bitmap(map, (blk_t) i)) { *ret = i; return 0; }
@@ -99,15 +100,26 @@ errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,return EXT2_ET_BLOCK_ALLOC_FAIL ; } +errcode_t ext2fs_new_block (ext2_filsys fs,blk_t goal, +ext2fs_block_bitmap map,blk_t *ret) +{ +errcode_t retval; +blk64_t val; + retval =ext2fs_new_block2 (fs, goal, map, &val); +if (!retval) + *ret = (blk_t ) val; +return retval; +} +/* * This function zeros out the allocated block, and updates all of the * appropriate filesystem records. */ -errcode_t ext2fs_alloc_block (ext2_filsys fs,blk_t goal, -char *block_buf,blk_t *ret) +errcode_t ext2fs_alloc_block2 (ext2_filsys fs,blk64_t goal, +char *block_buf,blk64_t *ret) {errcode_t retval; -blk_t block; +blk64_t block;char *buf =0 ;if (!block_buf) {
@@ -119,29 +131,27 @@ errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,memset (block_buf,0 , fs->blocksize);if (fs->get_alloc_block) { -blk64_t new; - - retval = (fs->get_alloc_block)(fs, (blk64_t ) goal, &new); + retval = (fs->get_alloc_block)(fs, goal, &block);if (retval) goto fail; - block = (blk_t ) new; }else {if (!fs->block_map) { +/* FIXME-64 */ retval =ext2fs_read_block_bitmap (fs);if (retval) goto fail; } - retval =ext2fs_new_block (fs, goal,0 , &block); + retval =ext2fs_new_block2 (fs, goal,0 , &block);if (retval) goto fail; } - retval =io_channel_write_blk (fs->io, block,1 , block_buf); + retval =io_channel_write_blk64 (fs->io, block,1 , block_buf);if (retval) goto fail; -ext2fs_block_alloc_stats (fs, block,+1 ); +ext2fs_block_alloc_stats2 (fs, block,+1 ); *ret = block; fail:
@@ -150,10 +160,21 @@ fail:return retval; } -errcode_t ext2fs_get_free_blocks (ext2_filsys fs,blk_t start,blk_t finish, -int num,ext2fs_block_bitmap map,blk_t *ret) +errcode_t ext2fs_alloc_block (ext2_filsys fs,blk_t goal, +char *block_buf,blk_t *ret) +{ +errcode_t retval; +blk64_t val; + retval =ext2fs_alloc_block2 (fs, goal, block_buf, &val); +if (!retval) + *ret = (blk_t ) val; +return retval; +} + +errcode_t ext2fs_get_free_blocks2 (ext2_filsys fs,blk64_t start,blk64_t finish, +int num,ext2fs_block_bitmap map,blk64_t *ret) { -blk_t b = start; +blk64_t b = start;EXT2_CHECK_MAGIC (fs,EXT2_ET_MAGIC_EXT2FS_FILSYS );
@@ -170,7 +191,9 @@ errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start, blk_t finish, do { if (b+num-1 > fs->super->s_blocks_count) b = fs->super->s_first_data_block; - if (ext2fs_fast_test_block_bitmap_range(map, b, num)) { + /* FIXME-64 */ + if (ext2fs_fast_test_block_bitmap_range(map, (blk_t) b, + (blk_t) num)) { *ret = b; return 0; }
@@ -179,6 +202,17 @@ errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start, blk_t finish,return EXT2_ET_BLOCK_ALLOC_FAIL ; } +errcode_t ext2fs_get_free_blocks (ext2_filsys fs,blk_t start,blk_t finish, +int num,ext2fs_block_bitmap map,blk_t *ret) +{ +errcode_t retval; +blk64_t val; + retval =ext2fs_get_free_blocks2 (fs, start, finish, num, map, &val); +if (!retval) + *ret = (blk_t ) val; +return retval; +} + void ext2fs_set_alloc_block_callback(ext2_filsys fs, errcode_t (*func)(ext2_filsys fs, blk64_t goal,
lib/ext2fs/ext2fs.h +8 -0
@@ -555,12 +555,20 @@ extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode, ext2fs_inode_bitmap map, ext2_ino_t *ret);extern errcode_t ext2fs_new_block (ext2_filsys fs,blk_t goal,ext2fs_block_bitmap map,blk_t *ret); +extern errcode_t ext2fs_new_block2 (ext2_filsys fs,blk64_t goal, +ext2fs_block_bitmap map,blk64_t *ret);extern errcode_t ext2fs_get_free_blocks (ext2_filsys fs,blk_t start,blk_t finish,int num,ext2fs_block_bitmap map,blk_t *ret); +extern errcode_t ext2fs_get_free_blocks2 (ext2_filsys fs,blk64_t start, +blk64_t finish,int num, +ext2fs_block_bitmap map, +blk64_t *ret);extern errcode_t ext2fs_alloc_block (ext2_filsys fs,blk_t goal,char *block_buf,blk_t *ret); +extern errcode_t ext2fs_alloc_block2 (ext2_filsys fs,blk64_t goal, +char *block_buf,blk64_t *ret); extern void ext2fs_set_alloc_block_callback(ext2_filsys fs, errcode_t (*func)(ext2_filsys fs, blk64_t goal,
PATCH 8/15 Add 64-bit ext_attr interface.
In reply to Jose R. SantosFrom: Jose R. Santos <[email protected]>
Add 64-bit ext_attr interface.
Add ext2fs_read_ext_attr2(), ext2fs_write_ext_attr2() and ext2fs_adjust_ea_refcount2() that take blk64_t as an input.
--
lib/ext2fs/ext2fs.h | 7 +++++++ lib/ext2fs/ext_attr.c | 31 ++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-)
--
lib/ext2fs/ext2fs.h | 7 +++++++ lib/ext2fs/ext_attr.c | 31 ++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-)
lib/ext2fs/ext2fs.h +7 -0
@@ -873,11 +873,18 @@ extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);extern __u32 ext2fs_ext_attr_hash_entry (struct ext2_ext_attr_entry *entry,void *data);extern errcode_t ext2fs_read_ext_attr (ext2_filsys fs,blk_t block,void *buf); +extern errcode_t ext2fs_read_ext_attr2 (ext2_filsys fs,blk64_t block, +void *buf);extern errcode_t ext2fs_write_ext_attr (ext2_filsys fs,blk_t block,void *buf); +extern errcode_t ext2fs_write_ext_attr2 (ext2_filsys fs,blk64_t block, +void *buf);extern errcode_t ext2fs_adjust_ea_refcount (ext2_filsys fs,blk_t blk,char *block_buf,int adjust,__u32 *newcount); +extern errcode_t ext2fs_adjust_ea_refcount2 (ext2_filsys fs,blk64_t blk, +char *block_buf, +int adjust,__u32 *newcount);/* extent.c */ extern errcode_t ext2fs_extent_header_verify (void *ptr,int size);
lib/ext2fs/ext_attr.c +24 -7
@@ -60,11 +60,11 @@ __u32 ext2fs_ext_attr_hash_entry(struct ext2_ext_attr_entry *entry, void *data)#undef NAME_HASH_SHIFT#undef VALUE_HASH_SHIFT -errcode_t ext2fs_read_ext_attr (ext2_filsys fs,blk_t block,void *buf) +errcode_t ext2fs_read_ext_attr2 (ext2_filsys fs,blk64_t block,void *buf) {errcode_t retval; - retval =io_channel_read_blk (fs->io, block,1 , buf); + retval =io_channel_read_blk64 (fs->io, block,1 , buf);if (retval)return retval;#ifdef WORDS_BIGENDIAN
@@ -73,7 +73,12 @@ errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf)return 0 ; } -errcode_t ext2fs_write_ext_attr (ext2_filsys fs,blk_t block,void *inbuf) +errcode_t ext2fs_read_ext_attr (ext2_filsys fs,blk_t block,void *buf) +{ +return ext2fs_read_ext_attr2 (fs, block, buf); +} + +errcode_t ext2fs_write_ext_attr2 (ext2_filsys fs,blk64_t block,void *inbuf) {errcode_t retval;char *write_buf;
@@ -88,7 +93,7 @@ errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block, void *inbuf)#else write_buf = (char *) inbuf;#endif - retval =io_channel_write_blk (fs->io, block,1 , write_buf); + retval =io_channel_write_blk64 (fs->io, block,1 , write_buf);if (buf)ext2fs_free_mem (&buf);if (!retval)
@@ -96,10 +101,15 @@ errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block, void *inbuf)return retval; } +errcode_t ext2fs_write_ext_attr (ext2_filsys fs,blk_t block,void *inbuf) +{ +return ext2fs_write_ext_attr2 (fs, block, inbuf); +} +/* * This function adjusts the reference count of the EA block. */ -errcode_t ext2fs_adjust_ea_refcount (ext2_filsys fs,blk_t blk, +errcode_t ext2fs_adjust_ea_refcount2 (ext2_filsys fs,blk64_t blk,char *block_buf,int adjust,__u32 *newcount) {
@@ -118,7 +128,7 @@ errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk, block_buf = buf; } - retval =ext2fs_read_ext_attr (fs, blk, block_buf); + retval =ext2fs_read_ext_attr2 (fs, blk, block_buf);if (retval) goto errout;
@@ -127,7 +137,7 @@ errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk,if (newcount) *newcount = header->h_refcount; - retval =ext2fs_write_ext_attr (fs, blk, block_buf); + retval =ext2fs_write_ext_attr2 (fs, blk, block_buf);if (retval) goto errout;
@@ -136,3 +146,10 @@ errout:ext2fs_free_mem (&buf);return retval; } + +errcode_t ext2fs_adjust_ea_refcount (ext2_filsys fs,blk_t blk, +char *block_buf,int adjust, +__u32 *newcount) +{ +return ext2fs_adjust_ea_refcount (fs, blk, block_buf, adjust, newcount); +}
PATCH 9/15 Add 64-bit closefs interface.
In reply to Jose R. SantosFrom: Jose R. Santos <[email protected]>
Add 64-bit closefs interface.
Add new ext2fs_super_and_bgd_loc2() that returns blk64_t pointers. The function now returns the number of blocks used by super block and group descriptors since with flex_bg, it can no longer be assumed that bitmaps and inode tables still resided within the block group.
--
lib/ext2fs/closefs.c | 120 +++++++++++++++++++++++++++++++++++--------------- lib/ext2fs/ext2fs.h | 6 +++ 2 files changed, 90 insertions(+), 36 deletions(-)
--
lib/ext2fs/closefs.c | 120 +++++++++++++++++++++++++++++++++++--------------- lib/ext2fs/ext2fs.h | 6 +++ 2 files changed, 90 insertions(+), 36 deletions(-)
lib/ext2fs/closefs.c +84 -36
@@ -46,31 +46,33 @@ int ext2fs_bg_has_super(ext2_filsys fs, int group_block) }/* -* This function returns the location of the superblock, block group -* descriptors for a given block group. It currently returns the -* number of free blocks assuming that inode table and allocation -* bitmaps will be in the group. This is not necessarily the case -* when the flex_bg feature is enabled, so callers should take care! -* It was only really intended for use by mke2fs, and even there it's -* not that useful. In the future, when we redo this function for -* 64-bit block numbers, we should probably return the number of -* blocks used by the super block and group descriptors instead. +* ext2fs_super_and_bgd_loc2() +* @fs: ext2 fs pointer +* @group given block group +* @ret_super_blk: if !NULL, returns super block location +* @ret_old_desc_blk: if !NULL, returns location of the old block +* group descriptor +* @ret_new_desc_blk: if !NULL, returns location of meta_bg block +* group descriptor +* @ret_used_blks: if !NULL, returns number of blocks used by +* super block and group_descriptors. * -* See also the comment for ext2fs_reserve_super_and_bgd() +* Returns errcode_t of 0 */ -int ext2fs_super_and_bgd_loc (ext2_filsys fs, -dgrp_t group, -blk_t *ret_super_blk, -blk_t *ret_old_desc_blk, -blk_t *ret_new_desc_blk, -int *ret_meta_bg) +errcode_t ext2fs_super_and_bgd_loc2 (ext2_filsys fs, +dgrp_t group, +blk64_t *ret_super_blk, +blk64_t *ret_old_desc_blk, +blk64_t *ret_new_desc_blk, +blk_t *ret_used_blks) { -blk_t group_block, super_blk =0 , old_desc_blk =0 , new_desc_blk =0 ; +blk64_t group_block, super_blk =0 , old_desc_blk =0 , new_desc_blk =0 ;unsigned int meta_bg, meta_bg_size; -blk_t numblocks, old_desc_blocks; +blk_t numblocks =0 ; +blk64_t old_desc_blocks;int has_super; - group_block =ext2fs_group_first_block (fs, group); + group_block =ext2fs_group_first_block2 (fs, group);if (fs->super->s_feature_incompat &EXT2_FEATURE_INCOMPAT_META_BG ) old_desc_blocks = fs->super->s_first_meta_bg;
@@ -78,20 +80,11 @@ int ext2fs_super_and_bgd_loc(ext2_filsys fs, old_desc_blocks = fs->desc_blocks + fs->super->s_reserved_gdt_blocks; -if (group == fs->group_desc_count-1 ) { - numblocks = (fs->super->s_blocks_count - - fs->super->s_first_data_block) % - fs->super->s_blocks_per_group; -if (!numblocks) - numblocks = fs->super->s_blocks_per_group; - }else - numblocks = fs->super->s_blocks_per_group; - has_super =ext2fs_bg_has_super (fs, group);if (has_super) { super_blk = group_block; - numblocks--; + numblocks++; } meta_bg_size =EXT2_DESC_PER_BLOCK (fs->super); meta_bg = group / meta_bg_size;
@@ -100,7 +93,7 @@ int ext2fs_super_and_bgd_loc(ext2_filsys fs, (meta_bg < fs->super->s_first_meta_bg)) { if (has_super) { old_desc_blk = group_block + 1; - numblocks -= old_desc_blocks; + numblocks += old_desc_blocks; } } else { if (((group % meta_bg_size) == 0) ||
@@ -109,11 +102,9 @@ int ext2fs_super_and_bgd_loc(ext2_filsys fs,if (has_super) has_super =1 ; new_desc_blk = group_block + has_super; - numblocks--; + numblocks++; } } - - numblocks -=2 + fs->inode_blocks_per_group;if (ret_super_blk) *ret_super_blk = super_blk;
@@ -121,11 +112,68 @@ int ext2fs_super_and_bgd_loc(ext2_filsys fs, *ret_old_desc_blk = old_desc_blk;if (ret_new_desc_blk) *ret_new_desc_blk = new_desc_blk; -if (ret_meta_bg) - *ret_meta_bg = meta_bg; -return (numblocks); +if (ret_used_blks) + *ret_used_blks = numblocks; + +return 0 ; } +/* +* This function returns the location of the superblock, block group +* descriptors for a given block group. It currently returns the +* number of free blocks assuming that inode table and allocation +* bitmaps will be in the group. This is not necessarily the case +* when the flex_bg feature is enabled, so callers should take care! +* It was only really intended for use by mke2fs, and even there it's +* not that useful. +* +* The ext2fs_super_and_bgd_loc2() function is 64-bit block number +* capable and returns the number of blocks used by super block and +* group descriptors. +*/ +int ext2fs_super_and_bgd_loc (ext2_filsys fs, +dgrp_t group, +blk_t *ret_super_blk, +blk_t *ret_old_desc_blk, +blk_t *ret_new_desc_blk, +int *ret_meta_bg) +{ +blk64_t ret_super_blk2; +blk64_t ret_old_desc_blk2; +blk64_t ret_new_desc_blk2; +blk_t ret_used_blks; +blk_t numblocks; +unsigned int meta_bg_size; + +ext2fs_super_and_bgd_loc2 (fs, group, &ret_super_blk2, + &ret_old_desc_blk2, + &ret_new_desc_blk2, + &ret_used_blks); + +if (group == fs->group_desc_count-1 ) { + numblocks = (fs->super->s_blocks_count - + fs->super->s_first_data_block) % + fs->super->s_blocks_per_group; +if (!numblocks) + numblocks = fs->super->s_blocks_per_group; + }else + numblocks = fs->super->s_blocks_per_group; + +if (ret_super_blk) + *ret_super_blk = (blk_t )ret_super_blk2; +if (ret_old_desc_blk) + *ret_old_desc_blk = (blk_t )ret_old_desc_blk2; +if (ret_new_desc_blk) + *ret_new_desc_blk = (blk_t )ret_new_desc_blk2; +if (ret_meta_bg) { + meta_bg_size =EXT2_DESC_PER_BLOCK (fs->super); + *ret_meta_bg = group / meta_bg_size; + } + + numblocks -=2 + fs->inode_blocks_per_group + ret_used_blks; + +return numblocks; +}/* * This function forces out the primary superblock. We need to only
lib/ext2fs/ext2fs.h +6 -0
@@ -769,6 +769,12 @@ extern errcode_t ext2fs_check_desc(ext2_filsys fs);extern errcode_t ext2fs_close (ext2_filsys fs);extern errcode_t ext2fs_flush (ext2_filsys fs);extern int ext2fs_bg_has_super (ext2_filsys fs,int group_block); +extern errcode_t ext2fs_super_and_bgd_loc2 (ext2_filsys fs, +dgrp_t group, +blk64_t *ret_super_blk, +blk64_t *ret_old_desc_blk, +blk64_t *ret_new_desc_blk, +blk_t *ret_used_blks); extern int ext2fs_super_and_bgd_loc(ext2_filsys fs, dgrp_t group, blk_t *ret_super_blk,
PATCH 10/15 Use new ext2fs_super_and_bgd_loc2 call in libext2fs.
In reply to Jose R. SantosFrom: Jose R. Santos <[email protected]>
Use new ext2fs_super_and_bgd_loc2 call in libext2fs.
The new ext2fs_super_and_bgd_loc2() function has some changes aside from just blk64_t support. Lets make sure that the interfaces are sane by adding libext2fs support early to get the new API tested here.
--
e2fsck/pass5.c | 7 ++++--- lib/ext2fs/alloc_sb.c | 23 +++++++++++++++++++---- lib/ext2fs/closefs.c | 9 +++++---- 3 files changed, 28 insertions(+), 11 deletions(-)
--
e2fsck/pass5.c | 7 ++++--- lib/ext2fs/alloc_sb.c | 23 +++++++++++++++++++---- lib/ext2fs/closefs.c | 9 +++++---- 3 files changed, 28 insertions(+), 11 deletions(-)
e2fsck/pass5.c +4 -3
@@ -111,7 +111,8 @@ static void print_bitmap_problem(e2fsck_t ctx, int problem,static void check_block_bitmaps (e2fsck_t ctx) {ext2_filsys fs = ctx->fs; -blk_t i, super; +blk64_t i; +blk_t super;int *free_array;int group =0 ;blk_t blocks =0 ;
@@ -174,10 +175,10 @@ redo_counts: actual =ext2fs_fast_test_block_bitmap (ctx->block_found_map, i);if (skip_group) { -blk_t super_blk, old_desc_blk, new_desc_blk; +blk64_t super_blk, old_desc_blk, new_desc_blk;int old_desc_blocks; -ext2fs_super_and_bgd_loc (fs, group, &super_blk, +ext2fs_super_and_bgd_loc2 (fs, group, &super_blk, &old_desc_blk, &new_desc_blk,0 ); if (fs->super->s_feature_incompat &
lib/ext2fs/alloc_sb.c +19 -4
@@ -44,11 +44,12 @@ int ext2fs_reserve_super_and_bgd(ext2_filsys fs, dgrp_t group, ext2fs_block_bitmap bmap) { -blk_t super_blk, old_desc_blk, new_desc_blk; +blk64_t super_blk, old_desc_blk, new_desc_blk; +blk_t used_blks;int j, old_desc_blocks, num_blocks; - num_blocks =ext2fs_super_and_bgd_loc (fs, group, &super_blk, - &old_desc_blk, &new_desc_blk,0 ); +ext2fs_super_and_bgd_loc2 (fs, group, &super_blk, + &old_desc_blk, &new_desc_blk, &used_blks);if (fs->super->s_feature_incompat &EXT2_FEATURE_INCOMPAT_META_BG ) old_desc_blocks = fs->super->s_first_meta_bg;
@@ -57,6 +58,7 @@ int ext2fs_reserve_super_and_bgd(ext2_filsys fs, fs->desc_blocks + fs->super->s_reserved_gdt_blocks;if (super_blk || (group ==0 )) +/* FIXME-64 */ ext2fs_mark_block_bitmap (bmap, super_blk);if (old_desc_blk) {
@@ -64,11 +66,24 @@ int ext2fs_reserve_super_and_bgd(ext2_filsys fs, fs->group_desc[group].bg_flags &= ~EXT2_BG_BLOCK_UNINIT ;for (j=0 ; j < old_desc_blocks; j++)if (old_desc_blk + j < fs->super->s_blocks_count) +/* FIXME-64 */ ext2fs_mark_block_bitmap (bmap, old_desc_blk + j); }if (new_desc_blk) +/* FIXME-64 */ ext2fs_mark_block_bitmap (bmap, new_desc_blk); -return num_blocks; +if (group == fs->group_desc_count-1 ) { + num_blocks = (fs->super->s_blocks_count - + fs->super->s_first_data_block) % + fs->super->s_blocks_per_group; +if (!num_blocks) + num_blocks = fs->super->s_blocks_per_group; + }else + num_blocks = fs->super->s_blocks_per_group; + + num_blocks -=2 + fs->inode_blocks_per_group + used_blks; + +return num_blocks ; }
lib/ext2fs/closefs.c +5 -4
@@ -338,11 +338,10 @@ errcode_t ext2fs_flush(ext2_filsys fs) old_desc_blocks = fs->desc_blocks;for (i =0 ; i < fs->group_desc_count; i++) { -blk_t super_blk, old_desc_blk, new_desc_blk; -int meta_bg; +blk64_t super_blk, old_desc_blk, new_desc_blk; -ext2fs_super_and_bgd_loc (fs, i, &super_blk, &old_desc_blk, - &new_desc_blk, &meta_bg); +ext2fs_super_and_bgd_loc2 (fs, i, &super_blk, &old_desc_blk, + &new_desc_blk,0 );if (!(fs->flags &EXT2_FLAG_MASTER_SB_ONLY ) &&i && super_blk) { retval = write_backup_super(fs, i, super_blk,
@@ -360,6 +359,8 @@ errcode_t ext2fs_flush(ext2_filsys fs) goto errout; }if (new_desc_blk) { +int meta_bg = i /EXT2_DESC_PER_BLOCK (fs->super); + retval =io_channel_write_blk (fs->io, new_desc_blk,1 , group_ptr + (meta_bg*fs->blocksize));if (retval)
PATCH 11/15 Add 64-bit openfs interface.
In reply to Jose R. SantosFrom: Jose R. Santos <[email protected]>
Add 64-bit openfs interface.
Add new ext2fs_descriptor_block_loc2() routine that takes blk64_t as an input.
--
lib/ext2fs/ext2fs.h | 2 ++ lib/ext2fs/openfs.c | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-)
--
lib/ext2fs/ext2fs.h | 2 ++ lib/ext2fs/openfs.c | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-)
lib/ext2fs/ext2fs.h +2 -0
@@ -1125,6 +1125,8 @@ extern errcode_t ext2fs_open2(const char *name, const char *io_options, int flags, int superblock, unsigned int block_size, io_manager manager, ext2_filsys *ret_fs); +extern blk64_t ext2fs_descriptor_block_loc2 (ext2_filsys fs, +blk64_t group_block,dgrp_t i);extern blk_t ext2fs_descriptor_block_loc (ext2_filsys fs,blk_t group_block,dgrp_t i);errcode_t ext2fs_get_data_io (ext2_filsys fs,io_channel *old_io);
lib/ext2fs/openfs.c +9 -3
@@ -29,11 +29,12 @@#include "ext2fs.h" #include "e2image.h" -blk_t ext2fs_descriptor_block_loc (ext2_filsys fs,blk_t group_block,dgrp_t i) +blk64_t ext2fs_descriptor_block_loc2 (ext2_filsys fs,blk64_t group_block, +dgrp_t i) {int bg;int has_super =0 ; -int ret_blk; +blk64_t ret_blk;if (!(fs->super->s_feature_incompat &EXT2_FEATURE_INCOMPAT_META_BG ) || (i < fs->super->s_first_meta_bg))
@@ -42,7 +43,7 @@ blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block, dgrp_t i) bg =EXT2_DESC_PER_BLOCK (fs->super) * i;if (ext2fs_bg_has_super (fs, bg)) has_super =1 ; - ret_blk =ext2fs_group_first_block (fs, bg) + has_super; + ret_blk =ext2fs_group_first_block2 (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
@@ -58,6 +59,11 @@ blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block, dgrp_t i)return ret_blk; } +blk_t ext2fs_descriptor_block_loc (ext2_filsys fs,blk_t group_block,dgrp_t i) +{ +return ext2fs_descriptor_block_loc2 (fs, group_block, i); +} +errcode_t ext2fs_open (const char *name,int flags,int superblock,unsigned int block_size,io_manager manager,ext2_filsys *ret_fs)
PATCH 12/15 Add ext2fs_div64_ceil()
In reply to Jose R. SantosFrom: Jose R. Santos <[email protected]>
Add ext2fs_div64_ceil()
Add a new div_cell routine able to handle 64bit values
--
lib/ext2fs/ext2fs.h | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
lib/ext2fs/ext2fs.h +8 -0
@@ -1415,6 +1415,14 @@ _INLINE_ unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b)return 0 ;return ((a -1 ) / b) +1 ; } + +_INLINE_ __u64 ext2fs_div64_ceil(__u64 a, __u64 b) +{ +if (!a) +return 0 ; +return ((a -1 ) / b) +1 ; +} +#undef _INLINE_#endif
PATCH 13/15 Add 64-bit getsize interface.
In reply to Jose R. SantosFrom: Jose R. Santos <[email protected]>
Add 64-bit getsize interface.
Added interface capable of opening 64-bit block device.
--
lib/ext2fs/ext2fs.h | 2 ++ lib/ext2fs/getsize.c | 38 ++++++++++++++++---------------------- 2 files changed, 18 insertions(+), 22 deletions(-)
lib/ext2fs/ext2fs.h +2 -0
@@ -985,6 +985,8 @@ extern errcode_t ext2fs_set_generic_bitmap_range(ext2fs_generic_bitmap bmap,/* getsize.c */ extern errcode_t ext2fs_get_device_size (const char *file,int blocksize,blk_t *retblocks); +extern errcode_t ext2fs_get_device_size2 (const char *file,int blocksize, +blk64_t *retblocks);/* getsectsize.c */ errcode_t ext2fs_get_device_sectsize (const char *file,int *sectsize);
lib/ext2fs/getsize.c +16 -22
@@ -138,8 +138,8 @@ static int valid_offset (int fd, ext2_loff_t offset)/* * Returns the number of blocks in a partition */ -errcode_t ext2fs_get_device_size (const char *file,int blocksize, -blk_t *retblocks) +errcode_t ext2fs_get_device_size2 (const char *file,int blocksize, +blk64_t *retblocks) {int fd, rc =0 ;int valid_blkgetsize64 =1 ;
@@ -169,11 +169,6 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize,#ifdef DKIOCGETBLOCKCOUNT /* For Apple Darwin */ if (ioctl (fd,DKIOCGETBLOCKCOUNT , &size64) >=0 ) { -if ((sizeof (*retblocks) <sizeof (unsigned long long )) - && ((size64 / (blocksize /512 )) >0xFFFFFFFF )) { - rc =EFBIG ; - goto out; - } *retblocks = size64 / (blocksize /512 ); goto out; }
@@ -188,11 +183,6 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize,#endif if (valid_blkgetsize64 &&ioctl (fd,BLKGETSIZE64 , &size64) >=0 ) { -if ((sizeof (*retblocks) <sizeof (unsigned long long )) && - ((size64 / blocksize) >0xFFFFFFFF )) { - rc =EFBIG ; - goto out; - } *retblocks = size64 / blocksize; goto out; }
@@ -253,11 +243,6 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize, 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; }
@@ -282,17 +267,26 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize, }valid_offset (fd,0 ); size64 = low +1 ; -if ((sizeof (*retblocks) <sizeof (unsigned long long )) - && ((size64 / blocksize) >0xFFFFFFFF )) { - rc =EFBIG ; - goto out; - } *retblocks = size64 / blocksize; out:close (fd);return rc; } +errcode_t ext2fs_get_device_size (const char *file,int blocksize, +blk_t *retblocks) +{ +errcode_t retval; +blk64_t blocks; + retval =ext2fs_get_device_size2 (file, blocksize, &blocks); + +if (!retval && blocks < (1ULL <<32 )) { + *retblocks = (blk_t ) blocks; +return retval; + } +return EFBIG ; +} +#endif /* WIN32 */ #ifdef DEBUG
PATCH 14/15 Add 64-bit mkjournal.c interface
In reply to Jose R. SantosFrom: Jose R. Santos <[email protected]>
Add 64-bit mkjournal.c interface
Added 64-bit mkjournal.c interface. Needed to zero inode tables.
--
lib/ext2fs/ext2fs.h | 2 ++ lib/ext2fs/mkjournal.c | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-)
lib/ext2fs/ext2fs.h +2 -0
@@ -1110,6 +1110,8 @@ extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum/* mkjournal.c */ extern errcode_t ext2fs_zero_blocks (ext2_filsys fs,blk_t blk,int num,blk_t *ret_blk,int *ret_count); +extern errcode_t ext2fs_zero_blocks2 (ext2_filsys fs,blk64_t blk,int num, +blk64_t *ret_blk,int *ret_count);extern errcode_t ext2fs_create_journal_superblock (ext2_filsys fs,__u32 size,int flags,char **ret_jsb);
lib/ext2fs/mkjournal.c +15 -3
@@ -145,8 +145,8 @@ errout:* programs that check for memory leaks happy.) */ #define STRIDE_LENGTH 8 -errcode_t ext2fs_zero_blocks (ext2_filsys fs,blk_t blk,int num, -blk_t *ret_blk,int *ret_count) +errcode_t ext2fs_zero_blocks2 (ext2_filsys fs,blk64_t blk,int num, +blk64_t *ret_blk,int *ret_count) {int j, count;static char *buf;
@@ -179,7 +179,7 @@ errcode_t ext2fs_zero_blocks(ext2_filsys fs, blk_t blk, int num,if (count >STRIDE_LENGTH ) count =STRIDE_LENGTH ; } - retval =io_channel_write_blk (fs->io, blk, count, buf); + retval =io_channel_write_blk64 (fs->io, blk, count, buf);if (retval) {if (ret_count) *ret_count = count;
@@ -192,6 +192,18 @@ errcode_t ext2fs_zero_blocks(ext2_filsys fs, blk_t blk, int num,return 0 ; } +errcode_t ext2fs_zero_blocks (ext2_filsys fs,blk_t blk,int num, +blk_t *ret_blk,int *ret_count) +{ +blk64_t ret_blk2; +errcode_t retval; + + retval =ext2fs_zero_blocks2 (fs, blk, num, &ret_blk2, ret_count); +if (retval) + *ret_blk = (blk_t ) ret_blk2; +return retval; +} +/* * Helper function for creating the journal using direct I/O routines */
PATCH 15/15 64-bit mke2fs cleanup
In reply to Jose R. SantosFrom: Jose R. Santos <[email protected]>
64-bit mke2fs cleanup
Use 64-bit interfaces in mke2fs. This should be most most of whats needed to support creating a 64-bit filesystem. Things missing:
- 64-bit bitmap support being developed by Ted. We cant make a 64bit fs without this.
- 64-bit badblock interface. Waiting on Ted 64-bit bitmap patches to shamelessly steel some of his code. (particularly, the handling of different interface through the structure magic numbers)
This is not needed to create a 64-bit filesystem, but you cant have bad blocks above the 32bit block number boundary.
- lost+found and journal file are not created as extent mapped files. Should not prevent from creating a 64-bit filesystem and since those are typically at the beginning of the disk, don't know if I should really care. Don't know much about the extent format to know for sure.
--
lib/ext2fs/alloc_tables.c | 81 +++++++++++---------- lib/ext2fs/ext2fs.h | 6 +- lib/ext2fs/initialize.c | 44 +++++++---- misc/mke2fs.c | 177 ++++++++++++++++++++++++--------------------- misc/util.c | 4 + 5 files changed, 173 insertions(+), 139 deletions(-)
lib/ext2fs/alloc_tables.c +42 -39
@@ -33,11 +33,11 @@* block number with a correct offset were the bitmaps and inode * tables can be allocated continously and in order. */ -static blk_t flexbg_offset (ext2_filsys fs,dgrp_t group,blk_t start_blk, +static blk64_t flexbg_offset (ext2_filsys fs,dgrp_t group,blk_t start_blk,ext2fs_block_bitmap bmap,int offset,int size) {int flexbg, flexbg_size, elem_size; -blk_t last_blk, first_free =0 ; +blk64_t last_blk, first_free =0 ;dgrp_t last_grp; flexbg_size =1 << fs->super->s_log_groups_per_flex;
@@ -63,18 +63,18 @@ static blk_t flexbg_offset(ext2_filsys fs, dgrp_t group, blk_t start_blk,return start_blk + elem_size; } - start_blk =ext2fs_group_first_block (fs, flexbg_size * flexbg); + start_blk =ext2fs_group_first_block2 (fs, flexbg_size * flexbg); last_grp = group | (flexbg_size -1 );if (last_grp > fs->group_desc_count) last_grp = fs->group_desc_count; - last_blk =ext2fs_group_last_block (fs, last_grp); + last_blk =ext2fs_group_last_block2 (fs, last_grp);/* Find the first available block */ -if (ext2fs_get_free_blocks (fs, start_blk, last_blk,1 , bmap, +if (ext2fs_get_free_blocks2 (fs, start_blk, last_blk,1 , bmap, &first_free))return first_free; -if (ext2fs_get_free_blocks (fs, first_free + offset, last_blk, size, +if (ext2fs_get_free_blocks2 (fs, first_free + offset, last_blk, size, bmap, &first_free))return first_free;
@@ -85,12 +85,12 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, ext2fs_block_bitmap bmap) {errcode_t retval; -blk_t group_blk, start_blk, last_blk, new_blk, blk; +blk64_t group_blk, start_blk, last_blk, new_blk, blk;dgrp_t last_grp =0 ;int j, rem_grps =0 , flexbg_size =0 ; - group_blk =ext2fs_group_first_block (fs, group); - last_blk =ext2fs_group_last_block (fs, group); + group_blk =ext2fs_group_first_block2 (fs, group); + last_blk =ext2fs_group_last_block2 (fs, group);if (!bmap) bmap = fs->block_map;
@@ -109,8 +109,8 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,* Allocate the block and inode bitmaps, if necessary */ if (fs->stride) { - retval =ext2fs_get_free_blocks (fs, group_blk, last_blk, -1 , bmap, &start_blk); + retval =ext2fs_get_free_blocks2 (fs, group_blk, last_blk, +1 , bmap, &start_blk);if (retval)return retval; start_blk += fs->inode_blocks_per_group;
@@ -123,27 +123,28 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,if (flexbg_size) {int prev_block =0 ; -if (group && fs->group_desc[group-1 ].bg_block_bitmap) - prev_block = fs->group_desc[group-1 ].bg_block_bitmap; +if (group &&ext2fs_block_bitmap_loc (fs, group -1 )) + prev_block =ext2fs_block_bitmap_loc (fs, group -1 ); start_blk =flexbg_offset (fs, group, prev_block, bmap,0 , rem_grps); - last_blk =ext2fs_group_last_block (fs, last_grp); + last_blk =ext2fs_group_last_block2 (fs, last_grp); } -if (!fs->group_desc[group].bg_block_bitmap) { - retval =ext2fs_get_free_blocks (fs, start_blk, last_blk, -1 , bmap, &new_blk); +if (!ext2fs_block_bitmap_loc (fs, group)) { + retval =ext2fs_get_free_blocks2 (fs, start_blk, last_blk, +1 , bmap, &new_blk);if (retval ==EXT2_ET_BLOCK_ALLOC_FAIL ) - retval =ext2fs_get_free_blocks (fs, group_blk, + retval =ext2fs_get_free_blocks2 (fs, group_blk, last_blk,1 , bmap, &new_blk);if (retval)return retval; +/* FIXME-64 */ ext2fs_mark_block_bitmap (bmap, new_blk); - fs->group_desc[group].bg_block_bitmap = new_blk; +ext2fs_block_bitmap_loc_set (fs, group, new_blk);if (flexbg_size) { -dgrp_t gr =ext2fs_group_of_blk (fs, new_blk); +dgrp_t gr =ext2fs_group_of_blk2 (fs, new_blk); fs->group_desc[gr].bg_free_blocks_count--; - fs->super->s_free_blocks_count--; +ext2fs_free_blocks_count_add (fs->super,-1 ); fs->group_desc[gr].bg_flags &= ~EXT2_BG_BLOCK_UNINIT ;ext2fs_group_desc_csum_set (fs, gr); }
@@ -151,27 +152,28 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,if (flexbg_size) {int prev_block =0 ; -if (group && fs->group_desc[group-1 ].bg_inode_bitmap) - prev_block = fs->group_desc[group-1 ].bg_inode_bitmap; +if (group &&ext2fs_inode_bitmap_loc (fs, group -1 )) + prev_block =ext2fs_inode_bitmap_loc (fs, group -1 ); start_blk =flexbg_offset (fs, group, prev_block, bmap, flexbg_size, rem_grps); - last_blk =ext2fs_group_last_block (fs, last_grp); + last_blk =ext2fs_group_last_block2 (fs, last_grp); } -if (!fs->group_desc[group].bg_inode_bitmap) { - retval =ext2fs_get_free_blocks (fs, start_blk, last_blk, -1 , bmap, &new_blk); +if (!ext2fs_inode_bitmap_loc (fs, group)) { + retval =ext2fs_get_free_blocks2 (fs, start_blk, last_blk, +1 , bmap, &new_blk);if (retval ==EXT2_ET_BLOCK_ALLOC_FAIL ) - retval =ext2fs_get_free_blocks (fs, group_blk, + retval =ext2fs_get_free_blocks2 (fs, group_blk, last_blk,1 , bmap, &new_blk);if (retval)return retval; +/* FIXME-64 */ ext2fs_mark_block_bitmap (bmap, new_blk); - fs->group_desc[group].bg_inode_bitmap = new_blk; +ext2fs_inode_bitmap_loc_set (fs, group, new_blk);if (flexbg_size) { -dgrp_t gr =ext2fs_group_of_blk (fs, new_blk); +dgrp_t gr =ext2fs_group_of_blk2 (fs, new_blk); fs->group_desc[gr].bg_free_blocks_count--; - fs->super->s_free_blocks_count--; +ext2fs_free_blocks_count_add (fs->super,-1 ); fs->group_desc[gr].bg_flags &= ~EXT2_BG_BLOCK_UNINIT ;ext2fs_group_desc_csum_set (fs, gr); }
@@ -182,17 +184,17 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,*/ if (flexbg_size) {int prev_block =0 ; -if (group && fs->group_desc[group-1 ].bg_inode_table) - prev_block = fs->group_desc[group-1 ].bg_inode_table; +if (group &&ext2fs_inode_table_loc (fs, group -1 )) + prev_block =ext2fs_inode_table_loc (fs, group -1 ); group_blk =flexbg_offset (fs, group, prev_block, bmap, flexbg_size *2 , fs->inode_blocks_per_group * rem_grps); - last_blk =ext2fs_group_last_block (fs, last_grp); + last_blk =ext2fs_group_last_block2 (fs, last_grp); } -if (!fs->group_desc[group].bg_inode_table) { - retval =ext2fs_get_free_blocks (fs, group_blk, last_blk, +if (!ext2fs_inode_table_loc (fs, group)) { + retval =ext2fs_get_free_blocks2 (fs, group_blk, last_blk, fs->inode_blocks_per_group, bmap, &new_blk);if (retval)
@@ -200,16 +202,17 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,for (j=0 , blk = new_blk; j < fs->inode_blocks_per_group; j++, blk++) { +/* FIXME-64 */ ext2fs_mark_block_bitmap (bmap, blk);if (flexbg_size) { -dgrp_t gr =ext2fs_group_of_blk (fs, blk); +dgrp_t gr =ext2fs_group_of_blk2 (fs, blk); fs->group_desc[gr].bg_free_blocks_count--; - fs->super->s_free_blocks_count--; +ext2fs_free_blocks_count_add (fs->super,-1 ); fs->group_desc[gr].bg_flags &= ~EXT2_BG_BLOCK_UNINIT ;ext2fs_group_desc_csum_set (fs, gr); } } - fs->group_desc[group].bg_inode_table = new_blk; +ext2fs_inode_table_loc_set (fs, group, new_blk); }ext2fs_group_desc_csum_set (fs, group);return 0 ;
lib/ext2fs/ext2fs.h +4 -2
@@ -523,14 +523,16 @@ typedef struct ext2_icount *ext2_icount_t; EXT2_FEATURE_INCOMPAT_META_BG|\ EXT3_FEATURE_INCOMPAT_RECOVER|\ EXT3_FEATURE_INCOMPAT_EXTENTS|\ - EXT4_FEATURE_INCOMPAT_FLEX_BG) + EXT4_FEATURE_INCOMPAT_FLEX_BG|\ + EXT4_FEATURE_INCOMPAT_64BIT)#else #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\ EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\ EXT2_FEATURE_INCOMPAT_META_BG|\ EXT3_FEATURE_INCOMPAT_RECOVER|\ EXT3_FEATURE_INCOMPAT_EXTENTS|\ - EXT4_FEATURE_INCOMPAT_FLEX_BG) + EXT4_FEATURE_INCOMPAT_FLEX_BG|\ + EXT4_FEATURE_INCOMPAT_64BIT)#endif #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\ EXT4_FEATURE_RO_COMPAT_HUGE_FILE|\
lib/ext2fs/initialize.c +29 -15
104 lines not on this page · raw message
misc/mke2fs.c +96 -81
335 lines not on this page · raw message
misc/util.c +2 -2
@@ -253,7 +253,7 @@ unsigned int figure_journal_size(int size, ext2_filsys fs) {int j_blocks; - j_blocks =ext2fs_default_journal_size (fs->super->s_blocks_count); + j_blocks =ext2fs_default_journal_size (ext2fs_blocks_count (fs->super));if (j_blocks <0 ) {fputs (_ ("\nFilesystem too small for a journal\n" ), stderr);return 0 ;
@@ -269,7 +269,7 @@ unsigned int figure_journal_size(int size, ext2_filsys fs) j_blocks);exit (1 ); } -if ((unsigned ) j_blocks > fs->super->s_free_blocks_count /2 ) { +if ((unsigned ) j_blocks >ext2fs_free_blocks_count (fs->super) /2 ) {fputs (_ ("\nJournal size too big for filesystem.\n" ), stderr);exit (1 );