diff options
| author | JP Abgrall <jpa@google.com> | 2014-03-06 13:50:20 -0800 |
|---|---|---|
| committer | JP Abgrall <jpa@google.com> | 2014-03-06 13:50:20 -0800 |
| commit | 65f0aab98b20b5994a726ab90d355248bcddfffd (patch) | |
| tree | 2b7c0cf831d8255e3b0d1bab367609100a7e0f18 /lib/ext2fs | |
| parent | 66b7b06812cc7ae835e0c0ed2656d1a27580c5ed (diff) | |
| download | android_external_e2fsprogs-65f0aab98b20b5994a726ab90d355248bcddfffd.tar.gz android_external_e2fsprogs-65f0aab98b20b5994a726ab90d355248bcddfffd.tar.bz2 android_external_e2fsprogs-65f0aab98b20b5994a726ab90d355248bcddfffd.zip | |
Revert changes that moved from 1.41.14 to 1.42.9
Revert "e2fsck: Don't use e2fsck_global_ctx unless HAVE_SIGNAL_H"
commit e80e74c41d85ff93f3d212ba6512340f48054a93.
Revert "Merge remote-tracking branch 'linaro/linaro-1.42.9' into aosp_master"
This reverts commit e97b2b6fc82f840e84dfc631b87f21be44ff2421, reversing
changes made to 7e2fb9d09c245eba70ee008b78007315e9c0f1df.
Revert "Prepare for upstream 1.42.9"
This reverts commit 7e2fb9d09c245eba70ee008b78007315e9c0f1df.
Bug: 13340735
Change-Id: If48b153a95ef5f69f7cdccb00e23524abff3c5a8
Signed-off-by: JP Abgrall <jpa@google.com>
Diffstat (limited to 'lib/ext2fs')
109 files changed, 2399 insertions, 12074 deletions
diff --git a/lib/ext2fs/Android.mk b/lib/ext2fs/Android.mk index 5cf6eb03..c34efd37 100644 --- a/lib/ext2fs/Android.mk +++ b/lib/ext2fs/Android.mk @@ -10,9 +10,6 @@ libext2fs_src_files := \ bb_inode.c \ bitmaps.c \ bitops.c \ - blkmap64_ba.c \ - blkmap64_rb.c \ - blknum.c \ block.c \ bmap.c \ check_desc.c \ @@ -28,12 +25,10 @@ libext2fs_src_files := \ expanddir.c \ ext_attr.c \ extent.c \ - fileio.c \ finddev.c \ flushb.c \ freefs.c \ gen_bitmap.c \ - gen_bitmap64.c \ get_pathname.c \ getsize.c \ getsectsize.c \ @@ -48,15 +43,11 @@ libext2fs_src_files := \ link.c \ llseek.c \ lookup.c \ - mmp.c \ mkdir.c \ mkjournal.c \ native.c \ newdir.c \ openfs.c \ - progress.c \ - punch.c \ - rbtree.c \ read_bb.c \ read_bb_file.c \ res_gdt.c \ diff --git a/lib/ext2fs/MODULE_LICENSE_LGPL b/lib/ext2fs/MODULE_LICENSE_LGPL new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/lib/ext2fs/MODULE_LICENSE_LGPL diff --git a/lib/ext2fs/Makefile.in b/lib/ext2fs/Makefile.in index 87678c6a..26b7ed9e 100644 --- a/lib/ext2fs/Makefile.in +++ b/lib/ext2fs/Makefile.in @@ -26,15 +26,11 @@ OBJS= $(DEBUGFS_LIB_OBJS) $(RESIZE_LIB_OBJS) $(E2IMAGE_LIB_OBJS) \ bb_inode.o \ bitmaps.o \ bitops.o \ - blkmap64_ba.o \ - blkmap64_rb.o \ - blknum.o \ block.o \ bmap.o \ check_desc.o \ closefs.o \ crc16.o \ - crc32c.o \ csum.o \ dblist.o \ dblist_dir.o \ @@ -49,7 +45,6 @@ OBJS= $(DEBUGFS_LIB_OBJS) $(RESIZE_LIB_OBJS) $(E2IMAGE_LIB_OBJS) \ flushb.o \ freefs.o \ gen_bitmap.o \ - gen_bitmap64.o \ get_pathname.o \ getsize.o \ getsectsize.o \ @@ -66,27 +61,21 @@ OBJS= $(DEBUGFS_LIB_OBJS) $(RESIZE_LIB_OBJS) $(E2IMAGE_LIB_OBJS) \ lookup.o \ mkdir.o \ mkjournal.o \ - mmp.o \ namei.o \ native.o \ newdir.o \ openfs.o \ - progress.o \ - punch.o \ - qcow2.o \ read_bb.o \ read_bb_file.o \ res_gdt.o \ rw_bitmaps.o \ swapfs.o \ - symlink.o \ tdb.o \ undo_io.o \ unix_io.o \ unlink.o \ valid_blk.o \ - version.o \ - rbtree.o + version.o SRCS= ext2_err.c \ $(srcdir)/alloc.c \ @@ -98,15 +87,11 @@ SRCS= ext2_err.c \ $(srcdir)/bb_inode.c \ $(srcdir)/bitmaps.c \ $(srcdir)/bitops.c \ - $(srcdir)/blkmap64_ba.c \ - $(srcdir)/blkmap64_rb.c \ $(srcdir)/block.c \ $(srcdir)/bmap.c \ $(srcdir)/check_desc.c \ $(srcdir)/closefs.c \ $(srcdir)/crc16.c \ - $(srcdir)/crc32c.c \ - $(srcdir)/gen_crc32ctable.c \ $(srcdir)/csum.c \ $(srcdir)/dblist.c \ $(srcdir)/dblist_dir.c \ @@ -122,7 +107,6 @@ SRCS= ext2_err.c \ $(srcdir)/flushb.c \ $(srcdir)/freefs.c \ $(srcdir)/gen_bitmap.c \ - $(srcdir)/gen_bitmap64.c \ $(srcdir)/get_pathname.c \ $(srcdir)/getsize.c \ $(srcdir)/getsectsize.c \ @@ -141,20 +125,15 @@ SRCS= ext2_err.c \ $(srcdir)/lookup.c \ $(srcdir)/mkdir.c \ $(srcdir)/mkjournal.c \ - $(srcdir)/mmp.c \ $(srcdir)/namei.c \ $(srcdir)/native.c \ $(srcdir)/newdir.c \ $(srcdir)/openfs.c \ - $(srcdir)/progress.c \ - $(srcdir)/punch.c \ - $(srcdir)/qcow2.c \ $(srcdir)/read_bb.c \ $(srcdir)/read_bb_file.c \ $(srcdir)/res_gdt.c \ $(srcdir)/rw_bitmaps.c \ $(srcdir)/swapfs.c \ - $(srcdir)/symlink.c \ $(srcdir)/tdb.c \ $(srcdir)/test_io.c \ $(srcdir)/tst_badblocks.c \ @@ -167,11 +146,10 @@ SRCS= ext2_err.c \ $(srcdir)/unlink.c \ $(srcdir)/valid_blk.c \ $(srcdir)/version.c \ - $(srcdir)/write_bb_file.c \ - $(srcdir)/rbtree.c \ + $(srcdir)/write_bb_file.c HFILES= bitops.h ext2fs.h ext2_io.h ext2_fs.h ext2_ext_attr.h ext3_extents.h \ - tdb.h qcow2.h + tdb.h HFILES_IN= ext2_err.h ext2_types.h LIBRARY= libext2fs @@ -182,7 +160,7 @@ ELF_SO_VERSION = 2 ELF_IMAGE = libext2fs ELF_MYDIR = ext2fs ELF_INSTALL_DIR = $(root_libdir) -ELF_OTHER_LIBS = -lcom_err +ELF_OTHER_LIBS = -L../.. -lcom_err BSDLIB_VERSION = 2.1 BSDLIB_IMAGE = libext2fs @@ -200,7 +178,6 @@ all:: ext2fs.pc .c.o: $(E) " CC $<" $(Q) $(CC) $(ALL_CFLAGS) -c $< -o $@ - $(Q) $(CHECK_CMD) $(ALL_CFLAGS) $< @PROFILE_CMT@ $(Q) $(CC) $(ALL_CFLAGS) -g -pg -o profiled/$*.o -c $< @CHECKER_CMT@ $(Q) $(CC) $(ALL_CFLAGS) -checker -g -o checker/$*.o -c $< @ELF_CMT@ $(Q) $(CC) $(ALL_CFLAGS) -fPIC -o elfshared/$*.o -c $< @@ -222,47 +199,45 @@ ext2fs.pc: $(srcdir)/ext2fs.pc.in $(top_builddir)/config.status $(E) " CONFIG.STATUS $@" $(Q) cd $(top_builddir); CONFIG_FILES=lib/ext2fs/ext2fs.pc ./config.status -tst_badblocks: tst_badblocks.o $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR) +tst_badblocks: tst_badblocks.o $(STATIC_LIBEXT2FS) $(DEPLIBCOM_ERR) $(E) " LD $@" $(Q) $(CC) -o tst_badblocks tst_badblocks.o $(STATIC_LIBEXT2FS) \ - $(STATIC_LIBCOM_ERR) + $(LIBCOM_ERR) -tst_icount: $(srcdir)/icount.c $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR) +tst_icount: $(srcdir)/icount.c $(STATIC_LIBEXT2FS) $(DEPLIBCOM_ERR) $(E) " LD $@" $(Q) $(CC) -o tst_icount $(srcdir)/icount.c -DDEBUG $(ALL_CFLAGS) \ - $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) + $(STATIC_LIBEXT2FS) $(LIBCOM_ERR) -tst_iscan: tst_iscan.o $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR) +tst_iscan: tst_iscan.o $(STATIC_LIBEXT2FS) $(DEPLIBCOM_ERR) $(E) " LD $@" - $(Q) $(CC) -o tst_iscan tst_iscan.o $(STATIC_LIBEXT2FS) \ - $(STATIC_LIBCOM_ERR) + $(Q) $(CC) -o tst_iscan tst_iscan.o $(STATIC_LIBEXT2FS) $(LIBCOM_ERR) -tst_getsize: tst_getsize.o $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR) +tst_getsize: tst_getsize.o $(STATIC_LIBEXT2FS) $(DEPLIBCOM_ERR) $(E) " LD $@" $(Q) $(CC) -o tst_getsize tst_getsize.o $(STATIC_LIBEXT2FS) \ - $(STATIC_LIBCOM_ERR) + $(LIBCOM_ERR) -tst_ismounted: $(srcdir)/ismounted.c $(STATIC_LIBEXT2FS) \ - $(DEPSTATIC_LIBCOM_ERR) +tst_ismounted: $(srcdir)/ismounted.c $(STATIC_LIBEXT2FS) $(DEPLIBCOM_ERR) $(E) " LD $@" $(Q) $(CC) -o tst_ismounted $(srcdir)/ismounted.c \ $(STATIC_LIBEXT2FS) -DDEBUG $(ALL_CFLAGS) \ - $(STATIC_LIBCOM_ERR) + $(LIBCOM_ERR) -tst_byteswap: tst_byteswap.o $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR) +tst_byteswap: tst_byteswap.o $(STATIC_LIBEXT2FS) $(DEPLIBCOM_ERR) $(E) " LD $@" $(Q) $(CC) -o tst_byteswap tst_byteswap.o $(STATIC_LIBEXT2FS) \ - $(STATIC_LIBCOM_ERR) + $(LIBCOM_ERR) -tst_bitops: tst_bitops.o $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR) +tst_bitops: tst_bitops.o $(STATIC_LIBEXT2FS) $(DEPLIBCOM_ERR) $(E) " LD $@" $(Q) $(CC) -o tst_bitops tst_bitops.o $(ALL_CFLAGS) \ - $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) + $(STATIC_LIBEXT2FS) $(LIBCOM_ERR) -tst_getsectsize: tst_getsectsize.o $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR) +tst_getsectsize: tst_getsectsize.o $(STATIC_LIBEXT2FS) $(DEPLIBCOM_ERR) $(E) " LD $@" $(Q) $(CC) -o tst_sectgetsize tst_getsectsize.o \ - $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) + $(STATIC_LIBEXT2FS) $(LIBCOM_ERR) tst_types.o: $(srcdir)/tst_types.c ext2_types.h @@ -276,18 +251,6 @@ tst_super_size: tst_super_size.o $(E) " LD $@" $(Q) $(CC) -o tst_super_size tst_super_size.o -tst_fs_struct.o: $(srcdir)/tst_fs_struct.c $(srcdir)/ext2fs.h - -tst_fs_struct: tst_fs_struct.o - $(E) " LD $@" - $(Q) $(CC) -o tst_fs_struct tst_fs_struct.o - -tst_inode_size.o: $(srcdir)/tst_inode_size.c $(srcdir)/ext2_fs.h - -tst_inode_size: tst_inode_size.o - $(E) " LD $@" - $(Q) $(CC) -o tst_inode_size tst_inode_size.o - ext2_tdbtool: tdbtool.o $(E) " LD $@" $(Q) $(CC) -o ext2_tdbtool tdbtool.o tdb.o @@ -297,25 +260,16 @@ extent_dbg.c: $(srcdir)/extent_dbg.ct $(Q) $(MK_CMDS) $(srcdir)/extent_dbg.ct debug_cmds.c debug_cmds.h: $(top_srcdir)/debugfs/debug_cmds.ct - $(E) " MK_CMDS $<" + $(E) " MK_CMDS $<@" $(Q) $(MK_CMDS) $(top_srcdir)/debugfs/debug_cmds.ct -extent_cmds.c extent_cmds.h: $(top_srcdir)/debugfs/extent_cmds.ct - $(E) " MK_CMDS $<" - $(Q) $(MK_CMDS) $(top_srcdir)/debugfs/extent_cmds.ct - DEBUG_OBJS= debug_cmds.o debugfs.o util.o ncheck.o icheck.o ls.o \ - lsdel.o dump.o set_fields.o logdump.o htree.o unused.o \ - e2freefrag.o filefrag.o extent_inode.o extent_cmds.o zap.o + lsdel.o dump.o set_fields.o logdump.o htree.o unused.o debugfs.o: $(top_srcdir)/debugfs/debugfs.c $(E) " CC $<" $(Q) $(CC) $(ALL_CFLAGS) -c $< -o $@ -extent_inode.o: $(top_srcdir)/debugfs/extent_inode.c - $(E) " CC $<" - $(Q) $(CC) $(ALL_CFLAGS) -c $< -o $@ - util.o: $(top_srcdir)/debugfs/util.c $(E) " CC $<" $(Q) $(CC) $(ALL_CFLAGS) -c $< -o $@ @@ -356,81 +310,32 @@ unused.o: $(top_srcdir)/debugfs/unused.c $(E) " CC $<" $(Q) $(CC) $(ALL_CFLAGS) -c $< -o $@ -zap.o: $(top_srcdir)/debugfs/zap.c - $(E) " CC $<" - $(Q) $(CC) $(ALL_CFLAGS) -c $< -o $@ - -e2freefrag.o: $(top_srcdir)/misc/e2freefrag.c - $(E) " CC $<" - $(Q) $(CC) $(ALL_CFLAGS) -DDEBUGFS -I$(top_srcdir)/debugfs -c $< -o $@ - -filefrag.o: $(top_srcdir)/debugfs/filefrag.c - $(E) " CC $<" - $(Q) $(CC) $(ALL_CFLAGS) -c $< -o $@ - -tst_bitmaps_cmd.c: tst_bitmaps_cmd.ct - $(E) " MK_CMDS $@" - $(Q) DIR=$(srcdir) $(MK_CMDS) $(srcdir)/tst_bitmaps_cmd.ct - -tst_bitmaps: tst_bitmaps.o tst_bitmaps_cmd.o $(STATIC_LIBEXT2FS) \ - $(DEPSTATIC_LIBSS) $(DEPSTATIC_LIBCOM_ERR) +tst_extents: $(srcdir)/extent.c extent_dbg.c $(DEBUG_OBJS) $(DEPLIBSS) \ + $(LIBE2P) $(DEPLIBUUID) $(DEPLIBBLKID) $(DEPLIBCOM_ERR) $(E) " LD $@" - $(Q) $(CC) -o $@ tst_bitmaps.o tst_bitmaps_cmd.o $(ALL_CFLAGS) \ - $(STATIC_LIBEXT2FS) $(STATIC_LIBSS) $(STATIC_LIBCOM_ERR) + $(Q) $(CC) -o tst_extents $(srcdir)/extent.c extent_dbg.c \ + $(ALL_CFLAGS) -DDEBUG $(DEBUG_OBJS) $(LIBSS) $(LIBE2P) \ + $(STATIC_LIBEXT2FS) $(LIBBLKID) $(LIBUUID) $(LIBCOM_ERR) \ + -I $(top_srcdir)/debugfs -tst_extents: $(srcdir)/extent.c $(DEBUG_OBJS) $(DEPSTATIC_LIBSS) \ - $(STATIC_LIBE2P) $(DEPLIBUUID) $(DEPLIBBLKID) $(DEPSTATIC_LIBCOM_ERR) - $(E) " LD $@" - $(Q) $(CC) -o tst_extents $(srcdir)/extent.c \ - $(ALL_CFLAGS) -DDEBUG $(DEBUG_OBJS) $(STATIC_LIBSS) \ - $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) $(LIBBLKID) $(LIBUUID) \ - $(STATIC_LIBCOM_ERR) -I $(top_srcdir)/debugfs - -tst_inline: $(srcdir)/inline.c $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR) - $(E) " LD $@" - $(Q) $(CC) -o tst_inline $(srcdir)/inline.c $(ALL_CFLAGS) -DDEBUG \ - $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) - -tst_csum: csum.c $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR) $(STATIC_LIBE2P) \ +tst_csum: csum.c $(STATIC_LIBEXT2FS) $(DEPLIBCOM_ERR) \ $(top_srcdir)/lib/e2p/e2p.h $(E) " LD $@" $(Q) $(CC) -o tst_csum $(srcdir)/csum.c -DDEBUG \ - $(ALL_CFLAGS) $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) \ - $(STATIC_LIBE2P) - -tst_crc32c: $(srcdir)/crc32c.c $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR) - $(Q) $(CC) $(BUILD_LDFLAGS) $(ALL_CFLAGS) -o tst_crc32c $(srcdir)/crc32c.c \ - -DUNITTEST $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) + $(ALL_CFLAGS) $(STATIC_LIBEXT2FS) $(LIBCOM_ERR) $(LIBE2P) mkjournal: mkjournal.c $(STATIC_LIBEXT2FS) $(DEPLIBCOM_ERR) $(E) " LD $@" $(Q) $(CC) -o mkjournal $(srcdir)/mkjournal.c -DDEBUG $(STATIC_LIBEXT2FS) $(LIBCOM_ERR) $(ALL_CFLAGS) -check:: tst_bitops tst_badblocks tst_iscan tst_types tst_icount \ - tst_super_size tst_types tst_inode_size tst_csum tst_crc32c tst_bitmaps \ - tst_inline +check:: tst_bitops tst_badblocks tst_iscan tst_types tst_icount tst_super_size tst_types tst_csum LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_bitops LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_badblocks LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_iscan LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_types LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_icount LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_super_size - LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_inode_size LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_csum - LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_inline - LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_crc32c - LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) \ - ./tst_bitmaps -f $(srcdir)/tst_bitmaps_cmds > tst_bitmaps_out - diff $(srcdir)/tst_bitmaps_exp tst_bitmaps_out - LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) \ - ./tst_bitmaps -t 2 -f $(srcdir)/tst_bitmaps_cmds > tst_bitmaps_out - diff $(srcdir)/tst_bitmaps_exp tst_bitmaps_out - LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) \ - ./tst_bitmaps -t 3 -f $(srcdir)/tst_bitmaps_cmds > tst_bitmaps_out - diff $(srcdir)/tst_bitmaps_exp tst_bitmaps_out - LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) \ - ./tst_bitmaps -l -f $(srcdir)/tst_bitmaps_cmds > tst_bitmaps_out - diff $(srcdir)/tst_bitmaps_exp tst_bitmaps_out installdirs:: $(E) " MKINSTALLDIRS $(libdir) $(includedir)/ext2fs" @@ -463,11 +368,8 @@ clean:: tst_badblocks tst_iscan ext2_err.et ext2_err.c ext2_err.h \ tst_byteswap tst_ismounted tst_getsize tst_sectgetsize \ tst_bitops tst_types tst_icount tst_super_size tst_csum \ - tst_bitmaps tst_bitmaps_out tst_extents tst_inline \ - tst_inline_data tst_inode_size tst_bitmaps_cmd.c \ - ext2_tdbtool mkjournal debug_cmds.c extent_cmds.c \ - ../libext2fs.a ../libext2fs_p.a ../libext2fs_chk.a \ - crc32c_table.h gen_crc32ctable tst_crc32c + ext2_tdbtool mkjournal debug_cmds.c \ + ../libext2fs.a ../libext2fs_p.a ../libext2fs_chk.a mostlyclean:: clean distclean:: clean @@ -480,495 +382,357 @@ $(top_builddir)/lib/ext2fs/ext2_err.h: ext2_err.h $(OBJS): subdirs -gen_crc32ctable: $(srcdir)/gen_crc32ctable.c - $(E) " CC $@" - $(Q) $(BUILD_CC) $(BUILD_CFLAGS) $(BUILD_LDFLAGS) -o gen_crc32ctable \ - $(srcdir)/gen_crc32ctable.c - -crc32c_table.h: gen_crc32ctable - $(E) " GEN32CTABLE $@" - $(Q) ./gen_crc32ctable > crc32c_table.h - # +++ Dependency line eater +++ # # Makefile dependencies follow. This must be the last section in # the Makefile.in file # ext2_err.o: ext2_err.c -alloc.o: $(srcdir)/alloc.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +alloc.o: $(srcdir)/alloc.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -alloc_sb.o: $(srcdir)/alloc_sb.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +alloc_sb.o: $(srcdir)/alloc_sb.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -alloc_stats.o: $(srcdir)/alloc_stats.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +alloc_stats.o: $(srcdir)/alloc_stats.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -alloc_tables.o: $(srcdir)/alloc_tables.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +alloc_tables.o: $(srcdir)/alloc_tables.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ - $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h $(srcdir)/ext2fsP.h -badblocks.o: $(srcdir)/badblocks.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ + $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h +badblocks.o: $(srcdir)/badblocks.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fsP.h \ $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \ $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ $(srcdir)/bitops.h -bb_compat.o: $(srcdir)/bb_compat.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +bb_compat.o: $(srcdir)/bb_compat.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fsP.h \ $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \ $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ $(srcdir)/bitops.h -bb_inode.o: $(srcdir)/bb_inode.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +bb_inode.o: $(srcdir)/bb_inode.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -bitmaps.o: $(srcdir)/bitmaps.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +bitmaps.o: $(srcdir)/bitmaps.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ - $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h $(srcdir)/ext2fsP.h \ - $(srcdir)/bmap64.h -bitops.o: $(srcdir)/bitops.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ + $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h +bitops.o: $(srcdir)/bitops.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -blkmap64_ba.o: $(srcdir)/blkmap64_ba.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ - $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fsP.h \ - $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \ - $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ - $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ - $(srcdir)/bitops.h $(srcdir)/bmap64.h -blkmap64_rb.o: $(srcdir)/blkmap64_rb.c $(srcdir)/ext2_fs.h \ - $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fsP.h \ - $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \ - $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ - $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ - $(srcdir)/bitops.h $(srcdir)/bmap64.h $(srcdir)/rbtree.h -block.o: $(srcdir)/block.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +block.o: $(srcdir)/block.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -bmap.o: $(srcdir)/bmap.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +bmap.o: $(srcdir)/bmap.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -check_desc.o: $(srcdir)/check_desc.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +check_desc.o: $(srcdir)/check_desc.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -closefs.o: $(srcdir)/closefs.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +closefs.o: $(srcdir)/closefs.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fsP.h \ $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \ $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ $(srcdir)/bitops.h -crc16.o: $(srcdir)/crc16.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(top_builddir)/lib/ext2fs/ext2_types.h \ +crc16.o: $(srcdir)/crc16.c $(top_builddir)/lib/ext2fs/ext2_types.h \ $(srcdir)/crc16.h -crc32c.o: $(srcdir)/crc32c.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/crc32c_defs.h $(srcdir)/ext2fs.h \ - $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2_fs.h \ - $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ - $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ - $(srcdir)/bitops.h crc32c_table.h -gen_crc32ctable.o: $(srcdir)/gen_crc32ctable.c $(srcdir)/crc32c_defs.h -csum.o: $(srcdir)/csum.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +csum.o: $(srcdir)/csum.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h $(srcdir)/crc16.h -dblist.o: $(srcdir)/dblist.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +dblist.o: $(srcdir)/dblist.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fsP.h \ $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \ $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ $(srcdir)/bitops.h -dblist_dir.o: $(srcdir)/dblist_dir.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +dblist_dir.o: $(srcdir)/dblist_dir.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fsP.h \ $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \ $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ $(srcdir)/bitops.h -dirblock.o: $(srcdir)/dirblock.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +dirblock.o: $(srcdir)/dirblock.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -dirhash.o: $(srcdir)/dirhash.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +dirhash.o: $(srcdir)/dirhash.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -dir_iterate.o: $(srcdir)/dir_iterate.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +dir_iterate.o: $(srcdir)/dir_iterate.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fsP.h \ $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \ $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ $(srcdir)/bitops.h -dupfs.o: $(srcdir)/dupfs.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +dupfs.o: $(srcdir)/dupfs.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fsP.h \ $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \ $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ $(srcdir)/bitops.h -expanddir.o: $(srcdir)/expanddir.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +expanddir.o: $(srcdir)/expanddir.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -ext_attr.o: $(srcdir)/ext_attr.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +ext_attr.o: $(srcdir)/ext_attr.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2_ext_attr.h \ $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \ $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ $(srcdir)/bitops.h -extent.o: $(srcdir)/extent.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +extent.o: $(srcdir)/extent.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fsP.h \ $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \ $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ $(srcdir)/bitops.h $(srcdir)/e2image.h -fileio.o: $(srcdir)/fileio.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +fileio.o: $(srcdir)/fileio.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -finddev.o: $(srcdir)/finddev.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +finddev.o: $(srcdir)/finddev.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ - $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h $(srcdir)/ext2fsP.h -flushb.o: $(srcdir)/flushb.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ + $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h +flushb.o: $(srcdir)/flushb.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -freefs.o: $(srcdir)/freefs.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +freefs.o: $(srcdir)/freefs.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fsP.h \ $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \ $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ $(srcdir)/bitops.h -gen_bitmap.o: $(srcdir)/gen_bitmap.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ - $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fsP.h \ - $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \ - $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ - $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ - $(srcdir)/bitops.h -gen_bitmap64.o: $(srcdir)/gen_bitmap64.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ - $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fsP.h \ - $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \ - $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ - $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ - $(srcdir)/bitops.h $(srcdir)/bmap64.h -get_pathname.o: $(srcdir)/get_pathname.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +gen_bitmap.o: $(srcdir)/gen_bitmap.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -getsize.o: $(srcdir)/getsize.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +get_pathname.o: $(srcdir)/get_pathname.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -getsectsize.o: $(srcdir)/getsectsize.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +getsize.o: $(srcdir)/getsize.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -i_block.o: $(srcdir)/i_block.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +getsectsize.o: $(srcdir)/getsectsize.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -icount.o: $(srcdir)/icount.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +i_block.o: $(srcdir)/i_block.c $(srcdir)/ext2_fs.h \ + $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ + $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ + $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ + $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h +icount.o: $(srcdir)/icount.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h $(srcdir)/tdb.h -ind_block.o: $(srcdir)/ind_block.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +ind_block.o: $(srcdir)/ind_block.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -initialize.o: $(srcdir)/initialize.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +initialize.o: $(srcdir)/initialize.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -inline.o: $(srcdir)/inline.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +inline.o: $(srcdir)/inline.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -inode.o: $(srcdir)/inode.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +inode.o: $(srcdir)/inode.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fsP.h \ $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \ $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ $(srcdir)/bitops.h $(srcdir)/e2image.h -inode_io.o: $(srcdir)/inode_io.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +inode_io.o: $(srcdir)/inode_io.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -imager.o: $(srcdir)/imager.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +imager.o: $(srcdir)/imager.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -io_manager.o: $(srcdir)/io_manager.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +io_manager.o: $(srcdir)/io_manager.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -ismounted.o: $(srcdir)/ismounted.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +ismounted.o: $(srcdir)/ismounted.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -link.o: $(srcdir)/link.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +link.o: $(srcdir)/link.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -llseek.o: $(srcdir)/llseek.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(top_srcdir)/lib/et/com_err.h \ +llseek.o: $(srcdir)/llseek.c $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h -lookup.o: $(srcdir)/lookup.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +lookup.o: $(srcdir)/lookup.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -mkdir.o: $(srcdir)/mkdir.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +mkdir.o: $(srcdir)/mkdir.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -mkjournal.o: $(srcdir)/mkjournal.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +mkjournal.o: $(srcdir)/mkjournal.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/e2p/e2p.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext2fs.h $(srcdir)/ext3_extents.h \ $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ $(srcdir)/bitops.h $(srcdir)/jfs_user.h $(srcdir)/kernel-jbd.h \ $(srcdir)/jfs_compat.h $(srcdir)/kernel-list.h -mmp.o: $(srcdir)/mmp.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ - $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ - $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ - $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ - $(srcdir)/bitops.h -namei.o: $(srcdir)/namei.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +namei.o: $(srcdir)/namei.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ - $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h $(srcdir)/ext2fsP.h -native.o: $(srcdir)/native.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ + $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h +native.o: $(srcdir)/native.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -newdir.o: $(srcdir)/newdir.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +newdir.o: $(srcdir)/newdir.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -openfs.o: $(srcdir)/openfs.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +openfs.o: $(srcdir)/openfs.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h $(srcdir)/e2image.h -progress.o: $(srcdir)/progress.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2fs.h \ - $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2_fs.h \ - $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ - $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ - $(srcdir)/bitops.h $(srcdir)/ext2fsP.h -punch.o: $(srcdir)/punch.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ - $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ - $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ - $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ - $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -qcow2.o: $(srcdir)/qcow2.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2fs.h \ - $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2_fs.h \ - $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ - $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ - $(srcdir)/bitops.h $(srcdir)/qcow2.h -read_bb.o: $(srcdir)/read_bb.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +read_bb.o: $(srcdir)/read_bb.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -read_bb_file.o: $(srcdir)/read_bb_file.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +read_bb_file.o: $(srcdir)/read_bb_file.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -res_gdt.o: $(srcdir)/res_gdt.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +res_gdt.o: $(srcdir)/res_gdt.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -rw_bitmaps.o: $(srcdir)/rw_bitmaps.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +rw_bitmaps.o: $(srcdir)/rw_bitmaps.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h $(srcdir)/e2image.h -swapfs.o: $(srcdir)/swapfs.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ - $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ - $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ - $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ - $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -symlink.o: $(srcdir)/symlink.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +swapfs.o: $(srcdir)/swapfs.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -tdb.o: $(srcdir)/tdb.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/tdb.h -test_io.o: $(srcdir)/test_io.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +tdb.o: $(srcdir)/tdb.c $(srcdir)/tdb.h +test_io.o: $(srcdir)/test_io.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -tst_badblocks.o: $(srcdir)/tst_badblocks.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +tst_badblocks.o: $(srcdir)/tst_badblocks.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -tst_bitops.o: $(srcdir)/tst_bitops.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +tst_bitops.o: $(srcdir)/tst_bitops.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -tst_byteswap.o: $(srcdir)/tst_byteswap.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +tst_byteswap.o: $(srcdir)/tst_byteswap.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -tst_getsize.o: $(srcdir)/tst_getsize.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +tst_getsize.o: $(srcdir)/tst_getsize.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -tst_iscan.o: $(srcdir)/tst_iscan.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +tst_iscan.o: $(srcdir)/tst_iscan.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -undo_io.o: $(srcdir)/undo_io.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/tdb.h $(srcdir)/ext2_fs.h \ +undo_io.o: $(srcdir)/undo_io.c $(srcdir)/tdb.h $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -unix_io.o: $(srcdir)/unix_io.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +unix_io.o: $(srcdir)/unix_io.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -unlink.o: $(srcdir)/unlink.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +unlink.o: $(srcdir)/unlink.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -valid_blk.o: $(srcdir)/valid_blk.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +valid_blk.o: $(srcdir)/valid_blk.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -version.o: $(srcdir)/version.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +version.o: $(srcdir)/version.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h $(top_srcdir)/version.h -write_bb_file.o: $(srcdir)/write_bb_file.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ +write_bb_file.o: $(srcdir)/write_bb_file.c $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h -rbtree.o: $(srcdir)/rbtree.c $(srcdir)/rbtree.h diff --git a/lib/ext2fs/Makefile.pq b/lib/ext2fs/Makefile.pq deleted file mode 100644 index 2f7b654b..00000000 --- a/lib/ext2fs/Makefile.pq +++ /dev/null @@ -1,49 +0,0 @@ -TOPSRC=..\.. -LIBNAME=EXT2.LIB -OBJFILE=EXT2.LST - -OBJS= alloc.obj \ - alloc_tables.obj \ - badblocks.obj \ - bb_compat.obj \ - bb_inode.obj \ - bitmaps.obj \ - bitops.obj \ - block.obj \ - bmap.obj \ - bmove.obj \ - check_desc.obj \ - closefs.obj \ - cmp_bitmaps.obj \ - dblist.obj \ - dblist_dir.obj \ - dirblock.obj \ - dir_iterate.obj \ - dupfs.obj \ - expanddir.obj \ - fileio.obj \ - freefs.obj \ - get_pathname.obj \ - icount.obj \ - initialize.obj \ - inline.obj \ - inode.obj \ - ismounted.obj \ - link.obj \ - lookup.obj \ - mkdir.obj \ - namei.obj \ - native.obj \ - newdir.obj \ - openfs.obj \ - read_bb.obj \ - read_bb_file.obj \ - rs_bitmap.obj \ - rw_bitmaps.obj \ - swapfs.obj \ - unlink.obj \ - valid_blk.obj \ - version.obj - -!include $(TOPSRC)\powerquest\MCONFIG - diff --git a/lib/ext2fs/alloc.c b/lib/ext2fs/alloc.c index 21d3e5ef..59d10890 100644 --- a/lib/ext2fs/alloc.c +++ b/lib/ext2fs/alloc.c @@ -29,21 +29,22 @@ * Check for uninit block bitmaps and deal with them appropriately */ static void check_block_uninit(ext2_filsys fs, ext2fs_block_bitmap map, - dgrp_t group) + dgrp_t group) { blk_t i; - blk64_t blk, super_blk, old_desc_blk, new_desc_blk; + blk_t blk, super_blk, old_desc_blk, new_desc_blk; int old_desc_blocks; if (!(EXT2_HAS_RO_COMPAT_FEATURE(fs->super, EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) || - !(ext2fs_bg_flags_test(fs, group, EXT2_BG_BLOCK_UNINIT))) + !(fs->group_desc[group].bg_flags & EXT2_BG_BLOCK_UNINIT)) return; - blk = ext2fs_group_first_block2(fs, group); + blk = (group * fs->super->s_blocks_per_group) + + fs->super->s_first_data_block; - ext2fs_super_and_bgd_loc2(fs, group, &super_blk, - &old_desc_blk, &new_desc_blk, 0); + ext2fs_super_and_bgd_loc(fs, group, &super_blk, + &old_desc_blk, &new_desc_blk, 0); if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) @@ -51,27 +52,23 @@ static void check_block_uninit(ext2_filsys fs, ext2fs_block_bitmap map, else old_desc_blocks = fs->desc_blocks + fs->super->s_reserved_gdt_blocks; - for (i=0; i < fs->super->s_blocks_per_group; i++, blk++) - ext2fs_fast_unmark_block_bitmap2(map, blk); - - blk = ext2fs_group_first_block2(fs, group); for (i=0; i < fs->super->s_blocks_per_group; i++, blk++) { if ((blk == super_blk) || (old_desc_blk && old_desc_blocks && (blk >= old_desc_blk) && (blk < old_desc_blk + old_desc_blocks)) || (new_desc_blk && (blk == new_desc_blk)) || - (blk == ext2fs_block_bitmap_loc(fs, group)) || - (blk == ext2fs_inode_bitmap_loc(fs, group)) || - (blk >= ext2fs_inode_table_loc(fs, group) && - (blk < ext2fs_inode_table_loc(fs, group) + (blk == fs->group_desc[group].bg_block_bitmap) || + (blk == fs->group_desc[group].bg_inode_bitmap) || + (blk >= fs->group_desc[group].bg_inode_table && + (blk < fs->group_desc[group].bg_inode_table + fs->inode_blocks_per_group))) - ext2fs_fast_mark_block_bitmap2(map, blk); + ext2fs_fast_mark_block_bitmap(map, blk); + else + ext2fs_fast_unmark_block_bitmap(map, blk); } - ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT); + fs->group_desc[group].bg_flags &= ~EXT2_BG_BLOCK_UNINIT; ext2fs_group_desc_csum_set(fs, group); - ext2fs_mark_super_dirty(fs); - ext2fs_mark_bb_dirty(fs); } /* @@ -84,17 +81,14 @@ static void check_inode_uninit(ext2_filsys fs, ext2fs_inode_bitmap map, if (!(EXT2_HAS_RO_COMPAT_FEATURE(fs->super, EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) || - !(ext2fs_bg_flags_test(fs, group, EXT2_BG_INODE_UNINIT))) + !(fs->group_desc[group].bg_flags & EXT2_BG_INODE_UNINIT)) return; ino = (group * fs->super->s_inodes_per_group) + 1; for (i=0; i < fs->super->s_inodes_per_group; i++, ino++) - ext2fs_fast_unmark_inode_bitmap2(map, ino); + ext2fs_fast_unmark_inode_bitmap(map, ino); - ext2fs_bg_flags_clear(fs, group, EXT2_BG_INODE_UNINIT); - ext2fs_group_desc_csum_set(fs, group); - ext2fs_mark_ib_dirty(fs); - ext2fs_mark_super_dirty(fs); + fs->group_desc[group].bg_flags &= ~EXT2_BG_INODE_UNINIT; check_block_uninit(fs, fs->block_map, group); } @@ -108,10 +102,9 @@ errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode EXT2FS_ATTR((unused)), ext2fs_inode_bitmap map, ext2_ino_t *ret) { - ext2_ino_t start_inode = 0; - ext2_ino_t i, ino_in_group, upto, first_zero; - errcode_t retval; - dgrp_t group; + ext2_ino_t dir_group = 0; + ext2_ino_t i; + ext2_ino_t start_inode; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); @@ -120,40 +113,29 @@ errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, if (!map) return EXT2_ET_NO_INODE_BITMAP; - if (dir > 0) { - group = (dir - 1) / EXT2_INODES_PER_GROUP(fs->super); - start_inode = (group * EXT2_INODES_PER_GROUP(fs->super)) + 1; - } + if (dir > 0) + dir_group = (dir - 1) / EXT2_INODES_PER_GROUP(fs->super); + + start_inode = (dir_group * EXT2_INODES_PER_GROUP(fs->super)) + 1; if (start_inode < EXT2_FIRST_INODE(fs->super)) start_inode = EXT2_FIRST_INODE(fs->super); if (start_inode > fs->super->s_inodes_count) return EXT2_ET_INODE_ALLOC_FAIL; i = start_inode; + do { - ino_in_group = (i - 1) % EXT2_INODES_PER_GROUP(fs->super); - group = (i - 1) / EXT2_INODES_PER_GROUP(fs->super); - - check_inode_uninit(fs, map, group); - upto = i + (EXT2_INODES_PER_GROUP(fs->super) - ino_in_group); - if (i < start_inode && upto >= start_inode) - upto = start_inode - 1; - if (upto > fs->super->s_inodes_count) - upto = fs->super->s_inodes_count; - - retval = ext2fs_find_first_zero_inode_bitmap2(map, i, upto, - &first_zero); - if (retval == 0) { - i = first_zero; + if (((i - 1) % EXT2_INODES_PER_GROUP(fs->super)) == 0) + check_inode_uninit(fs, map, (i - 1) / + EXT2_INODES_PER_GROUP(fs->super)); + + if (!ext2fs_fast_test_inode_bitmap(map, i)) break; - } - if (retval != ENOENT) - return EXT2_ET_INODE_ALLOC_FAIL; - i = upto + 1; + i++; if (i > fs->super->s_inodes_count) i = EXT2_FIRST_INODE(fs->super); } while (i != start_inode); - if (ext2fs_test_inode_bitmap2(map, i)) + if (ext2fs_test_inode_bitmap(map, i)) return EXT2_ET_INODE_ALLOC_FAIL; *ret = i; return 0; @@ -163,11 +145,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_block2(ext2_filsys fs, blk64_t goal, - ext2fs_block_bitmap map, blk64_t *ret) +errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal, + ext2fs_block_bitmap map, blk_t *ret) { - blk64_t i; - int c_ratio; + blk_t i; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); @@ -175,12 +156,9 @@ errcode_t ext2fs_new_block2(ext2_filsys fs, blk64_t goal, map = fs->block_map; if (!map) return EXT2_ET_NO_BLOCK_BITMAP; - if (!goal || (goal >= ext2fs_blocks_count(fs->super))) + if (!goal || (goal >= fs->super->s_blocks_count)) goal = fs->super->s_first_data_block; i = goal; - c_ratio = 1 << ext2fs_get_bitmap_granularity(map); - if (c_ratio > 1) - goal &= ~EXT2FS_CLUSTER_MASK(fs); check_block_uninit(fs, map, (i - fs->super->s_first_data_block) / EXT2_BLOCKS_PER_GROUP(fs->super)); @@ -191,37 +169,26 @@ errcode_t ext2fs_new_block2(ext2_filsys fs, blk64_t goal, (i - fs->super->s_first_data_block) / EXT2_BLOCKS_PER_GROUP(fs->super)); - if (!ext2fs_fast_test_block_bitmap2(map, i)) { + if (!ext2fs_fast_test_block_bitmap(map, i)) { *ret = i; return 0; } - i = (i + c_ratio) & ~(c_ratio - 1); - if (i >= ext2fs_blocks_count(fs->super)) + i++; + if (i >= fs->super->s_blocks_count) i = fs->super->s_first_data_block; } while (i != 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_block2(ext2_filsys fs, blk64_t goal, - char *block_buf, blk64_t *ret) +errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal, + char *block_buf, blk_t *ret) { errcode_t retval; - blk64_t block; + blk_t block; char *buf = 0; if (!block_buf) { @@ -233,9 +200,12 @@ errcode_t ext2fs_alloc_block2(ext2_filsys fs, blk64_t goal, memset(block_buf, 0, fs->blocksize); if (fs->get_alloc_block) { - retval = (fs->get_alloc_block)(fs, goal, &block); + blk64_t new; + + retval = (fs->get_alloc_block)(fs, (blk64_t) goal, &new); if (retval) goto fail; + block = (blk_t) new; } else { if (!fs->block_map) { retval = ext2fs_read_block_bitmap(fs); @@ -243,16 +213,16 @@ errcode_t ext2fs_alloc_block2(ext2_filsys fs, blk64_t goal, goto fail; } - retval = ext2fs_new_block2(fs, goal, 0, &block); + retval = ext2fs_new_block(fs, goal, 0, &block); if (retval) goto fail; } - retval = io_channel_write_blk64(fs->io, block, 1, block_buf); + retval = io_channel_write_blk(fs->io, block, 1, block_buf); if (retval) goto fail; - ext2fs_block_alloc_stats2(fs, block, +1); + ext2fs_block_alloc_stats(fs, block, +1); *ret = block; fail: @@ -261,22 +231,10 @@ fail: return retval; } -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) +errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start, blk_t finish, + int num, ext2fs_block_bitmap map, blk_t *ret) { - blk64_t b = start; - int c_ratio; + blk_t b = start; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); @@ -290,32 +248,18 @@ errcode_t ext2fs_get_free_blocks2(ext2_filsys fs, blk64_t start, blk64_t finish, finish = start; if (!num) num = 1; - c_ratio = 1 << ext2fs_get_bitmap_granularity(map); - b &= ~(c_ratio - 1); - finish &= ~(c_ratio -1); do { - if (b+num-1 > ext2fs_blocks_count(fs->super)) + if (b+num-1 > fs->super->s_blocks_count) b = fs->super->s_first_data_block; - if (ext2fs_fast_test_block_bitmap_range2(map, b, num)) { + if (ext2fs_fast_test_block_bitmap_range(map, b, num)) { *ret = b; return 0; } - b += c_ratio; + b++; } while (b != 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, diff --git a/lib/ext2fs/alloc_sb.c b/lib/ext2fs/alloc_sb.c index 73ef2cea..b491a9f6 100644 --- a/lib/ext2fs/alloc_sb.c +++ b/lib/ext2fs/alloc_sb.c @@ -44,12 +44,11 @@ int ext2fs_reserve_super_and_bgd(ext2_filsys fs, dgrp_t group, ext2fs_block_bitmap bmap) { - blk64_t super_blk, old_desc_blk, new_desc_blk; - blk_t used_blks; - int old_desc_blocks, num_blocks; + blk_t super_blk, old_desc_blk, new_desc_blk; + int j, old_desc_blocks, num_blocks; - ext2fs_super_and_bgd_loc2(fs, group, &super_blk, - &old_desc_blk, &new_desc_blk, &used_blks); + num_blocks = ext2fs_super_and_bgd_loc(fs, group, &super_blk, + &old_desc_blk, &new_desc_blk, 0); if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) old_desc_blocks = fs->super->s_first_meta_bg; @@ -58,25 +57,18 @@ int ext2fs_reserve_super_and_bgd(ext2_filsys fs, fs->desc_blocks + fs->super->s_reserved_gdt_blocks; if (super_blk || (group == 0)) - ext2fs_mark_block_bitmap2(bmap, super_blk); - if ((group == 0) && (fs->blocksize == 1024) && - EXT2FS_CLUSTER_RATIO(fs) > 1) - ext2fs_mark_block_bitmap2(bmap, 0); + ext2fs_mark_block_bitmap(bmap, super_blk); if (old_desc_blk) { if (fs->super->s_reserved_gdt_blocks && fs->block_map == bmap) - ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT); - num_blocks = old_desc_blocks; - if (old_desc_blk + num_blocks >= ext2fs_blocks_count(fs->super)) - num_blocks = ext2fs_blocks_count(fs->super) - - old_desc_blk; - ext2fs_mark_block_bitmap_range2(bmap, old_desc_blk, num_blocks); + 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) + ext2fs_mark_block_bitmap(bmap, + old_desc_blk + j); } if (new_desc_blk) - ext2fs_mark_block_bitmap2(bmap, new_desc_blk); + ext2fs_mark_block_bitmap(bmap, new_desc_blk); - num_blocks = ext2fs_group_blocks_count(fs, group); - num_blocks -= 2 + fs->inode_blocks_per_group + used_blks; - - return num_blocks ; + return num_blocks; } diff --git a/lib/ext2fs/alloc_stats.c b/lib/ext2fs/alloc_stats.c index 9a6697e0..5ac52050 100644 --- a/lib/ext2fs/alloc_stats.c +++ b/lib/ext2fs/alloc_stats.c @@ -27,24 +27,26 @@ void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino, } #endif if (inuse > 0) - ext2fs_mark_inode_bitmap2(fs->inode_map, ino); + ext2fs_mark_inode_bitmap(fs->inode_map, ino); else - ext2fs_unmark_inode_bitmap2(fs->inode_map, ino); - ext2fs_bg_free_inodes_count_set(fs, group, ext2fs_bg_free_inodes_count(fs, group) - inuse); + ext2fs_unmark_inode_bitmap(fs->inode_map, ino); + fs->group_desc[group].bg_free_inodes_count -= inuse; if (isdir) - ext2fs_bg_used_dirs_count_set(fs, group, ext2fs_bg_used_dirs_count(fs, group) + inuse); + fs->group_desc[group].bg_used_dirs_count += inuse; /* We don't strictly need to be clearing the uninit flag if inuse < 0 * (i.e. freeing inodes) but it also means something is bad. */ - ext2fs_bg_flags_clear(fs, group, EXT2_BG_INODE_UNINIT); + fs->group_desc[group].bg_flags &= ~EXT2_BG_INODE_UNINIT; if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { ext2_ino_t first_unused_inode = fs->super->s_inodes_per_group - - ext2fs_bg_itable_unused(fs, group) + + fs->group_desc[group].bg_itable_unused + group * fs->super->s_inodes_per_group + 1; if (ino >= first_unused_inode) - ext2fs_bg_itable_unused_set(fs, group, group * fs->super->s_inodes_per_group + fs->super->s_inodes_per_group - ino); + fs->group_desc[group].bg_itable_unused = + group * fs->super->s_inodes_per_group + + fs->super->s_inodes_per_group - ino; ext2fs_group_desc_csum_set(fs, group); } @@ -58,38 +60,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_stats2(ext2_filsys fs, blk64_t blk, int inuse) +void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse) { - int group = ext2fs_group_of_blk2(fs, blk); + int group = ext2fs_group_of_blk(fs, blk); #ifndef OMIT_COM_ERR - if (blk >= ext2fs_blocks_count(fs->super)) { + if (blk >= fs->super->s_blocks_count) { com_err("ext2fs_block_alloc_stats", 0, "Illegal block number: %lu", (unsigned long) blk); return; } #endif if (inuse > 0) - ext2fs_mark_block_bitmap2(fs->block_map, blk); + ext2fs_mark_block_bitmap(fs->block_map, blk); else - ext2fs_unmark_block_bitmap2(fs->block_map, blk); - ext2fs_bg_free_blocks_count_set(fs, group, ext2fs_bg_free_blocks_count(fs, group) - inuse); - ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT); + 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); - ext2fs_free_blocks_count_add(fs->super, - -inuse * EXT2FS_CLUSTER_RATIO(fs)); + fs->super->s_free_blocks_count -= 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, diff --git a/lib/ext2fs/alloc_tables.c b/lib/ext2fs/alloc_tables.c index 885d2b23..46465af4 100644 --- a/lib/ext2fs/alloc_tables.c +++ b/lib/ext2fs/alloc_tables.c @@ -26,7 +26,6 @@ #include "ext2_fs.h" #include "ext2fs.h" -#include "ext2fsP.h" /* * This routine searches for free blocks that can allocate a full @@ -34,46 +33,46 @@ * block number with a correct offset were the bitmaps and inode * tables can be allocated continously and in order. */ -static blk64_t flexbg_offset(ext2_filsys fs, dgrp_t group, blk64_t start_blk, - ext2fs_block_bitmap bmap, int rem_grp, - int elem_size) +static blk_t flexbg_offset(ext2_filsys fs, dgrp_t group, blk_t start_blk, + ext2fs_block_bitmap bmap, int offset, int size, + int elem_size) { - int flexbg, flexbg_size, size; - blk64_t last_blk, first_free = 0; + int flexbg, flexbg_size; + blk_t last_blk, first_free = 0; dgrp_t last_grp; flexbg_size = 1 << fs->super->s_log_groups_per_flex; flexbg = group / flexbg_size; - size = rem_grp * elem_size; if (size > (int) (fs->super->s_blocks_per_group / 8)) size = (int) fs->super->s_blocks_per_group / 8; + if (offset) + offset -= 1; + /* * Don't do a long search if the previous block * search is still valid. */ - if (start_blk && ext2fs_test_block_bitmap_range2(bmap, start_blk, - elem_size)) - return start_blk; + if (start_blk && group % flexbg_size) { + if (ext2fs_test_block_bitmap_range(bmap, start_blk + elem_size, + size)) + return start_blk + elem_size; + } - start_blk = ext2fs_group_first_block2(fs, flexbg_size * flexbg); + start_blk = ext2fs_group_first_block(fs, flexbg_size * flexbg); last_grp = group | (flexbg_size - 1); - if (last_grp > fs->group_desc_count-1) - last_grp = fs->group_desc_count-1; - last_blk = ext2fs_group_last_block2(fs, last_grp); + if (last_grp > fs->group_desc_count) + last_grp = fs->group_desc_count; + last_blk = ext2fs_group_last_block(fs, last_grp); /* Find the first available block */ - if (ext2fs_get_free_blocks2(fs, start_blk, last_blk, size, - bmap, &first_free) == 0) + if (ext2fs_get_free_blocks(fs, start_blk, last_blk, 1, bmap, + &first_free)) return first_free; - if (ext2fs_get_free_blocks2(fs, start_blk, last_blk, elem_size, - bmap, &first_free) == 0) - return first_free; - - if (ext2fs_get_free_blocks2(fs, 0, last_blk, elem_size, bmap, - &first_free) == 0) + if (ext2fs_get_free_blocks(fs, first_free + offset, last_blk, size, + bmap, &first_free)) return first_free; return first_free; @@ -82,14 +81,13 @@ static blk64_t flexbg_offset(ext2_filsys fs, dgrp_t group, blk64_t start_blk, errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, ext2fs_block_bitmap bmap) { - unsigned int j; errcode_t retval; - blk64_t group_blk, start_blk, last_blk, new_blk, blk; + blk_t group_blk, start_blk, last_blk, new_blk, blk; dgrp_t last_grp = 0; - int rem_grps = 0, flexbg_size = 0; + int j, rem_grps = 0, flexbg_size = 0; - group_blk = ext2fs_group_first_block2(fs, group); - last_blk = ext2fs_group_last_block2(fs, group); + group_blk = ext2fs_group_first_block(fs, group); + last_blk = ext2fs_group_last_block(fs, group); if (!bmap) bmap = fs->block_map; @@ -99,17 +97,17 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, fs->super->s_log_groups_per_flex) { flexbg_size = 1 << fs->super->s_log_groups_per_flex; last_grp = group | (flexbg_size - 1); - if (last_grp > fs->group_desc_count-1) - last_grp = fs->group_desc_count-1; - rem_grps = last_grp - group + 1; + rem_grps = last_grp - group; + if (last_grp > fs->group_desc_count) + last_grp = fs->group_desc_count; } /* * Allocate the block and inode bitmaps, if necessary */ if (fs->stride) { - retval = ext2fs_get_free_blocks2(fs, group_blk, last_blk, - 1, bmap, &start_blk); + retval = ext2fs_get_free_blocks(fs, group_blk, last_blk, + 1, bmap, &start_blk); if (retval) return retval; start_blk += fs->inode_blocks_per_group; @@ -121,61 +119,57 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, start_blk = group_blk; if (flexbg_size) { - blk64_t prev_block = 0; - - if (group % flexbg_size) - prev_block = ext2fs_block_bitmap_loc(fs, group - 1) + 1; + blk_t prev_block = 0; + if (group && fs->group_desc[group-1].bg_block_bitmap) + prev_block = fs->group_desc[group-1].bg_block_bitmap; start_blk = flexbg_offset(fs, group, prev_block, bmap, - rem_grps, 1); - last_blk = ext2fs_group_last_block2(fs, last_grp); + 0, rem_grps, 1); + last_blk = ext2fs_group_last_block(fs, last_grp); } - if (!ext2fs_block_bitmap_loc(fs, group)) { - retval = ext2fs_get_free_blocks2(fs, start_blk, last_blk, - 1, bmap, &new_blk); + if (!fs->group_desc[group].bg_block_bitmap) { + retval = ext2fs_get_free_blocks(fs, start_blk, last_blk, + 1, bmap, &new_blk); if (retval == EXT2_ET_BLOCK_ALLOC_FAIL) - retval = ext2fs_get_free_blocks2(fs, group_blk, + retval = ext2fs_get_free_blocks(fs, group_blk, last_blk, 1, bmap, &new_blk); if (retval) return retval; - ext2fs_mark_block_bitmap2(bmap, new_blk); - ext2fs_block_bitmap_loc_set(fs, group, new_blk); + ext2fs_mark_block_bitmap(bmap, new_blk); + fs->group_desc[group].bg_block_bitmap = new_blk; if (flexbg_size) { - dgrp_t gr = ext2fs_group_of_blk2(fs, new_blk); - ext2fs_bg_free_blocks_count_set(fs, gr, ext2fs_bg_free_blocks_count(fs, gr) - 1); - ext2fs_free_blocks_count_add(fs->super, -1); - ext2fs_bg_flags_clear(fs, gr, EXT2_BG_BLOCK_UNINIT); + dgrp_t gr = ext2fs_group_of_blk(fs, new_blk); + fs->group_desc[gr].bg_free_blocks_count--; + fs->super->s_free_blocks_count--; + fs->group_desc[gr].bg_flags &= ~EXT2_BG_BLOCK_UNINIT; ext2fs_group_desc_csum_set(fs, gr); } } if (flexbg_size) { - blk64_t prev_block = 0; - if (group % flexbg_size) - prev_block = ext2fs_inode_bitmap_loc(fs, group - 1) + 1; - else - prev_block = ext2fs_block_bitmap_loc(fs, group) + - flexbg_size; + blk_t prev_block = 0; + if (group && fs->group_desc[group-1].bg_inode_bitmap) + prev_block = fs->group_desc[group-1].bg_inode_bitmap; start_blk = flexbg_offset(fs, group, prev_block, bmap, - rem_grps, 1); - last_blk = ext2fs_group_last_block2(fs, last_grp); + flexbg_size, rem_grps, 1); + last_blk = ext2fs_group_last_block(fs, last_grp); } - if (!ext2fs_inode_bitmap_loc(fs, group)) { - retval = ext2fs_get_free_blocks2(fs, start_blk, last_blk, - 1, bmap, &new_blk); + if (!fs->group_desc[group].bg_inode_bitmap) { + retval = ext2fs_get_free_blocks(fs, start_blk, last_blk, + 1, bmap, &new_blk); if (retval == EXT2_ET_BLOCK_ALLOC_FAIL) - retval = ext2fs_get_free_blocks2(fs, group_blk, - last_blk, 1, bmap, &new_blk); + retval = ext2fs_get_free_blocks(fs, group_blk, + last_blk, 1, bmap, &new_blk); if (retval) return retval; - ext2fs_mark_block_bitmap2(bmap, new_blk); - ext2fs_inode_bitmap_loc_set(fs, group, new_blk); + ext2fs_mark_block_bitmap(bmap, new_blk); + fs->group_desc[group].bg_inode_bitmap = new_blk; if (flexbg_size) { - dgrp_t gr = ext2fs_group_of_blk2(fs, new_blk); - ext2fs_bg_free_blocks_count_set(fs, gr, ext2fs_bg_free_blocks_count(fs, gr) - 1); - ext2fs_free_blocks_count_add(fs->super, -1); - ext2fs_bg_flags_clear(fs, gr, EXT2_BG_BLOCK_UNINIT); + dgrp_t gr = ext2fs_group_of_blk(fs, new_blk); + fs->group_desc[gr].bg_free_blocks_count--; + fs->super->s_free_blocks_count--; + fs->group_desc[gr].bg_flags &= ~EXT2_BG_BLOCK_UNINIT; ext2fs_group_desc_csum_set(fs, gr); } } @@ -184,22 +178,21 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, * Allocate the inode table */ if (flexbg_size) { - blk64_t prev_block = 0; - - if (group % flexbg_size) - prev_block = ext2fs_inode_table_loc(fs, group - 1) + - fs->inode_blocks_per_group; - else - prev_block = ext2fs_inode_bitmap_loc(fs, group) + - flexbg_size; - + blk_t prev_block = 0; + if (group && fs->group_desc[group-1].bg_inode_table) + prev_block = fs->group_desc[group-1].bg_inode_table; + if (last_grp == fs->group_desc_count) + rem_grps = last_grp - group; group_blk = flexbg_offset(fs, group, prev_block, bmap, - rem_grps, fs->inode_blocks_per_group); - last_blk = ext2fs_group_last_block2(fs, last_grp); + flexbg_size * 2, + fs->inode_blocks_per_group * + rem_grps, + fs->inode_blocks_per_group); + last_blk = ext2fs_group_last_block(fs, last_grp); } - if (!ext2fs_inode_table_loc(fs, group)) { - retval = ext2fs_get_free_blocks2(fs, group_blk, last_blk, + if (!fs->group_desc[group].bg_inode_table) { + retval = ext2fs_get_free_blocks(fs, group_blk, last_blk, fs->inode_blocks_per_group, bmap, &new_blk); if (retval) @@ -207,17 +200,16 @@ 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++) { - ext2fs_mark_block_bitmap2(bmap, blk); + ext2fs_mark_block_bitmap(bmap, blk); if (flexbg_size) { - dgrp_t gr = ext2fs_group_of_blk2(fs, blk); - ext2fs_bg_free_blocks_count_set(fs, gr, ext2fs_bg_free_blocks_count(fs, gr) - 1); - ext2fs_free_blocks_count_add(fs->super, -1); - ext2fs_bg_flags_clear(fs, gr, - EXT2_BG_BLOCK_UNINIT); + dgrp_t gr = ext2fs_group_of_blk(fs, blk); + fs->group_desc[gr].bg_free_blocks_count--; + fs->super->s_free_blocks_count--; + fs->group_desc[gr].bg_flags &= ~EXT2_BG_BLOCK_UNINIT; ext2fs_group_desc_csum_set(fs, gr); } } - ext2fs_inode_table_loc_set(fs, group, new_blk); + fs->group_desc[group].bg_inode_table = new_blk; } ext2fs_group_desc_csum_set(fs, group); return 0; @@ -227,18 +219,12 @@ errcode_t ext2fs_allocate_tables(ext2_filsys fs) { errcode_t retval; dgrp_t i; - struct ext2fs_numeric_progress_struct progress; - - ext2fs_numeric_progress_init(fs, &progress, NULL, - fs->group_desc_count); for (i = 0; i < fs->group_desc_count; i++) { - ext2fs_numeric_progress_update(fs, &progress, i); retval = ext2fs_allocate_group_table(fs, i, fs->block_map); if (retval) return retval; } - ext2fs_numeric_progress_close(fs, &progress, NULL); return 0; } diff --git a/lib/ext2fs/badblocks.c b/lib/ext2fs/badblocks.c index 4312e190..5eb28b78 100644 --- a/lib/ext2fs/badblocks.c +++ b/lib/ext2fs/badblocks.c @@ -177,7 +177,7 @@ int ext2fs_u32_list_find(ext2_u32_list bb, __u32 blk) return high; while (low < high) { - mid = ((unsigned)low + (unsigned)high)/2; + mid = (low+high)/2; if (mid == low || mid == high) break; if (blk == bb->list[mid]) diff --git a/lib/ext2fs/bb_inode.c b/lib/ext2fs/bb_inode.c index 0b6c3dd2..26266869 100644 --- a/lib/ext2fs/bb_inode.c +++ b/lib/ext2fs/bb_inode.c @@ -65,7 +65,8 @@ errcode_t ext2fs_update_bb_inode(ext2_filsys fs, ext2_badblocks_list bb_list) if (!fs->block_map) return EXT2_ET_NO_BLOCK_BITMAP; - memset(&rec, 0, sizeof(rec)); + rec.bad_block_count = 0; + rec.ind_blocks_size = rec.ind_blocks_ptr = 0; rec.max_ind_blocks = 10; retval = ext2fs_get_array(rec.max_ind_blocks, sizeof(blk_t), &rec.ind_blocks); @@ -165,7 +166,7 @@ static int clear_bad_block_proc(ext2_filsys fs, blk_t *block_nr, /* * If the block number is outrageous, clear it and ignore it. */ - if (*block_nr >= ext2fs_blocks_count(fs->super) || + if (*block_nr >= fs->super->s_blocks_count || *block_nr < fs->super->s_first_data_block) { *block_nr = 0; return BLOCK_CHANGED; @@ -190,7 +191,7 @@ static int clear_bad_block_proc(ext2_filsys fs, blk_t *block_nr, /* * Mark the block as unused, and update accounting information */ - ext2fs_block_alloc_stats2(fs, *block_nr, -1); + ext2fs_block_alloc_stats(fs, *block_nr, -1); *block_nr = 0; return BLOCK_CHANGED; @@ -234,7 +235,7 @@ static int set_bad_block_proc(ext2_filsys fs, blk_t *block_nr, retry: if (rec->ind_blocks_ptr < rec->ind_blocks_size) { blk = rec->ind_blocks[rec->ind_blocks_ptr++]; - if (ext2fs_test_block_bitmap2(fs->block_map, blk)) + if (ext2fs_test_block_bitmap(fs->block_map, blk)) goto retry; } else { retval = ext2fs_new_block(fs, 0, 0, &blk); @@ -243,7 +244,7 @@ static int set_bad_block_proc(ext2_filsys fs, blk_t *block_nr, return BLOCK_ABORT; } } - retval = io_channel_write_blk64(fs->io, blk, 1, rec->block_buf); + retval = io_channel_write_blk(fs->io, blk, 1, rec->block_buf); if (retval) { rec->err = retval; return BLOCK_ABORT; @@ -253,7 +254,7 @@ static int set_bad_block_proc(ext2_filsys fs, blk_t *block_nr, /* * Update block counts */ - ext2fs_block_alloc_stats2(fs, blk, +1); + ext2fs_block_alloc_stats(fs, blk, +1); *block_nr = blk; return BLOCK_CHANGED; diff --git a/lib/ext2fs/bitmaps.c b/lib/ext2fs/bitmaps.c index f215122f..649c524f 100644 --- a/lib/ext2fs/bitmaps.c +++ b/lib/ext2fs/bitmaps.c @@ -26,34 +26,33 @@ #include "ext2_fs.h" #include "ext2fs.h" -#include "ext2fsP.h" -#include "bmap64.h" void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap) { - ext2fs_free_generic_bmap(bitmap); + ext2fs_free_generic_bitmap(bitmap); } void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap) { - ext2fs_free_generic_bmap(bitmap); + ext2fs_free_generic_bitmap(bitmap); } errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src, ext2fs_generic_bitmap *dest) { - return (ext2fs_copy_generic_bmap(src, dest)); + return (ext2fs_copy_generic_bitmap(src, dest)); } + void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map) { - ext2fs_set_generic_bmap_padding(map); + ext2fs_set_generic_bitmap_padding(map); } errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs, const char *descr, ext2fs_inode_bitmap *ret) { - __u64 start, end, real_end; + __u32 start, end, real_end; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); @@ -63,116 +62,39 @@ errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs, end = fs->super->s_inodes_count; real_end = (EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count); - /* Are we permitted to use new-style bitmaps? */ - if (fs->flags & EXT2_FLAG_64BITS) - return (ext2fs_alloc_generic_bmap(fs, - EXT2_ET_MAGIC_INODE_BITMAP64, - fs->default_bitmap_type, - start, end, real_end, descr, ret)); - - /* Otherwise, check to see if the file system is small enough - * to use old-style 32-bit bitmaps */ - if ((end > ~0U) || (real_end > ~0U)) - return EXT2_ET_CANT_USE_LEGACY_BITMAPS; - return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP, fs, - start, end, real_end, - descr, 0, - (ext2fs_generic_bitmap *) ret)); + start, end, real_end, + descr, 0, ret)); } errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs, const char *descr, ext2fs_block_bitmap *ret) { - __u64 start, end, real_end; + __u32 start, end, real_end; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); fs->write_bitmaps = ext2fs_write_bitmaps; - start = EXT2FS_B2C(fs, fs->super->s_first_data_block); - end = EXT2FS_B2C(fs, ext2fs_blocks_count(fs->super)-1); - real_end = ((__u64) EXT2_CLUSTERS_PER_GROUP(fs->super) - * (__u64) fs->group_desc_count)-1 + start; - - if (fs->flags & EXT2_FLAG_64BITS) - return (ext2fs_alloc_generic_bmap(fs, - EXT2_ET_MAGIC_BLOCK_BITMAP64, - fs->default_bitmap_type, - start, end, real_end, descr, ret)); - - if ((end > ~0U) || (real_end > ~0U)) - return EXT2_ET_CANT_USE_LEGACY_BITMAPS; + start = fs->super->s_first_data_block; + end = fs->super->s_blocks_count-1; + real_end = (EXT2_BLOCKS_PER_GROUP(fs->super) + * fs->group_desc_count)-1 + start; return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP, fs, start, end, real_end, - descr, 0, - (ext2fs_generic_bitmap *) ret)); -} - -/* - * ext2fs_allocate_block_bitmap() really allocates a per-cluster - * bitmap for backwards compatibility. This function allocates a - * block bitmap which is truly per-block, even if clusters/bigalloc - * are enabled. mke2fs and e2fsck need this for tracking the - * allocation of the file system metadata blocks. - */ -errcode_t ext2fs_allocate_subcluster_bitmap(ext2_filsys fs, - const char *descr, - ext2fs_block_bitmap *ret) -{ - __u64 start, end, real_end; - ext2fs_generic_bitmap bmap; - errcode_t retval; - - EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); - - fs->write_bitmaps = ext2fs_write_bitmaps; - - if (!fs->cluster_ratio_bits) - return ext2fs_allocate_block_bitmap(fs, descr, ret); - - if ((fs->flags & EXT2_FLAG_64BITS) == 0) - return EXT2_ET_CANT_USE_LEGACY_BITMAPS; - - start = fs->super->s_first_data_block; - end = ext2fs_blocks_count(fs->super)-1; - real_end = ((__u64) EXT2_BLOCKS_PER_GROUP(fs->super) - * (__u64) fs->group_desc_count)-1 + start; - - retval = ext2fs_alloc_generic_bmap(fs, EXT2_ET_MAGIC_BLOCK_BITMAP64, - fs->default_bitmap_type, start, - end, real_end, descr, &bmap); - if (retval) - return retval; - bmap->cluster_bits = 0; - *ret = bmap; - return 0; -} - -int ext2fs_get_bitmap_granularity(ext2fs_block_bitmap bitmap) -{ - ext2fs_generic_bitmap bmap = bitmap; - - if (!EXT2FS_IS_64_BITMAP(bmap)) - return 0; - - return bmap->cluster_bits; + descr, 0, ret)); } errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap, ext2_ino_t end, ext2_ino_t *oend) { - __u64 tmp_oend; - int retval; - retval = ext2fs_fudge_generic_bmap_end((ext2fs_generic_bitmap) bitmap, - EXT2_ET_FUDGE_INODE_BITMAP_END, - end, &tmp_oend); - if (oend) - *oend = tmp_oend; - return retval; + return (ext2fs_fudge_generic_bitmap_end(bitmap, + EXT2_ET_MAGIC_INODE_BITMAP, + EXT2_ET_FUDGE_INODE_BITMAP_END, + end, oend)); } errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap, @@ -184,22 +106,14 @@ errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap, end, oend)); } -errcode_t ext2fs_fudge_block_bitmap_end2(ext2fs_block_bitmap bitmap, - blk64_t end, blk64_t *oend) -{ - return (ext2fs_fudge_generic_bmap_end(bitmap, - EXT2_ET_FUDGE_BLOCK_BITMAP_END, - end, oend)); -} - void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap) { - ext2fs_clear_generic_bmap(bitmap); + ext2fs_clear_generic_bitmap(bitmap); } void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap) { - ext2fs_clear_generic_bmap(bitmap); + ext2fs_clear_generic_bitmap(bitmap); } errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end, @@ -209,12 +123,6 @@ errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end, new_end, new_real_end, bmap)); } -errcode_t ext2fs_resize_inode_bitmap2(__u64 new_end, __u64 new_real_end, - ext2fs_inode_bitmap bmap) -{ - return (ext2fs_resize_generic_bmap(bmap, new_end, new_real_end)); -} - errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end, ext2fs_block_bitmap bmap) { @@ -222,24 +130,20 @@ errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end, new_end, new_real_end, bmap)); } -errcode_t ext2fs_resize_block_bitmap2(__u64 new_end, __u64 new_real_end, - ext2fs_block_bitmap bmap) -{ - return (ext2fs_resize_generic_bmap(bmap, new_end, new_real_end)); -} - errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1, ext2fs_block_bitmap bm2) { - return (ext2fs_compare_generic_bmap(EXT2_ET_NEQ_BLOCK_BITMAP, - bm1, bm2)); + return (ext2fs_compare_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP, + EXT2_ET_NEQ_BLOCK_BITMAP, + bm1, bm2)); } errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1, ext2fs_inode_bitmap bm2) { - return (ext2fs_compare_generic_bmap(EXT2_ET_NEQ_INODE_BITMAP, - bm1, bm2)); + return (ext2fs_compare_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP, + EXT2_ET_NEQ_INODE_BITMAP, + bm1, bm2)); } errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap, @@ -251,13 +155,6 @@ errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap, start, num, in)); } -errcode_t ext2fs_set_inode_bitmap_range2(ext2fs_inode_bitmap bmap, - __u64 start, size_t num, - void *in) -{ - return (ext2fs_set_generic_bmap_range(bmap, start, num, in)); -} - errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap, ext2_ino_t start, unsigned int num, void *out) @@ -267,13 +164,6 @@ errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap, start, num, out)); } -errcode_t ext2fs_get_inode_bitmap_range2(ext2fs_inode_bitmap bmap, - __u64 start, size_t num, - void *out) -{ - return (ext2fs_get_generic_bmap_range(bmap, start, num, out)); -} - errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap, blk_t start, unsigned int num, void *in) @@ -283,13 +173,6 @@ errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap, start, num, in)); } -errcode_t ext2fs_set_block_bitmap_range2(ext2fs_block_bitmap bmap, - blk64_t start, size_t num, - void *in) -{ - return (ext2fs_set_generic_bmap_range(bmap, start, num, in)); -} - errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap, blk_t start, unsigned int num, void *out) @@ -298,10 +181,3 @@ errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap, EXT2_ET_MAGIC_BLOCK_BITMAP, start, num, out)); } - -errcode_t ext2fs_get_block_bitmap_range2(ext2fs_block_bitmap bmap, - blk64_t start, size_t num, - void *out) -{ - return (ext2fs_get_generic_bmap_range(bmap, start, num, out)); -} diff --git a/lib/ext2fs/bitops.c b/lib/ext2fs/bitops.c index 42328478..d7db9049 100644 --- a/lib/ext2fs/bitops.c +++ b/lib/ext2fs/bitops.c @@ -76,82 +76,3 @@ void ext2fs_warn_bitmap(errcode_t errcode, unsigned long arg, com_err(0, errcode, "#%lu", arg); #endif } - -/* - * C-only 64 bit ops. - */ - -int ext2fs_set_bit64(__u64 nr, void * addr) -{ - int mask, retval; - unsigned char *ADDR = (unsigned char *) addr; - - ADDR += nr >> 3; - mask = 1 << (nr & 0x07); - retval = mask & *ADDR; - *ADDR |= mask; - return retval; -} - -int ext2fs_clear_bit64(__u64 nr, void * addr) -{ - int mask, retval; - unsigned char *ADDR = (unsigned char *) addr; - - ADDR += nr >> 3; - mask = 1 << (nr & 0x07); - retval = mask & *ADDR; - *ADDR &= ~mask; - return retval; -} - -int ext2fs_test_bit64(__u64 nr, const void * addr) -{ - int mask; - const unsigned char *ADDR = (const unsigned char *) addr; - - ADDR += nr >> 3; - mask = 1 << (nr & 0x07); - return (mask & *ADDR); -} - -static unsigned int popcount8(unsigned int w) -{ - unsigned int res = w - ((w >> 1) & 0x55); - res = (res & 0x33) + ((res >> 2) & 0x33); - return (res + (res >> 4)) & 0x0F; -} - -static unsigned int popcount32(unsigned int w) -{ - unsigned int res = w - ((w >> 1) & 0x55555555); - res = (res & 0x33333333) + ((res >> 2) & 0x33333333); - res = (res + (res >> 4)) & 0x0F0F0F0F; - res = res + (res >> 8); - return (res + (res >> 16)) & 0x000000FF; -} - -unsigned int ext2fs_bitcount(const void *addr, unsigned int nbytes) -{ - const unsigned char *cp = addr; - const __u32 *p; - unsigned int res = 0; - - while (((((unsigned long) cp) & 3) != 0) && (nbytes > 0)) { - res += popcount8(*cp++); - nbytes--; - } - p = (const __u32 *) cp; - - while (nbytes > 4) { - res += popcount32(*p++); - nbytes -= 4; - } - cp = (const unsigned char *) p; - - while (nbytes > 0) { - res += popcount8(*cp++); - nbytes--; - } - return res; -} diff --git a/lib/ext2fs/bitops.h b/lib/ext2fs/bitops.h index 3e8132de..ce705394 100644 --- a/lib/ext2fs/bitops.h +++ b/lib/ext2fs/bitops.h @@ -10,6 +10,15 @@ * %End-Header% */ +extern int ext2fs_set_bit(unsigned int nr,void * addr); +extern int ext2fs_clear_bit(unsigned int nr, void * addr); +extern int ext2fs_test_bit(unsigned int nr, const void * addr); +extern void ext2fs_fast_set_bit(unsigned int nr,void * addr); +extern void ext2fs_fast_clear_bit(unsigned int nr, void * addr); +extern __u16 ext2fs_swab16(__u16 val); +extern __u32 ext2fs_swab32(__u32 val); +extern __u64 ext2fs_swab64(__u64 val); + #ifdef WORDS_BIGENDIAN #define ext2fs_cpu_to_le64(x) ext2fs_swab64((x)) #define ext2fs_le64_to_cpu(x) ext2fs_swab64((x)) @@ -17,8 +26,6 @@ #define ext2fs_le32_to_cpu(x) ext2fs_swab32((x)) #define ext2fs_cpu_to_le16(x) ext2fs_swab16((x)) #define ext2fs_le16_to_cpu(x) ext2fs_swab16((x)) -#define ext2fs_cpu_to_be64(x) ((__u64)(x)) -#define ext2fs_be64_to_cpu(x) ((__u64)(x)) #define ext2fs_cpu_to_be32(x) ((__u32)(x)) #define ext2fs_be32_to_cpu(x) ((__u32)(x)) #define ext2fs_cpu_to_be16(x) ((__u16)(x)) @@ -30,8 +37,6 @@ #define ext2fs_le32_to_cpu(x) ((__u32)(x)) #define ext2fs_cpu_to_le16(x) ((__u16)(x)) #define ext2fs_le16_to_cpu(x) ((__u16)(x)) -#define ext2fs_cpu_to_be64(x) ext2fs_swab64((x)) -#define ext2fs_be64_to_cpu(x) ext2fs_swab64((x)) #define ext2fs_cpu_to_be32(x) ext2fs_swab32((x)) #define ext2fs_be32_to_cpu(x) ext2fs_swab32((x)) #define ext2fs_cpu_to_be16(x) ext2fs_swab16((x)) @@ -53,15 +58,6 @@ extern void ext2fs_warn_bitmap(errcode_t errcode, unsigned long arg, extern void ext2fs_warn_bitmap2(ext2fs_generic_bitmap bitmap, int code, unsigned long arg); -#ifdef NO_INLINE_FUNCS -extern void ext2fs_fast_set_bit(unsigned int nr,void * addr); -extern void ext2fs_fast_clear_bit(unsigned int nr, void * addr); -extern void ext2fs_fast_set_bit64(__u64 nr,void * addr); -extern void ext2fs_fast_clear_bit64(__u64 nr, void * addr); -extern __u16 ext2fs_swab16(__u16 val); -extern __u32 ext2fs_swab32(__u32 val); -extern __u64 ext2fs_swab64(__u64 val); - extern int ext2fs_mark_block_bitmap(ext2fs_block_bitmap bitmap, blk_t block); extern int ext2fs_unmark_block_bitmap(ext2fs_block_bitmap bitmap, blk_t block); @@ -90,15 +86,6 @@ extern ext2_ino_t ext2fs_get_inode_bitmap_start(ext2fs_inode_bitmap bitmap); extern blk_t ext2fs_get_block_bitmap_end(ext2fs_block_bitmap bitmap); extern ext2_ino_t ext2fs_get_inode_bitmap_end(ext2fs_inode_bitmap bitmap); -extern void ext2fs_fast_mark_block_bitmap_range(ext2fs_block_bitmap bitmap, - blk_t block, int num); -extern void ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap, - blk_t block, int num); -extern int ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap, - blk_t block, int num); -#endif - -/* These functions routines moved to gen_bitmap.c */ extern void ext2fs_mark_block_bitmap_range(ext2fs_block_bitmap bitmap, blk_t block, int num); extern void ext2fs_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap, @@ -107,6 +94,15 @@ extern int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap, blk_t block, int num); extern int ext2fs_test_inode_bitmap_range(ext2fs_inode_bitmap bitmap, ino_t inode, int num); +extern void ext2fs_fast_mark_block_bitmap_range(ext2fs_block_bitmap bitmap, + blk_t block, int num); +extern void ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap, + blk_t block, int num); +extern int ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap, + blk_t block, int num); +extern void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map); + +/* These routines moved to gen_bitmap.c */ extern int ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap, __u32 bitno); extern int ext2fs_unmark_generic_bitmap(ext2fs_generic_bitmap bitmap, @@ -115,90 +111,9 @@ extern int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap, blk_t bitno); extern int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap, blk_t block, int num); -extern void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map); extern __u32 ext2fs_get_generic_bitmap_start(ext2fs_generic_bitmap bitmap); extern __u32 ext2fs_get_generic_bitmap_end(ext2fs_generic_bitmap bitmap); -/* 64-bit versions */ - -#ifdef NO_INLINE_FUNCS -extern int ext2fs_mark_block_bitmap2(ext2fs_block_bitmap bitmap, - blk64_t block); -extern int ext2fs_unmark_block_bitmap2(ext2fs_block_bitmap bitmap, - blk64_t block); -extern int ext2fs_test_block_bitmap2(ext2fs_block_bitmap bitmap, - blk64_t block); - -extern int ext2fs_mark_inode_bitmap2(ext2fs_inode_bitmap bitmap, - ext2_ino_t inode); -extern int ext2fs_unmark_inode_bitmap2(ext2fs_inode_bitmap bitmap, - ext2_ino_t inode); -extern int ext2fs_test_inode_bitmap2(ext2fs_inode_bitmap bitmap, - ext2_ino_t inode); - -extern void ext2fs_fast_mark_block_bitmap2(ext2fs_block_bitmap bitmap, - blk64_t block); -extern void ext2fs_fast_unmark_block_bitmap2(ext2fs_block_bitmap bitmap, - blk64_t block); -extern int ext2fs_fast_test_block_bitmap2(ext2fs_block_bitmap bitmap, - blk64_t block); - -extern void ext2fs_fast_mark_inode_bitmap2(ext2fs_inode_bitmap bitmap, - ext2_ino_t inode); -extern void ext2fs_fast_unmark_inode_bitmap2(ext2fs_inode_bitmap bitmap, - ext2_ino_t inode); -extern int ext2fs_fast_test_inode_bitmap2(ext2fs_inode_bitmap bitmap, - ext2_ino_t inode); -extern errcode_t ext2fs_find_first_zero_block_bitmap2(ext2fs_block_bitmap bitmap, - blk64_t start, - blk64_t end, - blk64_t *out); -extern errcode_t ext2fs_find_first_zero_inode_bitmap2(ext2fs_inode_bitmap bitmap, - ext2_ino_t start, - ext2_ino_t end, - ext2_ino_t *out); -extern blk64_t ext2fs_get_block_bitmap_start2(ext2fs_block_bitmap bitmap); -extern ext2_ino_t ext2fs_get_inode_bitmap_start2(ext2fs_inode_bitmap bitmap); -extern blk64_t ext2fs_get_block_bitmap_end2(ext2fs_block_bitmap bitmap); -extern ext2_ino_t ext2fs_get_inode_bitmap_end2(ext2fs_inode_bitmap bitmap); - -extern int ext2fs_fast_test_block_bitmap_range2(ext2fs_block_bitmap bitmap, - blk64_t block, - unsigned int num); -extern void ext2fs_fast_mark_block_bitmap_range2(ext2fs_block_bitmap bitmap, - blk64_t block, - unsigned int num); -extern void ext2fs_fast_unmark_block_bitmap_range2(ext2fs_block_bitmap bitmap, - blk64_t block, - unsigned int num); -#endif - -/* These routines moved to gen_bitmap64.c */ -extern void ext2fs_clear_generic_bmap(ext2fs_generic_bitmap bitmap); -extern errcode_t ext2fs_compare_generic_bmap(errcode_t neq, - ext2fs_generic_bitmap bm1, - ext2fs_generic_bitmap bm2); -extern void ext2fs_set_generic_bmap_padding(ext2fs_generic_bitmap bmap); -extern int ext2fs_mark_generic_bmap(ext2fs_generic_bitmap bitmap, - blk64_t bitno); -extern int ext2fs_unmark_generic_bmap(ext2fs_generic_bitmap bitmap, - blk64_t bitno); -extern int ext2fs_test_generic_bmap(ext2fs_generic_bitmap bitmap, - blk64_t bitno); -extern int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap bitmap, - blk64_t block, unsigned int num); -extern __u64 ext2fs_get_generic_bmap_start(ext2fs_generic_bitmap bitmap); -extern __u64 ext2fs_get_generic_bmap_end(ext2fs_generic_bitmap bitmap); -extern int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap bitmap, - blk64_t block, unsigned int num); -extern void ext2fs_mark_block_bitmap_range2(ext2fs_block_bitmap bitmap, - blk64_t block, unsigned int num); -extern void ext2fs_unmark_block_bitmap_range2(ext2fs_block_bitmap bitmap, - blk64_t block, unsigned int num); -extern errcode_t ext2fs_find_first_zero_generic_bmap(ext2fs_generic_bitmap bitmap, - __u64 start, __u64 end, - __u64 *out); - /* * The inline routines themselves... * @@ -208,7 +123,7 @@ extern errcode_t ext2fs_find_first_zero_generic_bmap(ext2fs_generic_bitmap bitma */ #ifdef NO_INLINE_FUNCS #if (defined(__GNUC__) && (defined(__i386__) || defined(__i486__) || \ - defined(__i586__))) + defined(__i586__) || defined(__mc68000__))) /* This prevents bitops.c from trying to include the C */ /* function version of these functions */ #define _EXT2_HAVE_ASM_BITOPS_ @@ -217,22 +132,14 @@ extern errcode_t ext2fs_find_first_zero_generic_bmap(ext2fs_generic_bitmap bitma #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS)) #ifdef INCLUDE_INLINE_FUNCS -#if (__STDC_VERSION__ >= 199901L) -#define _INLINE_ extern inline +#define _INLINE_ extern #else -#define _INLINE_ inline -#endif -#else /* !INCLUDE_INLINE FUNCS */ -#if (__STDC_VERSION__ >= 199901L) -#define _INLINE_ inline -#else /* not C99 */ #ifdef __GNUC__ #define _INLINE_ extern __inline__ #else /* For Watcom C */ #define _INLINE_ extern inline -#endif /* __GNUC__ */ -#endif /* __STDC_VERSION__ >= 199901L */ -#endif /* INCLUDE_INLINE_FUNCS */ +#endif +#endif /* * Fast bit set/clear functions that doesn't need to return the @@ -244,7 +151,7 @@ _INLINE_ void ext2fs_fast_set_bit(unsigned int nr,void * addr) unsigned char *ADDR = (unsigned char *) addr; ADDR += nr >> 3; - *ADDR |= (unsigned char) (1 << (nr & 0x07)); + *ADDR |= (1 << (nr & 0x07)); } _INLINE_ void ext2fs_fast_clear_bit(unsigned int nr, void * addr) @@ -252,24 +159,7 @@ _INLINE_ void ext2fs_fast_clear_bit(unsigned int nr, void * addr) unsigned char *ADDR = (unsigned char *) addr; ADDR += nr >> 3; - *ADDR &= (unsigned char) ~(1 << (nr & 0x07)); -} - - -_INLINE_ void ext2fs_fast_set_bit64(__u64 nr, void * addr) -{ - unsigned char *ADDR = (unsigned char *) addr; - - ADDR += nr >> 3; - *ADDR |= (unsigned char) (1 << (nr & 0x07)); -} - -_INLINE_ void ext2fs_fast_clear_bit64(__u64 nr, void * addr) -{ - unsigned char *ADDR = (unsigned char *) addr; - - ADDR += nr >> 3; - *ADDR &= (unsigned char) ~(1 << (nr & 0x07)); + *ADDR &= ~(1 << (nr & 0x07)); } @@ -353,12 +243,49 @@ _INLINE_ __u16 ext2fs_swab16(__u16 val) #endif /* i386 */ +#if ((defined __GNUC__) && !defined(_EXT2_USE_C_VERSIONS_) && \ + (defined(__mc68000__))) + +#define _EXT2_HAVE_ASM_BITOPS_ + +_INLINE_ int ext2fs_set_bit(unsigned int nr,void * addr) +{ + char retval; + + __asm__ __volatile__ ("bfset %2@{%1:#1}; sne %0" + : "=d" (retval) : "d" (nr^7), "a" (addr)); + + return retval; +} + +_INLINE_ int ext2fs_clear_bit(unsigned int nr, void * addr) +{ + char retval; + + __asm__ __volatile__ ("bfclr %2@{%1:#1}; sne %0" + : "=d" (retval) : "d" (nr^7), "a" (addr)); + + return retval; +} + +_INLINE_ int ext2fs_test_bit(unsigned int nr, const void * addr) +{ + char retval; + + __asm__ __volatile__ ("bftst %2@{%1:#1}; sne %0" + : "=d" (retval) : "d" (nr^7), "a" (addr)); + + return retval; +} + +#endif /* __mc68000__ */ + #if !defined(_EXT2_HAVE_ASM_SWAB_) _INLINE_ __u16 ext2fs_swab16(__u16 val) { - return (val >> 8) | (__u16) (val << 8); + return (val >> 8) | (val << 8); } _INLINE_ __u32 ext2fs_swab32(__u32 val) @@ -371,7 +298,7 @@ _INLINE_ __u32 ext2fs_swab32(__u32 val) _INLINE_ __u64 ext2fs_swab64(__u64 val) { - return (ext2fs_swab32((__u32) (val >> 32)) | + return (ext2fs_swab32(val >> 32) | (((__u64)ext2fs_swab32(val & 0xFFFFFFFFUL)) << 32)); } @@ -492,169 +419,6 @@ _INLINE_ void ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap, { ext2fs_unmark_block_bitmap_range(bitmap, block, num); } - -/* 64-bit versions */ - -_INLINE_ int ext2fs_mark_block_bitmap2(ext2fs_block_bitmap bitmap, - blk64_t block) -{ - return ext2fs_mark_generic_bmap((ext2fs_generic_bitmap) bitmap, - block); -} - -_INLINE_ int ext2fs_unmark_block_bitmap2(ext2fs_block_bitmap bitmap, - blk64_t block) -{ - return ext2fs_unmark_generic_bmap((ext2fs_generic_bitmap) bitmap, block); -} - -_INLINE_ int ext2fs_test_block_bitmap2(ext2fs_block_bitmap bitmap, - blk64_t block) -{ - return ext2fs_test_generic_bmap((ext2fs_generic_bitmap) bitmap, - block); -} - -_INLINE_ int ext2fs_mark_inode_bitmap2(ext2fs_inode_bitmap bitmap, - ext2_ino_t inode) -{ - return ext2fs_mark_generic_bmap((ext2fs_generic_bitmap) bitmap, - inode); -} - -_INLINE_ int ext2fs_unmark_inode_bitmap2(ext2fs_inode_bitmap bitmap, - ext2_ino_t inode) -{ - return ext2fs_unmark_generic_bmap((ext2fs_generic_bitmap) bitmap, - inode); -} - -_INLINE_ int ext2fs_test_inode_bitmap2(ext2fs_inode_bitmap bitmap, - ext2_ino_t inode) -{ - return ext2fs_test_generic_bmap((ext2fs_generic_bitmap) bitmap, - inode); -} - -_INLINE_ void ext2fs_fast_mark_block_bitmap2(ext2fs_block_bitmap bitmap, - blk64_t block) -{ - ext2fs_mark_generic_bmap((ext2fs_generic_bitmap) bitmap, block); -} - -_INLINE_ void ext2fs_fast_unmark_block_bitmap2(ext2fs_block_bitmap bitmap, - blk64_t block) -{ - ext2fs_unmark_generic_bmap((ext2fs_generic_bitmap) bitmap, block); -} - -_INLINE_ int ext2fs_fast_test_block_bitmap2(ext2fs_block_bitmap bitmap, - blk64_t block) -{ - return ext2fs_test_generic_bmap((ext2fs_generic_bitmap) bitmap, - block); -} - -_INLINE_ void ext2fs_fast_mark_inode_bitmap2(ext2fs_inode_bitmap bitmap, - ext2_ino_t inode) -{ - ext2fs_mark_generic_bmap((ext2fs_generic_bitmap) bitmap, inode); -} - -_INLINE_ void ext2fs_fast_unmark_inode_bitmap2(ext2fs_inode_bitmap bitmap, - ext2_ino_t inode) -{ - ext2fs_unmark_generic_bmap((ext2fs_generic_bitmap) bitmap, inode); -} - -_INLINE_ int ext2fs_fast_test_inode_bitmap2(ext2fs_inode_bitmap bitmap, - ext2_ino_t inode) -{ - return ext2fs_test_generic_bmap((ext2fs_generic_bitmap) bitmap, - inode); -} - -_INLINE_ errcode_t ext2fs_find_first_zero_block_bitmap2(ext2fs_block_bitmap bitmap, - blk64_t start, - blk64_t end, - blk64_t *out) -{ - __u64 o; - errcode_t rv; - - rv = ext2fs_find_first_zero_generic_bmap((ext2fs_generic_bitmap) bitmap, - start, end, &o); - if (!rv) - *out = o; - return rv; -} - -_INLINE_ errcode_t ext2fs_find_first_zero_inode_bitmap2(ext2fs_inode_bitmap bitmap, - ext2_ino_t start, - ext2_ino_t end, - ext2_ino_t *out) -{ - __u64 o; - errcode_t rv; - - rv = ext2fs_find_first_zero_generic_bmap((ext2fs_generic_bitmap) bitmap, - start, end, &o); - if (!rv) - *out = (ext2_ino_t) o; - return rv; -} - -_INLINE_ blk64_t ext2fs_get_block_bitmap_start2(ext2fs_block_bitmap bitmap) -{ - return ext2fs_get_generic_bmap_start((ext2fs_generic_bitmap) bitmap); -} - -_INLINE_ ext2_ino_t ext2fs_get_inode_bitmap_start2(ext2fs_inode_bitmap bitmap) -{ - return (ext2_ino_t) ext2fs_get_generic_bmap_start((ext2fs_generic_bitmap) bitmap); -} - -_INLINE_ blk64_t ext2fs_get_block_bitmap_end2(ext2fs_block_bitmap bitmap) -{ - return ext2fs_get_generic_bmap_end((ext2fs_generic_bitmap) bitmap); -} - -_INLINE_ ext2_ino_t ext2fs_get_inode_bitmap_end2(ext2fs_inode_bitmap bitmap) -{ - return (ext2_ino_t) ext2fs_get_generic_bmap_end((ext2fs_generic_bitmap) bitmap); -} - -_INLINE_ int ext2fs_fast_test_block_bitmap_range2(ext2fs_block_bitmap bitmap, - blk64_t block, - unsigned int num) -{ - return ext2fs_test_block_bitmap_range2(bitmap, block, num); -} - -_INLINE_ void ext2fs_fast_mark_block_bitmap_range2(ext2fs_block_bitmap bitmap, - blk64_t block, - unsigned int num) -{ - ext2fs_mark_block_bitmap_range2(bitmap, block, num); -} - -_INLINE_ void ext2fs_fast_unmark_block_bitmap_range2(ext2fs_block_bitmap bitmap, - blk64_t block, - unsigned int num) -{ - ext2fs_unmark_block_bitmap_range2(bitmap, block, num); -} - #undef _INLINE_ #endif -#ifndef _EXT2_HAVE_ASM_BITOPS_ -extern int ext2fs_set_bit(unsigned int nr,void * addr); -extern int ext2fs_clear_bit(unsigned int nr, void * addr); -extern int ext2fs_test_bit(unsigned int nr, const void * addr); -#endif - -extern int ext2fs_set_bit64(__u64 nr,void * addr); -extern int ext2fs_clear_bit64(__u64 nr, void * addr); -extern int ext2fs_test_bit64(__u64 nr, const void * addr); -extern unsigned int ext2fs_bitcount(const void *addr, unsigned int nbytes); diff --git a/lib/ext2fs/blkmap64_ba.c b/lib/ext2fs/blkmap64_ba.c deleted file mode 100644 index 72ef3ebd..00000000 --- a/lib/ext2fs/blkmap64_ba.c +++ /dev/null @@ -1,416 +0,0 @@ -/* - * blkmap64_ba.c --- Simple bitarray implementation for bitmaps - * - * Copyright (C) 2008 Theodore Ts'o. - * - * %Begin-Header% - * This file may be redistributed under the terms of the GNU Public - * License. - * %End-Header% - */ - -#include <stdio.h> -#include <string.h> -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <fcntl.h> -#include <time.h> -#if HAVE_SYS_STAT_H -#include <sys/stat.h> -#endif -#if HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif - -#include "ext2_fs.h" -#include "ext2fsP.h" -#include "bmap64.h" - -/* - * Private data for bit array implementation of bitmap ops. - * Currently, this is just a pointer to our big flat hunk of memory, - * exactly equivalent to the old-skool char * bitmap member. - */ - -struct ext2fs_ba_private_struct { - char *bitarray; -}; - -typedef struct ext2fs_ba_private_struct *ext2fs_ba_private; - -static errcode_t ba_alloc_private_data (ext2fs_generic_bitmap bitmap) -{ - ext2fs_ba_private bp; - errcode_t retval; - size_t size; - - /* - * Since we only have the one pointer, we could just shove our - * private data in the void *private field itself, but then - * we'd have to do a fair bit of rewriting if we ever added a - * field. I'm agnostic. - */ - retval = ext2fs_get_mem(sizeof (ext2fs_ba_private), &bp); - if (retval) - return retval; - - size = (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1); - - retval = ext2fs_get_mem(size, &bp->bitarray); - if (retval) { - ext2fs_free_mem(&bp); - bp = 0; - return retval; - } - bitmap->private = (void *) bp; - return 0; -} - -static errcode_t ba_new_bmap(ext2_filsys fs EXT2FS_ATTR((unused)), - ext2fs_generic_bitmap bitmap) -{ - ext2fs_ba_private bp; - errcode_t retval; - size_t size; - - retval = ba_alloc_private_data (bitmap); - if (retval) - return retval; - - bp = (ext2fs_ba_private) bitmap->private; - size = (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1); - memset(bp->bitarray, 0, size); - - return 0; -} - -static void ba_free_bmap(ext2fs_generic_bitmap bitmap) -{ - ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; - - if (!bp) - return; - - if (bp->bitarray) { - ext2fs_free_mem (&bp->bitarray); - bp->bitarray = 0; - } - ext2fs_free_mem (&bp); - bp = 0; -} - -static errcode_t ba_copy_bmap(ext2fs_generic_bitmap src, - ext2fs_generic_bitmap dest) -{ - ext2fs_ba_private src_bp = (ext2fs_ba_private) src->private; - ext2fs_ba_private dest_bp; - errcode_t retval; - size_t size; - - retval = ba_alloc_private_data (dest); - if (retval) - return retval; - - dest_bp = (ext2fs_ba_private) dest->private; - - size = (size_t) (((src->real_end - src->start) / 8) + 1); - memcpy (dest_bp->bitarray, src_bp->bitarray, size); - - return 0; -} - -static errcode_t ba_resize_bmap(ext2fs_generic_bitmap bmap, - __u64 new_end, __u64 new_real_end) -{ - ext2fs_ba_private bp = (ext2fs_ba_private) bmap->private; - errcode_t retval; - size_t size, new_size; - __u64 bitno; - - /* - * If we're expanding the bitmap, make sure all of the new - * parts of the bitmap are zero. - */ - if (new_end > bmap->end) { - bitno = bmap->real_end; - if (bitno > new_end) - bitno = new_end; - for (; bitno > bmap->end; bitno--) - ext2fs_clear_bit64(bitno - bmap->start, bp->bitarray); - } - if (new_real_end == bmap->real_end) { - bmap->end = new_end; - return 0; - } - - size = ((bmap->real_end - bmap->start) / 8) + 1; - new_size = ((new_real_end - bmap->start) / 8) + 1; - - if (size != new_size) { - retval = ext2fs_resize_mem(size, new_size, &bp->bitarray); - if (retval) - return retval; - } - if (new_size > size) - memset(bp->bitarray + size, 0, new_size - size); - - bmap->end = new_end; - bmap->real_end = new_real_end; - return 0; - -} - -static int ba_mark_bmap(ext2fs_generic_bitmap bitmap, __u64 arg) -{ - ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; - blk64_t bitno = (blk64_t) arg; - - return ext2fs_set_bit64(bitno - bitmap->start, bp->bitarray); -} - -static int ba_unmark_bmap(ext2fs_generic_bitmap bitmap, __u64 arg) -{ - ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; - blk64_t bitno = (blk64_t) arg; - - return ext2fs_clear_bit64(bitno - bitmap->start, bp->bitarray); -} - -static int ba_test_bmap(ext2fs_generic_bitmap bitmap, __u64 arg) -{ - ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; - blk64_t bitno = (blk64_t) arg; - - return ext2fs_test_bit64(bitno - bitmap->start, bp->bitarray); -} - -static void ba_mark_bmap_extent(ext2fs_generic_bitmap bitmap, __u64 arg, - unsigned int num) -{ - ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; - blk64_t bitno = (blk64_t) arg; - unsigned int i; - - for (i = 0; i < num; i++) - ext2fs_fast_set_bit64(bitno + i - bitmap->start, bp->bitarray); -} - -static void ba_unmark_bmap_extent(ext2fs_generic_bitmap bitmap, __u64 arg, - unsigned int num) -{ - ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; - blk64_t bitno = (blk64_t) arg; - unsigned int i; - - for (i = 0; i < num; i++) - ext2fs_fast_clear_bit64(bitno + i - bitmap->start, bp->bitarray); -} - -static int ba_test_clear_bmap_extent(ext2fs_generic_bitmap bitmap, - __u64 start, unsigned int len) -{ - ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; - __u64 start_byte, len_byte = len >> 3; - unsigned int start_bit, len_bit = len % 8; - unsigned int first_bit = 0; - unsigned int last_bit = 0; - int mark_count = 0; - int mark_bit = 0; - int i; - const char *ADDR; - - ADDR = bp->bitarray; - start -= bitmap->start; - start_byte = start >> 3; - start_bit = start % 8; - - if (start_bit != 0) { - /* - * The compared start block number or start inode number - * is not the first bit in a byte. - */ - mark_count = 8 - start_bit; - if (len < 8 - start_bit) { - mark_count = (int)len; - mark_bit = len + start_bit - 1; - } else - mark_bit = 7; - - for (i = mark_count; i > 0; i--, mark_bit--) - first_bit |= 1 << mark_bit; - - /* - * Compare blocks or inodes in the first byte. - * If there is any marked bit, this function returns 0. - */ - if (first_bit & ADDR[start_byte]) - return 0; - else if (len <= 8 - start_bit) - return 1; - - start_byte++; - len_bit = (len - mark_count) % 8; - len_byte = (len - mark_count) >> 3; - } - - /* - * The compared start block number or start inode number is - * the first bit in a byte. - */ - if (len_bit != 0) { - /* - * The compared end block number or end inode number is - * not the last bit in a byte. - */ - for (mark_bit = len_bit - 1; mark_bit >= 0; mark_bit--) - last_bit |= 1 << mark_bit; - - /* - * Compare blocks or inodes in the last byte. - * If there is any marked bit, this function returns 0. - */ - if (last_bit & ADDR[start_byte + len_byte]) - return 0; - else if (len_byte == 0) - return 1; - } - - /* Check whether all bytes are 0 */ - return ext2fs_mem_is_zero(ADDR + start_byte, len_byte); -} - - -static errcode_t ba_set_bmap_range(ext2fs_generic_bitmap bitmap, - __u64 start, size_t num, void *in) -{ - ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; - - memcpy (bp->bitarray + (start >> 3), in, (num + 7) >> 3); - - return 0; -} - -static errcode_t ba_get_bmap_range(ext2fs_generic_bitmap bitmap, - __u64 start, size_t num, void *out) -{ - ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; - - memcpy (out, bp->bitarray + (start >> 3), (num + 7) >> 3); - - return 0; -} - -static void ba_clear_bmap(ext2fs_generic_bitmap bitmap) -{ - ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; - - memset(bp->bitarray, 0, - (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1)); -} - -static void ba_print_stats(ext2fs_generic_bitmap bitmap) -{ - fprintf(stderr, "%16llu Bytes used by bitarray\n", - ((bitmap->real_end - bitmap->start) >> 3) + 1 + - sizeof(struct ext2fs_ba_private_struct)); -} - -/* Find the first zero bit between start and end, inclusive. */ -static errcode_t ba_find_first_zero(ext2fs_generic_bitmap bitmap, - __u64 start, __u64 end, __u64 *out) -{ - ext2fs_ba_private bp = (ext2fs_ba_private)bitmap->private; - unsigned long bitpos = start - bitmap->start; - unsigned long count = end - start + 1; - int byte_found = 0; /* whether a != 0xff byte has been found */ - const unsigned char *pos; - unsigned long max_loop_count, i; - - if (start < bitmap->start || end > bitmap->end || start > end) - return EINVAL; - - if (bitmap->cluster_bits) - return EINVAL; - - /* scan bits until we hit a byte boundary */ - while ((bitpos & 0x7) != 0 && count > 0) { - if (!ext2fs_test_bit64(bitpos, bp->bitarray)) { - *out = bitpos + bitmap->start; - return 0; - } - bitpos++; - count--; - } - - if (!count) - return ENOENT; - - pos = ((unsigned char *)bp->bitarray) + (bitpos >> 3); - /* scan bytes until 8-byte (64-bit) aligned */ - while (count >= 8 && (((unsigned long)pos) & 0x07)) { - if (*pos != 0xff) { - byte_found = 1; - break; - } - pos++; - count -= 8; - bitpos += 8; - } - - if (!byte_found) { - max_loop_count = count >> 6; /* 8-byte blocks */ - i = max_loop_count; - while (i) { - if (*((const __u64 *)pos) != ((__u64)-1)) - break; - pos += 8; - i--; - } - count -= 64 * (max_loop_count - i); - bitpos += 64 * (max_loop_count - i); - - max_loop_count = count >> 3; - i = max_loop_count; - while (i) { - if (*pos != 0xff) { - byte_found = 1; - break; - } - pos++; - i--; - } - count -= 8 * (max_loop_count - i); - bitpos += 8 * (max_loop_count - i); - } - - /* Here either count < 8 or byte_found == 1. */ - while (count-- > 0) { - if (!ext2fs_test_bit64(bitpos, bp->bitarray)) { - *out = bitpos + bitmap->start; - return 0; - } - bitpos++; - } - - return ENOENT; -} - -struct ext2_bitmap_ops ext2fs_blkmap64_bitarray = { - .type = EXT2FS_BMAP64_BITARRAY, - .new_bmap = ba_new_bmap, - .free_bmap = ba_free_bmap, - .copy_bmap = ba_copy_bmap, - .resize_bmap = ba_resize_bmap, - .mark_bmap = ba_mark_bmap, - .unmark_bmap = ba_unmark_bmap, - .test_bmap = ba_test_bmap, - .test_clear_bmap_extent = ba_test_clear_bmap_extent, - .mark_bmap_extent = ba_mark_bmap_extent, - .unmark_bmap_extent = ba_unmark_bmap_extent, - .set_bmap_range = ba_set_bmap_range, - .get_bmap_range = ba_get_bmap_range, - .clear_bmap = ba_clear_bmap, - .print_stats = ba_print_stats, - .find_first_zero = ba_find_first_zero -}; diff --git a/lib/ext2fs/blkmap64_rb.c b/lib/ext2fs/blkmap64_rb.c deleted file mode 100644 index a22682e8..00000000 --- a/lib/ext2fs/blkmap64_rb.c +++ /dev/null @@ -1,886 +0,0 @@ -/* - * blkmap64_rb.c --- Simple rb-tree implementation for bitmaps - * - * (C)2010 Red Hat, Inc., Lukas Czerner <lczerner@redhat.com> - * - * %Begin-Header% - * This file may be redistributed under the terms of the GNU Public - * License. - * %End-Header% - */ - -#include <stdio.h> -#include <string.h> -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <fcntl.h> -#include <time.h> -#if HAVE_SYS_STAT_H -#include <sys/stat.h> -#endif -#if HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif - -#include "ext2_fs.h" -#include "ext2fsP.h" -#include "bmap64.h" -#include "rbtree.h" - -#include <limits.h> - -struct bmap_rb_extent { - struct rb_node node; - __u64 start; - __u64 count; -}; - -struct ext2fs_rb_private { - struct rb_root root; - struct bmap_rb_extent *wcursor; - struct bmap_rb_extent *rcursor; - struct bmap_rb_extent *rcursor_next; -#ifdef BMAP_STATS_OPS - __u64 mark_hit; - __u64 test_hit; -#endif -}; - -inline static struct bmap_rb_extent *node_to_extent(struct rb_node *node) -{ - /* - * This depends on the fact the struct rb_node is at the - * beginning of the bmap_rb_extent structure. We use this - * instead of the ext2fs_rb_entry macro because it causes gcc - * -Wall to generate a huge amount of noise. - */ - return (struct bmap_rb_extent *) node; -} - -static int rb_insert_extent(__u64 start, __u64 count, - struct ext2fs_rb_private *); -static void rb_get_new_extent(struct bmap_rb_extent **, __u64, __u64); - -/* #define DEBUG_RB */ - -#ifdef DEBUG_RB -static void print_tree(struct rb_root *root) -{ - struct rb_node *node = NULL; - struct bmap_rb_extent *ext; - - printf("\t\t\t=================================\n"); - node = ext2fs_rb_first(root); - for (node = ext2fs_rb_first(root); node != NULL; - node = ext2fs_rb_next(node)) { - ext = node_to_extent(node); - printf("\t\t\t--> (%llu -> %llu)\n", - ext->start, ext->start + ext->count); - } - printf("\t\t\t=================================\n"); -} - -static void check_tree(struct rb_root *root, const char *msg) -{ - struct rb_node *new_node, *node, *next; - struct bmap_rb_extent *ext, *old = NULL; - - for (node = ext2fs_rb_first(root); node; - node = ext2fs_rb_next(node)) { - ext = node_to_extent(node); - if (ext->count <= 0) { - printf("Tree Error: count is crazy\n"); - printf("extent: %llu -> %llu (%u)\n", ext->start, - ext->start + ext->count, ext->count); - goto err_out; - } - if (ext->start < 0) { - printf("Tree Error: start is crazy\n"); - printf("extent: %llu -> %llu (%u)\n", ext->start, - ext->start + ext->count, ext->count); - goto err_out; - } - - if (old) { - if (old->start > ext->start) { - printf("Tree Error: start is crazy\n"); - printf("extent: %llu -> %llu (%u)\n", - old->start, old->start + old->count, - old->count); - printf("extent next: %llu -> %llu (%u)\n", - ext->start, ext->start + ext->count, - ext->count); - goto err_out; - } - if ((old->start + old->count) >= ext->start) { - printf("Tree Error: extent is crazy\n"); - printf("extent: %llu -> %llu (%u)\n", - old->start, old->start + old->count, - old->count); - printf("extent next: %llu -> %llu (%u)\n", - ext->start, ext->start + ext->count, - ext->count); - goto err_out; - } - } - old = ext; - } - return; - -err_out: - printf("%s\n", msg); - print_tree(root); - exit(1); -} -#else -#define check_tree(root, msg) do {} while (0) -#define print_tree(root, msg) do {} while (0) -#endif - -static void rb_get_new_extent(struct bmap_rb_extent **ext, __u64 start, - __u64 count) -{ - struct bmap_rb_extent *new_ext; - int retval; - - retval = ext2fs_get_mem(sizeof (struct bmap_rb_extent), - &new_ext); - if (retval) { - perror("ext2fs_get_mem"); - exit(1); - } - - new_ext->start = start; - new_ext->count = count; - *ext = new_ext; -} - -inline -static void rb_free_extent(struct ext2fs_rb_private *bp, - struct bmap_rb_extent *ext) -{ - if (bp->wcursor == ext) - bp->wcursor = NULL; - if (bp->rcursor == ext) - bp->rcursor = NULL; - if (bp->rcursor_next == ext) - bp->rcursor_next = NULL; - ext2fs_free_mem(&ext); -} - -static errcode_t rb_alloc_private_data (ext2fs_generic_bitmap bitmap) -{ - struct ext2fs_rb_private *bp; - errcode_t retval; - - retval = ext2fs_get_mem(sizeof (struct ext2fs_rb_private), &bp); - if (retval) - return retval; - - bp->root = RB_ROOT; - bp->rcursor = NULL; - bp->rcursor_next = NULL; - bp->wcursor = NULL; - -#ifdef BMAP_STATS_OPS - bp->test_hit = 0; - bp->mark_hit = 0; -#endif - - bitmap->private = (void *) bp; - return 0; -} - -static errcode_t rb_new_bmap(ext2_filsys fs EXT2FS_ATTR((unused)), - ext2fs_generic_bitmap bitmap) -{ - errcode_t retval; - - retval = rb_alloc_private_data (bitmap); - if (retval) - return retval; - - return 0; -} - -static void rb_free_tree(struct rb_root *root) -{ - struct bmap_rb_extent *ext; - struct rb_node *node, *next; - - for (node = ext2fs_rb_first(root); node; node = next) { - next = ext2fs_rb_next(node); - ext = node_to_extent(node); - ext2fs_rb_erase(node, root); - ext2fs_free_mem(&ext); - } -} - -static void rb_free_bmap(ext2fs_generic_bitmap bitmap) -{ - struct ext2fs_rb_private *bp; - - bp = (struct ext2fs_rb_private *) bitmap->private; - - rb_free_tree(&bp->root); - ext2fs_free_mem(&bp); - bp = 0; -} - -static errcode_t rb_copy_bmap(ext2fs_generic_bitmap src, - ext2fs_generic_bitmap dest) -{ - struct ext2fs_rb_private *src_bp, *dest_bp; - struct bmap_rb_extent *src_ext, *dest_ext; - struct rb_node *dest_node, *src_node, *dest_last, **n; - errcode_t retval = 0; - - retval = rb_alloc_private_data (dest); - if (retval) - return retval; - - src_bp = (struct ext2fs_rb_private *) src->private; - dest_bp = (struct ext2fs_rb_private *) dest->private; - src_bp->rcursor = NULL; - dest_bp->rcursor = NULL; - - src_node = ext2fs_rb_first(&src_bp->root); - while (src_node) { - src_ext = node_to_extent(src_node); - retval = ext2fs_get_mem(sizeof (struct bmap_rb_extent), - &dest_ext); - if (retval) - break; - - memcpy(dest_ext, src_ext, sizeof(struct bmap_rb_extent)); - - dest_node = &dest_ext->node; - n = &dest_bp->root.rb_node; - - dest_last = NULL; - if (*n) { - dest_last = ext2fs_rb_last(&dest_bp->root); - n = &(dest_last)->rb_right; - } - - ext2fs_rb_link_node(dest_node, dest_last, n); - ext2fs_rb_insert_color(dest_node, &dest_bp->root); - - src_node = ext2fs_rb_next(src_node); - } - - return retval; -} - -static void rb_truncate(__u64 new_max, struct rb_root *root) -{ - struct bmap_rb_extent *ext; - struct rb_node *node; - - node = ext2fs_rb_last(root); - while (node) { - ext = node_to_extent(node); - - if ((ext->start + ext->count - 1) <= new_max) - break; - else if (ext->start > new_max) { - ext2fs_rb_erase(node, root); - ext2fs_free_mem(&ext); - node = ext2fs_rb_last(root); - continue; - } else - ext->count = new_max - ext->start + 1; - } -} - -static errcode_t rb_resize_bmap(ext2fs_generic_bitmap bmap, - __u64 new_end, __u64 new_real_end) -{ - struct ext2fs_rb_private *bp; - - if (new_real_end >= bmap->real_end) { - bmap->end = new_end; - bmap->real_end = new_real_end; - return 0; - } - - bp = (struct ext2fs_rb_private *) bmap->private; - bp->rcursor = NULL; - bp->wcursor = NULL; - - /* truncate tree to new_real_end size */ - rb_truncate(new_real_end, &bp->root); - - bmap->end = new_end; - bmap->real_end = new_real_end; - return 0; - -} - -inline static int -rb_test_bit(struct ext2fs_rb_private *bp, __u64 bit) -{ - struct bmap_rb_extent *rcursor, *next_ext = NULL; - struct rb_node *parent = NULL, *next; - struct rb_node **n = &bp->root.rb_node; - struct bmap_rb_extent *ext; - - rcursor = bp->rcursor; - if (!rcursor) - goto search_tree; - - if (bit >= rcursor->start && bit < rcursor->start + rcursor->count) { -#ifdef BMAP_STATS_OPS - bp->test_hit++; -#endif - return 1; - } - - next_ext = bp->rcursor_next; - if (!next_ext) { - next = ext2fs_rb_next(&rcursor->node); - if (next) - next_ext = node_to_extent(next); - bp->rcursor_next = next_ext; - } - if (next_ext) { - if ((bit >= rcursor->start + rcursor->count) && - (bit < next_ext->start)) { -#ifdef BMAP_STATS_OPS - bp->test_hit++; -#endif - return 0; - } - } - bp->rcursor = NULL; - bp->rcursor_next = NULL; - - rcursor = bp->wcursor; - if (!rcursor) - goto search_tree; - - if (bit >= rcursor->start && bit < rcursor->start + rcursor->count) - return 1; - -search_tree: - - while (*n) { - parent = *n; - ext = node_to_extent(parent); - if (bit < ext->start) - n = &(*n)->rb_left; - else if (bit >= (ext->start + ext->count)) - n = &(*n)->rb_right; - else { - bp->rcursor = ext; - bp->rcursor_next = NULL; - return 1; - } - } - return 0; -} - -static int rb_insert_extent(__u64 start, __u64 count, - struct ext2fs_rb_private *bp) -{ - struct rb_root *root = &bp->root; - struct rb_node *parent = NULL, **n = &root->rb_node; - struct rb_node *new_node, *node, *next; - struct bmap_rb_extent *new_ext; - struct bmap_rb_extent *ext; - int retval = 0; - - bp->rcursor_next = NULL; - ext = bp->wcursor; - if (ext) { - if (start >= ext->start && - start <= (ext->start + ext->count)) { -#ifdef BMAP_STATS_OPS - bp->mark_hit++; -#endif - goto got_extent; - } - } - - while (*n) { - parent = *n; - ext = node_to_extent(parent); - - if (start < ext->start) { - n = &(*n)->rb_left; - } else if (start > (ext->start + ext->count)) { - n = &(*n)->rb_right; - } else { -got_extent: - if ((start + count) <= (ext->start + ext->count)) - return 1; - - if ((ext->start + ext->count) == start) - retval = 0; - else - retval = 1; - - count += (start - ext->start); - start = ext->start; - new_ext = ext; - new_node = &ext->node; - - goto skip_insert; - } - } - - rb_get_new_extent(&new_ext, start, count); - - new_node = &new_ext->node; - ext2fs_rb_link_node(new_node, parent, n); - ext2fs_rb_insert_color(new_node, root); - bp->wcursor = new_ext; - - node = ext2fs_rb_prev(new_node); - if (node) { - ext = node_to_extent(node); - if ((ext->start + ext->count) == start) { - start = ext->start; - count += ext->count; - ext2fs_rb_erase(node, root); - rb_free_extent(bp, ext); - } - } - -skip_insert: - /* See if we can merge extent to the right */ - for (node = ext2fs_rb_next(new_node); node != NULL; node = next) { - next = ext2fs_rb_next(node); - ext = node_to_extent(node); - - if ((ext->start + ext->count) <= start) - continue; - - /* No more merging */ - if ((start + count) < ext->start) - break; - - /* ext is embedded in new_ext interval */ - if ((start + count) >= (ext->start + ext->count)) { - ext2fs_rb_erase(node, root); - rb_free_extent(bp, ext); - continue; - } else { - /* merge ext with new_ext */ - count += ((ext->start + ext->count) - - (start + count)); - ext2fs_rb_erase(node, root); - rb_free_extent(bp, ext); - break; - } - } - - new_ext->start = start; - new_ext->count = count; - - return retval; -} - -static int rb_remove_extent(__u64 start, __u64 count, - struct ext2fs_rb_private *bp) -{ - struct rb_root *root = &bp->root; - struct rb_node *parent = NULL, **n = &root->rb_node; - struct rb_node *node; - struct bmap_rb_extent *ext; - __u64 new_start, new_count; - int retval = 0; - - if (EXT2FS_RB_EMPTY_ROOT(root)) - return 0; - - while (*n) { - parent = *n; - ext = node_to_extent(parent); - if (start < ext->start) { - n = &(*n)->rb_left; - continue; - } else if (start >= (ext->start + ext->count)) { - n = &(*n)->rb_right; - continue; - } - - if ((start > ext->start) && - (start + count) < (ext->start + ext->count)) { - /* We have to split extent into two */ - new_start = start + count; - new_count = (ext->start + ext->count) - new_start; - - ext->count = start - ext->start; - - rb_insert_extent(new_start, new_count, bp); - return 1; - } - - if ((start + count) >= (ext->start + ext->count)) { - ext->count = start - ext->start; - retval = 1; - } - - if (0 == ext->count) { - parent = ext2fs_rb_next(&ext->node); - ext2fs_rb_erase(&ext->node, root); - rb_free_extent(bp, ext); - break; - } - - if (start == ext->start) { - ext->start += count; - ext->count -= count; - return 1; - } - } - - /* See if we should delete or truncate extent on the right */ - for (; parent != NULL; parent = node) { - node = ext2fs_rb_next(parent); - ext = node_to_extent(parent); - if ((ext->start + ext->count) <= start) - continue; - - /* No more extents to be removed/truncated */ - if ((start + count) < ext->start) - break; - - /* The entire extent is within the region to be removed */ - if ((start + count) >= (ext->start + ext->count)) { - ext2fs_rb_erase(parent, root); - rb_free_extent(bp, ext); - retval = 1; - continue; - } else { - /* modify the last extent in reigon to be removed */ - ext->count -= ((start + count) - ext->start); - ext->start = start + count; - retval = 1; - break; - } - } - - return retval; -} - -static int rb_mark_bmap(ext2fs_generic_bitmap bitmap, __u64 arg) -{ - struct ext2fs_rb_private *bp; - - bp = (struct ext2fs_rb_private *) bitmap->private; - arg -= bitmap->start; - - return rb_insert_extent(arg, 1, bp); -} - -static int rb_unmark_bmap(ext2fs_generic_bitmap bitmap, __u64 arg) -{ - struct ext2fs_rb_private *bp; - int retval; - - bp = (struct ext2fs_rb_private *) bitmap->private; - arg -= bitmap->start; - - retval = rb_remove_extent(arg, 1, bp); - check_tree(&bp->root, __func__); - - return retval; -} - -inline -static int rb_test_bmap(ext2fs_generic_bitmap bitmap, __u64 arg) -{ - struct ext2fs_rb_private *bp; - - bp = (struct ext2fs_rb_private *) bitmap->private; - arg -= bitmap->start; - - return rb_test_bit(bp, arg); -} - -static void rb_mark_bmap_extent(ext2fs_generic_bitmap bitmap, __u64 arg, - unsigned int num) -{ - struct ext2fs_rb_private *bp; - - bp = (struct ext2fs_rb_private *) bitmap->private; - arg -= bitmap->start; - - rb_insert_extent(arg, num, bp); -} - -static void rb_unmark_bmap_extent(ext2fs_generic_bitmap bitmap, __u64 arg, - unsigned int num) -{ - struct ext2fs_rb_private *bp; - - bp = (struct ext2fs_rb_private *) bitmap->private; - arg -= bitmap->start; - - rb_remove_extent(arg, num, bp); - check_tree(&bp->root, __func__); -} - -static int rb_test_clear_bmap_extent(ext2fs_generic_bitmap bitmap, - __u64 start, unsigned int len) -{ - struct rb_node *parent = NULL, **n; - struct rb_node *node, *next; - struct ext2fs_rb_private *bp; - struct bmap_rb_extent *ext; - int retval = 1; - - bp = (struct ext2fs_rb_private *) bitmap->private; - n = &bp->root.rb_node; - start -= bitmap->start; - - if ((len == 0) || EXT2FS_RB_EMPTY_ROOT(&bp->root)) - return 1; - - /* - * If we find nothing, we should examine whole extent, but - * when we find match, the extent is not clean, thus be return - * false. - */ - while (*n) { - parent = *n; - ext = node_to_extent(parent); - if (start < ext->start) { - n = &(*n)->rb_left; - } else if (start >= (ext->start + ext->count)) { - n = &(*n)->rb_right; - } else { - /* - * We found extent int the tree -> extent is not - * clean - */ - return 0; - } - } - - node = parent; - while (node) { - next = ext2fs_rb_next(node); - ext = node_to_extent(node); - node = next; - - if ((ext->start + ext->count) <= start) - continue; - - /* No more merging */ - if ((start + len) <= ext->start) - break; - - retval = 0; - break; - } - return retval; -} - -static errcode_t rb_set_bmap_range(ext2fs_generic_bitmap bitmap, - __u64 start, size_t num, void *in) -{ - struct ext2fs_rb_private *bp; - unsigned char *cp = in; - size_t i; - int first_set = -1; - - bp = (struct ext2fs_rb_private *) bitmap->private; - - for (i = 0; i < num; i++) { - if ((i & 7) == 0) { - unsigned char c = cp[i/8]; - if (c == 0xFF) { - if (first_set == -1) - first_set = i; - i += 7; - continue; - } - if ((c == 0x00) && (first_set == -1)) { - i += 7; - continue; - } - } - if (ext2fs_test_bit(i, in)) { - if (first_set == -1) - first_set = i; - continue; - } - if (first_set == -1) - continue; - - rb_insert_extent(start + first_set - bitmap->start, - i - first_set, bp); - first_set = -1; - } - if (first_set != -1) - rb_insert_extent(start + first_set - bitmap->start, - num - first_set, bp); - - return 0; -} - -static errcode_t rb_get_bmap_range(ext2fs_generic_bitmap bitmap, - __u64 start, size_t num, void *out) -{ - - struct rb_node *parent = NULL, *next, **n; - struct ext2fs_rb_private *bp; - struct bmap_rb_extent *ext; - int count; - __u64 pos; - - bp = (struct ext2fs_rb_private *) bitmap->private; - n = &bp->root.rb_node; - start -= bitmap->start; - - if (EXT2FS_RB_EMPTY_ROOT(&bp->root)) - return 0; - - while (*n) { - parent = *n; - ext = node_to_extent(parent); - if (start < ext->start) { - n = &(*n)->rb_left; - } else if (start >= (ext->start + ext->count)) { - n = &(*n)->rb_right; - } else - break; - } - - memset(out, 0, (num + 7) >> 3); - - for (; parent != NULL; parent = next) { - next = ext2fs_rb_next(parent); - ext = node_to_extent(parent); - - pos = ext->start; - count = ext->count; - if (pos >= start + num) - break; - if (pos < start) { - count -= start - pos; - if (count < 0) - continue; - pos = start; - } - if (pos + count > start + num) - count = start + num - pos; - - while (count > 0) { - if ((count >= 8) && - ((pos - start) % 8) == 0) { - int nbytes = count >> 3; - int offset = (pos - start) >> 3; - - memset(((char *) out) + offset, 0xFF, nbytes); - pos += nbytes << 3; - count -= nbytes << 3; - continue; - } - ext2fs_fast_set_bit64((pos - start), out); - pos++; - count--; - } - } - return 0; -} - -static void rb_clear_bmap(ext2fs_generic_bitmap bitmap) -{ - struct ext2fs_rb_private *bp; - - bp = (struct ext2fs_rb_private *) bitmap->private; - - rb_free_tree(&bp->root); - bp->rcursor = NULL; - bp->rcursor_next = NULL; - bp->wcursor = NULL; -} - -#ifdef BMAP_STATS -static void rb_print_stats(ext2fs_generic_bitmap bitmap) -{ - struct ext2fs_rb_private *bp; - struct rb_node *node = NULL; - struct bmap_rb_extent *ext; - __u64 count = 0; - __u64 max_size = 0; - __u64 min_size = ULONG_MAX; - __u64 size = 0, avg_size = 0; - double eff; -#ifdef BMAP_STATS_OPS - __u64 mark_all, test_all; - double m_hit = 0.0, t_hit = 0.0; -#endif - - bp = (struct ext2fs_rb_private *) bitmap->private; - - node = ext2fs_rb_first(&bp->root); - for (node = ext2fs_rb_first(&bp->root); node != NULL; - node = ext2fs_rb_next(node)) { - ext = node_to_extent(node); - count++; - if (ext->count > max_size) - max_size = ext->count; - if (ext->count < min_size) - min_size = ext->count; - size += ext->count; - } - - if (count) - avg_size = size / count; - if (min_size == ULONG_MAX) - min_size = 0; - eff = (double)((count * sizeof(struct bmap_rb_extent)) << 3) / - (bitmap->real_end - bitmap->start); -#ifdef BMAP_STATS_OPS - mark_all = bitmap->stats.mark_count + bitmap->stats.mark_ext_count; - test_all = bitmap->stats.test_count + bitmap->stats.test_ext_count; - if (mark_all) - m_hit = ((double)bp->mark_hit / mark_all) * 100; - if (test_all) - t_hit = ((double)bp->test_hit / test_all) * 100; - - fprintf(stderr, "%16llu cache hits on test (%.2f%%)\n" - "%16llu cache hits on mark (%.2f%%)\n", - bp->test_hit, t_hit, bp->mark_hit, m_hit); -#endif - fprintf(stderr, "%16llu extents (%llu bytes)\n", - count, ((count * sizeof(struct bmap_rb_extent)) + - sizeof(struct ext2fs_rb_private))); - fprintf(stderr, "%16llu bits minimum size\n", - min_size); - fprintf(stderr, "%16llu bits maximum size\n" - "%16llu bits average size\n", - max_size, avg_size); - fprintf(stderr, "%16llu bits set in bitmap (out of %llu)\n", size, - bitmap->real_end - bitmap->start); - fprintf(stderr, - "%16.4lf memory / bitmap bit memory ratio (bitarray = 1)\n", - eff); -} -#else -static void rb_print_stats(ext2fs_generic_bitmap bitmap){} -#endif - -struct ext2_bitmap_ops ext2fs_blkmap64_rbtree = { - .type = EXT2FS_BMAP64_RBTREE, - .new_bmap = rb_new_bmap, - .free_bmap = rb_free_bmap, - .copy_bmap = rb_copy_bmap, - .resize_bmap = rb_resize_bmap, - .mark_bmap = rb_mark_bmap, - .unmark_bmap = rb_unmark_bmap, - .test_bmap = rb_test_bmap, - .test_clear_bmap_extent = rb_test_clear_bmap_extent, - .mark_bmap_extent = rb_mark_bmap_extent, - .unmark_bmap_extent = rb_unmark_bmap_extent, - .set_bmap_range = rb_set_bmap_range, - .get_bmap_range = rb_get_bmap_range, - .clear_bmap = rb_clear_bmap, - .print_stats = rb_print_stats, -}; diff --git a/lib/ext2fs/blknum.c b/lib/ext2fs/blknum.c deleted file mode 100644 index e2f0f1bb..00000000 --- a/lib/ext2fs/blknum.c +++ /dev/null @@ -1,494 +0,0 @@ -/* - * blknum.c --- Functions to handle blk64_t and high/low 64-bit block - * number. - * - * Copyright IBM Corporation, 2007 - * Author Jose R. Santos <jrs@us.ibm.com> - * - * %Begin-Header% - * This file may be redistributed under the terms of the GNU Public - * License. - * %End-Header% - */ - -#include "ext2fs.h" - -/* - * Return the group # of a block - */ -dgrp_t ext2fs_group_of_blk2(ext2_filsys fs, blk64_t blk) -{ - return (blk - fs->super->s_first_data_block) / - fs->super->s_blocks_per_group; -} - -/* - * Return the first block (inclusive) in a group - */ -blk64_t ext2fs_group_first_block2(ext2_filsys fs, dgrp_t group) -{ - return fs->super->s_first_data_block + - ((blk64_t)group * fs->super->s_blocks_per_group); -} - -/* - * Return the last block (inclusive) in a group - */ -blk64_t ext2fs_group_last_block2(ext2_filsys fs, dgrp_t group) -{ - return (group == fs->group_desc_count - 1 ? - ext2fs_blocks_count(fs->super) - 1 : - ext2fs_group_first_block2(fs, group) + - (fs->super->s_blocks_per_group - 1)); -} - -/* - * Return the number of blocks in a group - */ -int ext2fs_group_blocks_count(ext2_filsys fs, dgrp_t group) -{ - int num_blocks; - - if (group == fs->group_desc_count - 1) { - num_blocks = (ext2fs_blocks_count(fs->super) - - 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; - - return num_blocks; -} - -/* - * Return the inode data block count - */ -blk64_t ext2fs_inode_data_blocks2(ext2_filsys fs, - struct ext2_inode *inode) -{ - return (inode->i_blocks | - ((fs->super->s_feature_ro_compat & - EXT4_FEATURE_RO_COMPAT_HUGE_FILE) ? - (__u64) inode->osd2.linux2.l_i_blocks_hi << 32 : 0)) - - (inode->i_file_acl ? fs->blocksize >> 9 : 0); -} - -/* - * Return the inode i_blocks count - */ -blk64_t ext2fs_inode_i_blocks(ext2_filsys fs, - struct ext2_inode *inode) -{ - return (inode->i_blocks | - ((fs->super->s_feature_ro_compat & - EXT4_FEATURE_RO_COMPAT_HUGE_FILE) ? - (__u64)inode->osd2.linux2.l_i_blocks_hi << 32 : 0)); -} - -/* - * Return the fs block count - */ -blk64_t ext2fs_blocks_count(struct ext2_super_block *super) -{ - return super->s_blocks_count | - (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ? - (__u64) super->s_blocks_count_hi << 32 : 0); -} - -/* - * Set the fs block count - */ -void ext2fs_blocks_count_set(struct ext2_super_block *super, blk64_t blk) -{ - super->s_blocks_count = blk; - if (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) - super->s_blocks_count_hi = (__u64) blk >> 32; -} - -/* - * Add to the current fs block count - */ -void ext2fs_blocks_count_add(struct ext2_super_block *super, blk64_t blk) -{ - blk64_t tmp; - tmp = ext2fs_blocks_count(super) + blk; - ext2fs_blocks_count_set(super, tmp); -} - -/* - * Return the fs reserved block count - */ -blk64_t ext2fs_r_blocks_count(struct ext2_super_block *super) -{ - return super->s_r_blocks_count | - (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ? - (__u64) super->s_r_blocks_count_hi << 32 : 0); -} - -/* - * Set the fs reserved block count - */ -void ext2fs_r_blocks_count_set(struct ext2_super_block *super, blk64_t blk) -{ - super->s_r_blocks_count = blk; - if (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) - super->s_r_blocks_count_hi = (__u64) blk >> 32; -} - -/* - * Add to the current reserved fs block count - */ -void ext2fs_r_blocks_count_add(struct ext2_super_block *super, blk64_t blk) -{ - blk64_t tmp; - tmp = ext2fs_r_blocks_count(super) + blk; - ext2fs_r_blocks_count_set(super, tmp); -} - -/* - * Return the fs free block count - */ -blk64_t ext2fs_free_blocks_count(struct ext2_super_block *super) -{ - return super->s_free_blocks_count | - (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ? - (__u64) super->s_free_blocks_hi << 32 : 0); -} - -/* - * Set the fs free block count - */ -void ext2fs_free_blocks_count_set(struct ext2_super_block *super, blk64_t blk) -{ - super->s_free_blocks_count = blk; - if (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) - super->s_free_blocks_hi = (__u64) blk >> 32; -} - -/* - * Add to the current free fs block count - */ -void ext2fs_free_blocks_count_add(struct ext2_super_block *super, blk64_t blk) -{ - blk64_t tmp; - tmp = ext2fs_free_blocks_count(super) + blk; - ext2fs_free_blocks_count_set(super, tmp); -} - -/* - * Get a pointer to a block group descriptor. We need the explicit - * pointer to the group desc for code that swaps block group - * descriptors before writing them out, as it wants to make a copy and - * do the swap there. - */ -struct ext2_group_desc *ext2fs_group_desc(ext2_filsys fs, - struct opaque_ext2_group_desc *gdp, - dgrp_t group) -{ - return (struct ext2_group_desc *)((char *)gdp + - group * EXT2_DESC_SIZE(fs->super)); -} - -/* Do the same but as an ext4 group desc for internal use here */ -static struct ext4_group_desc *ext4fs_group_desc(ext2_filsys fs, - struct opaque_ext2_group_desc *gdp, - dgrp_t group) -{ - return (struct ext4_group_desc *)ext2fs_group_desc(fs, gdp, group); -} - -/* - * Return the block bitmap block of a group - */ -blk64_t ext2fs_block_bitmap_loc(ext2_filsys fs, dgrp_t group) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - return gdp->bg_block_bitmap | - (fs->super->s_feature_incompat - & EXT4_FEATURE_INCOMPAT_64BIT ? - (__u64)gdp->bg_block_bitmap_hi << 32 : 0); -} - -/* - * Set the block bitmap block of a group - */ -void ext2fs_block_bitmap_loc_set(ext2_filsys fs, dgrp_t group, blk64_t blk) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - gdp->bg_block_bitmap = blk; - if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) - gdp->bg_block_bitmap_hi = (__u64) blk >> 32; -} - -/* - * Return the inode bitmap block of a group - */ -blk64_t ext2fs_inode_bitmap_loc(ext2_filsys fs, dgrp_t group) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - return gdp->bg_inode_bitmap | - (fs->super->s_feature_incompat - & EXT4_FEATURE_INCOMPAT_64BIT ? - (__u64) gdp->bg_inode_bitmap_hi << 32 : 0); -} - -/* - * Set the inode bitmap block of a group - */ -void ext2fs_inode_bitmap_loc_set(ext2_filsys fs, dgrp_t group, blk64_t blk) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - gdp->bg_inode_bitmap = blk; - if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) - gdp->bg_inode_bitmap_hi = (__u64) blk >> 32; -} - -/* - * Return the inode table block of a group - */ -blk64_t ext2fs_inode_table_loc(ext2_filsys fs, dgrp_t group) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - return gdp->bg_inode_table | - (fs->super->s_feature_incompat - & EXT4_FEATURE_INCOMPAT_64BIT ? - (__u64) gdp->bg_inode_table_hi << 32 : 0); -} - -/* - * Set the inode table block of a group - */ -void ext2fs_inode_table_loc_set(ext2_filsys fs, dgrp_t group, blk64_t blk) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - gdp->bg_inode_table = blk; - if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) - gdp->bg_inode_table_hi = (__u64) blk >> 32; -} - -/* - * Return the free blocks count of a group - */ -__u32 ext2fs_bg_free_blocks_count(ext2_filsys fs, dgrp_t group) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - return gdp->bg_free_blocks_count | - (fs->super->s_feature_incompat - & EXT4_FEATURE_INCOMPAT_64BIT ? - (__u32) gdp->bg_free_blocks_count_hi << 16 : 0); -} - -/* - * Set the free blocks count of a group - */ -void ext2fs_bg_free_blocks_count_set(ext2_filsys fs, dgrp_t group, __u32 n) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - gdp->bg_free_blocks_count = n; - - if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) - gdp->bg_free_blocks_count_hi = (__u32) n >> 16; -} - -/* - * Return the free inodes count of a group - */ -__u32 ext2fs_bg_free_inodes_count(ext2_filsys fs, dgrp_t group) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - return gdp->bg_free_inodes_count | - (fs->super->s_feature_incompat - & EXT4_FEATURE_INCOMPAT_64BIT ? - (__u32) gdp->bg_free_inodes_count_hi << 16 : 0); -} - -/* - * Set the free inodes count of a group - */ -void ext2fs_bg_free_inodes_count_set(ext2_filsys fs, dgrp_t group, __u32 n) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - gdp->bg_free_inodes_count = n; - if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) - gdp->bg_free_inodes_count_hi = (__u32) n >> 16; -} - -/* - * Return the used dirs count of a group - */ -__u32 ext2fs_bg_used_dirs_count(ext2_filsys fs, dgrp_t group) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - return gdp->bg_used_dirs_count | - (fs->super->s_feature_incompat - & EXT4_FEATURE_INCOMPAT_64BIT ? - (__u32) gdp->bg_used_dirs_count_hi << 16 : 0); -} - -/* - * Set the used dirs count of a group - */ -void ext2fs_bg_used_dirs_count_set(ext2_filsys fs, dgrp_t group, __u32 n) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - gdp->bg_used_dirs_count = n; - if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) - gdp->bg_used_dirs_count_hi = (__u32) n >> 16; -} - -/* - * Return the unused inodes count of a group - */ -__u32 ext2fs_bg_itable_unused(ext2_filsys fs, dgrp_t group) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - return gdp->bg_itable_unused | - (fs->super->s_feature_incompat - & EXT4_FEATURE_INCOMPAT_64BIT ? - (__u32) gdp->bg_itable_unused_hi << 16 : 0); -} - -/* - * Set the unused inodes count of a group - */ -void ext2fs_bg_itable_unused_set(ext2_filsys fs, dgrp_t group, __u32 n) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - gdp->bg_itable_unused = n; - if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) - gdp->bg_itable_unused_hi = (__u32) n >> 16; -} - -/* - * Get the flags for this block group - */ -__u16 ext2fs_bg_flags(ext2_filsys fs, dgrp_t group) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - return gdp->bg_flags; -} - -/* - * Zero out the flags for this block group - */ -void ext2fs_bg_flags_zap(ext2_filsys fs, dgrp_t group) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - gdp->bg_flags = 0; - return; -} - -/* - * Get the value of a particular flag for this block group - */ -int ext2fs_bg_flags_test(ext2_filsys fs, dgrp_t group, __u16 bg_flag) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - return gdp->bg_flags & bg_flag; -} - -/* - * Set a flag or set of flags for this block group - */ -void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - gdp->bg_flags |= bg_flags; - return; -} - -/* - * Clear a flag or set of flags for this block group - */ -void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flags) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - gdp->bg_flags &= ~bg_flags; - return; -} - -/* - * Get the checksum for this block group - */ -__u16 ext2fs_bg_checksum(ext2_filsys fs, dgrp_t group) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - return gdp->bg_checksum; -} - -/* - * Set the checksum for this block group to a previously calculated value - */ -void ext2fs_bg_checksum_set(ext2_filsys fs, dgrp_t group, __u16 checksum) -{ - struct ext4_group_desc *gdp; - - gdp = ext4fs_group_desc(fs, fs->group_desc, group); - gdp->bg_checksum = checksum; - return; -} - -/* - * Get the acl block of a file - */ -blk64_t ext2fs_file_acl_block(ext2_filsys fs, const struct ext2_inode *inode) -{ - blk64_t blk = inode->i_file_acl; - - if (fs && fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) - blk |= ((__u64) inode->osd2.linux2.l_i_file_acl_high) << 32; - return blk; -} - -/* - * Set the acl block of a file - */ -void ext2fs_file_acl_block_set(ext2_filsys fs, struct ext2_inode *inode, - blk64_t blk) -{ - inode->i_file_acl = blk; - if (fs && fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) - inode->osd2.linux2.l_i_file_acl_high = (__u64) blk >> 32; -} - diff --git a/lib/ext2fs/block.c b/lib/ext2fs/block.c index 3e4bbde2..4054a07b 100644 --- a/lib/ext2fs/block.c +++ b/lib/ext2fs/block.c @@ -21,9 +21,9 @@ struct block_context { ext2_filsys fs; int (*func)(ext2_filsys fs, - blk64_t *blocknr, + blk_t *blocknr, e2_blkcnt_t bcount, - blk64_t ref_blk, + blk_t ref_blk, int ref_offset, void *priv_data); e2_blkcnt_t bcount; @@ -62,23 +62,19 @@ static int block_iterate_ind(blk_t *ind_block, blk_t ref_block, int ret = 0, changed = 0; int i, flags, limit, offset; blk_t *block_nr; - blk64_t blk64; limit = ctx->fs->blocksize >> 2; if (!(ctx->flags & BLOCK_FLAG_DEPTH_TRAVERSE) && - !(ctx->flags & BLOCK_FLAG_DATA_ONLY)) { - blk64 = *ind_block; - ret = (*ctx->func)(ctx->fs, &blk64, + !(ctx->flags & BLOCK_FLAG_DATA_ONLY)) + ret = (*ctx->func)(ctx->fs, ind_block, BLOCK_COUNT_IND, ref_block, ref_offset, ctx->priv_data); - *ind_block = blk64; - } check_for_ro_violation_return(ctx, ret); if (!*ind_block || (ret & BLOCK_ABORT)) { ctx->bcount += limit; return ret; } - if (*ind_block >= ext2fs_blocks_count(ctx->fs->super) || + if (*ind_block >= ctx->fs->super->s_blocks_count || *ind_block < ctx->fs->super->s_first_data_block) { ctx->errcode = EXT2_ET_BAD_IND_BLOCK; ret |= BLOCK_ERROR; @@ -95,11 +91,9 @@ static int block_iterate_ind(blk_t *ind_block, blk_t ref_block, offset = 0; if (ctx->flags & BLOCK_FLAG_APPEND) { for (i = 0; i < limit; i++, ctx->bcount++, block_nr++) { - blk64 = *block_nr; - flags = (*ctx->func)(ctx->fs, &blk64, ctx->bcount, + flags = (*ctx->func)(ctx->fs, block_nr, ctx->bcount, *ind_block, offset, ctx->priv_data); - *block_nr = blk64; changed |= flags; if (flags & BLOCK_ABORT) { ret |= BLOCK_ABORT; @@ -111,11 +105,9 @@ static int block_iterate_ind(blk_t *ind_block, blk_t ref_block, for (i = 0; i < limit; i++, ctx->bcount++, block_nr++) { if (*block_nr == 0) goto skip_sparse; - blk64 = *block_nr; - flags = (*ctx->func)(ctx->fs, &blk64, ctx->bcount, + flags = (*ctx->func)(ctx->fs, block_nr, ctx->bcount, *ind_block, offset, ctx->priv_data); - *block_nr = blk64; changed |= flags; if (flags & BLOCK_ABORT) { ret |= BLOCK_ABORT; @@ -134,13 +126,10 @@ static int block_iterate_ind(blk_t *ind_block, blk_t ref_block, } if ((ctx->flags & BLOCK_FLAG_DEPTH_TRAVERSE) && !(ctx->flags & BLOCK_FLAG_DATA_ONLY) && - !(ret & BLOCK_ABORT)) { - blk64 = *ind_block; - ret |= (*ctx->func)(ctx->fs, &blk64, + !(ret & BLOCK_ABORT)) + ret |= (*ctx->func)(ctx->fs, ind_block, BLOCK_COUNT_IND, ref_block, ref_offset, ctx->priv_data); - *ind_block = blk64; - } check_for_ro_violation_return(ctx, ret); return ret; } @@ -151,23 +140,19 @@ static int block_iterate_dind(blk_t *dind_block, blk_t ref_block, int ret = 0, changed = 0; int i, flags, limit, offset; blk_t *block_nr; - blk64_t blk64; limit = ctx->fs->blocksize >> 2; if (!(ctx->flags & (BLOCK_FLAG_DEPTH_TRAVERSE | - BLOCK_FLAG_DATA_ONLY))) { - blk64 = *dind_block; - ret = (*ctx->func)(ctx->fs, &blk64, + BLOCK_FLAG_DATA_ONLY))) + ret = (*ctx->func)(ctx->fs, dind_block, BLOCK_COUNT_DIND, ref_block, ref_offset, ctx->priv_data); - *dind_block = blk64; - } check_for_ro_violation_return(ctx, ret); if (!*dind_block || (ret & BLOCK_ABORT)) { ctx->bcount += limit*limit; return ret; } - if (*dind_block >= ext2fs_blocks_count(ctx->fs->super) || + if (*dind_block >= ctx->fs->super->s_blocks_count || *dind_block < ctx->fs->super->s_first_data_block) { ctx->errcode = EXT2_ET_BAD_DIND_BLOCK; ret |= BLOCK_ERROR; @@ -220,13 +205,10 @@ static int block_iterate_dind(blk_t *dind_block, blk_t ref_block, } if ((ctx->flags & BLOCK_FLAG_DEPTH_TRAVERSE) && !(ctx->flags & BLOCK_FLAG_DATA_ONLY) && - !(ret & BLOCK_ABORT)) { - blk64 = *dind_block; - ret |= (*ctx->func)(ctx->fs, &blk64, + !(ret & BLOCK_ABORT)) + ret |= (*ctx->func)(ctx->fs, dind_block, BLOCK_COUNT_DIND, ref_block, ref_offset, ctx->priv_data); - *dind_block = blk64; - } check_for_ro_violation_return(ctx, ret); return ret; } @@ -237,23 +219,19 @@ static int block_iterate_tind(blk_t *tind_block, blk_t ref_block, int ret = 0, changed = 0; int i, flags, limit, offset; blk_t *block_nr; - blk64_t blk64; limit = ctx->fs->blocksize >> 2; if (!(ctx->flags & (BLOCK_FLAG_DEPTH_TRAVERSE | - BLOCK_FLAG_DATA_ONLY))) { - blk64 = *tind_block; - ret = (*ctx->func)(ctx->fs, &blk64, + BLOCK_FLAG_DATA_ONLY))) + ret = (*ctx->func)(ctx->fs, tind_block, BLOCK_COUNT_TIND, ref_block, ref_offset, ctx->priv_data); - *tind_block = blk64; - } check_for_ro_violation_return(ctx, ret); if (!*tind_block || (ret & BLOCK_ABORT)) { ctx->bcount += limit*limit*limit; return ret; } - if (*tind_block >= ext2fs_blocks_count(ctx->fs->super) || + if (*tind_block >= ctx->fs->super->s_blocks_count || *tind_block < ctx->fs->super->s_first_data_block) { ctx->errcode = EXT2_ET_BAD_TIND_BLOCK; ret |= BLOCK_ERROR; @@ -306,25 +284,22 @@ static int block_iterate_tind(blk_t *tind_block, blk_t ref_block, } if ((ctx->flags & BLOCK_FLAG_DEPTH_TRAVERSE) && !(ctx->flags & BLOCK_FLAG_DATA_ONLY) && - !(ret & BLOCK_ABORT)) { - blk64 = *tind_block; - ret |= (*ctx->func)(ctx->fs, &blk64, + !(ret & BLOCK_ABORT)) + ret |= (*ctx->func)(ctx->fs, tind_block, BLOCK_COUNT_TIND, ref_block, ref_offset, ctx->priv_data); - *tind_block = blk64; - } check_for_ro_violation_return(ctx, ret); return ret; } -errcode_t ext2fs_block_iterate3(ext2_filsys fs, +errcode_t ext2fs_block_iterate2(ext2_filsys fs, ext2_ino_t ino, int flags, char *block_buf, int (*func)(ext2_filsys fs, - blk64_t *blocknr, + blk_t *blocknr, e2_blkcnt_t blockcnt, - blk64_t ref_blk, + blk_t ref_blk, int ref_offset, void *priv_data), void *priv_data) @@ -335,7 +310,6 @@ errcode_t ext2fs_block_iterate3(ext2_filsys fs, errcode_t retval; struct block_context ctx; int limit; - blk64_t blk64; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); @@ -375,11 +349,10 @@ errcode_t ext2fs_block_iterate3(ext2_filsys fs, if ((fs->super->s_creator_os == EXT2_OS_HURD) && !(flags & BLOCK_FLAG_DATA_ONLY)) { if (inode.osd1.hurd1.h_i_translator) { - blk64 = inode.osd1.hurd1.h_i_translator; - ret |= (*ctx.func)(fs, &blk64, + ret |= (*ctx.func)(fs, + &inode.osd1.hurd1.h_i_translator, BLOCK_COUNT_TRANSLATOR, 0, 0, priv_data); - inode.osd1.hurd1.h_i_translator = (blk_t) blk64; if (ret & BLOCK_ABORT) goto abort_exit; check_for_ro_violation_goto(&ctx, ret, abort_exit); @@ -388,9 +361,9 @@ errcode_t ext2fs_block_iterate3(ext2_filsys fs, if (inode.i_flags & EXT4_EXTENTS_FL) { ext2_extent_handle_t handle; - struct ext2fs_extent extent, next; + struct ext2fs_extent extent; e2_blkcnt_t blockcnt = 0; - blk64_t blk, new_blk; + blk_t blk, new_blk; int op = EXT2_EXTENT_ROOT; int uninit; unsigned int j; @@ -400,11 +373,7 @@ errcode_t ext2fs_block_iterate3(ext2_filsys fs, goto abort_exit; while (1) { - if (op == EXT2_EXTENT_CURRENT) - ctx.errcode = 0; - else - ctx.errcode = ext2fs_extent_get(handle, op, - &extent); + ctx.errcode = ext2fs_extent_get(handle, op, &extent); if (ctx.errcode) { if (ctx.errcode != EXT2_ET_EXTENT_NO_NEXT) break; @@ -417,7 +386,7 @@ errcode_t ext2fs_block_iterate3(ext2_filsys fs, 0, 0, priv_data); ret |= r; check_for_ro_violation_goto(&ctx, ret, - extent_done); + extent_errout); if (r & BLOCK_CHANGED) { ctx.errcode = ext2fs_extent_set_bmap(handle, @@ -451,32 +420,12 @@ errcode_t ext2fs_block_iterate3(ext2_filsys fs, if (ctx.errcode) break; } - if (ret & BLOCK_ABORT) - break; } continue; } uninit = 0; if (extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT) uninit = EXT2_EXTENT_SET_BMAP_UNINIT; - - /* - * Get the next extent before we start messing - * with the current extent - */ - retval = ext2fs_extent_get(handle, op, &next); - -#if 0 - printf("lblk %llu pblk %llu len %d blockcnt %llu\n", - extent.e_lblk, extent.e_pblk, - extent.e_len, blockcnt); -#endif - if (extent.e_lblk + extent.e_len <= (blk64_t) blockcnt) - continue; - if (extent.e_lblk > (blk64_t) blockcnt) - blockcnt = extent.e_lblk; - j = blockcnt - extent.e_lblk; - blk += j; for (blockcnt = extent.e_lblk, j = 0; j < extent.e_len; blk++, blockcnt++, j++) { @@ -485,27 +434,24 @@ errcode_t ext2fs_block_iterate3(ext2_filsys fs, 0, 0, priv_data); ret |= r; check_for_ro_violation_goto(&ctx, ret, - extent_done); + extent_errout); if (r & BLOCK_CHANGED) { ctx.errcode = ext2fs_extent_set_bmap(handle, (blk64_t) blockcnt, - new_blk, uninit); + (blk64_t) new_blk, + uninit); if (ctx.errcode) - goto extent_done; + goto extent_errout; } if (ret & BLOCK_ABORT) - goto extent_done; - } - if (retval == 0) { - extent = next; - op = EXT2_EXTENT_CURRENT; + break; } } - extent_done: + extent_errout: ext2fs_extent_free(handle); - ret |= BLOCK_ERROR; /* ctx.errcode is always valid here */ + ret |= BLOCK_ERROR | BLOCK_ABORT; goto errout; } @@ -514,17 +460,15 @@ errcode_t ext2fs_block_iterate3(ext2_filsys fs, */ for (i = 0; i < EXT2_NDIR_BLOCKS ; i++, ctx.bcount++) { if (inode.i_block[i] || (flags & BLOCK_FLAG_APPEND)) { - blk64 = inode.i_block[i]; - ret |= (*ctx.func)(fs, &blk64, ctx.bcount, 0, i, - priv_data); - inode.i_block[i] = (blk_t) blk64; + ret |= (*ctx.func)(fs, &inode.i_block[i], + ctx.bcount, 0, i, priv_data); if (ret & BLOCK_ABORT) goto abort_exit; } } check_for_ro_violation_goto(&ctx, ret, abort_exit); if (inode.i_block[EXT2_IND_BLOCK] || (flags & BLOCK_FLAG_APPEND)) { - ret |= block_iterate_ind(&inode.i_block[EXT2_IND_BLOCK], + ret |= block_iterate_ind(&inode.i_block[EXT2_IND_BLOCK], 0, EXT2_IND_BLOCK, &ctx); if (ret & BLOCK_ABORT) goto abort_exit; @@ -563,52 +507,6 @@ errout: * Emulate the old ext2fs_block_iterate function! */ -struct xlate64 { - int (*func)(ext2_filsys fs, - blk_t *blocknr, - e2_blkcnt_t blockcnt, - blk_t ref_blk, - int ref_offset, - void *priv_data); - void *real_private; -}; - -static int xlate64_func(ext2_filsys fs, blk64_t *blocknr, - e2_blkcnt_t blockcnt, blk64_t ref_blk, - int ref_offset, void *priv_data) -{ - struct xlate64 *xl = (struct xlate64 *) priv_data; - int ret; - blk_t block32 = *blocknr; - - ret = (*xl->func)(fs, &block32, blockcnt, (blk_t) ref_blk, ref_offset, - xl->real_private); - *blocknr = block32; - return ret; -} - -errcode_t ext2fs_block_iterate2(ext2_filsys fs, - ext2_ino_t ino, - int flags, - char *block_buf, - int (*func)(ext2_filsys fs, - blk_t *blocknr, - e2_blkcnt_t blockcnt, - blk_t ref_blk, - int ref_offset, - void *priv_data), - void *priv_data) -{ - struct xlate64 xl; - - xl.real_private = priv_data; - xl.func = func; - - return ext2fs_block_iterate3(fs, ino, flags, block_buf, - xlate64_func, &xl); -} - - struct xlate { int (*func)(ext2_filsys fs, blk_t *blocknr, diff --git a/lib/ext2fs/bmap.c b/lib/ext2fs/bmap.c index 28a33207..fbcb3753 100644 --- a/lib/ext2fs/bmap.c +++ b/lib/ext2fs/bmap.c @@ -17,7 +17,7 @@ #include <errno.h> #include "ext2_fs.h" -#include "ext2fsP.h" +#include "ext2fs.h" #if defined(__GNUC__) && !defined(NO_INLINE_FUNCS) #define _BMAP_INLINE_ __inline__ @@ -94,7 +94,7 @@ static _BMAP_INLINE_ errcode_t block_dind_bmap(ext2_filsys fs, int flags, int *blocks_alloc, blk_t nr, blk_t *ret_blk) { - blk_t b = 0; + blk_t b; errcode_t retval; blk_t addr_per_block; @@ -114,7 +114,7 @@ static _BMAP_INLINE_ errcode_t block_tind_bmap(ext2_filsys fs, int flags, int *blocks_alloc, blk_t nr, blk_t *ret_blk) { - blk_t b = 0; + blk_t b; errcode_t retval; blk_t addr_per_block; @@ -129,165 +129,6 @@ static _BMAP_INLINE_ errcode_t block_tind_bmap(ext2_filsys fs, int flags, return retval; } -static errcode_t extent_bmap(ext2_filsys fs, ext2_ino_t ino, - struct ext2_inode *inode, - ext2_extent_handle_t handle, - char *block_buf, int bmap_flags, blk64_t block, - int *ret_flags, int *blocks_alloc, - blk64_t *phys_blk); - -static errcode_t implied_cluster_alloc(ext2_filsys fs, ext2_ino_t ino, - struct ext2_inode *inode, - ext2_extent_handle_t handle, - blk64_t lblk, blk64_t *phys_blk) -{ - blk64_t base_block, pblock = 0; - int i; - - if (!EXT2_HAS_RO_COMPAT_FEATURE(fs->super, - EXT4_FEATURE_RO_COMPAT_BIGALLOC)) - return 0; - - base_block = lblk & ~EXT2FS_CLUSTER_MASK(fs); - /* - * Except for the logical block (lblk) that was passed in, search all - * blocks in this logical cluster for a mapping to a physical cluster. - * If any such map exists, calculate the physical block that maps to - * the logical block and return that. - * - * The old code wouldn't even look if (block % cluster_ratio) == 0; - * this is incorrect if we're allocating blocks in reverse order. - */ - for (i = 0; i < EXT2FS_CLUSTER_RATIO(fs); i++) { - if (base_block + i == lblk) - continue; - extent_bmap(fs, ino, inode, handle, 0, 0, - base_block + i, 0, 0, &pblock); - if (pblock) - break; - } - if (pblock == 0) - return 0; - *phys_blk = pblock - i + (lblk - base_block); - return 0; -} - -/* Try to map a logical block to an already-allocated physical cluster. */ -errcode_t ext2fs_map_cluster_block(ext2_filsys fs, ext2_ino_t ino, - struct ext2_inode *inode, blk64_t lblk, - blk64_t *pblk) -{ - ext2_extent_handle_t handle; - errcode_t retval; - - /* Need bigalloc and extents to be enabled */ - *pblk = 0; - if (!EXT2_HAS_RO_COMPAT_FEATURE(fs->super, - EXT4_FEATURE_RO_COMPAT_BIGALLOC) || - !(inode->i_flags & EXT4_EXTENTS_FL)) - return 0; - - retval = ext2fs_extent_open2(fs, ino, inode, &handle); - if (retval) - goto out; - - retval = implied_cluster_alloc(fs, ino, inode, handle, lblk, pblk); - if (retval) - goto out2; - -out2: - ext2fs_extent_free(handle); -out: - return retval; -} - -static errcode_t extent_bmap(ext2_filsys fs, ext2_ino_t ino, - struct ext2_inode *inode, - ext2_extent_handle_t handle, - char *block_buf, int bmap_flags, blk64_t block, - int *ret_flags, int *blocks_alloc, - blk64_t *phys_blk) -{ - struct ext2fs_extent extent; - unsigned int offset; - errcode_t retval = 0; - blk64_t blk64 = 0; - int alloc = 0; - - if (bmap_flags & BMAP_SET) { - retval = ext2fs_extent_set_bmap(handle, block, - *phys_blk, 0); - return retval; - } - retval = ext2fs_extent_goto(handle, block); - if (retval) { - /* If the extent is not found, return phys_blk = 0 */ - if (retval == EXT2_ET_EXTENT_NOT_FOUND) - goto got_block; - return retval; - } - retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, &extent); - if (retval) - return retval; - offset = block - extent.e_lblk; - if (block >= extent.e_lblk && (offset <= extent.e_len)) { - *phys_blk = extent.e_pblk + offset; - if (ret_flags && extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT) - *ret_flags |= BMAP_RET_UNINIT; - } -got_block: - if ((*phys_blk == 0) && (bmap_flags & BMAP_ALLOC)) { - implied_cluster_alloc(fs, ino, inode, handle, block, &blk64); - if (blk64) - goto set_extent; - retval = extent_bmap(fs, ino, inode, handle, block_buf, - 0, block-1, 0, blocks_alloc, &blk64); - if (retval) - blk64 = 0; - retval = ext2fs_alloc_block2(fs, blk64, block_buf, - &blk64); - if (retval) - return retval; - blk64 &= ~EXT2FS_CLUSTER_MASK(fs); - blk64 += EXT2FS_CLUSTER_MASK(fs) & block; - alloc++; - set_extent: - retval = ext2fs_extent_set_bmap(handle, block, - blk64, 0); - if (retval) - return retval; - /* Update inode after setting extent */ - retval = ext2fs_read_inode(fs, ino, inode); - if (retval) - return retval; - *blocks_alloc += alloc; - *phys_blk = blk64; - } - return 0; -} - -int ext2fs_file_block_offset_too_big(ext2_filsys fs, - struct ext2_inode *inode, - blk64_t offset) -{ - blk64_t addr_per_block, max_map_block; - - /* Kernel seems to cut us off at 4294967294 blocks */ - if (offset >= (1ULL << 32) - 1) - return 1; - - if (inode->i_flags & EXT4_EXTENTS_FL) - return 0; - - addr_per_block = fs->blocksize >> 2; - max_map_block = addr_per_block; - max_map_block += addr_per_block * addr_per_block; - max_map_block += addr_per_block * addr_per_block * addr_per_block; - max_map_block += 12; - - return offset >= max_map_block; -} - errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, char *block_buf, int bmap_flags, blk64_t block, int *ret_flags, blk64_t *phys_blk) @@ -315,8 +156,53 @@ errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, } addr_per_block = (blk_t) fs->blocksize >> 2; - if (ext2fs_file_block_offset_too_big(fs, inode, block)) - return EXT2_ET_FILE_TOO_BIG; + if (inode->i_flags & EXT4_EXTENTS_FL) { + struct ext2fs_extent extent; + unsigned int offset; + + retval = ext2fs_extent_open2(fs, ino, inode, &handle); + if (retval) + goto done; + if (bmap_flags & BMAP_SET) { + retval = ext2fs_extent_set_bmap(handle, block, + *phys_blk, 0); + goto done; + } + retval = ext2fs_extent_goto(handle, block); + if (retval) { + /* If the extent is not found, return phys_blk = 0 */ + if (retval == EXT2_ET_EXTENT_NOT_FOUND) + goto got_block; + goto done; + } + retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, &extent); + if (retval) + goto done; + offset = block - extent.e_lblk; + if (block >= extent.e_lblk && (offset <= extent.e_len)) { + *phys_blk = extent.e_pblk + offset; + if (ret_flags && extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT) + *ret_flags |= BMAP_RET_UNINIT; + } + got_block: + if ((*phys_blk == 0) && (bmap_flags & BMAP_ALLOC)) { + retval = ext2fs_alloc_block(fs, b, block_buf, &b); + if (retval) + goto done; + retval = ext2fs_extent_set_bmap(handle, block, + (blk64_t) b, 0); + if (retval) + goto done; + /* Update inode after setting extent */ + retval = ext2fs_read_inode(fs, ino, inode); + if (retval) + return retval; + blocks_alloc++; + *phys_blk = b; + } + retval = 0; + goto done; + } if (!block_buf) { retval = ext2fs_get_array(2, fs->blocksize, &buf); @@ -325,16 +211,6 @@ errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, block_buf = buf; } - if (inode->i_flags & EXT4_EXTENTS_FL) { - retval = ext2fs_extent_open2(fs, ino, inode, &handle); - if (retval) - goto done; - retval = extent_bmap(fs, ino, inode, handle, block_buf, - bmap_flags, block, ret_flags, - &blocks_alloc, phys_blk); - goto done; - } - if (block < EXT2_NDIR_BLOCKS) { if (bmap_flags & BMAP_SET) { b = *phys_blk; diff --git a/lib/ext2fs/bmap64.h b/lib/ext2fs/bmap64.h deleted file mode 100644 index f44d379c..00000000 --- a/lib/ext2fs/bmap64.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * bmap64.h --- 64-bit bitmap structure - * - * Copyright (C) 2007, 2008 Theodore Ts'o. - * - * %Begin-Header% - * This file may be redistributed under the terms of the GNU Public - * License. - * %End-Header% - */ - -struct ext2_bmap_statistics { - int type; - struct timeval created; - -#ifdef BMAP_STATS_OPS - unsigned long copy_count; - unsigned long resize_count; - unsigned long mark_count; - unsigned long unmark_count; - unsigned long test_count; - unsigned long mark_ext_count; - unsigned long unmark_ext_count; - unsigned long test_ext_count; - unsigned long set_range_count; - unsigned long get_range_count; - unsigned long clear_count; - - blk64_t last_marked; - blk64_t last_tested; - blk64_t mark_back; - blk64_t test_back; - - unsigned long mark_seq; - unsigned long test_seq; -#endif /* BMAP_STATS_OPS */ -}; - - -struct ext2fs_struct_generic_bitmap { - errcode_t magic; - ext2_filsys fs; - struct ext2_bitmap_ops *bitmap_ops; - int flags; - __u64 start, end; - __u64 real_end; - int cluster_bits; - char *description; - void *private; - errcode_t base_error_code; -#ifdef BMAP_STATS - struct ext2_bmap_statistics stats; -#endif -}; - -#define EXT2FS_IS_32_BITMAP(bmap) \ - (((bmap)->magic == EXT2_ET_MAGIC_GENERIC_BITMAP) || \ - ((bmap)->magic == EXT2_ET_MAGIC_BLOCK_BITMAP) || \ - ((bmap)->magic == EXT2_ET_MAGIC_INODE_BITMAP)) - -#define EXT2FS_IS_64_BITMAP(bmap) \ - (((bmap)->magic == EXT2_ET_MAGIC_GENERIC_BITMAP64) || \ - ((bmap)->magic == EXT2_ET_MAGIC_BLOCK_BITMAP64) || \ - ((bmap)->magic == EXT2_ET_MAGIC_INODE_BITMAP64)) - -struct ext2_bitmap_ops { - int type; - /* Generic bmap operators */ - errcode_t (*new_bmap)(ext2_filsys fs, ext2fs_generic_bitmap bmap); - void (*free_bmap)(ext2fs_generic_bitmap bitmap); - errcode_t (*copy_bmap)(ext2fs_generic_bitmap src, - ext2fs_generic_bitmap dest); - errcode_t (*resize_bmap)(ext2fs_generic_bitmap bitmap, - __u64 new_end, - __u64 new_real_end); - /* bit set/test operators */ - int (*mark_bmap)(ext2fs_generic_bitmap bitmap, __u64 arg); - int (*unmark_bmap)(ext2fs_generic_bitmap bitmap, __u64 arg); - int (*test_bmap)(ext2fs_generic_bitmap bitmap, __u64 arg); - void (*mark_bmap_extent)(ext2fs_generic_bitmap bitmap, __u64 arg, - unsigned int num); - void (*unmark_bmap_extent)(ext2fs_generic_bitmap bitmap, __u64 arg, - unsigned int num); - int (*test_clear_bmap_extent)(ext2fs_generic_bitmap bitmap, - __u64 arg, unsigned int num); - errcode_t (*set_bmap_range)(ext2fs_generic_bitmap bitmap, - __u64 start, size_t num, void *in); - errcode_t (*get_bmap_range)(ext2fs_generic_bitmap bitmap, - __u64 start, size_t num, void *out); - void (*clear_bmap)(ext2fs_generic_bitmap bitmap); - void (*print_stats)(ext2fs_generic_bitmap); - - /* Find the first zero bit between start and end, inclusive. - * May be NULL, in which case a generic function is used. */ - errcode_t (*find_first_zero)(ext2fs_generic_bitmap bitmap, - __u64 start, __u64 end, __u64 *out); -}; - -extern struct ext2_bitmap_ops ext2fs_blkmap64_bitarray; -extern struct ext2_bitmap_ops ext2fs_blkmap64_rbtree; diff --git a/lib/ext2fs/bmove.c b/lib/ext2fs/bmove.c index f9480c88..1caf2fa9 100644 --- a/lib/ext2fs/bmove.c +++ b/lib/ext2fs/bmove.c @@ -36,14 +36,14 @@ struct process_block_struct { int flags; }; -static int process_block(ext2_filsys fs, blk64_t *block_nr, - e2_blkcnt_t blockcnt, blk64_t ref_block, +static int process_block(ext2_filsys fs, blk_t *block_nr, + e2_blkcnt_t blockcnt, blk_t ref_block, int ref_offset, void *priv_data) { struct process_block_struct *pb; errcode_t retval; int ret; - blk64_t block, orig; + blk_t block, orig; pb = (struct process_block_struct *) priv_data; block = orig = *block_nr; @@ -52,39 +52,37 @@ static int process_block(ext2_filsys fs, blk64_t *block_nr, /* * Let's see if this is one which we need to relocate */ - if (ext2fs_test_block_bitmap2(pb->reserve, block)) { + if (ext2fs_test_block_bitmap(pb->reserve, block)) { do { - if (++block >= ext2fs_blocks_count(fs->super)) + if (++block >= fs->super->s_blocks_count) block = fs->super->s_first_data_block; if (block == orig) { pb->error = EXT2_ET_BLOCK_ALLOC_FAIL; return BLOCK_ABORT; } - } while (ext2fs_test_block_bitmap2(pb->reserve, block) || - ext2fs_test_block_bitmap2(pb->alloc_map, block)); + } while (ext2fs_test_block_bitmap(pb->reserve, block) || + ext2fs_test_block_bitmap(pb->alloc_map, block)); - retval = io_channel_read_blk64(fs->io, orig, 1, pb->buf); + retval = io_channel_read_blk(fs->io, orig, 1, pb->buf); if (retval) { pb->error = retval; return BLOCK_ABORT; } - retval = io_channel_write_blk64(fs->io, block, 1, pb->buf); + retval = io_channel_write_blk(fs->io, block, 1, pb->buf); if (retval) { pb->error = retval; return BLOCK_ABORT; } *block_nr = block; - ext2fs_mark_block_bitmap2(pb->alloc_map, block); + ext2fs_mark_block_bitmap(pb->alloc_map, block); ret = BLOCK_CHANGED; if (pb->flags & EXT2_BMOVE_DEBUG) - printf("ino=%u, blockcnt=%lld, %llu->%llu\n", - (unsigned) pb->ino, blockcnt, - (unsigned long long) orig, - (unsigned long long) block); + printf("ino=%ld, blockcnt=%lld, %u->%u\n", pb->ino, + blockcnt, orig, block); } if (pb->add_dir) { - retval = ext2fs_add_dir_block2(fs->dblist, pb->ino, - block, blockcnt); + retval = ext2fs_add_dir_block(fs->dblist, pb->ino, + block, (int) blockcnt); if (retval) { pb->error = retval; ret |= BLOCK_ABORT; @@ -140,7 +138,7 @@ errcode_t ext2fs_move_blocks(ext2_filsys fs, while (ino) { if ((inode.i_links_count == 0) || - !ext2fs_inode_has_valid_blocks2(fs, &inode)) + !ext2fs_inode_has_valid_blocks(&inode)) goto next; pb.ino = ino; @@ -149,8 +147,8 @@ errcode_t ext2fs_move_blocks(ext2_filsys fs, pb.add_dir = (LINUX_S_ISDIR(inode.i_mode) && flags & EXT2_BMOVE_GET_DBLIST); - retval = ext2fs_block_iterate3(fs, ino, 0, block_buf, - process_block, &pb); + retval = ext2fs_block_iterate2(fs, ino, 0, block_buf, + process_block, &pb); if (retval) return retval; if (pb.error) diff --git a/lib/ext2fs/brel.h b/lib/ext2fs/brel.h index 9fdddd40..a0dd5b9c 100644 --- a/lib/ext2fs/brel.h +++ b/lib/ext2fs/brel.h @@ -10,11 +10,11 @@ */ struct ext2_block_relocate_entry { - blk64_t new; + blk_t new; __s16 offset; __u16 flags; union { - blk64_t block_ref; + blk_t block_ref; ext2_ino_t inode_ref; } owner; }; @@ -28,19 +28,19 @@ typedef struct ext2_block_relocation_table *ext2_brel; struct ext2_block_relocation_table { __u32 magic; char *name; - blk64_t current; + blk_t current; void *priv_data; /* * Add a block relocation entry. */ - errcode_t (*put)(ext2_brel brel, blk64_t old, + errcode_t (*put)(ext2_brel brel, blk_t old, struct ext2_block_relocate_entry *ent); /* * Get a block relocation entry. */ - errcode_t (*get)(ext2_brel brel, blk64_t old, + errcode_t (*get)(ext2_brel brel, blk_t old, struct ext2_block_relocate_entry *ent); /* @@ -52,19 +52,19 @@ struct ext2_block_relocation_table { * The iterator function for the inode relocation entries. * Returns an inode number of 0 when out of entries. */ - errcode_t (*next)(ext2_brel brel, blk64_t *old, + errcode_t (*next)(ext2_brel brel, blk_t *old, struct ext2_block_relocate_entry *ent); /* * Move the inode relocation table from one block number to * another. */ - errcode_t (*move)(ext2_brel brel, blk64_t old, blk_t new); + errcode_t (*move)(ext2_brel brel, blk_t old, blk_t new); /* * Remove a block relocation entry. */ - errcode_t (*delete)(ext2_brel brel, blk64_t old); + errcode_t (*delete)(ext2_brel brel, blk_t old); /* @@ -73,7 +73,7 @@ struct ext2_block_relocation_table { errcode_t (*free)(ext2_brel brel); }; -errcode_t ext2fs_brel_memarray_create(char *name, blk64_t max_block, +errcode_t ext2fs_brel_memarray_create(char *name, blk_t max_block, ext2_brel *brel); #define ext2fs_brel_put(brel, old, ent) ((brel)->put((brel), old, ent)) diff --git a/lib/ext2fs/brel_ma.c b/lib/ext2fs/brel_ma.c index e398c1e0..1a55702b 100644 --- a/lib/ext2fs/brel_ma.c +++ b/lib/ext2fs/brel_ma.c @@ -26,24 +26,24 @@ #include "ext2fs.h" #include "brel.h" -static errcode_t bma_put(ext2_brel brel, blk64_t old, +static errcode_t bma_put(ext2_brel brel, blk_t old, struct ext2_block_relocate_entry *ent); -static errcode_t bma_get(ext2_brel brel, blk64_t old, +static errcode_t bma_get(ext2_brel brel, blk_t old, struct ext2_block_relocate_entry *ent); static errcode_t bma_start_iter(ext2_brel brel); -static errcode_t bma_next(ext2_brel brel, blk64_t *old, +static errcode_t bma_next(ext2_brel brel, blk_t *old, struct ext2_block_relocate_entry *ent); -static errcode_t bma_move(ext2_brel brel, blk64_t old, blk64_t new); -static errcode_t bma_delete(ext2_brel brel, blk64_t old); +static errcode_t bma_move(ext2_brel brel, blk_t old, blk_t new); +static errcode_t bma_delete(ext2_brel brel, blk_t old); static errcode_t bma_free(ext2_brel brel); struct brel_ma { __u32 magic; - blk64_t max_block; + blk_t max_block; struct ext2_block_relocate_entry *entries; }; -errcode_t ext2fs_brel_memarray_create(char *name, blk64_t max_block, +errcode_t ext2fs_brel_memarray_create(char *name, blk_t max_block, ext2_brel *new_brel) { ext2_brel brel = 0; @@ -101,7 +101,7 @@ errout: return retval; } -static errcode_t bma_put(ext2_brel brel, blk64_t old, +static errcode_t bma_put(ext2_brel brel, blk_t old, struct ext2_block_relocate_entry *ent) { struct brel_ma *ma; @@ -113,7 +113,7 @@ static errcode_t bma_put(ext2_brel brel, blk64_t old, return 0; } -static errcode_t bma_get(ext2_brel brel, blk64_t old, +static errcode_t bma_get(ext2_brel brel, blk_t old, struct ext2_block_relocate_entry *ent) { struct brel_ma *ma; @@ -133,7 +133,7 @@ static errcode_t bma_start_iter(ext2_brel brel) return 0; } -static errcode_t bma_next(ext2_brel brel, blk64_t *old, +static errcode_t bma_next(ext2_brel brel, blk_t *old, struct ext2_block_relocate_entry *ent) { struct brel_ma *ma; @@ -150,7 +150,7 @@ static errcode_t bma_next(ext2_brel brel, blk64_t *old, return 0; } -static errcode_t bma_move(ext2_brel brel, blk64_t old, blk64_t new) +static errcode_t bma_move(ext2_brel brel, blk_t old, blk_t new) { struct brel_ma *ma; @@ -164,7 +164,7 @@ static errcode_t bma_move(ext2_brel brel, blk64_t old, blk64_t new) return 0; } -static errcode_t bma_delete(ext2_brel brel, blk64_t old) +static errcode_t bma_delete(ext2_brel brel, blk_t old) { struct brel_ma *ma; diff --git a/lib/ext2fs/check_desc.c b/lib/ext2fs/check_desc.c index d2cc5659..5ab95147 100644 --- a/lib/ext2fs/check_desc.c +++ b/lib/ext2fs/check_desc.c @@ -34,17 +34,14 @@ errcode_t ext2fs_check_desc(ext2_filsys fs) ext2fs_block_bitmap bmap; errcode_t retval; dgrp_t i; - blk64_t first_block = fs->super->s_first_data_block; - blk64_t last_block = ext2fs_blocks_count(fs->super)-1; - blk64_t blk, b; - unsigned int j; + blk_t first_block = fs->super->s_first_data_block; + blk_t last_block = fs->super->s_blocks_count-1; + blk_t blk, b; + int j; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); - if (EXT2_DESC_SIZE(fs->super) & (EXT2_DESC_SIZE(fs->super) - 1)) - return EXT2_ET_BAD_DESC_SIZE; - - retval = ext2fs_allocate_subcluster_bitmap(fs, "check_desc map", &bmap); + retval = ext2fs_allocate_block_bitmap(fs, "check_desc map", &bmap); if (retval) return retval; @@ -54,36 +51,38 @@ errcode_t ext2fs_check_desc(ext2_filsys fs) for (i = 0; i < fs->group_desc_count; i++) { if (!EXT2_HAS_INCOMPAT_FEATURE(fs->super, EXT4_FEATURE_INCOMPAT_FLEX_BG)) { - first_block = ext2fs_group_first_block2(fs, i); - last_block = ext2fs_group_last_block2(fs, i); + first_block = ext2fs_group_first_block(fs, i); + last_block = ext2fs_group_last_block(fs, i); + if (i == (fs->group_desc_count - 1)) + last_block = fs->super->s_blocks_count-1; } /* * Check to make sure the block bitmap for group is sane */ - blk = ext2fs_block_bitmap_loc(fs, i); + blk = fs->group_desc[i].bg_block_bitmap; if (blk < first_block || blk > last_block || - ext2fs_test_block_bitmap2(bmap, blk)) { + ext2fs_test_block_bitmap(bmap, blk)) { retval = EXT2_ET_GDESC_BAD_BLOCK_MAP; goto errout; } - ext2fs_mark_block_bitmap2(bmap, blk); + ext2fs_mark_block_bitmap(bmap, blk); /* * Check to make sure the inode bitmap for group is sane */ - blk = ext2fs_inode_bitmap_loc(fs, i); + blk = fs->group_desc[i].bg_inode_bitmap; if (blk < first_block || blk > last_block || - ext2fs_test_block_bitmap2(bmap, blk)) { + ext2fs_test_block_bitmap(bmap, blk)) { retval = EXT2_ET_GDESC_BAD_INODE_MAP; goto errout; } - ext2fs_mark_block_bitmap2(bmap, blk); + ext2fs_mark_block_bitmap(bmap, blk); /* * Check to make sure the inode table for group is sane */ - blk = ext2fs_inode_table_loc(fs, i); + blk = fs->group_desc[i].bg_inode_table; if (blk < first_block || ((blk + fs->inode_blocks_per_group - 1) > last_block)) { retval = EXT2_ET_GDESC_BAD_INODE_TABLE; @@ -91,11 +90,11 @@ errcode_t ext2fs_check_desc(ext2_filsys fs) } for (j = 0, b = blk; j < fs->inode_blocks_per_group; j++, b++) { - if (ext2fs_test_block_bitmap2(bmap, b)) { + if (ext2fs_test_block_bitmap(bmap, b)) { retval = EXT2_ET_GDESC_BAD_INODE_TABLE; goto errout; } - ext2fs_mark_block_bitmap2(bmap, b); + ext2fs_mark_block_bitmap(bmap, b); } } errout: diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c index 87403839..99430d7b 100644 --- a/lib/ext2fs/closefs.c +++ b/lib/ext2fs/closefs.c @@ -19,12 +19,12 @@ #include "ext2_fs.h" #include "ext2fsP.h" -static int test_root(unsigned int a, unsigned int b) +static int test_root(int a, int b) { + if (a == 0) + return 1; while (1) { - if (a < b) - return 0; - if (a == b) + if (a == 1) return 1; if (a % b) return 0; @@ -32,50 +32,45 @@ static int test_root(unsigned int a, unsigned int b) } } -int ext2fs_bg_has_super(ext2_filsys fs, dgrp_t group) +int ext2fs_bg_has_super(ext2_filsys fs, int group_block) { if (!(fs->super->s_feature_ro_compat & - EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) || group <= 1) + EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) return 1; - if (!(group & 1)) - return 0; - if (test_root(group, 3) || (test_root(group, 5)) || - test_root(group, 7)) + + if (test_root(group_block, 3) || (test_root(group_block, 5)) || + test_root(group_block, 7)) return 1; return 0; } /* - * 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. + * 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. * - * Returns errcode_t of 0 + * See also the comment for ext2fs_reserve_super_and_bgd() */ -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) +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 group_block, super_blk = 0, old_desc_blk = 0, new_desc_blk = 0; + blk_t group_block, super_blk = 0, old_desc_blk = 0, new_desc_blk = 0; unsigned int meta_bg, meta_bg_size; - blk_t numblocks = 0; - blk64_t old_desc_blocks; + blk_t numblocks, old_desc_blocks; int has_super; - group_block = ext2fs_group_first_block2(fs, group); - if (group_block == 0 && fs->blocksize == 1024) - group_block = 1; /* Deal with 1024 blocksize && bigalloc */ + 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; @@ -83,11 +78,20 @@ errcode_t ext2fs_super_and_bgd_loc2(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; @@ -96,7 +100,7 @@ errcode_t ext2fs_super_and_bgd_loc2(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) || @@ -105,71 +109,23 @@ errcode_t ext2fs_super_and_bgd_loc2(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; if (ret_old_desc_blk) *ret_old_desc_blk = old_desc_blk; if (ret_new_desc_blk) *ret_new_desc_blk = new_desc_blk; - if (ret_used_blks) - *ret_used_blks = numblocks; - - return 0; + if (ret_meta_bg) + *ret_meta_bg = meta_bg; + return (numblocks); } -/* - * 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); - - numblocks = ext2fs_group_blocks_count(fs, 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 @@ -191,7 +147,7 @@ static errcode_t write_primary_superblock(ext2_filsys fs, if (!fs->io->manager->write_byte || !fs->orig_super) { fallback: io_channel_set_blksize(fs->io, SUPERBLOCK_OFFSET); - retval = io_channel_write_blk64(fs->io, 1, -SUPERBLOCK_SIZE, + retval = io_channel_write_blk(fs->io, 1, -SUPERBLOCK_SIZE, super); io_channel_set_blksize(fs->io, fs->blocksize); return retval; @@ -243,7 +199,7 @@ void ext2fs_update_dynamic_rev(ext2_filsys fs) } static errcode_t write_backup_super(ext2_filsys fs, dgrp_t group, - blk64_t group_block, + blk_t group_block, struct ext2_super_block *super_shadow) { dgrp_t sgrp = group; @@ -256,16 +212,12 @@ static errcode_t write_backup_super(ext2_filsys fs, dgrp_t group, fs->super->s_block_group_nr = sgrp; #endif - return io_channel_write_blk64(fs->io, group_block, -SUPERBLOCK_SIZE, + return io_channel_write_blk(fs->io, group_block, -SUPERBLOCK_SIZE, super_shadow); } -errcode_t ext2fs_flush(ext2_filsys fs) -{ - return ext2fs_flush2(fs, 0); -} -errcode_t ext2fs_flush2(ext2_filsys fs, int flags) +errcode_t ext2fs_flush(ext2_filsys fs) { dgrp_t i; errcode_t retval; @@ -274,12 +226,11 @@ errcode_t ext2fs_flush2(ext2_filsys fs, int flags) struct ext2_super_block *super_shadow = 0; struct ext2_group_desc *group_shadow = 0; #ifdef WORDS_BIGENDIAN - struct ext2_group_desc *gdp; + struct ext2_group_desc *s, *t; dgrp_t j; #endif char *group_ptr; int old_desc_blocks; - struct ext2fs_numeric_progress_struct progress; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); @@ -297,17 +248,18 @@ errcode_t ext2fs_flush2(ext2_filsys fs, int flags) &group_shadow); if (retval) goto errout; - memcpy(group_shadow, fs->group_desc, (size_t) fs->blocksize * + memset(group_shadow, 0, (size_t) fs->blocksize * fs->desc_blocks); /* swap the group descriptors */ - for (j = 0; j < fs->group_desc_count; j++) { - gdp = ext2fs_group_desc(fs, group_shadow, j); - ext2fs_swap_group_desc2(fs, gdp); + for (j=0, s=fs->group_desc, t=group_shadow; + j < fs->group_desc_count; j++, t++, s++) { + *t = *s; + ext2fs_swap_group_desc(t); } #else super_shadow = fs->super; - group_shadow = ext2fs_group_desc(fs, fs->group_desc, 0); + group_shadow = fs->group_desc; #endif /* @@ -340,16 +292,12 @@ errcode_t ext2fs_flush2(ext2_filsys fs, int flags) else old_desc_blocks = fs->desc_blocks; - ext2fs_numeric_progress_init(fs, &progress, NULL, - fs->group_desc_count); - - for (i = 0; i < fs->group_desc_count; i++) { - blk64_t super_blk, old_desc_blk, new_desc_blk; + blk_t super_blk, old_desc_blk, new_desc_blk; + int meta_bg; - ext2fs_numeric_progress_update(fs, &progress, i); - ext2fs_super_and_bgd_loc2(fs, i, &super_blk, &old_desc_blk, - &new_desc_blk, 0); + ext2fs_super_and_bgd_loc(fs, i, &super_blk, &old_desc_blk, + &new_desc_blk, &meta_bg); if (!(fs->flags & EXT2_FLAG_MASTER_SB_ONLY) &&i && super_blk) { retval = write_backup_super(fs, i, super_blk, @@ -361,23 +309,19 @@ errcode_t ext2fs_flush2(ext2_filsys fs, int flags) continue; if ((old_desc_blk) && (!(fs->flags & EXT2_FLAG_MASTER_SB_ONLY) || (i == 0))) { - retval = io_channel_write_blk64(fs->io, + retval = io_channel_write_blk(fs->io, old_desc_blk, old_desc_blocks, group_ptr); if (retval) goto errout; } if (new_desc_blk) { - int meta_bg = i / EXT2_DESC_PER_BLOCK(fs->super); - - retval = io_channel_write_blk64(fs->io, new_desc_blk, + retval = io_channel_write_blk(fs->io, new_desc_blk, 1, group_ptr + (meta_bg*fs->blocksize)); if (retval) goto errout; } } - ext2fs_numeric_progress_close(fs, &progress, NULL); - /* * If the write_bitmaps() function is present, call it to * flush the bitmaps. This is done this way so that a simple @@ -407,16 +351,14 @@ write_primary_superblock_only: ext2fs_swap_super(super_shadow); #endif - if (!(flags & EXT2_FLAG_FLUSH_NO_SYNC)) - retval = io_channel_flush(fs->io); + retval = io_channel_flush(fs->io); retval = write_primary_superblock(fs, super_shadow); if (retval) goto errout; fs->flags &= ~EXT2_FLAG_DIRTY; - if (!(flags & EXT2_FLAG_FLUSH_NO_SYNC)) - retval = io_channel_flush(fs->io); + retval = io_channel_flush(fs->io); errout: fs->super->s_state = fs_state; #ifdef WORDS_BIGENDIAN @@ -430,11 +372,6 @@ errout: errcode_t ext2fs_close(ext2_filsys fs) { - return ext2fs_close2(fs, 0); -} - -errcode_t ext2fs_close2(ext2_filsys fs, int flags) -{ errcode_t retval; int meta_blks; io_stats stats = 0; @@ -459,15 +396,10 @@ errcode_t ext2fs_close2(ext2_filsys fs, int flags) fs->flags |= EXT2_FLAG_SUPER_ONLY | EXT2_FLAG_DIRTY; } if (fs->flags & EXT2_FLAG_DIRTY) { - retval = ext2fs_flush2(fs, flags); + retval = ext2fs_flush(fs); if (retval) return retval; } - - retval = ext2fs_mmp_stop(fs); - if (retval) - return retval; - ext2fs_free(fs); return 0; } diff --git a/lib/ext2fs/crc32c.c b/lib/ext2fs/crc32c.c deleted file mode 100644 index 5907500b..00000000 --- a/lib/ext2fs/crc32c.c +++ /dev/null @@ -1,1143 +0,0 @@ -/* - * crc32c.c - * - * August 26, 2011 Darrick J. Wong <djwong at us.ibm.com> - * Reuse Bob Pearson's slice-by-8 implementation for e2fsprogs. - * - * July 20, 2011 Bob Pearson <rpearson at systemfabricworks.com> - * added slice by 8 algorithm to the existing conventional and - * slice by 4 algorithms. - * - * Oct 15, 2000 Matt Domsch <Matt_Domsch@dell.com> - * Nicer crc32 functions/docs submitted by linux@horizon.com. Thanks! - * Code was from the public domain, copyright abandoned. Code was - * subsequently included in the kernel, thus was re-licensed under the - * GNU GPL v2. - * - * Oct 12, 2000 Matt Domsch <Matt_Domsch@dell.com> - * Same crc32 function was used in 5 other places in the kernel. - * I made one version, and deleted the others. - * There are various incantations of crc32(). Some use a seed of 0 or ~0. - * Some xor at the end with ~0. The generic crc32() function takes - * seed as an argument, and doesn't xor at the end. Then individual - * users can do whatever they need. - * drivers/net/smc9194.c uses seed ~0, doesn't xor with ~0. - * fs/jffs2 uses seed 0, doesn't xor with ~0. - * fs/partitions/efi.c uses seed ~0, xor's with ~0. - * - * This source code is licensed under the GNU General Public License, - * Version 2. See the file COPYING for more details. - */ -#include <stdint.h> -#include <stdlib.h> -#include <stdio.h> -#define __force -#define min(x, y) ((x) > (y) ? (y) : (x)) -#define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) -#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1) -#define ALIGN(x, a) __ALIGN_KERNEL((x), (a)) -#define PTR_ALIGN(p, a) ((__typeof__(p))ALIGN((unsigned long)(p), (a))) -#include "crc32c_defs.h" - -#include "ext2fs.h" -#ifdef WORDS_BIGENDIAN -#define __constant_cpu_to_le32(x) ___constant_swab32((x)) -#define __constant_cpu_to_be32(x) (x) -#define __be32_to_cpu(x) (x) -#define __cpu_to_be32(x) (x) -#define __cpu_to_le32(x) (ext2fs_cpu_to_le32((x))) -#define __le32_to_cpu(x) (ext2fs_le32_to_cpu((x))) -#else -#define __constant_cpu_to_le32(x) (x) -#define __constant_cpu_to_be32(x) ___constant_swab32((x)) -#define __be32_to_cpu(x) (ext2fs_be32_to_cpu((x))) -#define __cpu_to_be32(x) (ext2fs_cpu_to_be32((x))) -#define __cpu_to_le32(x) (x) -#define __le32_to_cpu(x) (x) -#endif - -#if CRC_LE_BITS > 8 -# define tole(x) (__force uint32_t) __constant_cpu_to_le32(x) -#else -# define tole(x) (x) -#endif - -#if CRC_BE_BITS > 8 -# define tobe(x) (__force uint32_t) __constant_cpu_to_be32(x) -#else -# define tobe(x) (x) -#endif - -#include "crc32c_table.h" - -#if CRC_LE_BITS == 32 -/* slice by 4 algorithm */ -static uint32_t crc32c_le_body(uint32_t crc, uint8_t const *buf, size_t len) -{ - const uint8_t *p8; - const uint32_t *p32; - size_t init_bytes; - size_t words; - size_t end_bytes; - size_t i; - uint32_t q; - uint8_t i0, i1, i2, i3; - - crc = (__force uint32_t) __cpu_to_le32(crc); - - /* unroll loop into 'init_bytes' odd bytes followed by - * 'words' aligned 4 byte words followed by - * 'end_bytes' odd bytes at the end */ - p8 = buf; - p32 = (uint32_t *)PTR_ALIGN(p8, 4); - init_bytes = min((uintptr_t)p32 - (uintptr_t)p8, len); - words = (len - init_bytes) >> 2; - end_bytes = (len - init_bytes) & 3; - - for (i = 0; i < init_bytes; i++) { -#ifndef WORDS_BIGENDIAN - i0 = *p8++ ^ crc; - crc = t0_le[i0] ^ (crc >> 8); -#else - i0 = *p8++ ^ (crc >> 24); - crc = t0_le[i0] ^ (crc << 8); -#endif - } - - /* using pre-increment below slightly faster */ - p32--; - - for (i = 0; i < words; i++) { -#ifndef WORDS_BIGENDIAN - q = *++p32 ^ crc; - i3 = q; - i2 = q >> 8; - i1 = q >> 16; - i0 = q >> 24; - crc = t3_le[i3] ^ t2_le[i2] ^ t1_le[i1] ^ t0_le[i0]; -#else - q = *++p32 ^ crc; - i3 = q >> 24; - i2 = q >> 16; - i1 = q >> 8; - i0 = q; - crc = t3_le[i3] ^ t2_le[i2] ^ t1_le[i1] ^ t0_le[i0]; -#endif - } - - p8 = (uint8_t *)(++p32); - - for (i = 0; i < end_bytes; i++) { -#ifndef WORDS_BIGENDIAN - i0 = *p8++ ^ crc; - crc = t0_le[i0] ^ (crc >> 8); -#else - i0 = *p8++ ^ (crc >> 24); - crc = t0_le[i0] ^ (crc << 8); -#endif - } - - return __le32_to_cpu((__force __le32)crc); -} -#endif - -#if CRC_BE_BITS == 32 -static uint32_t crc32c_be_body(uint32_t crc, uint8_t const *buf, size_t len) -{ - const uint8_t *p8; - const uint32_t *p32; - size_t init_bytes; - size_t words; - size_t end_bytes; - size_t i; - uint32_t q; - uint8_t i0, i1, i2, i3; - - crc = (__force uint32_t) __cpu_to_be32(crc); - - p8 = buf; - p32 = (uint32_t *)PTR_ALIGN(p8, 4); - init_bytes = min((uintptr_t)p32 - (uintptr_t)p8, len); - words = (len - init_bytes) >> 2; - end_bytes = (len - init_bytes) & 3; - - for (i = 0; i < init_bytes; i++) { -#ifndef WORDS_BIGENDIAN - i0 = *p8++ ^ crc; - crc = t0_be[i0] ^ (crc >> 8); -#else - i0 = *p8++ ^ (crc >> 24); - crc = t0_be[i0] ^ (crc << 8); -#endif - } - - p32--; - - for (i = 0; i < words; i++) { -#ifndef WORDS_BIGENDIAN - q = *++p32 ^ crc; - i3 = q; - i2 = q >> 8; - i1 = q >> 16; - i0 = q >> 24; - crc = t3_be[i3] ^ t2_be[i2] ^ t1_be[i1] ^ t0_be[i0]; -#else - q = *++p32 ^ crc; - i3 = q >> 24; - i2 = q >> 16; - i1 = q >> 8; - i0 = q; - crc = t3_be[i3] ^ t2_be[i2] ^ t1_be[i1] ^ t0_be[i0]; -#endif - } - - p8 = (uint8_t *)(++p32); - - for (i = 0; i < end_bytes; i++) { -#ifndef WORDS_BIGENDIAN - i0 = *p8++ ^ crc; - crc = t0_be[i0] ^ (crc >> 8); -#else - i0 = *p8++ ^ (crc >> 24); - crc = t0_be[i0] ^ (crc << 8); -#endif - } - - return __be32_to_cpu((__force __be32)crc); -} -#endif - -#if CRC_LE_BITS == 64 -/* slice by 8 algorithm */ -static uint32_t crc32c_le_body(uint32_t crc, uint8_t const *buf, size_t len) -{ - const uint8_t *p8; - const uint32_t *p32; - size_t init_bytes; - size_t words; - size_t end_bytes; - size_t i; - uint32_t q; - uint8_t i0, i1, i2, i3; - - crc = (__force uint32_t) __cpu_to_le32(crc); - - p8 = buf; - p32 = (const uint32_t *)PTR_ALIGN(p8, 8); - init_bytes = min((uintptr_t)p32 - (uintptr_t)p8, len); - words = (len - init_bytes) >> 3; - end_bytes = (len - init_bytes) & 7; - - for (i = 0; i < init_bytes; i++) { -#ifndef WORDS_BIGENDIAN - i0 = *p8++ ^ crc; - crc = t0_le[i0] ^ (crc >> 8); -#else - i0 = *p8++ ^ (crc >> 24); - crc = t0_le[i0] ^ (crc << 8); -#endif - } - - p32--; - - for (i = 0; i < words; i++) { -#ifndef WORDS_BIGENDIAN - q = *++p32 ^ crc; - i3 = q; - i2 = q >> 8; - i1 = q >> 16; - i0 = q >> 24; - crc = t7_le[i3] ^ t6_le[i2] ^ t5_le[i1] ^ t4_le[i0]; - - q = *++p32; - i3 = q; - i2 = q >> 8; - i1 = q >> 16; - i0 = q >> 24; - crc ^= t3_le[i3] ^ t2_le[i2] ^ t1_le[i1] ^ t0_le[i0]; -#else - q = *++p32 ^ crc; - i3 = q >> 24; - i2 = q >> 16; - i1 = q >> 8; - i0 = q; - crc = t7_le[i3] ^ t6_le[i2] ^ t5_le[i1] ^ t4_le[i0]; - - q = *++p32; - i3 = q >> 24; - i2 = q >> 16; - i1 = q >> 8; - i0 = q; - crc ^= t3_le[i3] ^ t2_le[i2] ^ t1_le[i1] ^ t0_le[i0]; -#endif - } - - p8 = (const uint8_t *)(++p32); - - for (i = 0; i < end_bytes; i++) { -#ifndef WORDS_BIGENDIAN - i0 = *p8++ ^ crc; - crc = t0_le[i0] ^ (crc >> 8); -#else - i0 = *p8++ ^ (crc >> 24); - crc = t0_le[i0] ^ (crc << 8); -#endif - } - - return __le32_to_cpu(crc); -} -#endif - -#if CRC_BE_BITS == 64 -static uint32_t crc32c_be_body(uint32_t crc, uint8_t const *buf, size_t len) -{ - const uint8_t *p8; - const uint32_t *p32; - size_t init_bytes; - size_t words; - size_t end_bytes; - size_t i; - uint32_t q; - uint8_t i0, i1, i2, i3; - - crc = (__force uint32_t) __cpu_to_be32(crc); - - p8 = buf; - p32 = (const uint32_t *)PTR_ALIGN(p8, 8); - init_bytes = min((uintptr_t)p32 - (uintptr_t)p8, len); - words = (len - init_bytes) >> 3; - end_bytes = (len - init_bytes) & 7; - - for (i = 0; i < init_bytes; i++) { -#ifndef WORDS_BIGENDIAN - i0 = *p8++ ^ crc; - crc = t0_be[i0] ^ (crc >> 8); -#else - i0 = *p8++ ^ (crc >> 24); - crc = t0_be[i0] ^ (crc << 8); -#endif - } - - p32--; - - for (i = 0; i < words; i++) { -#ifndef WORDS_BIGENDIAN - q = *++p32 ^ crc; - i3 = q; - i2 = q >> 8; - i1 = q >> 16; - i0 = q >> 24; - crc = t7_be[i3] ^ t6_be[i2] ^ t5_be[i1] ^ t4_be[i0]; - - q = *++p32; - i3 = q; - i2 = q >> 8; - i1 = q >> 16; - i0 = q >> 24; - crc ^= t3_be[i3] ^ t2_be[i2] ^ t1_be[i1] ^ t0_be[i0]; -#else - q = *++p32 ^ crc; - i3 = q >> 24; - i2 = q >> 16; - i1 = q >> 8; - i0 = q; - crc = t7_be[i3] ^ t6_be[i2] ^ t5_be[i1] ^ t4_be[i0]; - - q = *++p32; - i3 = q >> 24; - i2 = q >> 16; - i1 = q >> 8; - i0 = q; - crc ^= t3_be[i3] ^ t2_be[i2] ^ t1_be[i1] ^ t0_be[i0]; -#endif - } - - p8 = (const uint8_t *)(++p32); - - for (i = 0; i < end_bytes; i++) { -#ifndef WORDS_BIGENDIAN - i0 = *p8++ ^ crc; - crc = t0_be[i0] ^ (crc >> 8); -#else - i0 = *p8++ ^ (crc >> 24); - crc = t0_be[i0] ^ (crc << 8); -#endif - } - - return __be32_to_cpu(crc); -} -#endif - -/** - * crc32c_le() - Calculate bitwise little-endian CRC32c. - * @crc: seed value for computation. ~0 for ext4, sometimes 0 for - * other uses, or the previous crc32c value if computing incrementally. - * @p: pointer to buffer over which CRC is run - * @len: length of buffer @p - */ -uint32_t ext2fs_crc32c_le(uint32_t crc, unsigned char const *p, size_t len) -{ -#if CRC_LE_BITS == 1 - int i; - while (len--) { - crc ^= *p++; - for (i = 0; i < 8; i++) - crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); - } -# elif CRC_LE_BITS == 2 - while (len--) { - crc ^= *p++; - crc = (crc >> 2) ^ t0_le[crc & 0x03]; - crc = (crc >> 2) ^ t0_le[crc & 0x03]; - crc = (crc >> 2) ^ t0_le[crc & 0x03]; - crc = (crc >> 2) ^ t0_le[crc & 0x03]; - } -# elif CRC_LE_BITS == 4 - while (len--) { - crc ^= *p++; - crc = (crc >> 4) ^ t0_le[crc & 0x0f]; - crc = (crc >> 4) ^ t0_le[crc & 0x0f]; - } -# elif CRC_LE_BITS == 8 - while (len--) { - crc ^= *p++; - crc = (crc >> 8) ^ t0_le[crc & 0xff]; - } -# else - crc = crc32c_le_body(crc, p, len); -# endif - return crc; -} - -/** - * crc32c_be() - Calculate bitwise big-endian CRC32c. - * @crc: seed value for computation. ~0 for ext4, sometimes 0 for - * other uses, or the previous crc32c value if computing incrementally. - * @p: pointer to buffer over which CRC is run - * @len: length of buffer @p - */ -uint32_t ext2fs_crc32c_be(uint32_t crc, unsigned char const *p, size_t len) -{ -#if CRC_BE_BITS == 1 - int i; - while (len--) { - crc ^= *p++ << 24; - for (i = 0; i < 8; i++) - crc = (crc << 1) ^ - ((crc & 0x80000000) ? CRCPOLY_BE : 0); - } -# elif CRC_BE_BITS == 2 - while (len--) { - crc ^= *p++ << 24; - crc = (crc << 2) ^ t0_be[crc >> 30]; - crc = (crc << 2) ^ t0_be[crc >> 30]; - crc = (crc << 2) ^ t0_be[crc >> 30]; - crc = (crc << 2) ^ t0_be[crc >> 30]; - } -# elif CRC_BE_BITS == 4 - while (len--) { - crc ^= *p++ << 24; - crc = (crc << 4) ^ t0_be[crc >> 28]; - crc = (crc << 4) ^ t0_be[crc >> 28]; - } -# elif CRC_BE_BITS == 8 - while (len--) { - crc ^= *p++ << 24; - crc = (crc << 8) ^ t0_be[crc >> 24]; - } -# else - crc = crc32c_be_body(crc, p, len); -# endif - return crc; -} - -#ifdef UNITTEST -static uint8_t test_buf[] = { - 0xd9, 0xd7, 0x6a, 0x13, 0x3a, 0xb1, 0x05, 0x48, - 0xda, 0xad, 0x14, 0xbd, 0x03, 0x3a, 0x58, 0x5e, - 0x6e, 0xd1, 0x56, 0xc9, 0x2e, 0xc4, 0xcb, 0x6b, - 0xe8, 0x77, 0x52, 0x37, 0x4e, 0x0f, 0x55, 0xd2, - 0x12, 0x65, 0x90, 0xc2, 0x41, 0x49, 0x81, 0x01, - 0xf5, 0x01, 0xeb, 0x2d, 0x78, 0x74, 0x23, 0x5d, - 0x84, 0x5c, 0x81, 0x92, 0x21, 0xe9, 0x8d, 0x1d, - 0x89, 0xf2, 0x4a, 0xac, 0xdd, 0xf9, 0xaf, 0xee, - 0x44, 0xe7, 0x6e, 0xed, 0xfb, 0xd8, 0x89, 0x0e, - 0x96, 0x62, 0xcd, 0xa4, 0x4b, 0xa9, 0xe5, 0x45, - 0xb1, 0x29, 0x9b, 0x0f, 0xfc, 0xbd, 0x83, 0xab, - 0xa8, 0x54, 0x96, 0x44, 0x2c, 0x7f, 0xbb, 0xe7, - 0x52, 0x29, 0x08, 0xee, 0x14, 0xc5, 0xc2, 0xec, - 0x5a, 0xeb, 0x40, 0x40, 0xea, 0xd1, 0x3d, 0x15, - 0x73, 0xaa, 0x8c, 0x73, 0xfc, 0xf2, 0x2b, 0x49, - 0x0b, 0x13, 0x96, 0xd9, 0x8e, 0x4b, 0xbc, 0xe0, - 0xf4, 0xd2, 0xe0, 0x2e, 0x7a, 0xf0, 0x5d, 0x1f, - 0xd2, 0x92, 0x97, 0xe0, 0xaa, 0x59, 0xab, 0xc9, - 0x5c, 0xa6, 0x51, 0x1a, 0xe3, 0xd6, 0x06, 0xb9, - 0xae, 0xb8, 0x76, 0x36, 0x79, 0x37, 0x52, 0xf6, - 0x34, 0xaf, 0x27, 0x19, 0xe1, 0xc0, 0x2b, 0xdd, - 0x01, 0x15, 0xcd, 0xce, 0x44, 0xf6, 0x4c, 0x18, - 0x92, 0x69, 0xbe, 0x8a, 0x76, 0x23, 0x52, 0x13, - 0x3f, 0xf9, 0xe0, 0xf5, 0x06, 0x28, 0x7c, 0xc7, - 0xf3, 0x42, 0x0f, 0xdd, 0x40, 0x33, 0xf7, 0x99, - 0xe2, 0xad, 0x26, 0xd9, 0x53, 0x10, 0x72, 0x0c, - 0x4e, 0x43, 0x4c, 0x61, 0xfe, 0xd9, 0xc1, 0x16, - 0xa1, 0x93, 0xca, 0x3c, 0x75, 0x7f, 0x07, 0x7a, - 0x65, 0xb3, 0x53, 0x2a, 0x52, 0x00, 0xa0, 0x62, - 0xe0, 0xa3, 0x1f, 0xad, 0xd7, 0xbb, 0xc0, 0x83, - 0x5d, 0x54, 0x87, 0x5f, 0xc8, 0x2f, 0xc8, 0xbf, - 0x69, 0x04, 0x91, 0xc8, 0xa6, 0x1d, 0x4d, 0x46, - 0x91, 0xfc, 0x26, 0xf4, 0x16, 0xd1, 0xa4, 0xbf, - 0x5c, 0xa2, 0x6c, 0xdd, 0xb4, 0x40, 0xf2, 0x2e, - 0xa2, 0xad, 0xf7, 0xf4, 0xa5, 0x8a, 0x3e, 0x23, - 0x64, 0x08, 0xc8, 0xa1, 0xa0, 0xf0, 0x5d, 0x70, - 0xd2, 0x77, 0xfd, 0xc8, 0x50, 0x83, 0x0f, 0xd6, - 0x2b, 0xe4, 0x1f, 0x52, 0x34, 0x33, 0x68, 0xfd, - 0x92, 0xbe, 0x9f, 0x97, 0x6b, 0x8d, 0x81, 0x91, - 0x0f, 0xef, 0x65, 0xc8, 0x0d, 0x15, 0x01, 0x77, - 0x58, 0xb2, 0xf4, 0x1b, 0x06, 0x7e, 0xf5, 0xca, - 0x15, 0x2e, 0x38, 0xd8, 0x81, 0x1c, 0x1c, 0xa0, - 0xb6, 0x13, 0x6a, 0x2b, 0x71, 0x34, 0x52, 0xd7, - 0x1d, 0xbd, 0x37, 0x59, 0xbc, 0x86, 0x25, 0x2b, - 0xa8, 0x93, 0xce, 0x1a, 0x03, 0x16, 0xfe, 0x01, - 0x57, 0x99, 0x24, 0x25, 0x2c, 0xb3, 0xab, 0x1e, - 0x2d, 0x65, 0x20, 0x89, 0x17, 0x02, 0x0e, 0x0a, - 0xf5, 0x1e, 0xc7, 0xff, 0x1f, 0x61, 0xa9, 0x54, - 0x18, 0xd4, 0xba, 0x50, 0x57, 0x02, 0xa1, 0xab, - 0x22, 0x2e, 0x07, 0xea, 0xa9, 0xa3, 0x83, 0x4f, - 0x27, 0xf5, 0xc5, 0xee, 0x3c, 0x3b, 0x10, 0xad, - 0x32, 0x2b, 0x1c, 0x03, 0xcb, 0xaf, 0x98, 0x83, - 0x54, 0xc3, 0x68, 0x63, 0xd4, 0xe0, 0x0e, 0x3c, - 0x1a, 0x4e, 0xc0, 0x81, 0xd0, 0xe8, 0x6a, 0x62, - 0x6b, 0x3e, 0x6f, 0xc4, 0xc6, 0x33, 0x4e, 0x26, - 0x21, 0xf5, 0x04, 0xdf, 0xfa, 0xce, 0x45, 0xaf, - 0xdc, 0x5e, 0x1b, 0xad, 0x93, 0xca, 0xf5, 0xcf, - 0xd7, 0xee, 0x0c, 0x5c, 0x5e, 0xb4, 0xf0, 0x92, - 0xd2, 0xf2, 0xf0, 0xa9, 0x1e, 0xab, 0x80, 0x68, - 0x46, 0xef, 0xcc, 0x26, 0x0c, 0x5c, 0xdd, 0x4e, - 0x83, 0xb8, 0xb9, 0x53, 0x6e, 0xf8, 0x93, 0x38, - 0x67, 0xa4, 0x41, 0x87, 0x72, 0xe7, 0x7e, 0x86, - 0xc9, 0x49, 0x00, 0x33, 0xb1, 0x38, 0x6c, 0x71, - 0xd7, 0x1d, 0x8e, 0x61, 0x01, 0xb6, 0x57, 0xa9, - 0xf1, 0xac, 0x15, 0xc2, 0x83, 0x77, 0xca, 0x64, - 0xca, 0x7b, 0x6c, 0xa1, 0x10, 0x1b, 0x13, 0xd0, - 0xd3, 0x9e, 0x9e, 0x10, 0x70, 0xc8, 0x1a, 0xbb, - 0x3f, 0x19, 0x86, 0xab, 0x01, 0x0e, 0xea, 0x34, - 0x22, 0xea, 0xe2, 0x15, 0xb7, 0xed, 0x21, 0x21, - 0x75, 0xa5, 0xe7, 0x08, 0xa1, 0x38, 0xe0, 0x91, - 0x05, 0x60, 0xea, 0xa7, 0x50, 0x27, 0x18, 0x07, - 0x9d, 0xe0, 0x18, 0x2b, 0xd4, 0x07, 0x59, 0x00, - 0xe6, 0x45, 0x18, 0x2a, 0x30, 0x6e, 0xf3, 0xb4, - 0xd0, 0xef, 0xa6, 0x5b, 0x71, 0xa2, 0x5a, 0x3b, - 0x89, 0x4c, 0xaf, 0x3f, 0xcb, 0x9f, 0x03, 0xfb, - 0x43, 0x7c, 0x6b, 0xd3, 0x6a, 0xea, 0xce, 0x4a, - 0x5f, 0x64, 0xb5, 0x62, 0xda, 0x5d, 0x27, 0xb7, - 0xb8, 0x11, 0xca, 0x33, 0x30, 0xec, 0x70, 0xf0, - 0x1b, 0x03, 0x50, 0xff, 0x5e, 0xa6, 0x08, 0xde, - 0x37, 0x70, 0xc0, 0x81, 0x55, 0x60, 0x17, 0xa1, - 0x85, 0xae, 0x26, 0x44, 0xe4, 0x67, 0x3c, 0x91, - 0xfd, 0xc4, 0x3d, 0x97, 0x72, 0x23, 0xf3, 0x3c, - 0x8f, 0xe0, 0xe2, 0xf2, 0x09, 0x96, 0x10, 0x67, - 0xb5, 0xfe, 0xff, 0x3d, 0x4a, 0xc8, 0x62, 0x11, - 0xa5, 0x98, 0xc1, 0x2d, 0x40, 0x82, 0x88, 0x8b, - 0xe5, 0xb0, 0x75, 0xbf, 0x2f, 0xa8, 0x6a, 0x55, - 0x49, 0x2e, 0x9c, 0x29, 0xd2, 0x7c, 0xbf, 0xf3, - 0xaa, 0x3a, 0x16, 0x4a, 0xa4, 0x15, 0xf3, 0x48, - 0xde, 0x38, 0x13, 0x44, 0x26, 0x02, 0xe6, 0xe9, - 0xa8, 0x24, 0x89, 0xb5, 0x43, 0x95, 0xe4, 0x4c, - 0xc3, 0xa0, 0xdf, 0xcc, 0x42, 0xf8, 0x8d, 0xb0, - 0x3b, 0xea, 0x10, 0xb7, 0xe1, 0x40, 0x54, 0xb9, - 0xa3, 0x2d, 0xfb, 0xb4, 0x91, 0xc0, 0x3e, 0x94, - 0xf1, 0xa1, 0x3c, 0xbe, 0xef, 0xb8, 0x70, 0x55, - 0x0a, 0x26, 0x93, 0xbf, 0xe6, 0x21, 0x92, 0x32, - 0x3c, 0x39, 0x27, 0x6a, 0x23, 0x48, 0x02, 0x35, - 0x3c, 0xd4, 0xcc, 0x04, 0xc0, 0x4e, 0xa7, 0x02, - 0x63, 0x37, 0xc2, 0xb8, 0x56, 0x1d, 0x57, 0x57, - 0x42, 0x04, 0x8d, 0xee, 0xcf, 0x8b, 0xc9, 0xc3, - 0xba, 0x3b, 0x15, 0xd7, 0xaf, 0xbf, 0x9e, 0xcd, - 0x44, 0xcf, 0xf0, 0x00, 0xb7, 0x3a, 0xfc, 0xa8, - 0x12, 0xab, 0x3a, 0x62, 0x01, 0x21, 0x46, 0xe9, - 0x1e, 0x48, 0x37, 0xfc, 0x13, 0x4d, 0xf6, 0x2a, - 0x72, 0x40, 0x75, 0x38, 0x71, 0xf2, 0x17, 0x20, - 0x2c, 0xdd, 0xc0, 0x49, 0xbc, 0x63, 0x33, 0xea, - 0x06, 0x75, 0x41, 0xe7, 0x5c, 0x1f, 0xfb, 0xf9, - 0x68, 0x83, 0xc2, 0x5a, 0x4a, 0x1e, 0x61, 0x08, - 0x57, 0xf3, 0x00, 0xba, 0x77, 0x92, 0x63, 0xa5, - 0xb7, 0xfe, 0x97, 0x22, 0xda, 0x5e, 0xd3, 0xaf, - 0xbc, 0x89, 0x0d, 0x4c, 0x37, 0xa9, 0x27, 0x4a, - 0x7f, 0xdb, 0x81, 0x39, 0x11, 0x86, 0x12, 0xf9, - 0x10, 0x50, 0xe4, 0xdb, 0x72, 0xf9, 0xae, 0x10, - 0x7c, 0xed, 0x50, 0x5c, 0x61, 0xeb, 0x42, 0x1e, - 0xa4, 0xf4, 0xf0, 0xfa, 0x45, 0x4d, 0x95, 0x2b, - 0xd4, 0x67, 0x4a, 0xe3, 0x8a, 0x15, 0x55, 0x92, - 0x77, 0x64, 0x8c, 0x51, 0x38, 0xf9, 0x26, 0x3e, - 0x68, 0xe2, 0xac, 0xbb, 0x64, 0x77, 0xe2, 0x82, - 0xa4, 0x42, 0x41, 0x38, 0xa0, 0xf0, 0xc9, 0xd8, - 0x6c, 0xe0, 0xef, 0x4c, 0xda, 0xb4, 0x92, 0xef, - 0x1b, 0xe3, 0x9b, 0xc1, 0x44, 0x3c, 0xb9, 0xb7, - 0x39, 0xac, 0x5c, 0x32, 0x39, 0xb4, 0x21, 0x85, - 0x93, 0xbc, 0xf2, 0x51, 0x43, 0xb7, 0xae, 0x1e, - 0x61, 0x9c, 0x38, 0x9c, 0xaa, 0xff, 0xde, 0xfc, - 0xbf, 0x85, 0xef, 0x17, 0x34, 0x36, 0x71, 0x5f, - 0x04, 0x16, 0xa6, 0x9e, 0xfd, 0x3a, 0x03, 0xd8, - 0xbf, 0x71, 0x70, 0x20, 0x8f, 0x7c, 0xfb, 0xff, - 0x61, 0xe0, 0xe2, 0x60, 0xa7, 0xb1, 0xc0, 0xe0, - 0xd9, 0x3f, 0xdc, 0x8d, 0x4a, 0xa4, 0x52, 0x61, - 0xaf, 0x9d, 0xdf, 0x8a, 0x0d, 0x41, 0xc0, 0x25, - 0x68, 0x12, 0x7b, 0xd5, 0xc7, 0xdb, 0x68, 0x70, - 0x2d, 0x7d, 0x95, 0x12, 0x03, 0x23, 0x0c, 0xe8, - 0x14, 0x41, 0x11, 0x28, 0xec, 0x9d, 0xd3, 0x28, - 0x77, 0x7a, 0x3c, 0x93, 0x8e, 0x5c, 0x7e, 0xb3, - 0x42, 0x9a, 0x18, 0x25, 0x93, 0xc8, 0xea, 0x43, - 0x1b, 0xbe, 0xd5, 0x27, 0xf1, 0xd4, 0xe0, 0x1e, - 0xce, 0xc7, 0xc7, 0x2c, 0x25, 0x35, 0x58, 0xb8, - 0x6c, 0xf3, 0xa2, 0xad, 0xe7, 0x58, 0x49, 0x47, - 0xf7, 0xca, 0xde, 0x8b, 0x81, 0xb7, 0x75, 0xf4, - 0x95, 0xa7, 0x5c, 0xc3, 0x2c, 0x0e, 0x1c, 0x52, - 0x9a, 0xc3, 0x2a, 0x00, 0x21, 0xa7, 0x51, 0x6b, - 0xf0, 0x05, 0x87, 0x8c, 0x42, 0x1b, 0xc3, 0x2e, - 0xa3, 0x76, 0x22, 0xd5, 0x7f, 0x56, 0x10, 0xef, - 0x98, 0x85, 0x65, 0x86, 0x71, 0x87, 0xd2, 0x8c, - 0xc0, 0x47, 0x20, 0xe8, 0xb5, 0x1c, 0xe3, 0xdd, - 0x3c, 0x5c, 0x03, 0xbb, 0x0e, 0x97, 0x3b, 0xe1, - 0x56, 0x9a, 0xd5, 0x0a, 0x63, 0xd5, 0x33, 0xaf, - 0x36, 0xca, 0xcf, 0x8f, 0x00, 0x28, 0xa3, 0x45, - 0xb8, 0xcd, 0xde, 0x73, 0xd4, 0xfa, 0x2d, 0x6f, - 0xdb, 0x93, 0xaa, 0xdd, 0x7f, 0xd2, 0x22, 0x9c, - 0x96, 0x48, 0x1e, 0xa8, 0x63, 0xbe, 0xbc, 0x0d, - 0x14, 0x3c, 0x2e, 0x11, 0x1f, 0xd2, 0xf4, 0x57, - 0xb3, 0x47, 0xf8, 0xa6, 0x1b, 0xc3, 0xa7, 0x95, - 0x2d, 0xd4, 0xca, 0xb8, 0x0d, 0xfb, 0x06, 0x85, - 0xda, 0x63, 0xf0, 0x3e, 0x9d, 0x5e, 0xee, 0xce, - 0xed, 0x74, 0x1d, 0x2c, 0x97, 0x3f, 0x71, 0x95, - 0x12, 0x03, 0xc5, 0x92, 0x46, 0x84, 0x1b, 0x07, - 0xe6, 0xb4, 0x1d, 0x3a, 0xf1, 0x89, 0x90, 0x50, - 0x10, 0x29, 0x34, 0xc0, 0x90, 0xbe, 0x4a, 0xa9, - 0x0d, 0xb0, 0x7b, 0xfb, 0x35, 0xee, 0x4e, 0x34, - 0xec, 0x5a, 0x58, 0xbc, 0xb8, 0xda, 0x38, 0x88, - 0x8c, 0x74, 0x1e, 0xc9, 0xab, 0x78, 0x2e, 0x2a, - 0x17, 0x8a, 0x43, 0x3d, 0xa1, 0x2a, 0x41, 0xb5, - 0xd6, 0xe8, 0x5b, 0xc5, 0x4a, 0x1c, 0x3c, 0x9f, - 0x8d, 0x3a, 0x69, 0x88, 0xf8, 0x80, 0xd2, 0x11, - 0xfc, 0x7e, 0x80, 0x8e, 0x7f, 0x85, 0x64, 0x9c, - 0x46, 0x58, 0xc8, 0x48, 0x98, 0x4b, 0xf5, 0x73, - 0x3f, 0x49, 0xce, 0x53, 0x2c, 0xd5, 0xfc, 0x33, - 0xf1, 0x6f, 0xd8, 0xe9, 0x2e, 0x70, 0x2e, 0xdc, - 0xe5, 0x43, 0x80, 0x38, 0xf2, 0x87, 0xed, 0x85, - 0xe4, 0x3e, 0x45, 0x14, 0x20, 0xcf, 0xa0, 0x61, - 0x4f, 0xe8, 0xd7, 0x5b, 0xb3, 0x0d, 0x0e, 0x4e, - 0x4d, 0xce, 0xbe, 0xba, 0xaa, 0x90, 0x09, 0xcb, - 0x4b, 0x5d, 0x08, 0xff, 0x52, 0xd5, 0x23, 0xbc, - 0xad, 0x8d, 0xd3, 0x06, 0x4a, 0xa0, 0x51, 0x56, - 0xa7, 0xd8, 0x33, 0xab, 0xbc, 0xd0, 0xdf, 0x92, - 0x87, 0x20, 0x2d, 0x7b, 0x5e, 0xfa, 0x30, 0xa7, - 0x06, 0x06, 0xe5, 0x4f, 0x2c, 0xb5, 0x61, 0xd7, - 0x54, 0xd3, 0xdf, 0xd0, 0x0a, 0xb0, 0x06, 0xce, - 0xf6, 0x86, 0xb7, 0x8e, 0xaa, 0x7b, 0x78, 0xd5, - 0xb9, 0xeb, 0x07, 0xac, 0x5f, 0xc5, 0xd2, 0x8c, - 0x40, 0xe0, 0x7f, 0x98, 0xd4, 0xe5, 0x4b, 0xca, - 0xfb, 0x47, 0xef, 0xef, 0xb9, 0x4d, 0x6d, 0x8f, - 0x82, 0x68, 0x74, 0x84, 0xe0, 0x0a, 0x93, 0x0f, - 0xb2, 0x01, 0xa9, 0x9f, 0x68, 0x6a, 0xe8, 0xf7, - 0xfb, 0x0b, 0xde, 0x17, 0xe0, 0x30, 0x38, 0x51, - 0xbc, 0x07, 0xb8, 0x2c, 0x91, 0x0f, 0xc1, 0x0e, - 0xa6, 0xf9, 0xf0, 0xd5, 0x48, 0x76, 0x8a, 0xde, - 0x74, 0xe3, 0x30, 0x65, 0x56, 0xb3, 0x5c, 0xe2, - 0x89, 0x8d, 0xda, 0x80, 0xad, 0x0f, 0x22, 0xfb, - 0x24, 0x1d, 0x16, 0xdd, 0x34, 0x4b, 0x90, 0x58, - 0x4e, 0x0c, 0x13, 0x28, 0xcf, 0x1d, 0xa4, 0xaa, - 0xb7, 0xf3, 0xb1, 0x66, 0xad, 0x3b, 0xcf, 0x79, - 0x12, 0x04, 0xd7, 0x79, 0xd9, 0x5f, 0xdf, 0x89, - 0xb2, 0x5b, 0xa7, 0x9a, 0x26, 0x1e, 0x67, 0x46, - 0x7c, 0x66, 0x95, 0x67, 0xe6, 0x45, 0x8b, 0x1f, - 0x65, 0x79, 0x9f, 0x6d, 0x11, 0x81, 0x17, 0x0d, - 0x11, 0xb0, 0x5c, 0xb4, 0xc7, 0x27, 0x87, 0xab, - 0x5d, 0x0a, 0x18, 0xae, 0x4e, 0x06, 0xa3, 0x3d, - 0xc7, 0xb0, 0x22, 0xba, 0x03, 0xa4, 0x0f, 0xe5, - 0x1c, 0x72, 0x2a, 0x04, 0xce, 0x83, 0xe9, 0xf3, - 0xd7, 0xc9, 0x67, 0x6c, 0x1e, 0x6b, 0x3c, 0x9b, - 0x0b, 0x5e, 0x6a, 0xa6, 0x79, 0x0a, 0xf1, 0xbe, - 0xd7, 0xb4, 0x6f, 0x45, 0x1e, 0xfb, 0x78, 0x97, - 0xaf, 0x34, 0x76, 0x95, 0x52, 0xf7, 0x3d, 0x5d, - 0x07, 0x28, 0x57, 0x9c, 0x4a, 0x0f, 0xcf, 0x0b, - 0x1b, 0xc4, 0xc2, 0x72, 0xd7, 0x72, 0x38, 0x9b, - 0xea, 0xeb, 0xee, 0xae, 0x34, 0xc8, 0x01, 0xd7, - 0xa5, 0xe3, 0xce, 0x41, 0xad, 0x02, 0x60, 0x23, - 0x18, 0x36, 0xba, 0x17, 0xfa, 0xcf, 0xe4, 0xda, - 0xdc, 0xfc, 0x82, 0xdc, 0x7c, 0x11, 0xf4, 0xb8, - 0x52, 0x5d, 0xf7, 0x2f, 0xc8, 0xfe, 0x4a, 0xe6, - 0xb9, 0xaf, 0x4b, 0x17, 0x18, 0x91, 0xc2, 0xfe, - 0xd7, 0x3a, 0x77, 0x0c, 0xa0, 0x43, 0x9c, 0x6f, - 0x13, 0x06, 0xbe, 0x6e, 0xe0, 0x1a, 0x3c, 0xf3, - 0xf5, 0xcc, 0x78, 0xfb, 0x5d, 0xd5, 0xda, 0xb7, - 0x58, 0xea, 0x86, 0x42, 0x6b, 0x32, 0xff, 0xb2, - 0xe2, 0xee, 0x03, 0x1f, 0xf4, 0xef, 0xdb, 0x53, - 0x79, 0xd5, 0x4e, 0xaf, 0x60, 0x8e, 0x02, 0xc2, - 0xcc, 0x39, 0x97, 0x7b, 0xfd, 0xa1, 0xf8, 0x7a, - 0x26, 0xe8, 0x55, 0xd6, 0xa4, 0x8b, 0xa0, 0x1b, - 0x2d, 0x63, 0xaa, 0x73, 0x71, 0x6e, 0xbf, 0x8b, - 0x3b, 0xe3, 0x1b, 0x0d, 0xbb, 0x2e, 0x44, 0x09, - 0x64, 0xac, 0xc7, 0x9e, 0xb5, 0xc6, 0x77, 0xb0, - 0x79, 0xb3, 0xaa, 0xfc, 0x67, 0x57, 0x9a, 0x50, - 0x81, 0x37, 0x14, 0x7c, 0xd7, 0xa0, 0xd4, 0x6a, - 0x79, 0x84, 0x51, 0x0e, 0x95, 0x0a, 0x30, 0xa3, - 0x60, 0x55, 0x48, 0x05, 0x16, 0xae, 0x43, 0x90, - 0xdc, 0x8e, 0x09, 0xbe, 0x79, 0xf6, 0x90, 0x74, - 0xf8, 0x20, 0x96, 0x4d, 0xa7, 0xf5, 0x1a, 0x2b, - 0xc7, 0x15, 0x9d, 0x18, 0xf7, 0x94, 0x87, 0xf7, - 0xf4, 0xfb, 0x0d, 0x61, 0xb6, 0xd7, 0xbe, 0x10, - 0x8e, 0x47, 0x3c, 0x10, 0x44, 0x90, 0x52, 0x21, - 0x83, 0xc0, 0xf5, 0x99, 0xaa, 0xbc, 0xf6, 0x55, - 0xae, 0xf5, 0xb2, 0xa4, 0xcd, 0x4d, 0xb9, 0x38, - 0x6c, 0xbc, 0x80, 0xc3, 0xad, 0xf4, 0x46, 0x31, - 0x01, 0x58, 0x2d, 0x88, 0x57, 0xc3, 0x23, 0xd1, - 0x64, 0xc9, 0xa3, 0x21, 0x6b, 0x8b, 0x8a, 0x23, - 0x2c, 0x4f, 0xa9, 0xcd, 0x67, 0xfa, 0x77, 0xad, - 0xa3, 0x16, 0xa2, 0xe5, 0x19, 0x14, 0x70, 0x41, - 0x5b, 0xda, 0x14, 0xde, 0xe3, 0xe5, 0xc1, 0x15, - 0xb4, 0x77, 0xa4, 0x9b, 0xb8, 0xb1, 0x28, 0x51, - 0x30, 0xb4, 0xf1, 0xf3, 0xf8, 0x6d, 0xd0, 0xc3, - 0x8c, 0x4c, 0x76, 0xb0, 0x9a, 0xdf, 0xc8, 0xbe, - 0xf8, 0x4a, 0x61, 0x6e, 0x3e, 0xd6, 0x3c, 0xe8, - 0xde, 0x56, 0xa0, 0x9c, 0x25, 0xbe, 0xce, 0x93, - 0x1f, 0x88, 0xfb, 0x9a, 0x1a, 0xe2, 0xff, 0x88, - 0xad, 0x10, 0xcb, 0x6c, 0xd6, 0xe7, 0x39, 0x0b, - 0xe5, 0x1a, 0x06, 0x05, 0x64, 0x5b, 0x0a, 0xdf, - 0x22, 0x58, 0xd7, 0xfb, 0x88, 0x12, 0xdd, 0xb7, - 0x52, 0x3a, 0xc9, 0xbf, 0x49, 0xdf, 0x8c, 0x87, - 0x9f, 0x84, 0xb5, 0x0a, 0xf6, 0x00, 0x52, 0xae, - 0x67, 0x12, 0x1a, 0x8c, 0x71, 0x15, 0xf5, 0xa1, - 0x13, 0x39, 0xf0, 0x91, 0x7e, 0x88, 0x7c, 0xb3, - 0x95, 0x50, 0x02, 0xa6, 0x63, 0xb5, 0x64, 0xfb, - 0x90, 0x87, 0x61, 0xe2, 0x27, 0xaf, 0x11, 0x0c, - 0x73, 0x83, 0xef, 0xa9, 0x28, 0xfe, 0xc8, 0x85, - 0x1a, 0x3a, 0xde, 0xf2, 0xe5, 0x25, 0x64, 0x6d, - 0xaa, 0x41, 0x4c, 0x80, 0x2e, 0x84, 0xff, 0xc1, - 0xc0, 0x54, 0x0c, 0x29, 0x1b, 0xa3, 0x07, 0x7c, - 0x33, 0x4c, 0x10, 0xf6, 0x6f, 0x79, 0xdf, 0xd3, - 0xf0, 0x24, 0x57, 0xf1, 0x60, 0xe1, 0xf0, 0xbd, - 0xc4, 0x1f, 0xf4, 0x67, 0xd2, 0xd3, 0xcc, 0x6a, - 0x07, 0x72, 0x44, 0x16, 0x85, 0x46, 0xd0, 0x73, - 0x87, 0xa9, 0xc7, 0x2f, 0xd1, 0xf5, 0xec, 0xe3, - 0x28, 0xa3, 0x93, 0x4f, 0xd7, 0x76, 0xc1, 0x3c, - 0x0d, 0x13, 0x33, 0xcf, 0x5b, 0xbd, 0x6a, 0x52, - 0x4e, 0xee, 0xc8, 0x5e, 0xa1, 0x58, 0x4a, 0x08, - 0x81, 0xd9, 0x23, 0xcc, 0xfb, 0x1c, 0xb2, 0xd8, - 0xa3, 0xe4, 0x53, 0xfe, 0xf4, 0x4b, 0x48, 0xc1, - 0x20, 0xa4, 0x97, 0xf8, 0x38, 0xa3, 0x69, 0xc1, - 0x11, 0xf0, 0xa1, 0x3b, 0xa9, 0x9a, 0x12, 0x61, - 0xe8, 0x8d, 0x99, 0x44, 0x3f, 0x94, 0x72, 0x82, - 0x19, 0x96, 0x62, 0xb0, 0xa6, 0x64, 0x05, 0x19, - 0x8f, 0xd6, 0x5d, 0x05, 0xbf, 0x79, 0x9e, 0x9d, - 0xe4, 0x93, 0x4c, 0xad, 0x61, 0x8c, 0x18, 0xda, - 0xb6, 0x2e, 0xb3, 0xca, 0x14, 0x4d, 0x53, 0xa4, - 0x97, 0x27, 0x10, 0x56, 0xa2, 0x67, 0x5a, 0x5a, - 0x5e, 0x13, 0xc0, 0xdb, 0xa7, 0x9f, 0x45, 0x5b, - 0xeb, 0x1a, 0x14, 0x0c, 0x8c, 0x38, 0x5e, 0x77, - 0x9a, 0xec, 0x75, 0x68, 0x93, 0x65, 0x02, 0x9c, - 0xfb, 0x62, 0x60, 0x49, 0xdd, 0xb2, 0x2a, 0x67, - 0x86, 0xe3, 0x8a, 0x7d, 0x8c, 0x46, 0x78, 0x81, - 0x60, 0x69, 0xf2, 0x3f, 0x74, 0x11, 0x35, 0xff, - 0x77, 0xa3, 0x66, 0x20, 0xfc, 0x98, 0x4a, 0x35, - 0x7a, 0x52, 0xe4, 0x90, 0x13, 0x80, 0xb9, 0xa6, - 0x73, 0x7a, 0x7d, 0x66, 0x6e, 0x6b, 0xb6, 0x43, - 0x10, 0xd5, 0x91, 0x2b, 0x66, 0xdd, 0x89, 0x87, - 0xe3, 0x8c, 0x58, 0x53, 0x2f, 0x40, 0x74, 0x45, - 0x1b, 0x77, 0x7a, 0xa4, 0x44, 0x19, 0x78, 0xba, - 0x87, 0x10, 0x41, 0x31, 0x32, 0x5f, 0x87, 0x68, - 0xde, 0x43, 0x4a, 0xef, 0x33, 0xb3, 0x11, 0x83, - 0xa9, 0xc2, 0x6f, 0x8d, 0x34, 0xe2, 0x95, 0x84, - 0x3a, 0x4f, 0x6f, 0x8c, 0x31, 0x1d, 0xb6, 0xf5, - 0x95, 0x0d, 0x01, 0x11, 0x20, 0xdf, 0x72, 0xf3, - 0x3f, 0x9a, 0x33, 0xaa, 0xb1, 0x06, 0x6a, 0x63, - 0x47, 0x91, 0x01, 0xdf, 0xb3, 0x54, 0x36, 0xfd, - 0x06, 0x2d, 0xb8, 0x08, 0xe3, 0xd3, 0x65, 0xac, - 0x66, 0x03, 0xee, 0xa4, 0x63, 0xbd, 0xd4, 0xce, - 0xbd, 0x79, 0xa7, 0x48, 0x38, 0xc5, 0x7d, 0xb5, - 0x71, 0x9a, 0x3c, 0x11, 0x7c, 0x6c, 0xe2, 0x54, - 0x02, 0x5d, 0x42, 0xab, 0x25, 0x93, 0x66, 0x01, - 0x37, 0x78, 0x35, 0x4a, 0x8c, 0x19, 0x4d, 0x00, - 0x75, 0x4f, 0xcc, 0xc0, 0x26, 0x82, 0xc1, 0x35, - 0x8c, 0xc7, 0xc2, 0x59, 0x01, 0x3e, 0x98, 0x22, - 0x88, 0x9c, 0x90, 0x75, 0x05, 0x33, 0x07, 0xb9, - 0x39, 0x81, 0x38, 0x58, 0x10, 0x29, 0xcf, 0xc8, - 0x98, 0xb2, 0x03, 0xd7, 0x5b, 0xb3, 0x18, 0xba, - 0x34, 0x0c, 0x9f, 0xab, 0xd7, 0xed, 0x29, 0x82, - 0x41, 0xe0, 0x20, 0x97, 0x57, 0x92, 0xb2, 0xb8, - 0x10, 0x2d, 0x0b, 0xa2, 0xc5, 0x8f, 0x90, 0x6f, - 0xed, 0x12, 0x56, 0x25, 0xbe, 0xfd, 0x75, 0xf7, - 0xb6, 0xf8, 0x40, 0x67, 0x39, 0x11, 0xfa, 0x15, - 0xae, 0x6a, 0x54, 0x5f, 0x32, 0x2b, 0xf8, 0x48, - 0x55, 0xbe, 0x86, 0x2f, 0x69, 0x48, 0x5b, 0x5d, - 0x4d, 0xb7, 0x35, 0xaa, 0xb6, 0x91, 0x88, 0x19, - 0x96, 0x1c, 0x68, 0xf6, 0x85, 0x9e, 0xb3, 0xb2, - 0xa3, 0x32, 0xd4, 0x52, 0x70, 0xb7, 0x62, 0xe3, - 0x14, 0xb6, 0x78, 0x5f, 0x1b, 0x1d, 0x04, 0x9c, - 0x26, 0x0c, 0x33, 0x94, 0xb1, 0x97, 0x08, 0xdb, - 0x0b, 0x39, 0x29, 0xd4, 0xbc, 0x6d, 0xdf, 0x02, - 0xc6, 0x99, 0xab, 0x99, 0x32, 0xe5, 0xce, 0x51, - 0x4f, 0xae, 0xb8, 0x8b, 0xe0, 0xaf, 0x07, 0xc4, - 0xf9, 0x41, 0x7c, 0x59, 0xa0, 0xac, 0x74, 0x4d, - 0x7e, 0x43, 0x77, 0x9c, 0x06, 0x49, 0x79, 0x8a, - 0x14, 0x73, 0x93, 0xa8, 0x5b, 0x1b, 0x34, 0x29, - 0x78, 0x04, 0x2f, 0xd7, 0x1f, 0x13, 0x90, 0xe0, - 0xdd, 0x3b, 0x42, 0x6b, 0x79, 0x6e, 0x52, 0xc7, - 0x0f, 0x38, 0xda, 0x01, 0x2c, 0x8d, 0xe6, 0x94, - 0x5d, 0x59, 0x27, 0x1d, 0x10, 0x4e, 0x11, 0x36, - 0xfb, 0x53, 0x16, 0x05, 0x25, 0xf2, 0x64, 0xd8, - 0xf9, 0xcd, 0x5c, 0xfe, 0xb4, 0x18, 0x44, 0x80, - 0x10, 0xbc, 0x3d, 0xf3, 0x1d, 0x5a, 0xf0, 0xc1, - 0xc3, 0x55, 0xff, 0x41, 0x3e, 0xe3, 0xef, 0x44, - 0xb2, 0xc0, 0x01, 0x18, 0xa2, 0x49, 0x88, 0x78, - 0x0d, 0x4c, 0xc8, 0x73, 0xcf, 0x30, 0x85, 0x3a, - 0x88, 0x90, 0x01, 0xcf, 0x69, 0x53, 0xa3, 0x18, - 0x3f, 0xd6, 0xe7, 0x94, 0x14, 0xa7, 0xae, 0xcd, - 0x6f, 0x11, 0x72, 0xfe, 0x2b, 0xb0, 0x81, 0x53, - 0xea, 0x67, 0xd6, 0xe4, 0xca, 0x42, 0xa0, 0xf9, - 0xb1, 0xd4, 0xb5, 0x3b, 0xc9, 0xf0, 0x36, 0xc1, - 0x1c, 0xf4, 0xb1, 0xf6, 0x84, 0xd0, 0x86, 0x6c, - 0x76, 0x9a, 0x03, 0xc2, 0xb6, 0x2e, 0x9a, 0x46, - 0xf5, 0x5f, 0x2c, 0x38, 0xac, 0xad, 0x6f, 0x2e, - 0x7a, 0x18, 0x2d, 0x22, 0x95, 0x5e, 0x5e, 0xc9, - 0x7a, 0x0a, 0x56, 0xe1, 0xc7, 0x15, 0xfd, 0xbf, - 0xff, 0xf7, 0x7e, 0x85, 0x20, 0xa9, 0x8a, 0x9c, - 0xa9, 0x7d, 0xe8, 0xed, 0xfc, 0x7f, 0xbb, 0xf0, - 0x05, 0x3f, 0xce, 0x4f, 0x4c, 0xee, 0xa4, 0xa0, - 0xcc, 0x9c, 0x62, 0x1e, 0xd6, 0xd0, 0x30, 0x37, - 0xb8, 0x98, 0x56, 0x1d, 0xaa, 0xd6, 0x5e, 0x73, - 0x12, 0xe4, 0x88, 0x82, 0x48, 0x64, 0x06, 0xd7, - 0x2a, 0x31, 0x50, 0x7b, 0x10, 0x17, 0xb8, 0x4c, - 0x5a, 0x8d, 0xf1, 0xfc, 0xf1, 0x33, 0x3b, 0x98, - 0x42, 0x18, 0x5b, 0x35, 0x78, 0xca, 0x8e, 0x41, - 0x52, 0xae, 0x6d, 0xe1, 0xa2, 0x9d, 0x5b, 0xbd, - 0xf3, 0x5f, 0x49, 0xc1, 0x27, 0x06, 0xc1, 0xaf, - 0xc0, 0xa3, 0x9d, 0xf3, 0x1c, 0x8e, 0x90, 0x8a, - 0xb0, 0x69, 0xb0, 0xc5, 0x11, 0x0c, 0x91, 0x14, - 0x1f, 0x5e, 0x10, 0xe1, 0x1d, 0x14, 0x30, 0x54, - 0x1e, 0x17, 0x3d, 0x31, 0x7b, 0xbf, 0x2f, 0x9d, - 0x6d, 0x63, 0x32, 0xf0, 0x9d, 0x9f, 0x95, 0x3d, - 0x0b, 0xd2, 0x4d, 0x10, 0xe2, 0x3f, 0x67, 0x69, - 0x43, 0x9a, 0x4a, 0x2c, 0x54, 0x71, 0xa8, 0xa0, - 0x9e, 0x9f, 0x10, 0xaf, 0x1b, 0xce, 0x99, 0xe3, - 0x25, 0x32, 0x10, 0x54, 0x80, 0xfe, 0xda, 0x57, - 0xd0, 0xb2, 0x92, 0x7f, 0xbb, 0x5f, 0xe7, 0x4d, - 0x1b, 0x3d, 0x46, 0x4d, 0xe4, 0x4c, 0xd6, 0xaf, - 0x1a, 0x32, 0x12, 0x40, 0xb8, 0x84, 0x8e, 0xe4, - 0x80, 0xce, 0x7e, 0xc1, 0x13, 0x8b, 0xb0, 0xb7, - 0x6f, 0x24, 0xba, 0x85, 0x50, 0x83, 0xc3, 0xcf, - 0x19, 0xb3, 0xf0, 0xc7, 0xee, 0x68, 0xbe, 0x9e, - 0x6d, 0xb9, 0xfb, 0xd5, 0x29, 0xce, 0x82, 0xcd, - 0x69, 0x16, 0x68, 0x6b, 0x6a, 0xf4, 0x02, 0x32, - 0xce, 0x60, 0x37, 0x0c, 0xb9, 0x38, 0x92, 0x9c, - 0x42, 0xa9, 0x0b, 0x53, 0x96, 0xfe, 0x39, 0xc1, - 0x24, 0x65, 0x9b, 0xcd, 0xe7, 0x8d, 0x36, 0x07, - 0x9f, 0x1d, 0x35, 0x8e, 0xdc, 0x4c, 0xb5, 0x68, - 0xc5, 0xfd, 0x44, 0x19, 0xf2, 0x6c, 0x59, 0x1c, - 0xb1, 0x0b, 0x35, 0x48, 0x86, 0x1a, 0x05, 0x22, - 0x03, 0x0c, 0x0c, 0xa2, 0x92, 0x90, 0x35, 0xfb, - 0x37, 0x94, 0xc7, 0x15, 0x84, 0xae, 0xe8, 0x05, - 0xa0, 0xf7, 0x30, 0x11, 0x5c, 0xe4, 0x5d, 0x3e, - 0x12, 0x54, 0x80, 0x54, 0x6b, 0x09, 0x8c, 0xce, - 0x80, 0x5e, 0xa7, 0xc8, 0x6a, 0x0c, 0x56, 0xe1, - 0x18, 0x7d, 0xc9, 0x39, 0xc1, 0xef, 0xe3, 0x25, - 0xa0, 0x8b, 0x2f, 0x60, 0x3a, 0x43, 0x39, 0xa6, - 0x28, 0x28, 0x7b, 0x4c, 0x77, 0xd4, 0x49, 0x61, - 0x46, 0xe9, 0x1b, 0x45, 0xd6, 0xb1, 0x56, 0xe1, - 0x7d, 0x34, 0xcd, 0x06, 0xb6, 0x67, 0x8d, 0x7d, - 0x7a, 0xe2, 0xbe, 0x68, 0x35, 0xa6, 0x78, 0xe5, - 0x47, 0x48, 0xb7, 0xc7, 0xde, 0xcd, 0xc9, 0x05, - 0xb4, 0xe7, 0x50, 0x48, 0xe1, 0x4b, 0xfe, 0x76, - 0x77, 0xc6, 0xf7, 0x5f, 0xcb, 0xc2, 0xa8, 0xd7, - 0xd6, 0x8a, 0xe5, 0x49, 0xd9, 0xca, 0x45, 0xf4, - 0xda, 0xcd, 0x33, 0xd1, 0x59, 0x2d, 0x9e, 0xc1, - 0x5c, 0xe6, 0x01, 0x18, 0xb8, 0xf0, 0x5e, 0xb1, - 0x69, 0x95, 0x2f, 0x02, 0x2a, 0xe7, 0x4a, 0xd7, - 0xd1, 0xc3, 0xd5, 0x6f, 0x15, 0xc8, 0xdc, 0x29, - 0xde, 0xb9, 0x3f, 0x8b, 0xa6, 0xbc, 0xdd, 0x25, - 0x84, 0x35, 0x3c, 0x90, 0x2d, 0xc2, 0x1e, 0x98, - 0x8a, 0x50, 0x09, 0x77, 0x42, 0xe9, 0x35, 0x8a, - 0x7c, 0x97, 0xbf, 0xe8, 0xbf, 0x56, 0xd0, 0x8b, - 0x65, 0xd3, 0xaf, 0x1e, 0x05, 0x94, 0xfa, 0xac, - 0xa8, 0x2b, 0x28, 0xcb, 0x37, 0x3e, 0xe8, 0xbb, - 0x66, 0x3a, 0xed, 0xb2, 0x48, 0x10, 0x0f, 0x3a, - 0x5a, 0xc5, 0xdb, 0x26, 0x0e, 0xaa, 0x5e, 0x69, - 0x15, 0xd6, 0x81, 0xae, 0xbd, 0xe6, 0x03, 0xf1, - 0xf6, 0x37, 0xc8, 0xde, 0x70, 0x1f, 0x64, 0xb9, - 0x5e, 0xbf, 0x2e, 0x4f, 0xb1, 0xea, 0xa0, 0x17, - 0xe6, 0x7c, 0xf9, 0x2f, 0x1e, 0xd8, 0x58, 0xde, - 0xa7, 0xf0, 0x46, 0x52, 0x95, 0xdf, 0xa4, 0x96, - 0xd0, 0xc4, 0x97, 0x2b, 0x95, 0xcd, 0x5e, 0x40, - 0x23, 0x5c, 0x10, 0xee, 0xba, 0x72, 0x9b, 0xcf, - 0x0b, 0xe8, 0x18, 0x3a, 0x70, 0xd2, 0x5e, 0x07, - 0x68, 0x93, 0xef, 0x4a, 0x5b, 0x8d, 0x72, 0x41, - 0x4e, 0xea, 0x33, 0x6a, 0x0a, 0x5e, 0xfb, 0x02, - 0x3f, 0xd4, 0xed, 0x5b, 0xe0, 0x42, 0x84, 0xd4, - 0xaa, 0x85, 0xdc, 0x5b, 0x67, 0xee, 0x71, 0x67, - 0xba, 0x8e, 0xd2, 0xbe, 0x61, 0xdf, 0x5a, 0x26, - 0xb9, 0xf0, 0x77, 0x81, 0x53, 0x24, 0x16, 0xcb, - 0x8c, 0xb8, 0x06, 0x6e, 0x68, 0xda, 0xc8, 0x2d, - 0x17, 0x54, 0xdb, 0x46, 0xcb, 0xfd, 0x1f, 0x3d, - 0x94, 0x81, 0x09, 0x4b, 0xfa, 0xb1, 0x46, 0xd9, - 0x11, 0xa3, 0xb7, 0x31, 0x9c, 0xd2, 0x38, 0xd6, - 0xba, 0x3d, 0xa3, 0x74, 0xd8, 0xf1, 0x24, 0xe8, - 0x9c, 0xcb, 0x1d, 0xf9, 0x4a, 0xf7, 0xc8, 0x4b, - 0xfe, 0x97, 0x7c, 0xa1, 0x02, 0xeb, 0x40, 0xc3, - 0x89, 0x71, 0x01, 0xcd, 0x33, 0x2a, 0xc2, 0x82, - 0xce, 0x62, 0x8d, 0x53, 0x7c, 0xdf, 0xce, 0xd7, - 0xf5, 0xa8, 0x4f, 0xf2, 0xf2, 0x2e, 0xc1, 0xeb, - 0x97, 0x99, 0x37, 0x3c, 0x53, 0xa6, 0xb4, 0x46, - 0x05, 0x64, 0x92, 0x87, 0x08, 0x3c, 0x23, 0x4b, - 0x9d, 0x67, 0x18, 0xf9, 0xe2, 0x0b, 0x1c, 0x39, - 0xd3, 0x87, 0x70, 0xc0, 0xb9, 0x1e, 0x52, 0x0a, - 0x0f, 0x48, 0xe2, 0xe7, 0x51, 0x72, 0x94, 0xf7, - 0xa3, 0xdc, 0xe5, 0x66, 0x33, 0x39, 0x54, 0x06, - 0x55, 0x93, 0x30, 0xf9, 0x5e, 0x76, 0x8f, 0xe0, - 0x59, 0x4d, 0x0d, 0xa7, 0xf5, 0xbe, 0xdb, 0x20, - 0xad, 0x0d, 0x76, 0x88, 0x5f, 0x9c, 0x7c, 0x75, - 0x2f, 0x2a, 0x0b, 0x79, 0x6e, 0xd3, 0xe2, 0x66, - 0xf5, 0x4a, 0x2d, 0x87, 0x87, 0x49, 0x84, 0x17, - 0xa2, 0x62, 0x4c, 0xbb, 0xe4, 0x6e, 0x98, 0x10, - 0xc9, 0xfb, 0x8a, 0x04, 0x68, 0x8d, 0x22, 0x66, - 0xad, 0xea, 0x2a, 0xc9, 0x97, 0x2d, 0x3c, 0xbc, - 0xd0, 0x77, 0x5f, 0xe6, 0xb8, 0x7f, 0xe6, 0xf6, - 0x39, 0xbf, 0x56, 0x0e, 0x26, 0x6d, 0xc5, 0x3e, - 0x53, 0x19, 0xd6, 0xb4, 0x57, 0x36, 0xa3, 0xc6, - 0xd3, 0x3d, 0x66, 0x79, 0x30, 0x5c, 0x14, 0x0c, - 0x0f, 0x3e, 0x96, 0xae, 0x90, 0x97, 0xab, 0x0d, - 0x9f, 0xc3, 0xe7, 0x66, 0x3e, 0xe0, 0x31, 0x43, - 0x4b, 0x01, 0xb3, 0x0e, 0x9e, 0x8c, 0x82, 0x4a, - 0x8c, 0xc7, 0x79, 0x85, 0xdf, 0x75, 0x0d, 0xb4, - 0x2b, 0x03, 0x14, 0xef, 0x72, 0x58, 0xfd, 0x64, - 0xc8, 0xe3, 0x0d, 0x9a, 0x14, 0x6f, 0x76, 0xf9, - 0x46, 0xd1, 0xd2, 0x81, 0xb3, 0x16, 0x6e, 0xc7, - 0x76, 0x82, 0xce, 0xf4, 0xee, 0x33, 0x00, 0xe6, - 0x77, 0xc4, 0xad, 0x4f, 0x06, 0xa7, 0x48, 0x80, - 0x9e, 0x21, 0x66, 0xca, 0x75, 0x69, 0x57, 0xcb, - 0xf0, 0x67, 0x6a, 0xaa, 0x8f, 0x88, 0x14, 0xbd, - 0x65, 0x62, 0xe2, 0xad, 0xcc, 0x22, 0x88, 0x7b, - 0x94, 0xbd, 0x0e, 0xcd, 0xb6, 0x69, 0xa2, 0xcb, - 0x7d, 0x57, 0x5c, 0xb4, 0x92, 0x80, 0x13, 0x99, - 0x84, 0xf3, 0x79, 0x0a, 0x2d, 0x70, 0xa4, 0xe0, - 0xde, 0xc6, 0x32, 0xb0, 0x8a, 0x62, 0xb5, 0xcf, - 0xfa, 0x5e, 0x5a, 0x92, 0x32, 0x7d, 0x34, 0x07, - 0xb5, 0x52, 0x3a, 0xb5, 0x7d, 0x0f, 0xa1, 0xba, - 0x56, 0xd0, 0x07, 0x76, 0x11, 0xf2, 0xc3, 0x33, - 0x9d, 0xbd, 0x12, 0x35, 0x5e, 0xf7, 0x05, 0x88, - 0x76, 0x94, 0xa6, 0xbf, 0xed, 0xb8, 0xa4, 0xa2, - 0x0c, 0xbe, 0x0f, 0x6a, 0xaf, 0xf3, 0x1b, 0x33, - 0x4a, 0xb7, 0x68, 0x3f, 0xbe, 0x95, 0x13, 0x97, - 0x0f, 0x15, 0x17, 0x1b, 0x23, 0xaa, 0x08, 0x78, - 0xa6, 0x5b, 0x08, 0xa2, 0x9d, 0x03, 0xa8, 0xa7, - 0x39, 0xdc, 0xbc, 0x9a, 0x85, 0xf5, 0xe5, 0x55, - 0x59, 0x3c, 0xef, 0xf9, 0x3f, 0x22, 0x8e, 0xf8, - 0xd8, 0x3e, 0x02, 0x0b, 0xd8, 0x78, 0x4b, 0x15, - 0x7f, 0xaa, 0x2c, 0xff, 0xbe, 0x77, 0x33, 0xc7, - 0x6a, 0x12, 0xaa, 0xa4, 0xbe, 0xc0, 0x3b, 0xcb, - 0x13, 0x9d, 0x9c, 0x5a, 0x9f, 0x8a, 0x57, 0x36, - 0x4f, 0x02, 0x5a, 0xf8, 0x1d, 0x97, 0x77, 0x43, - 0xc8, 0xa5, 0xb7, 0x9b, 0x10, 0x98, 0xfd, 0x58, - 0xbf, 0x42, 0xf6, 0xbf, 0xff, 0x6c, 0x40, 0x18, - 0x18, 0xdf, 0xac, 0x57, 0x71, 0xea, 0xcc, 0x8e, - 0xfd, 0xfe, 0x10, 0xfb, 0xb9, 0xfe, 0xbc, 0x9a, - 0x9c, 0x27, 0xe4, 0x10, 0x15, 0x94, 0x41, 0xa1, - 0xcc, 0xf6, 0x25, 0x49, 0x4f, 0x96, 0xc1, 0x8c, - 0x9e, 0x3e, 0x18, 0x29, 0x49, 0x92, 0xe7, 0xfe, - 0x22, 0xff, 0xed, 0x02, 0x16, 0x90, 0xef, 0xac, - 0xec, 0x95, 0x1d, 0x5b, 0x94, 0x9c, 0xf6, 0x7c, - 0x1b, 0x5a, 0x9d, 0xb0, 0x9b, 0x05, 0x36, 0xbf, - 0xef, 0xec, 0x63, 0x35, 0x40, 0x24, 0x45, 0x40, - 0x30, 0x1a, 0x9b, 0x90, 0xc3, 0xc2, 0xf7, 0x37, - 0xfb, 0x08, 0x8e, 0x48, 0x19, 0x48, 0xed, 0xa8, - 0xa8, 0x04, 0x6f, 0xd0, 0x33, 0xe9, 0xb8, 0x8d, - 0xe7, 0x1e, 0x5c, 0x47, 0x74, 0xc0, 0x66, 0x30, - 0x4e, 0xa7, 0x86, 0x73, 0xf1, 0xe5, 0x78, 0xa6, - 0xe0, 0xc1, 0xda, 0x13, 0x72, 0x07, 0x85, 0x34, - 0x63, 0x95, 0x49, 0x30, 0x4b, 0x9d, 0x03, 0xf1, - 0x7a, 0x6b, 0x91, 0xa2, 0x85, 0x41, 0xf9, 0x4a, - 0xd6, 0xff, 0xff, 0x86, 0xf7, 0xf0, 0xce, 0xb9, - 0x07, 0xf1, 0x88, 0x04, 0x33, 0xaa, 0xeb, 0x54, - 0xb2, 0x1c, 0x8e, 0x2e, 0x7b, 0x04, 0xa8, 0xcc, - 0x2c, 0x7a, 0xb3, 0xad, 0x1a, 0x89, 0x38, 0x89, - 0xd7, 0x11, 0x3a, 0x8c, 0xcf, 0xe3, 0xc5, 0xba, - 0xb0, 0xcc, 0xc4, 0xe3, 0x33, 0xf3, 0x18, 0xba, - 0xec, 0x56, 0xd9, 0x1c, 0x40, 0x70, 0x0d, 0x4e, - 0x97, 0x01, 0x23, 0xf3, 0x5a, 0xdc, 0xbf, 0x68, - 0x93, 0xc2, 0x1d, 0x8a, 0x96, 0xb7, 0xac, 0x18, - 0x6f, 0xf7, 0x84, 0x71, 0x0d, 0x3d, 0xf8, 0xba, - 0xdf, 0xb6, 0x89, 0x1d, 0x78, 0x19, 0xf2, 0x59, - 0xe9, 0x15, 0x55, 0x29, 0x73, 0x50, 0x59, 0x14, - 0x02, 0x21, 0x16, 0x8f, 0x0f, 0xdf, 0xa5, 0xf0, -}; - -static struct crc_test { - uint32_t crc; /* random starting crc */ - uint32_t start; /* random offset in buf */ - uint32_t length; /* random length of test */ - uint32_t crc_le; /* expected crc32_le result */ - uint32_t crc_be; /* expected crc32_be result */ -} test[] = { - {0xffffffff, 0x00000000, 0x00001000, 0x13934bef, 0x14f3b75f}, - {0xfe7328ea, 0x00000763, 0x00000717, 0xed2c0d70, 0x57531214}, - {0x4c40684e, 0x00000721, 0x0000011e, 0xd7f46ccc, 0xedf12ec3}, - {0x6b487f90, 0x00000264, 0x000007bc, 0x759e9939, 0x9af8e387}, - {0x9f5810db, 0x00000afa, 0x00000255, 0x2685197f, 0x716de6ed}, - {0xb15c4755, 0x00000d5b, 0x000002a4, 0xd8fadcb5, 0xfc34ae3f}, - {0x06518253, 0x00000ffb, 0x00000004, 0xabee2433, 0xfa30ac9e}, - {0xd9e71c55, 0x00000a2a, 0x00000259, 0x96682af2, 0xe5907ea3}, - {0x0c1ae843, 0x00000ce4, 0x0000031b, 0x7b637c43, 0xe7f71b04}, - {0xec3cd517, 0x000002ff, 0x00000566, 0x5d719a77, 0xed16e045}, - {0x77828e95, 0x0000067f, 0x0000038f, 0x43ee5b6c, 0x35999927}, - {0xec87b4e3, 0x00000d1c, 0x000002e3, 0x2ddd2eee, 0x9452d3f8}, - {0x412158bb, 0x00000eee, 0x00000111, 0x67b38ba2, 0x177976d0}, - {0x2e52de3e, 0x00000c4a, 0x000003b5, 0xbcc5d61d, 0xf60fee71}, - {0x6ddaae8b, 0x00000d99, 0x00000266, 0x8b535544, 0x1dab8596}, - {0x049b6cb1, 0x000009c5, 0x000000b0, 0xfc22cabc, 0x47ebc954}, - {0x77d4b954, 0x0000028a, 0x000007fa, 0x71d00923, 0x905585ef}, - {0x5e192355, 0x00000ac1, 0x000001fa, 0xb966b81a, 0x33c12903}, - {0x7d80b71d, 0x00000213, 0x000001e0, 0x2bba371a, 0x5f4bd8d9}, - {0x01f6f1e4, 0x000001d6, 0x00000395, 0xb7e8a647, 0x2a7943a1}, - {0x1dfabb13, 0x00000e14, 0x000001eb, 0x53917fba, 0x8dee1e5d}, - {0xb00a4449, 0x00000bf6, 0x00000409, 0xedecb577, 0x628e087d}, - {0x7ecd3981, 0x0000083f, 0x0000016b, 0xefef62b9, 0xda4f94e6}, - {0xf8f330d2, 0x000004be, 0x00000757, 0x9357c9f3, 0x8e2d5c2f}, - {0x03c38af2, 0x00000d23, 0x000002dc, 0x360fa8c0, 0x6294c0d6}, - {0x687bb79b, 0x00000f3d, 0x000000c2, 0x448d3be2, 0x08f48f3a}, - {0x6710f550, 0x000009e9, 0x00000603, 0xdbfd1998, 0xc950ac29}, - {0x873171d1, 0x00000787, 0x000004d5, 0xab7f1b62, 0xe66896ab}, - {0x373b1314, 0x00000f0f, 0x000000f0, 0x184098ab, 0x4038e674}, - {0x90fad9cd, 0x00000ead, 0x00000152, 0x23ce52ff, 0x9eff3974}, - {0x19676fe7, 0x0000007d, 0x0000070d, 0xf8a76f1e, 0xfbc5c8a9}, - {0x89facd45, 0x000005f3, 0x00000473, 0x4331a006, 0xb8f0f0cc}, - {0x6f173747, 0x00000fc3, 0x0000003c, 0xb012f08e, 0x5126e378}, - {0x4b44a106, 0x0000075a, 0x0000008b, 0xf6f7ac38, 0xf9b1781b}, - {0xb620ad06, 0x00000774, 0x0000017e, 0xd34558e6, 0xb175edd3}, - {0x976f21e9, 0x000008d7, 0x0000034a, 0xe533aa3a, 0x1e4367b9}, - {0x687628c0, 0x000006c5, 0x0000061b, 0x3a840b15, 0xfb5989a0}, - {0xe24ac108, 0x00000cd0, 0x0000032f, 0x51010ae8, 0xcdd8f182}, - {0x361c44a3, 0x00000304, 0x00000719, 0xfd7bd481, 0x12de540f}, - {0xd93ff95e, 0x00000db7, 0x0000008e, 0xcfbbc304, 0x42eecd5a}, - {0xed752d12, 0x00000883, 0x00000091, 0x65a6c868, 0x9ebfa578}, - {0xb4ff4b54, 0x000003d3, 0x000001c1, 0xf82597e7, 0xa8ad2b19}, - {0x111b520f, 0x00000708, 0x000000eb, 0xc3e109f3, 0x323ace17}, - {0x62c806f2, 0x00000ba3, 0x0000045c, 0x874d3a72, 0xaf1a1360}, - {0x40d97470, 0x000005e1, 0x0000058d, 0x87a9684f, 0x524244a8}, - {0x4312179c, 0x00000056, 0x0000070e, 0x809a00f5, 0xf9e940b0}, - {0x13d5f84c, 0x00000a2d, 0x00000104, 0xf3d27578, 0x5d33341c}, - {0x1f302cb2, 0x00000151, 0x00000014, 0x1e162693, 0x53c3cfc3}, - {0xe491db24, 0x00000600, 0x000006f6, 0x7ff09615, 0xa300ecf7}, - {0xf9a98069, 0x000002ba, 0x000002ad, 0x01af7387, 0x31c0911e}, - {0xe9c477ad, 0x0000015f, 0x00000778, 0x6facf9a0, 0x1993b688}, - {0x353f32b2, 0x0000087c, 0x00000783, 0x6cc964ea, 0x418db561}, - {0x78e1b24f, 0x00000650, 0x000006a8, 0xb3bb7c27, 0xf2aad006}, - {0x61aa400e, 0x00000049, 0x00000254, 0xb8cd1681, 0x79150b15}, - {0xb84b10b0, 0x00000f73, 0x0000008c, 0x406a6450, 0x0c705222}, - {0x9fa99c9c, 0x00000a7c, 0x000004d7, 0xfb3d21b4, 0xe4e789df}, - {0x3fc9ebe3, 0x00000cd9, 0x000000d6, 0x43803f9c, 0x5a152be5}, - {0x529879cd, 0x000002f2, 0x00000595, 0x78b4c6a6, 0xf7236ec4}, - {0x3a933019, 0x00000516, 0x00000266, 0xdcb45436, 0x2c7935f5}, - {0x887b4977, 0x00000227, 0x0000038d, 0xc5f7c3d9, 0x0d6d7df6}, - {0x770745de, 0x000008c6, 0x00000739, 0xf69145e8, 0x47d5efc9}, - {0x28be3b47, 0x00000c46, 0x0000032b, 0x764c028f, 0x1eb70d64}, - {0x5013a050, 0x00000cf6, 0x00000309, 0xea8fe164, 0x186affa4}, - {0x2ec4c9ba, 0x000006e8, 0x0000078d, 0xa35557a9, 0xb41f49ec}, - {0xa9f950c9, 0x00000d33, 0x000002cc, 0x41ea8618, 0xab8dfae3}, - {0x5b520229, 0x000007b2, 0x00000484, 0x44569f1f, 0x607a8052}, - {0xd8dcbbfc, 0x0000002f, 0x0000048c, 0xdb88ab8b, 0xf1c411f1}, - {0x25529792, 0x00000d1d, 0x000002e2, 0x20cda404, 0x32683a2d}, - {0x9f3f6d71, 0x00000238, 0x0000079a, 0x0720443e, 0x4b8ba2ff}, - {0x64121215, 0x000007ff, 0x0000038f, 0x6aacff2c, 0x3b84233b}, - {0xfb6cdde0, 0x00000ef8, 0x00000107, 0xbd43a0f1, 0x926624d0}, - {0x221c9d6f, 0x000007b6, 0x0000014f, 0xb67f834b, 0x2bdedda4}, - {0x030e1de4, 0x00000836, 0x000004b4, 0x0d67d26a, 0x75a73b73}, - {0xb56fa6cf, 0x00000c07, 0x000003f8, 0x60601ac1, 0x10a43f35}, - {0xb55c89f5, 0x0000098e, 0x000001d4, 0x2400efbe, 0x006e28eb}, - {0x5e90b6d5, 0x0000070b, 0x000003ea, 0x3bb5d6ea, 0xb175fa6b}, - {0x2a7045ae, 0x00000961, 0x00000633, 0xfca89e4b, 0x962cd6d2}, - {0x8b374ea9, 0x000006ba, 0x00000780, 0xbce036ed, 0x4dc8279b}, - {0x8bd90bc9, 0x00000562, 0x00000369, 0xcb26a24b, 0x50dee743}, - {0x5b1b1762, 0x000000fd, 0x0000051a, 0x33cdda07, 0xee75ff7b}, - {0xa4153555, 0x0000058f, 0x000005c7, 0xbe50eeca, 0xe73fffcc}, - {0x0be1f931, 0x00000651, 0x00000672, 0x95a25753, 0x4ad6270f}, - {0xb7e78618, 0x00000a7f, 0x000002bb, 0xe06bcc1c, 0x1a35ee59}, - {0x4a9bc41b, 0x00000e51, 0x000001ae, 0x709e8d2c, 0x75080ca8}, - {0xfc359d13, 0x00000440, 0x000002f8, 0x0a58451f, 0x6fa3cfbf}, - {0x5aa48619, 0x000006d1, 0x00000284, 0x928ead83, 0xbd600efc}, - {0xa609afa8, 0x0000053e, 0x00000272, 0xb048c141, 0x184f80bb}, - {0x3f108afb, 0x00000949, 0x00000150, 0x9a6bb5bc, 0x0ea02be1}, - {0x79bec2d3, 0x000008ed, 0x00000712, 0x32692d57, 0x2eb13289}, - {0x9429e067, 0x00000bc3, 0x0000043c, 0x5295ceff, 0x8a9014a7}, - {0xae58b96a, 0x0000082d, 0x000007d2, 0xc2a681ba, 0x6af94089}, - {0x95df24be, 0x00000985, 0x000004c1, 0x3a287765, 0x379fcb42}, - {0x5e94976f, 0x00000596, 0x000004ed, 0xff00c489, 0x991fc1f5}, - {0xf5e5f1de, 0x00000d31, 0x000002ce, 0x35f28e91, 0x543def1a}, - {0xa2c219cf, 0x00000a3c, 0x00000374, 0x707d21eb, 0xa6d28bc1}, - {0xf21b6ceb, 0x00000919, 0x00000135, 0x0847fb8b, 0x224468c2}, - {0xaa988728, 0x00000787, 0x00000771, 0x885aeaa4, 0x814db00b}, - {0xaa5dfaac, 0x000003e5, 0x0000051b, 0x52c48ab7, 0x725bef8a}, - {0x0a053968, 0x00000d2a, 0x000002d5, 0x7a90256d, 0xc53b9402}, - {0x1421dc20, 0x00000eef, 0x00000110, 0x97d6da24, 0x10846935}, - {0xb47c2166, 0x00000a6a, 0x00000209, 0xcfd6cc52, 0x46e2797e}, - {0x77dd1955, 0x000000de, 0x00000266, 0xba74bcaa, 0x4fa3fe9c}, - {0x68a03cc2, 0x0000082f, 0x000007b0, 0x752bd5d8, 0x4f760c63}, - {0x0226b0a3, 0x00000a5f, 0x000005a0, 0x82de4970, 0x8ee1310e}, - {0x637bf3b1, 0x00000d93, 0x0000026c, 0x5c7115cb, 0x9f6a0ced}, - {0x3b120edf, 0x00000c13, 0x000003ec, 0x80d7d20f, 0x241657d5}, - {0xe2456780, 0x000002eb, 0x00000641, 0xc0a5d289, 0x74df96b4}, - {0x9b2e7125, 0x00000c0c, 0x000003f3, 0xcc15f57e, 0x03e290bf}, - {0x153033ef, 0x00000787, 0x000006b6, 0x3cde443b, 0x7bf1d121}, - {0x18458b3f, 0x0000066c, 0x00000561, 0x9a2bd8c6, 0x9d564bef}, - {0x4ff9d4b9, 0x00000c8f, 0x0000033a, 0xd0ee6d6d, 0xee00aa0b}, - {0xdf84b5d9, 0x00000802, 0x0000029a, 0xdab0d74a, 0xd0cb63dc}, - {0x81ee15df, 0x000003ce, 0x00000725, 0x9942e2de, 0xe48fb26b}, - {0x5c768e04, 0x00000afd, 0x00000160, 0x36110831, 0x8dc74483}, - {0xe5e18094, 0x00000b4b, 0x000000a0, 0xffa3e4a7, 0xc0145e1b}, - {0xed7263b6, 0x00000d0d, 0x000002f2, 0xb0006a35, 0x5468ae3a}, - {0x5bfde7d7, 0x000006fb, 0x00000554, 0xa4193b76, 0xb73d34b2}, - {0x67f4a743, 0x00000b85, 0x0000047a, 0xf05c8d8f, 0x4f843e49}, - {0xf13bdf22, 0x00000ff7, 0x00000008, 0x816351eb, 0x41f537f6}, - {0x08ecc608, 0x00000d5d, 0x00000098, 0x90492772, 0xf5172204}, - {0x296f52ba, 0x000004f9, 0x00000788, 0x5e5a4896, 0xe01d5b46}, - {0xbe4624c2, 0x00000427, 0x000004ef, 0xcd267b94, 0x7b9069f4}, - {0x906f7c7c, 0x00000a05, 0x0000003f, 0x03fcfc33, 0x7b6ff563}, - {0x8f7b323e, 0x00000458, 0x000004c7, 0xcd4969c8, 0xd4c22ada}, - {0x88d6593d, 0x00000597, 0x000005b5, 0xf199cd3b, 0x5c3e8ca2}, - {0x978a7768, 0x00000268, 0x000001d3, 0xb28c95bd, 0x49a2cc67}, - {0x857a621e, 0x000007a7, 0x000003a8, 0xf4bf84ab, 0xde26f369}, - {0xb0e121ef, 0x000005be, 0x00000644, 0x28747c14, 0x61d4dc6b}, - {0, 0, 0, 0, 0}, -}; - -static int test_crc32c(void) -{ - struct crc_test *t = test; - int failures = 0; - - while (t->length) { - uint32_t be, le; - le = ext2fs_crc32c_le(t->crc, test_buf + t->start, t->length); - be = ext2fs_crc32c_be(t->crc, test_buf + t->start, t->length); - if (le != t->crc_le) { - printf("Test %d LE fails, %x != %x\n", - (int) (t - test), le, t->crc_le); - failures++; - } - if (be != t->crc_be) { - printf("Test %d BE fails, %x != %x\n", - (int) (t - test), be, t->crc_be); - failures++; - } - t++; - } - - return failures; -} - -int main(int argc, char *argv[]) -{ - int ret; - - ret = test_crc32c(); - if (!ret) - printf("No failures.\n"); - - return ret; -} -#endif /* UNITTEST */ diff --git a/lib/ext2fs/crc32c_defs.h b/lib/ext2fs/crc32c_defs.h deleted file mode 100644 index 023f2c01..00000000 --- a/lib/ext2fs/crc32c_defs.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This is the CRC32c polynomial, as outlined by Castagnoli. - * x^32+x^28+x^27+x^26+x^25+x^23+x^22+x^20+x^19+x^18+x^14+x^13+x^11+x^10+x^9+ - * x^8+x^6+x^0 - */ -#define CRCPOLY_LE 0x82F63B78 -#define CRCPOLY_BE 0x1EDC6F41 - -/* How many bits at a time to use. Valid values are 1, 2, 4, 8, 32 and 64. */ -/* For less performance-sensitive, use 4 */ -#ifndef CRC_LE_BITS -# define CRC_LE_BITS 64 -#endif -#ifndef CRC_BE_BITS -# define CRC_BE_BITS 64 -#endif - -/* - * Little-endian CRC computation. Used with serial bit streams sent - * lsbit-first. Be sure to use cpu_to_le32() to append the computed CRC. - */ -#if CRC_LE_BITS > 64 || CRC_LE_BITS < 1 || CRC_LE_BITS == 16 || \ - CRC_LE_BITS & CRC_LE_BITS-1 -# error "CRC_LE_BITS must be one of {1, 2, 4, 8, 32, 64}" -#endif - -/* - * Big-endian CRC computation. Used with serial bit streams sent - * msbit-first. Be sure to use cpu_to_be32() to append the computed CRC. - */ -#if CRC_BE_BITS > 64 || CRC_BE_BITS < 1 || CRC_BE_BITS == 16 || \ - CRC_BE_BITS & CRC_BE_BITS-1 -# error "CRC_BE_BITS must be one of {1, 2, 4, 8, 32, 64}" -#endif - - -#define ___constant_swab32(x) \ - ((uint32_t)( \ - (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \ - (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \ - (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \ - (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24))) - - -#if (__GNUC__ >= 3) -#define likely(x) __builtin_expect(!!(x), 1) -#define unlikely(x) __builtin_expect(!!(x), 0) -#else -#define likely(x) (x) -#define unlikely(x) (x) -#endif diff --git a/lib/ext2fs/csum.c b/lib/ext2fs/csum.c index b588ead3..10f3423d 100644 --- a/lib/ext2fs/csum.c +++ b/lib/ext2fs/csum.c @@ -29,30 +29,22 @@ #define STATIC static #endif -__u16 ext2fs_group_desc_csum(ext2_filsys fs, dgrp_t group) +STATIC __u16 ext2fs_group_desc_csum(ext2_filsys fs, dgrp_t group) { - struct ext2_group_desc *desc = ext2fs_group_desc(fs, fs->group_desc, - group); - size_t size = EXT2_DESC_SIZE(fs->super); - size_t offset; - __u16 crc; + __u16 crc = 0; + struct ext2_group_desc *desc; + + desc = &fs->group_desc[group]; if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_GDT_CSUM) { - size_t offset = offsetof(struct ext2_group_desc, bg_checksum); + int offset = offsetof(struct ext2_group_desc, bg_checksum); #ifdef WORDS_BIGENDIAN - struct ext4_group_desc swabdesc; - size_t save_size = size; - const size_t ext4_bg_size = sizeof(struct ext4_group_desc); - struct ext2_group_desc *save_desc = desc; + struct ext2_group_desc swabdesc = *desc; /* Have to swab back to little-endian to do the checksum */ - if (size > ext4_bg_size) - size = ext4_bg_size; - memcpy(&swabdesc, desc, size); - ext2fs_swap_group_desc2(fs, - (struct ext2_group_desc *) &swabdesc); - desc = (struct ext2_group_desc *) &swabdesc; + ext2fs_swap_group_desc(&swabdesc); + desc = &swabdesc; group = ext2fs_swab32(group); #endif @@ -61,22 +53,12 @@ __u16 ext2fs_group_desc_csum(ext2_filsys fs, dgrp_t group) crc = ext2fs_crc16(crc, &group, sizeof(group)); crc = ext2fs_crc16(crc, desc, offset); offset += sizeof(desc->bg_checksum); /* skip checksum */ + assert(offset == sizeof(*desc)); /* for checksum of struct ext4_group_desc do the rest...*/ - if (offset < size) { + if (offset < fs->super->s_desc_size) { crc = ext2fs_crc16(crc, (char *)desc + offset, - size - offset); + fs->super->s_desc_size - offset); } -#ifdef WORDS_BIGENDIAN - /* - * If the size of the bg descriptor is greater than 64 - * bytes, which is the size of the traditional ext4 bg - * descriptor, checksum the rest of the descriptor here - */ - if (save_size > ext4_bg_size) - crc = ext2fs_crc16(crc, - (char *)save_desc + ext4_bg_size, - save_size - ext4_bg_size); -#endif } return crc; @@ -86,7 +68,7 @@ int ext2fs_group_desc_csum_verify(ext2_filsys fs, dgrp_t group) { if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, EXT4_FEATURE_RO_COMPAT_GDT_CSUM) && - (ext2fs_bg_checksum(fs, group) != + (fs->group_desc[group].bg_checksum != ext2fs_group_desc_csum(fs, group))) return 0; @@ -95,13 +77,10 @@ int ext2fs_group_desc_csum_verify(ext2_filsys fs, dgrp_t group) void ext2fs_group_desc_csum_set(ext2_filsys fs, dgrp_t group) { - if (!EXT2_HAS_RO_COMPAT_FEATURE(fs->super, - EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) - return; - - /* ext2fs_bg_checksum_set() sets the actual checksum field but - * does not calculate the checksum itself. */ - ext2fs_bg_checksum_set(fs, group, ext2fs_group_desc_csum(fs, group)); + if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, + EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) + fs->group_desc[group].bg_checksum = + ext2fs_group_desc_csum(fs, group); } static __u32 find_last_inode_ingrp(ext2fs_inode_bitmap bitmap, @@ -113,7 +92,7 @@ static __u32 find_last_inode_ingrp(ext2fs_inode_bitmap bitmap, end_ino = start_ino + inodes_per_grp - 1; for (i = end_ino; i >= start_ino; i--) { - if (ext2fs_fast_test_inode_bitmap2(bitmap, i)) + if (ext2fs_fast_test_inode_bitmap(bitmap, i)) return i - start_ino + 1; } return inodes_per_grp; @@ -124,6 +103,7 @@ static __u32 find_last_inode_ingrp(ext2fs_inode_bitmap bitmap, errcode_t ext2fs_set_gdt_csum(ext2_filsys fs) { struct ext2_super_block *sb = fs->super; + struct ext2_group_desc *bg = fs->group_desc; int dirty = 0; dgrp_t i; @@ -134,31 +114,27 @@ errcode_t ext2fs_set_gdt_csum(ext2_filsys fs) EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) return 0; - for (i = 0; i < fs->group_desc_count; i++) { - __u32 old_csum = ext2fs_bg_checksum(fs, i); - __u32 old_unused = ext2fs_bg_itable_unused(fs, i); - __u32 old_flags = ext2fs_bg_flags(fs, i); - __u32 old_free_inodes_count = ext2fs_bg_free_inodes_count(fs, i); + for (i = 0; i < fs->group_desc_count; i++, bg++) { + int old_csum = bg->bg_checksum; + int old_unused = bg->bg_itable_unused; + int old_flags = bg->bg_flags; - if (old_free_inodes_count == sb->s_inodes_per_group) { - ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_UNINIT); - ext2fs_bg_itable_unused_set(fs, i, sb->s_inodes_per_group); + if (bg->bg_free_inodes_count == sb->s_inodes_per_group) { + bg->bg_flags |= EXT2_BG_INODE_UNINIT; + bg->bg_itable_unused = sb->s_inodes_per_group; } else { - int unused = - sb->s_inodes_per_group - + bg->bg_flags &= ~EXT2_BG_INODE_UNINIT; + bg->bg_itable_unused = sb->s_inodes_per_group - find_last_inode_ingrp(fs->inode_map, - sb->s_inodes_per_group, i); - - ext2fs_bg_flags_clear(fs, i, EXT2_BG_INODE_UNINIT); - ext2fs_bg_itable_unused_set(fs, i, unused); + sb->s_inodes_per_group,i); } ext2fs_group_desc_csum_set(fs, i); - if (old_flags != ext2fs_bg_flags(fs, i)) + if (old_flags != bg->bg_flags) dirty = 1; - if (old_unused != ext2fs_bg_itable_unused(fs, i)) + if (old_unused != bg->bg_itable_unused) dirty = 1; - if (old_csum != ext2fs_bg_checksum(fs, i)) + if (old_csum != bg->bg_checksum) dirty = 1; } if (dirty) @@ -173,25 +149,15 @@ void print_csum(const char *msg, ext2_filsys fs, dgrp_t group) { __u16 crc1, crc2, crc3; dgrp_t swabgroup; - struct ext2_group_desc *desc = ext2fs_group_desc(fs, fs->group_desc, - group); - size_t size = EXT2_DESC_SIZE(fs->super); + struct ext2_group_desc *desc = &fs->group_desc[group]; struct ext2_super_block *sb = fs->super; - int offset = offsetof(struct ext2_group_desc, bg_checksum); -#ifdef WORDS_BIGENDIAN - struct ext4_group_desc swabdesc; - struct ext2_group_desc *save_desc = desc; - const size_t ext4_bg_size = sizeof(struct ext4_group_desc); - size_t save_size = size; -#endif #ifdef WORDS_BIGENDIAN + struct ext2_group_desc swabdesc = fs->group_desc[group]; + /* Have to swab back to little-endian to do the checksum */ - if (size > ext4_bg_size) - size = ext4_bg_size; - memcpy(&swabdesc, desc, size); - ext2fs_swap_group_desc2(fs, (struct ext2_group_desc *) &swabdesc); - desc = (struct ext2_group_desc *) &swabdesc; + ext2fs_swap_group_desc(&swabdesc); + desc = &swabdesc; swabgroup = ext2fs_swab32(group); #else @@ -200,19 +166,10 @@ void print_csum(const char *msg, ext2_filsys fs, dgrp_t group) crc1 = ext2fs_crc16(~0, sb->s_uuid, sizeof(fs->super->s_uuid)); crc2 = ext2fs_crc16(crc1, &swabgroup, sizeof(swabgroup)); - crc3 = ext2fs_crc16(crc2, desc, offset); - offset += sizeof(desc->bg_checksum); /* skip checksum */ - /* for checksum of struct ext4_group_desc do the rest...*/ - if (offset < size) - crc3 = ext2fs_crc16(crc3, (char *)desc + offset, size - offset); -#ifdef WORDS_BIGENDIAN - if (save_size > ext4_bg_size) - crc3 = ext2fs_crc16(crc3, (char *)save_desc + ext4_bg_size, - save_size - ext4_bg_size); -#endif - - printf("%s UUID %s=%04x, grp %u=%04x: %04x=%04x\n", - msg, e2p_uuid2str(sb->s_uuid), crc1, group, crc2, crc3, + crc3 = ext2fs_crc16(crc2, desc, + offsetof(struct ext2_group_desc, bg_checksum)); + printf("%s: UUID %s(%04x), grp %u(%04x): %04x=%04x\n", + msg, e2p_uuid2str(sb->s_uuid), crc1, group, crc2,crc3, ext2fs_group_desc_csum(fs, group)); } @@ -228,14 +185,9 @@ int main(int argc, char **argv) __u16 csum1, csum2, csum_known = 0xd3a4; memset(¶m, 0, sizeof(param)); - ext2fs_blocks_count_set(¶m, 32768); -#if 0 - param.s_feature_incompat |= EXT4_FEATURE_INCOMPAT_64BIT; - param.s_desc_size = 128; - csum_known = 0x5b6e; -#endif + param.s_blocks_count = 32768; - retval = ext2fs_initialize("test fs", EXT2_FLAG_64BITS, ¶m, + retval = ext2fs_initialize("test fs", 0, ¶m, test_io_manager, &fs); if (retval) { com_err("setup", retval, @@ -246,13 +198,13 @@ int main(int argc, char **argv) fs->super->s_feature_ro_compat = EXT4_FEATURE_RO_COMPAT_GDT_CSUM; for (i=0; i < fs->group_desc_count; i++) { - ext2fs_block_bitmap_loc_set(fs, i, 124); - ext2fs_inode_bitmap_loc_set(fs, i, 125); - ext2fs_inode_table_loc_set(fs, i, 126); - ext2fs_bg_free_blocks_count_set(fs, i, 31119); - ext2fs_bg_free_inodes_count_set(fs, i, 15701); - ext2fs_bg_used_dirs_count_set(fs, i, 2); - ext2fs_bg_flags_zap(fs, i); + fs->group_desc[i].bg_block_bitmap = 124; + fs->group_desc[i].bg_inode_bitmap = 125; + fs->group_desc[i].bg_inode_table = 126; + fs->group_desc[i].bg_free_blocks_count = 31119; + fs->group_desc[i].bg_free_inodes_count = 15701; + fs->group_desc[i].bg_used_dirs_count = 2; + fs->group_desc[i].bg_flags = 0; }; csum1 = ext2fs_group_desc_csum(fs, 0); @@ -274,7 +226,7 @@ int main(int argc, char **argv) printf("checksums for different groups shouldn't match\n"); exit(1); } - ext2fs_bg_checksum_set(fs, 0, csum1); + fs->group_desc[0].bg_checksum = csum1; csum2 = ext2fs_group_desc_csum(fs, 0); print_csum("csum_set", fs, 0); if (csum1 != csum2) { @@ -291,10 +243,9 @@ int main(int argc, char **argv) printf("checksums for different filesystems shouldn't match\n"); exit(1); } - csum1 = ext2fs_group_desc_csum(fs, 0); - ext2fs_bg_checksum_set(fs, 0, csum1); + csum1 = fs->group_desc[0].bg_checksum = ext2fs_group_desc_csum(fs, 0); print_csum("csum_new", fs, 0); - ext2fs_bg_free_blocks_count_set(fs, 0, 1); + fs->group_desc[0].bg_free_blocks_count = 1; csum2 = ext2fs_group_desc_csum(fs, 0); print_csum("csum_blk", fs, 0); if (csum1 == csum2) { diff --git a/lib/ext2fs/dblist.c b/lib/ext2fs/dblist.c index e5b685a1..84adcb2b 100644 --- a/lib/ext2fs/dblist.c +++ b/lib/ext2fs/dblist.c @@ -20,8 +20,6 @@ #include "ext2fsP.h" static EXT2_QSORT_TYPE dir_block_cmp(const void *a, const void *b); -static EXT2_QSORT_TYPE dir_block_cmp2(const void *a, const void *b); -static EXT2_QSORT_TYPE (*sortfunc32)(const void *a, const void *b); /* * Returns the number of directories in the filesystem as reported by @@ -38,10 +36,10 @@ errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs) num_dirs = 0; max_dirs = fs->super->s_inodes_per_group; for (i = 0; i < fs->group_desc_count; i++) { - if (ext2fs_bg_used_dirs_count(fs, i) > max_dirs) + if (fs->group_desc[i].bg_used_dirs_count > max_dirs) num_dirs += max_dirs / 8; else - num_dirs += ext2fs_bg_used_dirs_count(fs, i); + num_dirs += fs->group_desc[i].bg_used_dirs_count; } if (num_dirs > fs->super->s_inodes_count) num_dirs = fs->super->s_inodes_count; @@ -55,14 +53,12 @@ errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs) * helper function for making a new directory block list (for * initialize and copy). */ -static errcode_t make_dblist(ext2_filsys fs, ext2_ino_t size, - ext2_ino_t count, - struct ext2_db_entry2 *list, +static errcode_t make_dblist(ext2_filsys fs, ext2_ino_t size, ext2_ino_t count, + struct ext2_db_entry *list, ext2_dblist *ret_dblist) { - ext2_dblist dblist = NULL; + ext2_dblist dblist; errcode_t retval; - ext2_ino_t num_dirs; size_t len; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); @@ -73,7 +69,7 @@ static errcode_t make_dblist(ext2_filsys fs, ext2_ino_t size, retval = ext2fs_get_mem(sizeof(struct ext2_struct_dblist), &dblist); if (retval) - goto cleanup; + return retval; memset(dblist, 0, sizeof(struct ext2_struct_dblist)); dblist->magic = EXT2_ET_MAGIC_DBLIST; @@ -81,14 +77,14 @@ static errcode_t make_dblist(ext2_filsys fs, ext2_ino_t size, if (size) dblist->size = size; else { - retval = ext2fs_get_num_dirs(fs, &num_dirs); + retval = ext2fs_get_num_dirs(fs, &dblist->size); if (retval) goto cleanup; - dblist->size = (num_dirs * 2) + 12; + dblist->size = (dblist->size * 2) + 12; } - len = (size_t) sizeof(struct ext2_db_entry2) * dblist->size; + len = (size_t) sizeof(struct ext2_db_entry) * dblist->size; dblist->count = count; - retval = ext2fs_get_array(dblist->size, sizeof(struct ext2_db_entry2), + retval = ext2fs_get_array(dblist->size, sizeof(struct ext2_db_entry), &dblist->list); if (retval) goto cleanup; @@ -156,27 +152,27 @@ errcode_t ext2fs_copy_dblist(ext2_dblist src, ext2_dblist *dest) /* * Add a directory block to the directory block list */ -errcode_t ext2fs_add_dir_block2(ext2_dblist dblist, ext2_ino_t ino, - blk64_t blk, e2_blkcnt_t blockcnt) +errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino, blk_t blk, + int blockcnt) { - struct ext2_db_entry2 *new_entry; + struct ext2_db_entry *new_entry; errcode_t retval; unsigned long old_size; EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST); if (dblist->count >= dblist->size) { - old_size = dblist->size * sizeof(struct ext2_db_entry2); + old_size = dblist->size * sizeof(struct ext2_db_entry); dblist->size += dblist->size > 200 ? dblist->size / 2 : 100; retval = ext2fs_resize_mem(old_size, (size_t) dblist->size * - sizeof(struct ext2_db_entry2), + sizeof(struct ext2_db_entry), &dblist->list); if (retval) { - dblist->size = old_size / sizeof(struct ext2_db_entry2); + dblist->size -= 100; return retval; } } - new_entry = dblist->list + ( dblist->count++); + new_entry = dblist->list + ( (int) dblist->count++); new_entry->blk = blk; new_entry->ino = ino; new_entry->blockcnt = blockcnt; @@ -189,8 +185,8 @@ errcode_t ext2fs_add_dir_block2(ext2_dblist dblist, ext2_ino_t ino, /* * Change the directory block to the directory block list */ -errcode_t ext2fs_set_dir_block2(ext2_dblist dblist, ext2_ino_t ino, - blk64_t blk, e2_blkcnt_t blockcnt) +errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino, blk_t blk, + int blockcnt) { dgrp_t i; @@ -207,47 +203,47 @@ errcode_t ext2fs_set_dir_block2(ext2_dblist dblist, ext2_ino_t ino, return EXT2_ET_DB_NOT_FOUND; } -void ext2fs_dblist_sort2(ext2_dblist dblist, - EXT2_QSORT_TYPE (*sortfunc)(const void *, - const void *)) +void ext2fs_dblist_sort(ext2_dblist dblist, + EXT2_QSORT_TYPE (*sortfunc)(const void *, + const void *)) { if (!sortfunc) - sortfunc = dir_block_cmp2; + sortfunc = dir_block_cmp; qsort(dblist->list, (size_t) dblist->count, - sizeof(struct ext2_db_entry2), sortfunc); + sizeof(struct ext2_db_entry), sortfunc); dblist->sorted = 1; } /* * This function iterates over the directory block list */ -errcode_t ext2fs_dblist_iterate2(ext2_dblist dblist, - int (*func)(ext2_filsys fs, - struct ext2_db_entry2 *db_info, - void *priv_data), - void *priv_data) +errcode_t ext2fs_dblist_iterate(ext2_dblist dblist, + int (*func)(ext2_filsys fs, + struct ext2_db_entry *db_info, + void *priv_data), + void *priv_data) { - unsigned long long i; + ext2_ino_t i; int ret; EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST); if (!dblist->sorted) - ext2fs_dblist_sort2(dblist, 0); + ext2fs_dblist_sort(dblist, 0); for (i=0; i < dblist->count; i++) { - ret = (*func)(dblist->fs, &dblist->list[i], priv_data); + ret = (*func)(dblist->fs, &dblist->list[(int)i], priv_data); if (ret & DBLIST_ABORT) return 0; } return 0; } -static EXT2_QSORT_TYPE dir_block_cmp2(const void *a, const void *b) +static EXT2_QSORT_TYPE dir_block_cmp(const void *a, const void *b) { - const struct ext2_db_entry2 *db_a = - (const struct ext2_db_entry2 *) a; - const struct ext2_db_entry2 *db_b = - (const struct ext2_db_entry2 *) b; + const struct ext2_db_entry *db_a = + (const struct ext2_db_entry *) a; + const struct ext2_db_entry *db_b = + (const struct ext2_db_entry *) b; if (db_a->blk != db_b->blk) return (int) (db_a->blk - db_b->blk); @@ -255,16 +251,16 @@ static EXT2_QSORT_TYPE dir_block_cmp2(const void *a, const void *b) if (db_a->ino != db_b->ino) return (int) (db_a->ino - db_b->ino); - return (db_a->blockcnt - db_b->blockcnt); + return (int) (db_a->blockcnt - db_b->blockcnt); } -blk64_t ext2fs_dblist_count2(ext2_dblist dblist) +int ext2fs_dblist_count(ext2_dblist dblist) { - return dblist->count; + return (int) dblist->count; } -errcode_t ext2fs_dblist_get_last2(ext2_dblist dblist, - struct ext2_db_entry2 **entry) +errcode_t ext2fs_dblist_get_last(ext2_dblist dblist, + struct ext2_db_entry **entry) { EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST); @@ -272,7 +268,7 @@ errcode_t ext2fs_dblist_get_last2(ext2_dblist dblist, return EXT2_ET_DBLIST_EMPTY; if (entry) - *entry = dblist->list + ( dblist->count-1); + *entry = dblist->list + ( (int) dblist->count-1); return 0; } @@ -286,130 +282,3 @@ errcode_t ext2fs_dblist_drop_last(ext2_dblist dblist) dblist->count--; return 0; } - -/* - * Legacy 32-bit versions - */ - -/* - * Add a directory block to the directory block list - */ -errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino, blk_t blk, - int blockcnt) -{ - return ext2fs_add_dir_block2(dblist, ino, blk, blockcnt); -} - -/* - * Change the directory block to the directory block list - */ -errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino, blk_t blk, - int blockcnt) -{ - return ext2fs_set_dir_block2(dblist, ino, blk, blockcnt); -} - -void ext2fs_dblist_sort(ext2_dblist dblist, - EXT2_QSORT_TYPE (*sortfunc)(const void *, - const void *)) -{ - if (sortfunc) { - sortfunc32 = sortfunc; - sortfunc = dir_block_cmp; - } else - sortfunc = dir_block_cmp2; - qsort(dblist->list, (size_t) dblist->count, - sizeof(struct ext2_db_entry2), sortfunc); - dblist->sorted = 1; -} - -/* - * This function iterates over the directory block list - */ -struct iterate_passthrough { - int (*func)(ext2_filsys fs, - struct ext2_db_entry *db_info, - void *priv_data); - void *priv_data; -}; - -static int passthrough_func(ext2_filsys fs, - struct ext2_db_entry2 *db_info, - void *priv_data) -{ - struct iterate_passthrough *p = priv_data; - struct ext2_db_entry db; - int ret; - - db.ino = db_info->ino; - db.blk = (blk_t) db_info->blk; - db.blockcnt = (int) db_info->blockcnt; - ret = (p->func)(fs, &db, p->priv_data); - db_info->ino = db.ino; - db_info->blk = db.blk; - db_info->blockcnt = db.blockcnt; - return ret; -} - -errcode_t ext2fs_dblist_iterate(ext2_dblist dblist, - int (*func)(ext2_filsys fs, - struct ext2_db_entry *db_info, - void *priv_data), - void *priv_data) -{ - struct iterate_passthrough pass; - - EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST); - pass.func = func; - pass.priv_data = priv_data; - - return ext2fs_dblist_iterate2(dblist, passthrough_func, &pass); -} - -static EXT2_QSORT_TYPE dir_block_cmp(const void *a, const void *b) -{ - const struct ext2_db_entry2 *db_a = - (const struct ext2_db_entry2 *) a; - const struct ext2_db_entry2 *db_b = - (const struct ext2_db_entry2 *) b; - - struct ext2_db_entry a32, b32; - - a32.ino = db_a->ino; a32.blk = db_a->blk; - a32.blockcnt = db_a->blockcnt; - - b32.ino = db_b->ino; b32.blk = db_b->blk; - b32.blockcnt = db_b->blockcnt; - - return sortfunc32(&a32, &b32); -} - -int ext2fs_dblist_count(ext2_dblist dblist) -{ - return dblist->count; -} - -errcode_t ext2fs_dblist_get_last(ext2_dblist dblist, - struct ext2_db_entry **entry) -{ - static struct ext2_db_entry ret_entry; - struct ext2_db_entry2 *last; - - EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST); - - if (dblist->count == 0) - return EXT2_ET_DBLIST_EMPTY; - - if (!entry) - return 0; - - last = dblist->list + dblist->count -1; - - ret_entry.ino = last->ino; - ret_entry.blk = last->blk; - ret_entry.blockcnt = last->blockcnt; - *entry = &ret_entry; - - return 0; -} - diff --git a/lib/ext2fs/dblist_dir.c b/lib/ext2fs/dblist_dir.c index 07ed8afa..8c38d315 100644 --- a/lib/ext2fs/dblist_dir.c +++ b/lib/ext2fs/dblist_dir.c @@ -19,7 +19,7 @@ #include "ext2_fs.h" #include "ext2fsP.h" -static int db_dir_proc(ext2_filsys fs, struct ext2_db_entry2 *db_info, +static int db_dir_proc(ext2_filsys fs, struct ext2_db_entry *db_info, void *priv_data); errcode_t ext2fs_dblist_dir_iterate(ext2_dblist dblist, @@ -52,7 +52,7 @@ errcode_t ext2fs_dblist_dir_iterate(ext2_dblist dblist, ctx.priv_data = priv_data; ctx.errcode = 0; - retval = ext2fs_dblist_iterate2(dblist, db_dir_proc, &ctx); + retval = ext2fs_dblist_iterate(dblist, db_dir_proc, &ctx); if (!block_buf) ext2fs_free_mem(&ctx.buf); @@ -61,7 +61,7 @@ errcode_t ext2fs_dblist_dir_iterate(ext2_dblist dblist, return ctx.errcode; } -static int db_dir_proc(ext2_filsys fs, struct ext2_db_entry2 *db_info, +static int db_dir_proc(ext2_filsys fs, struct ext2_db_entry *db_info, void *priv_data) { struct dir_context *ctx; diff --git a/lib/ext2fs/dir_iterate.c b/lib/ext2fs/dir_iterate.c index 8412218c..124862ea 100644 --- a/lib/ext2fs/dir_iterate.c +++ b/lib/ext2fs/dir_iterate.c @@ -122,7 +122,7 @@ errcode_t ext2fs_dir_iterate2(ext2_filsys fs, ctx.func = func; ctx.priv_data = priv_data; ctx.errcode = 0; - retval = ext2fs_block_iterate3(fs, dir, BLOCK_FLAG_READ_ONLY, 0, + retval = ext2fs_block_iterate2(fs, dir, BLOCK_FLAG_READ_ONLY, 0, ext2fs_process_dir_block, &ctx); if (!block_buf) ext2fs_free_mem(&ctx.buf); @@ -150,16 +150,16 @@ static int xlate_func(ext2_ino_t dir EXT2FS_ATTR((unused)), return (*xl->func)(dirent, offset, blocksize, buf, xl->real_private); } -errcode_t ext2fs_dir_iterate(ext2_filsys fs, - ext2_ino_t dir, - int flags, - char *block_buf, - int (*func)(struct ext2_dir_entry *dirent, - int offset, - int blocksize, - char *buf, - void *priv_data), - void *priv_data) +extern errcode_t ext2fs_dir_iterate(ext2_filsys fs, + ext2_ino_t dir, + int flags, + char *block_buf, + int (*func)(struct ext2_dir_entry *dirent, + int offset, + int blocksize, + char *buf, + void *priv_data), + void *priv_data) { struct xlate xl; @@ -176,9 +176,9 @@ errcode_t ext2fs_dir_iterate(ext2_filsys fs, * ext2fs_dir_iterate() and ext2fs_dblist_dir_iterate() */ int ext2fs_process_dir_block(ext2_filsys fs, - blk64_t *blocknr, + blk_t *blocknr, e2_blkcnt_t blockcnt, - blk64_t ref_block EXT2FS_ATTR((unused)), + blk_t ref_block EXT2FS_ATTR((unused)), int ref_offset EXT2FS_ATTR((unused)), void *priv_data) { @@ -197,7 +197,7 @@ int ext2fs_process_dir_block(ext2_filsys fs, entry = blockcnt ? DIRENT_OTHER_FILE : DIRENT_DOT_FILE; - ctx->errcode = ext2fs_read_dir_block3(fs, *blocknr, ctx->buf, 0); + ctx->errcode = ext2fs_read_dir_block(fs, *blocknr, ctx->buf); if (ctx->errcode) return BLOCK_ABORT; @@ -258,8 +258,7 @@ next: } if (changed) { - ctx->errcode = ext2fs_write_dir_block3(fs, *blocknr, ctx->buf, - 0); + ctx->errcode = ext2fs_write_dir_block(fs, *blocknr, ctx->buf); if (ctx->errcode) return BLOCK_ABORT; } diff --git a/lib/ext2fs/dirblock.c b/lib/ext2fs/dirblock.c index 73e1f0ab..29b4fcd2 100644 --- a/lib/ext2fs/dirblock.c +++ b/lib/ext2fs/dirblock.c @@ -19,7 +19,7 @@ #include "ext2_fs.h" #include "ext2fs.h" -errcode_t ext2fs_read_dir_block3(ext2_filsys fs, blk64_t block, +errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block, void *buf, int flags EXT2FS_ATTR((unused))) { errcode_t retval; @@ -28,7 +28,7 @@ errcode_t ext2fs_read_dir_block3(ext2_filsys fs, blk64_t block, unsigned int name_len, rec_len; - retval = io_channel_read_blk64(fs->io, block, 1, buf); + retval = io_channel_read_blk(fs->io, block, 1, buf); if (retval) return retval; @@ -58,20 +58,14 @@ errcode_t ext2fs_read_dir_block3(ext2_filsys fs, blk64_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_block3(fs, block, buf, 0); + return ext2fs_read_dir_block2(fs, block, buf, 0); } -errcode_t ext2fs_write_dir_block3(ext2_filsys fs, blk64_t block, +errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block, void *inbuf, int flags EXT2FS_ATTR((unused))) { #ifdef WORDS_BIGENDIAN @@ -104,23 +98,18 @@ errcode_t ext2fs_write_dir_block3(ext2_filsys fs, blk64_t block, if (flags & EXT2_DIRBLOCK_V2_STRUCT) dirent->name_len = ext2fs_swab16(dirent->name_len); } - retval = io_channel_write_blk64(fs->io, block, 1, buf); + retval = io_channel_write_blk(fs->io, block, 1, buf); ext2fs_free_mem(&buf); return retval; #else - return io_channel_write_blk64(fs->io, block, 1, (char *) inbuf); + return io_channel_write_blk(fs->io, block, 1, (char *) inbuf); #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_block3(fs, block, inbuf, 0); + return ext2fs_write_dir_block2(fs, block, inbuf, 0); } diff --git a/lib/ext2fs/dirhash.c b/lib/ext2fs/dirhash.c index 5477bfbc..a0697069 100644 --- a/lib/ext2fs/dirhash.c +++ b/lib/ext2fs/dirhash.c @@ -217,13 +217,11 @@ errcode_t ext2fs_dirhash(int version, const char *name, int len, switch (version) { case EXT2_HASH_LEGACY_UNSIGNED: unsigned_flag++; - /* fallthrough */ case EXT2_HASH_LEGACY: hash = dx_hack_hash(name, len, unsigned_flag); break; case EXT2_HASH_HALF_MD4_UNSIGNED: unsigned_flag++; - /* fallthrough */ case EXT2_HASH_HALF_MD4: p = name; while (len > 0) { @@ -237,7 +235,6 @@ errcode_t ext2fs_dirhash(int version, const char *name, int len, break; case EXT2_HASH_TEA_UNSIGNED: unsigned_flag++; - /* fallthrough */ case EXT2_HASH_TEA: p = name; while (len > 0) { diff --git a/lib/ext2fs/dupfs.c b/lib/ext2fs/dupfs.c index 13a48121..a9e2a976 100644 --- a/lib/ext2fs/dupfs.c +++ b/lib/ext2fs/dupfs.c @@ -39,9 +39,6 @@ errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest) fs->block_map = 0; fs->badblocks = 0; fs->dblist = 0; - fs->mmp_buf = 0; - fs->mmp_cmp = 0; - fs->mmp_fd = -1; io_channel_bumpcount(fs->io); if (fs->icache) @@ -89,28 +86,6 @@ errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest) if (retval) goto errout; } - if (src->mmp_buf) { - retval = ext2fs_get_mem(src->blocksize, &fs->mmp_buf); - if (retval) - goto errout; - memcpy(fs->mmp_buf, src->mmp_buf, src->blocksize); - } - if (src->mmp_fd >= 0) { - fs->mmp_fd = dup(src->mmp_fd); - if (fs->mmp_fd < 0) { - retval = EXT2_ET_MMP_OPEN_DIRECT; - goto errout; - } - } - if (src->mmp_cmp) { - int align = ext2fs_get_dio_alignment(src->mmp_fd); - - retval = ext2fs_get_memalign(src->blocksize, align, - &fs->mmp_cmp); - if (retval) - goto errout; - memcpy(fs->mmp_cmp, src->mmp_cmp, src->blocksize); - } *dest = fs; return 0; errout: diff --git a/lib/ext2fs/e2image.h b/lib/ext2fs/e2image.h index 53b20cc7..4de2c8d9 100644 --- a/lib/ext2fs/e2image.h +++ b/lib/ext2fs/e2image.h @@ -12,6 +12,7 @@ * %End-Header% */ + struct ext2_image_hdr { __u32 magic_number; /* This must be EXT2_ET_MAGIC_E2IMAGE */ char magic_descriptor[16]; /* "Ext2 Image 1.0", w/ null padding */ @@ -35,3 +36,16 @@ struct ext2_image_hdr { __u32 offset_blockmap; /* Byte offset of the inode bitmaps */ __u32 offset_reserved[8]; }; + + + + + + + + + + + + + diff --git a/lib/ext2fs/expanddir.c b/lib/ext2fs/expanddir.c index c89385be..a71c6c9d 100644 --- a/lib/ext2fs/expanddir.c +++ b/lib/ext2fs/expanddir.c @@ -21,39 +21,30 @@ struct expand_dir_struct { int done; int newblocks; - blk64_t goal; errcode_t err; }; static int expand_dir_proc(ext2_filsys fs, - blk64_t *blocknr, + blk_t *blocknr, e2_blkcnt_t blockcnt, - blk64_t ref_block EXT2FS_ATTR((unused)), + blk_t ref_block EXT2FS_ATTR((unused)), int ref_offset EXT2FS_ATTR((unused)), void *priv_data) { struct expand_dir_struct *es = (struct expand_dir_struct *) priv_data; - blk64_t new_blk; + blk_t new_blk; + static blk_t last_blk = 0; char *block; errcode_t retval; if (*blocknr) { - if (blockcnt >= 0) - es->goal = *blocknr; + last_blk = *blocknr; return 0; } - if (blockcnt && - (EXT2FS_B2C(fs, es->goal) == EXT2FS_B2C(fs, es->goal+1))) - new_blk = es->goal+1; - else { - es->goal &= ~EXT2FS_CLUSTER_MASK(fs); - retval = ext2fs_new_block2(fs, es->goal, 0, &new_blk); - if (retval) { - es->err = retval; - return BLOCK_ABORT; - } - es->newblocks++; - ext2fs_block_alloc_stats2(fs, new_blk, +1); + retval = ext2fs_new_block(fs, last_blk, 0, &new_blk); + if (retval) { + es->err = retval; + return BLOCK_ABORT; } if (blockcnt > 0) { retval = ext2fs_new_dir_block(fs, 0, 0, &block); @@ -70,16 +61,16 @@ static int expand_dir_proc(ext2_filsys fs, return BLOCK_ABORT; } memset(block, 0, fs->blocksize); - retval = io_channel_write_blk64(fs->io, new_blk, 1, block); + retval = io_channel_write_blk(fs->io, new_blk, 1, block); } - if (blockcnt >= 0) - es->goal = new_blk; if (retval) { es->err = retval; return BLOCK_ABORT; } ext2fs_free_mem(&block); *blocknr = new_blk; + ext2fs_block_alloc_stats(fs, new_blk, +1); + es->newblocks++; if (es->done) return (BLOCK_CHANGED | BLOCK_ABORT); @@ -107,10 +98,9 @@ errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir) es.done = 0; es.err = 0; - es.goal = 0; es.newblocks = 0; - retval = ext2fs_block_iterate3(fs, dir, BLOCK_FLAG_APPEND, + retval = ext2fs_block_iterate2(fs, dir, BLOCK_FLAG_APPEND, 0, expand_dir_proc, &es); if (es.err) diff --git a/lib/ext2fs/ext2_err.c b/lib/ext2fs/ext2_err.c index 3d6f0b4a..9008ac86 100644 --- a/lib/ext2fs/ext2_err.c +++ b/lib/ext2fs/ext2_err.c @@ -5,165 +5,144 @@ #include <stdlib.h> -#define N_(a) a - static const char * const text[] = { - N_( "EXT2FS Library version 1.42.9"), - N_( "Wrong magic number for ext2_filsys structure"), - N_( "Wrong magic number for badblocks_list structure"), - N_( "Wrong magic number for badblocks_iterate structure"), - N_( "Wrong magic number for inode_scan structure"), - N_( "Wrong magic number for io_channel structure"), - N_( "Wrong magic number for unix io_channel structure"), - N_( "Wrong magic number for io_manager structure"), - N_( "Wrong magic number for block_bitmap structure"), - N_( "Wrong magic number for inode_bitmap structure"), - N_( "Wrong magic number for generic_bitmap structure"), - N_( "Wrong magic number for test io_channel structure"), - N_( "Wrong magic number for directory block list structure"), - N_( "Wrong magic number for icount structure"), - N_( "Wrong magic number for Powerquest io_channel structure"), - N_( "Wrong magic number for ext2 file structure"), - N_( "Wrong magic number for Ext2 Image Header"), - N_( "Wrong magic number for inode io_channel structure"), - N_( "Wrong magic number for ext4 extent handle"), - N_( "Bad magic number in super-block"), - N_( "Filesystem revision too high"), - N_( "Attempt to write to filesystem opened read-only"), - N_( "Can't read group descriptors"), - N_( "Can't write group descriptors"), - N_( "Corrupt group descriptor: bad block for block bitmap"), - N_( "Corrupt group descriptor: bad block for inode bitmap"), - N_( "Corrupt group descriptor: bad block for inode table"), - N_( "Can't write an inode bitmap"), - N_( "Can't read an inode bitmap"), - N_( "Can't write a block bitmap"), - N_( "Can't read a block bitmap"), - N_( "Can't write an inode table"), - N_( "Can't read an inode table"), - N_( "Can't read next inode"), - N_( "Filesystem has unexpected block size"), - N_( "EXT2 directory corrupted"), - N_( "Attempt to read block from filesystem resulted in short read"), - N_( "Attempt to write block to filesystem resulted in short write"), - N_( "No free space in the directory"), - N_( "Inode bitmap not loaded"), - N_( "Block bitmap not loaded"), - N_( "Illegal inode number"), - N_( "Illegal block number"), - N_( "Internal error in ext2fs_expand_dir"), - N_( "Not enough space to build proposed filesystem"), - N_( "Illegal block number passed to ext2fs_mark_block_bitmap"), - N_( "Illegal block number passed to ext2fs_unmark_block_bitmap"), - N_( "Illegal block number passed to ext2fs_test_block_bitmap"), - N_( "Illegal inode number passed to ext2fs_mark_inode_bitmap"), - N_( "Illegal inode number passed to ext2fs_unmark_inode_bitmap"), - N_( "Illegal inode number passed to ext2fs_test_inode_bitmap"), - N_( "Attempt to fudge end of block bitmap past the real end"), - N_( "Attempt to fudge end of inode bitmap past the real end"), - N_( "Illegal indirect block found" ), - N_( "Illegal doubly indirect block found" ), - N_( "Illegal triply indirect block found" ), - N_( "Block bitmaps are not the same"), - N_( "Inode bitmaps are not the same"), - N_( "Illegal or malformed device name"), - N_( "A block group is missing an inode table"), - N_( "The ext2 superblock is corrupt"), - N_( "Illegal generic bit number passed to ext2fs_mark_generic_bitmap"), - N_( "Illegal generic bit number passed to ext2fs_unmark_generic_bitmap"), - N_( "Illegal generic bit number passed to ext2fs_test_generic_bitmap"), - N_( "Too many symbolic links encountered."), - N_( "The callback function will not handle this case"), - N_( "The inode is from a bad block in the inode table"), - N_( "Filesystem has unsupported feature(s)"), - N_( "Filesystem has unsupported read-only feature(s)"), - N_( "IO Channel failed to seek on read or write"), - N_( "Memory allocation failed"), - N_( "Invalid argument passed to ext2 library"), - N_( "Could not allocate block in ext2 filesystem"), - N_( "Could not allocate inode in ext2 filesystem"), - N_( "Ext2 inode is not a directory"), - N_( "Too many references in table"), - N_( "File not found by ext2_lookup"), - N_( "File open read-only"), - N_( "Ext2 directory block not found"), - N_( "Ext2 directory already exists"), - N_( "Unimplemented ext2 library function"), - N_( "User cancel requested"), - N_( "Ext2 file too big"), - N_( "Supplied journal device not a block device"), - N_( "Journal superblock not found"), - N_( "Journal must be at least 1024 blocks"), - N_( "Unsupported journal version"), - N_( "Error loading external journal"), - N_( "Journal not found"), - N_( "Directory hash unsupported"), - N_( "Illegal extended attribute block number"), - N_( "Cannot create filesystem with requested number of inodes"), - N_( "E2image snapshot not in use"), - N_( "Too many reserved group descriptor blocks"), - N_( "Resize inode is corrupt"), - N_( "Tried to set block bmap with missing indirect block"), - N_( "TDB: Success"), - N_( "TDB: Corrupt database"), - N_( "TDB: IO Error"), - N_( "TDB: Locking error"), - N_( "TDB: Out of memory"), - N_( "TDB: Record exists"), - N_( "TDB: Lock exists on other keys"), - N_( "TDB: Invalid parameter"), - N_( "TDB: Record does not exist"), - N_( "TDB: Write not permitted"), - N_( "Ext2fs directory block list is empty"), - N_( "Attempt to modify a block mapping via a read-only block iterator"), - N_( "Wrong magic number for ext4 extent saved path"), - N_( "Wrong magic number for 64-bit generic bitmap"), - N_( "Wrong magic number for 64-bit block bitmap"), - N_( "Wrong magic number for 64-bit inode bitmap"), - N_( "Wrong magic number --- RESERVED_13"), - N_( "Wrong magic number --- RESERVED_14"), - N_( "Wrong magic number --- RESERVED_15"), - N_( "Wrong magic number --- RESERVED_16"), - N_( "Wrong magic number --- RESERVED_17"), - N_( "Wrong magic number --- RESERVED_18"), - N_( "Wrong magic number --- RESERVED_19"), - N_( "Corrupt extent header"), - N_( "Corrupt extent index"), - N_( "Corrupt extent"), - N_( "No free space in extent map"), - N_( "Inode does not use extents"), - N_( "No 'next' extent"), - N_( "No 'previous' extent"), - N_( "No 'up' extent"), - N_( "No 'down' extent"), - N_( "No current node"), - N_( "Ext2fs operation not supported"), - N_( "No room to insert extent in node"), - N_( "Splitting would result in empty node"), - N_( "Extent not found"), - N_( "Operation not supported for inodes containing extents"), - N_( "Extent length is invalid"), - N_( "I/O Channel does not support 64-bit block numbers"), - N_( "Can't check if filesystem is mounted due to missing mtab file"), - N_( "Filesystem too large to use legacy bitmaps"), - N_( "MMP: invalid magic number"), - N_( "MMP: device currently active"), - N_( "MMP: fsck being run"), - N_( "MMP: block number beyond filesystem range"), - N_( "MMP: undergoing an unknown operation"), - N_( "MMP: filesystem still in use"), - N_( "MMP: open with O_DIRECT failed"), - N_( "Block group descriptor size incorrect"), - N_( "Inode checksum does not match inode"), - N_( "Inode bitmap checksum does not match bitmap"), - N_( "Extent block checksum does not match extent block"), - N_( "Directory block does not have space for checksum"), - N_( "Directory block checksum does not match directory block"), - N_( "Extended attribute block checksum does not match block"), - N_( "Superblock checksum does not match superblock"), - N_( "Unknown checksum algorithm"), - N_( "MMP block checksum does not match MMP block"), - N_( "Ext2 file already exists"), + "EXT2FS Library version 1.41.14", + "Wrong magic number for ext2_filsys structure", + "Wrong magic number for badblocks_list structure", + "Wrong magic number for badblocks_iterate structure", + "Wrong magic number for inode_scan structure", + "Wrong magic number for io_channel structure", + "Wrong magic number for unix io_channel structure", + "Wrong magic number for io_manager structure", + "Wrong magic number for block_bitmap structure", + "Wrong magic number for inode_bitmap structure", + "Wrong magic number for generic_bitmap structure", + "Wrong magic number for test io_channel structure", + "Wrong magic number for directory block list structure", + "Wrong magic number for icount structure", + "Wrong magic number for Powerquest io_channel structure", + "Wrong magic number for ext2 file structure", + "Wrong magic number for Ext2 Image Header", + "Wrong magic number for inode io_channel structure", + "Wrong magic number for ext4 extent handle", + "Bad magic number in super-block", + "Filesystem revision too high", + "Attempt to write to filesystem opened read-only", + "Can't read group descriptors", + "Can't write group descriptors", + "Corrupt group descriptor: bad block for block bitmap", + "Corrupt group descriptor: bad block for inode bitmap", + "Corrupt group descriptor: bad block for inode table", + "Can't write an inode bitmap", + "Can't read an inode bitmap", + "Can't write an block bitmap", + "Can't read an block bitmap", + "Can't write an inode table", + "Can't read an inode table", + "Can't read next inode", + "Filesystem has unexpected block size", + "EXT2 directory corrupted", + "Attempt to read block from filesystem resulted in short read", + "Attempt to write block from filesystem resulted in short write", + "No free space in the directory", + "Inode bitmap not loaded", + "Block bitmap not loaded", + "Illegal inode number", + "Illegal block number", + "Internal error in ext2fs_expand_dir", + "Not enough space to build proposed filesystem", + "Illegal block number passed to ext2fs_mark_block_bitmap", + "Illegal block number passed to ext2fs_unmark_block_bitmap", + "Illegal block number passed to ext2fs_test_block_bitmap", + "Illegal inode number passed to ext2fs_mark_inode_bitmap", + "Illegal inode number passed to ext2fs_unmark_inode_bitmap", + "Illegal inode number passed to ext2fs_test_inode_bitmap", + "Attempt to fudge end of block bitmap past the real end", + "Attempt to fudge end of inode bitmap past the real end", + "Illegal indirect block found" , + "Illegal doubly indirect block found" , + "Illegal triply indirect block found" , + "Block bitmaps are not the same", + "Inode bitmaps are not the same", + "Illegal or malformed device name", + "A block group is missing an inode table", + "The ext2 superblock is corrupt", + "Illegal generic bit number passed to ext2fs_mark_generic_bitmap", + "Illegal generic bit number passed to ext2fs_unmark_generic_bitmap", + "Illegal generic bit number passed to ext2fs_test_generic_bitmap", + "Too many symbolic links encountered.", + "The callback function will not handle this case", + "The inode is from a bad block in the inode table", + "Filesystem has unsupported feature(s)", + "Filesystem has unsupported read-only feature(s)", + "IO Channel failed to seek on read or write", + "Memory allocation failed", + "Invalid argument passed to ext2 library", + "Could not allocate block in ext2 filesystem", + "Could not allocate inode in ext2 filesystem", + "Ext2 inode is not a directory", + "Too many references in table", + "File not found by ext2_lookup", + "File open read-only", + "Ext2 directory block not found", + "Ext2 directory already exists", + "Unimplemented ext2 library function", + "User cancel requested", + "Ext2 file too big", + "Supplied journal device not a block device", + "Journal superblock not found", + "Journal must be at least 1024 blocks", + "Unsupported journal version", + "Error loading external journal", + "Journal not found", + "Directory hash unsupported", + "Illegal extended attribute block number", + "Cannot create filesystem with requested number of inodes", + "E2image snapshot not in use", + "Too many reserved group descriptor blocks", + "Resize inode is corrupt", + "Missing indirect block not present", + "TDB: Success", + "TDB: Corrupt database", + "TDB: IO Error", + "TDB: Locking error", + "TDB: Out of memory", + "TDB: Record exists", + "TDB: Lock exists on other keys", + "TDB: Invalid parameter", + "TDB: Record does not exist", + "TDB: Write not permitted", + "Ext2fs directory block list is empty", + "Attempt to modify a block mapping via a read-only block iterator", + "Wrong magic number for ext4 extent saved path", + "Wrong magic number --- RESERVED_10", + "Wrong magic number --- RESERVED_11", + "Wrong magic number --- RESERVED_12", + "Wrong magic number --- RESERVED_13", + "Wrong magic number --- RESERVED_14", + "Wrong magic number --- RESERVED_15", + "Wrong magic number --- RESERVED_16", + "Wrong magic number --- RESERVED_17", + "Wrong magic number --- RESERVED_18", + "Wrong magic number --- RESERVED_19", + "Corrupt extent header", + "Corrupt extent index", + "Corrupt extent", + "No free space in extent map", + "Inode does not use extents", + "No 'next' extent", + "No 'previous' extent", + "No 'up' extent", + "No 'down' extent", + "No current node", + "Ext2fs operation not supported", + "No room to insert extent in node", + "Splitting would result in empty node", + "Extent not found", + "Operation not supported for inodes containing extents", + "Extent length is invalid", + "I/O Channel does not support 64-bit block numbers", + "Can't check if filesystem is mounted due to missing mtab file", 0 }; @@ -178,7 +157,7 @@ struct et_list { }; extern struct et_list *_et_list; -const struct error_table et_ext2_error_table = { text, 2133571328L, 156 }; +const struct error_table et_ext2_error_table = { text, 2133571328L, 137 }; static struct et_list link = { 0, 0 }; diff --git a/lib/ext2fs/ext2_err.et.in b/lib/ext2fs/ext2_err.et.in index 87812ab4..406f3ae8 100644 --- a/lib/ext2fs/ext2_err.et.in +++ b/lib/ext2fs/ext2_err.et.in @@ -96,10 +96,10 @@ ec EXT2_ET_INODE_BITMAP_READ, "Can't read an inode bitmap" ec EXT2_ET_BLOCK_BITMAP_WRITE, - "Can't write a block bitmap" + "Can't write an block bitmap" ec EXT2_ET_BLOCK_BITMAP_READ, - "Can't read a block bitmap" + "Can't read an block bitmap" ec EXT2_ET_INODE_TABLE_WRITE, "Can't write an inode table" @@ -120,7 +120,7 @@ ec EXT2_ET_SHORT_READ, "Attempt to read block from filesystem resulted in short read" ec EXT2_ET_SHORT_WRITE, - "Attempt to write block to filesystem resulted in short write" + "Attempt to write block from filesystem resulted in short write" ec EXT2_ET_DIR_NO_SPACE, "No free space in the directory" @@ -294,7 +294,7 @@ ec EXT2_ET_RESIZE_INODE_CORRUPT, "Resize inode is corrupt" ec EXT2_ET_SET_BMAP_NO_IND, - "Tried to set block bmap with missing indirect block" + "Missing indirect block not present" ec EXT2_ET_TDB_SUCCESS, "TDB: Success" @@ -335,14 +335,14 @@ ec EXT2_ET_RO_BLOCK_ITERATE, ec EXT2_ET_MAGIC_EXTENT_PATH, "Wrong magic number for ext4 extent saved path" -ec EXT2_ET_MAGIC_GENERIC_BITMAP64, - "Wrong magic number for 64-bit generic bitmap" +ec EXT2_ET_MAGIC_RESERVED_10, + "Wrong magic number --- RESERVED_10" -ec EXT2_ET_MAGIC_BLOCK_BITMAP64, - "Wrong magic number for 64-bit block bitmap" +ec EXT2_ET_MAGIC_RESERVED_11, + "Wrong magic number --- RESERVED_11" -ec EXT2_ET_MAGIC_INODE_BITMAP64, - "Wrong magic number for 64-bit inode bitmap" +ec EXT2_ET_MAGIC_RESERVED_12, + "Wrong magic number --- RESERVED_12" ec EXT2_ET_MAGIC_RESERVED_13, "Wrong magic number --- RESERVED_13" @@ -416,64 +416,7 @@ ec EXT2_ET_EXTENT_INVALID_LENGTH, ec EXT2_ET_IO_CHANNEL_NO_SUPPORT_64, "I/O Channel does not support 64-bit block numbers" -ec EXT2_ET_NO_MTAB_FILE, +ec EXT2_NO_MTAB_FILE, "Can't check if filesystem is mounted due to missing mtab file" -ec EXT2_ET_CANT_USE_LEGACY_BITMAPS, - "Filesystem too large to use legacy bitmaps" - -ec EXT2_ET_MMP_MAGIC_INVALID, - "MMP: invalid magic number" - -ec EXT2_ET_MMP_FAILED, - "MMP: device currently active" - -ec EXT2_ET_MMP_FSCK_ON, - "MMP: fsck being run" - -ec EXT2_ET_MMP_BAD_BLOCK, - "MMP: block number beyond filesystem range" - -ec EXT2_ET_MMP_UNKNOWN_SEQ, - "MMP: undergoing an unknown operation" - -ec EXT2_ET_MMP_CHANGE_ABORT, - "MMP: filesystem still in use" - -ec EXT2_ET_MMP_OPEN_DIRECT, - "MMP: open with O_DIRECT failed" - -ec EXT2_ET_BAD_DESC_SIZE, - "Block group descriptor size incorrect" - -ec EXT2_ET_INODE_CSUM_INVALID, - "Inode checksum does not match inode" - -ec EXT2_ET_INODE_BITMAP_CSUM_INVALID, - "Inode bitmap checksum does not match bitmap" - -ec EXT2_ET_EXTENT_CSUM_INVALID, - "Extent block checksum does not match extent block" - -ec EXT2_ET_DIR_NO_SPACE_FOR_CSUM, - "Directory block does not have space for checksum" - -ec EXT2_ET_DIR_CSUM_INVALID, - "Directory block checksum does not match directory block" - -ec EXT2_ET_EXT_ATTR_CSUM_INVALID, - "Extended attribute block checksum does not match block" - -ec EXT2_ET_SB_CSUM_INVALID, - "Superblock checksum does not match superblock" - -ec EXT2_ET_UNKNOWN_CSUM, - "Unknown checksum algorithm" - -ec EXT2_ET_MMP_CSUM_INVALID, - "MMP block checksum does not match MMP block" - -ec EXT2_ET_FILE_EXISTS, - "Ext2 file already exists" - end diff --git a/lib/ext2fs/ext2_err.h b/lib/ext2fs/ext2_err.h index 70224181..7b2df090 100644 --- a/lib/ext2fs/ext2_err.h +++ b/lib/ext2fs/ext2_err.h @@ -114,9 +114,9 @@ #define EXT2_ET_DBLIST_EMPTY (2133571434L) #define EXT2_ET_RO_BLOCK_ITERATE (2133571435L) #define EXT2_ET_MAGIC_EXTENT_PATH (2133571436L) -#define EXT2_ET_MAGIC_GENERIC_BITMAP64 (2133571437L) -#define EXT2_ET_MAGIC_BLOCK_BITMAP64 (2133571438L) -#define EXT2_ET_MAGIC_INODE_BITMAP64 (2133571439L) +#define EXT2_ET_MAGIC_RESERVED_10 (2133571437L) +#define EXT2_ET_MAGIC_RESERVED_11 (2133571438L) +#define EXT2_ET_MAGIC_RESERVED_12 (2133571439L) #define EXT2_ET_MAGIC_RESERVED_13 (2133571440L) #define EXT2_ET_MAGIC_RESERVED_14 (2133571441L) #define EXT2_ET_MAGIC_RESERVED_15 (2133571442L) @@ -141,26 +141,7 @@ #define EXT2_ET_EXTENT_NOT_SUPPORTED (2133571461L) #define EXT2_ET_EXTENT_INVALID_LENGTH (2133571462L) #define EXT2_ET_IO_CHANNEL_NO_SUPPORT_64 (2133571463L) -#define EXT2_ET_NO_MTAB_FILE (2133571464L) -#define EXT2_ET_CANT_USE_LEGACY_BITMAPS (2133571465L) -#define EXT2_ET_MMP_MAGIC_INVALID (2133571466L) -#define EXT2_ET_MMP_FAILED (2133571467L) -#define EXT2_ET_MMP_FSCK_ON (2133571468L) -#define EXT2_ET_MMP_BAD_BLOCK (2133571469L) -#define EXT2_ET_MMP_UNKNOWN_SEQ (2133571470L) -#define EXT2_ET_MMP_CHANGE_ABORT (2133571471L) -#define EXT2_ET_MMP_OPEN_DIRECT (2133571472L) -#define EXT2_ET_BAD_DESC_SIZE (2133571473L) -#define EXT2_ET_INODE_CSUM_INVALID (2133571474L) -#define EXT2_ET_INODE_BITMAP_CSUM_INVALID (2133571475L) -#define EXT2_ET_EXTENT_CSUM_INVALID (2133571476L) -#define EXT2_ET_DIR_NO_SPACE_FOR_CSUM (2133571477L) -#define EXT2_ET_DIR_CSUM_INVALID (2133571478L) -#define EXT2_ET_EXT_ATTR_CSUM_INVALID (2133571479L) -#define EXT2_ET_SB_CSUM_INVALID (2133571480L) -#define EXT2_ET_UNKNOWN_CSUM (2133571481L) -#define EXT2_ET_MMP_CSUM_INVALID (2133571482L) -#define EXT2_ET_FILE_EXISTS (2133571483L) +#define EXT2_NO_MTAB_FILE (2133571464L) extern const struct error_table et_ext2_error_table; extern void initialize_ext2_error_table(void); diff --git a/lib/ext2fs/ext2_fs.h b/lib/ext2fs/ext2_fs.h index 930c2a3f..afd33a93 100644 --- a/lib/ext2fs/ext2_fs.h +++ b/lib/ext2fs/ext2_fs.h @@ -44,14 +44,13 @@ */ #define EXT2_BAD_INO 1 /* Bad blocks inode */ #define EXT2_ROOT_INO 2 /* Root inode */ -#define EXT4_USR_QUOTA_INO 3 /* User quota inode */ -#define EXT4_GRP_QUOTA_INO 4 /* Group quota inode */ +#define EXT2_ACL_IDX_INO 3 /* ACL inode */ +#define EXT2_ACL_DATA_INO 4 /* ACL inode */ #define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */ #define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */ #define EXT2_RESIZE_INO 7 /* Reserved group descriptors inode */ #define EXT2_JOURNAL_INO 8 /* Journal inode */ #define EXT2_EXCLUDE_INO 9 /* The "exclude" inode, for snapshots */ -#define EXT4_REPLICA_INO 10 /* Used by non-upstream feature */ /* First non-reserved inode for old ext2 filesystems */ #define EXT2_GOOD_OLD_FIRST_INO 11 @@ -99,27 +98,18 @@ #define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof(__u32)) /* - * Macro-instructions used to manage allocation clusters - */ -#define EXT2_MIN_CLUSTER_LOG_SIZE EXT2_MIN_BLOCK_LOG_SIZE -#define EXT2_MAX_CLUSTER_LOG_SIZE 29 /* 512MB */ -#define EXT2_MIN_CLUSTER_SIZE EXT2_MIN_BLOCK_SIZE -#define EXT2_MAX_CLUSTER_SIZE (1 << EXT2_MAX_CLUSTER_LOG_SIZE) -#define EXT2_CLUSTER_SIZE(s) (EXT2_MIN_BLOCK_SIZE << \ - (s)->s_log_cluster_size) -#define EXT2_CLUSTER_SIZE_BITS(s) ((s)->s_log_cluster_size + 10) - -/* * Macro-instructions used to manage fragments - * - * Note: for backwards compatibility only, for the dump program. - * Ext2/3/4 will never support fragments.... */ -#define EXT2_MIN_FRAG_SIZE EXT2_MIN_BLOCK_SIZE -#define EXT2_MAX_FRAG_SIZE EXT2_MAX_BLOCK_SIZE -#define EXT2_MIN_FRAG_LOG_SIZE EXT2_MIN_BLOCK_LOG_SIZE -#define EXT2_FRAG_SIZE(s) EXT2_BLOCK_SIZE(s) -#define EXT2_FRAGS_PER_BLOCK(s) 1 +#define EXT2_MIN_FRAG_SIZE EXT2_MIN_BLOCK_SIZE +#define EXT2_MAX_FRAG_SIZE EXT2_MAX_BLOCK_SIZE +#define EXT2_MIN_FRAG_LOG_SIZE EXT2_MIN_BLOCK_LOG_SIZE +#ifdef __KERNEL__ +# define EXT2_FRAG_SIZE(s) (EXT2_SB(s)->s_frag_size) +# define EXT2_FRAGS_PER_BLOCK(s) (EXT2_SB(s)->s_frags_per_block) +#else +# define EXT2_FRAG_SIZE(s) (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size) +# define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s)) +#endif /* * ACL structures @@ -155,16 +145,11 @@ struct ext2_group_desc __u16 bg_free_inodes_count; /* Free inodes count */ __u16 bg_used_dirs_count; /* Directories count */ __u16 bg_flags; - __u32 bg_exclude_bitmap_lo; /* Exclude bitmap for snapshots */ - __u16 bg_block_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+bitmap) LSB */ - __u16 bg_inode_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+bitmap) LSB */ + __u32 bg_reserved[2]; __u16 bg_itable_unused; /* Unused inodes count */ - __u16 bg_checksum; /* crc16(s_uuid+group_num+group_desc)*/ + __u16 bg_checksum; /* crc16(s_uuid+grouo_num+group_desc)*/ }; -/* - * Structure of a blocks group descriptor - */ struct ext4_group_desc { __u32 bg_block_bitmap; /* Blocks bitmap block */ @@ -173,23 +158,18 @@ struct ext4_group_desc __u16 bg_free_blocks_count; /* Free blocks count */ __u16 bg_free_inodes_count; /* Free inodes count */ __u16 bg_used_dirs_count; /* Directories count */ - __u16 bg_flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */ - __u32 bg_exclude_bitmap_lo; /* Exclude bitmap for snapshots */ - __u16 bg_block_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+bitmap) LSB */ - __u16 bg_inode_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+bitmap) LSB */ + __u16 bg_flags; + __u32 bg_reserved[2]; __u16 bg_itable_unused; /* Unused inodes count */ - __u16 bg_checksum; /* crc16(sb_uuid+group+desc) */ + __u16 bg_checksum; /* crc16(s_uuid+grouo_num+group_desc)*/ __u32 bg_block_bitmap_hi; /* Blocks bitmap block MSB */ __u32 bg_inode_bitmap_hi; /* Inodes bitmap block MSB */ __u32 bg_inode_table_hi; /* Inodes table block MSB */ __u16 bg_free_blocks_count_hi;/* Free blocks count MSB */ __u16 bg_free_inodes_count_hi;/* Free inodes count MSB */ __u16 bg_used_dirs_count_hi; /* Directories count MSB */ - __u16 bg_itable_unused_hi; /* Unused inodes count MSB */ - __u32 bg_exclude_bitmap_hi; /* Exclude bitmap block MSB */ - __u16 bg_block_bitmap_csum_hi;/* crc32c(s_uuid+grp_num+bitmap) MSB */ - __u16 bg_inode_bitmap_csum_hi;/* crc32c(s_uuid+grp_num+bitmap) MSB */ - __u32 bg_reserved; + __u16 bg_pad; + __u32 bg_reserved2[3]; }; #define EXT2_BG_INODE_UNINIT 0x0001 /* Inode table/bitmap not initialized */ @@ -248,15 +228,10 @@ struct ext2_dx_countlimit { #define EXT2_BLOCKS_PER_GROUP(s) (EXT2_SB(s)->s_blocks_per_group) #define EXT2_INODES_PER_GROUP(s) (EXT2_SB(s)->s_inodes_per_group) -#define EXT2_CLUSTERS_PER_GROUP(s) (EXT2_SB(s)->s_clusters_per_group) #define EXT2_INODES_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s)/EXT2_INODE_SIZE(s)) /* limits imposed by 16-bit value gd_free_{blocks,inode}_count */ -#define EXT2_MAX_BLOCKS_PER_GROUP(s) ((((unsigned) 1 << 16) - 8) * \ - (EXT2_CLUSTER_SIZE(s) / \ - EXT2_BLOCK_SIZE(s))) -#define EXT2_MAX_CLUSTERS_PER_GROUP(s) (((unsigned) 1 << 16) - 8) -#define EXT2_MAX_INODES_PER_GROUP(s) (((unsigned) 1 << 16) - \ - EXT2_INODES_PER_BLOCK(s)) +#define EXT2_MAX_BLOCKS_PER_GROUP(s) ((1 << 16) - 8) +#define EXT2_MAX_INODES_PER_GROUP(s) ((1 << 16) - EXT2_INODES_PER_BLOCK(s)) #ifdef __KERNEL__ #define EXT2_DESC_PER_BLOCK(s) (EXT2_SB(s)->s_desc_per_block) #define EXT2_DESC_PER_BLOCK_BITS(s) (EXT2_SB(s)->s_desc_per_block_bits) @@ -300,8 +275,7 @@ struct ext2_dx_countlimit { #define EXT4_HUGE_FILE_FL 0x00040000 /* Set to each huge file */ #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */ #define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */ -/* EXT4_EOFBLOCKS_FL 0x00400000 was here */ -#define FS_NOCOW_FL 0x00800000 /* Do not cow file */ +#define EXT4_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */ #define EXT4_SNAPFILE_FL 0x01000000 /* Inode is a snapshot */ #define EXT4_SNAPFILE_DELETED_FL 0x04000000 /* Snapshot is being deleted */ #define EXT4_SNAPFILE_SHRUNK_FL 0x08000000 /* Snapshot shrink has completed */ @@ -348,7 +322,6 @@ struct ext4_new_group_input { #define EXT2_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long) #define EXT2_IOC_GROUP_ADD _IOW('f', 8,struct ext2_new_group_input) #define EXT4_IOC_GROUP_ADD _IOW('f', 8,struct ext4_new_group_input) -#define EXT4_IOC_RESIZE_FS _IOW('f', 16, __u64) /* * Structure of an inode on the disk @@ -376,7 +349,7 @@ struct ext2_inode { __u32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */ __u32 i_generation; /* File version (for NFS) */ __u32 i_file_acl; /* File ACL */ - __u32 i_size_high; /* Formerly i_dir_acl, directory ACL */ + __u32 i_dir_acl; /* Directory ACL */ __u32 i_faddr; /* Fragment address */ union { struct { @@ -384,8 +357,7 @@ struct ext2_inode { __u16 l_i_file_acl_high; __u16 l_i_uid_high; /* these 2 fields */ __u16 l_i_gid_high; /* were reserved2[0] */ - __u16 l_i_checksum_lo; /* crc32c(uuid+inum+inode) */ - __u16 l_i_reserved; + __u32 l_i_reserved2; } linux2; struct { __u8 h_i_frag; /* Fragment number */ @@ -424,7 +396,7 @@ struct ext2_inode_large { __u32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */ __u32 i_generation; /* File version (for NFS) */ __u32 i_file_acl; /* File ACL */ - __u32 i_size_high; /* Formerly i_dir_acl, directory ACL */ + __u32 i_dir_acl; /* Directory ACL */ __u32 i_faddr; /* Fragment address */ union { struct { @@ -432,8 +404,7 @@ struct ext2_inode_large { __u16 l_i_file_acl_high; __u16 l_i_uid_high; /* these 2 fields */ __u16 l_i_gid_high; /* were reserved2[0] */ - __u16 l_i_checksum_lo; /* crc32c(uuid+inum+inode) */ - __u16 l_i_reserved; + __u32 l_i_reserved2; } linux2; struct { __u8 h_i_frag; /* Fragment number */ @@ -445,7 +416,7 @@ struct ext2_inode_large { } hurd2; } osd2; /* OS dependent 2 */ __u16 i_extra_isize; - __u16 i_checksum_hi; /* crc32c(uuid+inum+inode) */ + __u16 i_pad1; __u32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */ __u32 i_mtime_extra; /* extra Modification time (nsec << 2 | epoch) */ __u32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */ @@ -454,7 +425,7 @@ struct ext2_inode_large { __u32 i_version_hi; /* high 32 bits for 64-bit version */ }; -#define i_dir_acl i_size_high +#define i_size_high i_dir_acl #if defined(__KERNEL__) || defined(__linux__) #define i_reserved1 osd1.linux1.l_i_reserved1 @@ -464,6 +435,7 @@ struct ext2_inode_large { #define i_gid_low i_gid #define i_uid_high osd2.linux2.l_i_uid_high #define i_gid_high osd2.linux2.l_i_gid_high +#define i_reserved2 osd2.linux2.l_i_reserved2 #else #if defined(__GNU__) @@ -546,9 +518,9 @@ struct ext2_super_block { __u32 s_free_inodes_count; /* Free inodes count */ __u32 s_first_data_block; /* First Data Block */ __u32 s_log_block_size; /* Block size */ - __u32 s_log_cluster_size; /* Allocation cluster size */ + __s32 s_log_frag_size; /* Fragment size */ __u32 s_blocks_per_group; /* # Blocks per group */ - __u32 s_clusters_per_group; /* # Fragments per group */ + __u32 s_frags_per_group; /* # Fragments per group */ __u32 s_inodes_per_group; /* # Inodes per group */ __u32 s_mtime; /* Mount time */ __u32 s_wtime; /* Write time */ @@ -616,7 +588,7 @@ struct ext2_super_block { __u16 s_want_extra_isize; /* New inodes should reserve # bytes */ __u32 s_flags; /* Miscellaneous flags */ __u16 s_raid_stride; /* RAID stride */ - __u16 s_mmp_update_interval; /* # seconds to wait in MMP checking */ + __u16 s_mmp_interval; /* # seconds to wait in MMP checking */ __u64 s_mmp_block; /* Block for multi-mount protection */ __u32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/ __u8 s_log_groups_per_flex; /* FLEX_BG group size */ @@ -642,11 +614,7 @@ struct ext2_super_block { __u8 s_last_error_func[32]; /* function where the error happened */ #define EXT4_S_ERR_END ext4_offsetof(struct ext2_super_block, s_mount_opts) __u8 s_mount_opts[64]; - __u32 s_usr_quota_inum; /* inode number of user quota file */ - __u32 s_grp_quota_inum; /* inode number of group quota file */ - __u32 s_overhead_blocks; /* overhead blocks/clusters in fs */ - __u32 s_reserved[108]; /* Padding to the end of the block */ - __u32 s_checksum; /* crc32c(superblock) */ + __u32 s_reserved[112]; /* Padding to the end of the block */ }; #define EXT4_S_ERR_LEN (EXT4_S_ERR_END - EXT4_S_ERR_START) @@ -694,9 +662,7 @@ struct ext2_super_block { #define EXT2_FEATURE_COMPAT_RESIZE_INODE 0x0010 #define EXT2_FEATURE_COMPAT_DIR_INDEX 0x0020 #define EXT2_FEATURE_COMPAT_LAZY_BG 0x0040 -/* #define EXT2_FEATURE_COMPAT_EXCLUDE_INODE 0x0080 not used, legacy */ -#define EXT2_FEATURE_COMPAT_EXCLUDE_BITMAP 0x0100 - +#define EXT2_FEATURE_COMPAT_EXCLUDE_INODE 0x0080 #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 #define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002 @@ -706,10 +672,6 @@ struct ext2_super_block { #define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020 #define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040 #define EXT4_FEATURE_RO_COMPAT_HAS_SNAPSHOT 0x0080 -#define EXT4_FEATURE_RO_COMPAT_QUOTA 0x0100 -#define EXT4_FEATURE_RO_COMPAT_BIGALLOC 0x0200 -#define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400 -#define EXT4_FEATURE_RO_COMPAT_REPLICA 0x0800 #define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001 #define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002 @@ -722,13 +684,10 @@ struct ext2_super_block { #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 #define EXT4_FEATURE_INCOMPAT_EA_INODE 0x0400 #define EXT4_FEATURE_INCOMPAT_DIRDATA 0x1000 -/* 0x2000 was EXT4_FEATURE_INCOMPAT_BG_USE_META_CSUM but this was never used */ -#define EXT4_FEATURE_INCOMPAT_LARGEDIR 0x4000 /* >2GB or 3-lvl htree */ -#define EXT4_FEATURE_INCOMPAT_INLINEDATA 0x8000 /* data in inode */ + #define EXT2_FEATURE_COMPAT_SUPP 0 -#define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \ - EXT4_FEATURE_INCOMPAT_MMP) +#define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE) #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \ EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \ EXT4_FEATURE_RO_COMPAT_DIR_NLINK| \ @@ -809,52 +768,28 @@ struct ext2_dir_entry_2 { ~EXT2_DIR_ROUND) /* - * This structure is used for multiple mount protection. It is written - * into the block number saved in the s_mmp_block field in the superblock. - * Programs that check MMP should assume that if SEQ_FSCK (or any unknown - * code above SEQ_MAX) is present then it is NOT safe to use the filesystem, - * regardless of how old the timestamp is. - * - * The timestamp in the MMP structure will be updated by e2fsck at some - * arbitary intervals (start of passes, after every few groups of inodes - * in pass1 and pass1b). There is no guarantee that e2fsck is updating - * the MMP block in a timely manner, and the updates it does are purely - * for the convenience of the sysadmin and not for automatic validation. - * - * Note: Only the mmp_seq value is used to determine whether the MMP block - * is being updated. The mmp_time, mmp_nodename, and mmp_bdevname - * fields are only for informational purposes for the administrator, - * due to clock skew between nodes and hostname HA service takeover. + * This structure will be used for multiple mount protection. It will be + * written into the block number saved in the s_mmp_block field in the + * superblock. */ -#define EXT4_MMP_MAGIC 0x004D4D50U /* ASCII for MMP */ -#define EXT4_MMP_SEQ_CLEAN 0xFF4D4D50U /* mmp_seq value for clean unmount */ -#define EXT4_MMP_SEQ_FSCK 0xE24D4D50U /* mmp_seq value when being fscked */ -#define EXT4_MMP_SEQ_MAX 0xE24D4D4FU /* maximum valid mmp_seq value */ +#define EXT2_MMP_MAGIC 0x004D4D50 /* ASCII for MMP */ +#define EXT2_MMP_CLEAN 0xFF4D4D50 /* Value of mmp_seq for clean unmount */ +#define EXT2_MMP_FSCK_ON 0xE24D4D50 /* Value of mmp_seq when being fscked */ struct mmp_struct { - __u32 mmp_magic; /* Magic number for MMP */ - __u32 mmp_seq; /* Sequence no. updated periodically */ - __u64 mmp_time; /* Time last updated */ - char mmp_nodename[64]; /* Node which last updated MMP block */ - char mmp_bdevname[32]; /* Bdev which last updated MMP block */ - __u16 mmp_check_interval; /* Changed mmp_check_interval */ + __u32 mmp_magic; + __u32 mmp_seq; + __u64 mmp_time; + char mmp_nodename[64]; + char mmp_bdevname[32]; + __u16 mmp_interval; __u16 mmp_pad1; - __u32 mmp_pad2[227]; + __u32 mmp_pad2; }; /* - * Default interval for MMP update in seconds. - */ -#define EXT4_MMP_UPDATE_INTERVAL 5 - -/* - * Maximum interval for MMP update in seconds. - */ -#define EXT4_MMP_MAX_UPDATE_INTERVAL 300 - -/* - * Minimum interval for MMP checking in seconds. + * Interval in number of seconds to update the MMP sequence number. */ -#define EXT4_MMP_MIN_CHECK_INTERVAL 5 +#define EXT2_MMP_DEF_INTERVAL 5 #endif /* _LINUX_EXT2_FS_H */ diff --git a/lib/ext2fs/ext2_io.h b/lib/ext2fs/ext2_io.h index 1894fb8c..b917559c 100644 --- a/lib/ext2fs/ext2_io.h +++ b/lib/ext2fs/ext2_io.h @@ -29,10 +29,6 @@ typedef struct struct_io_channel *io_channel; typedef struct struct_io_stats *io_stats; #define CHANNEL_FLAGS_WRITETHROUGH 0x01 -#define CHANNEL_FLAGS_DISCARD_ZEROES 0x02 -#define CHANNEL_FLAGS_BLOCK_DEVICE 0x04 - -#define io_channel_discard_zeroes_data(i) (i->flags & CHANNEL_FLAGS_DISCARD_ZEROES) struct struct_io_channel { errcode_t magic; @@ -58,7 +54,6 @@ struct struct_io_channel { long reserved[14]; void *private_data; void *app_data; - int align; }; struct struct_io_stats { @@ -88,8 +83,6 @@ struct struct_io_manager { int count, void *data); errcode_t (*write_blk64)(io_channel channel, unsigned long long block, int count, const void *data); - errcode_t (*discard)(io_channel channel, unsigned long long block, - unsigned long long count); long reserved[16]; }; @@ -119,11 +112,6 @@ extern errcode_t io_channel_read_blk64(io_channel channel, extern errcode_t io_channel_write_blk64(io_channel channel, unsigned long long block, int count, const void *data); -extern errcode_t io_channel_discard(io_channel channel, - unsigned long long block, - unsigned long long count); -extern errcode_t io_channel_alloc_buf(io_channel channel, - int count, void *ptr); /* unix_io.c */ extern io_manager unix_io_manager; @@ -139,10 +127,6 @@ extern void (*test_io_cb_read_blk) (unsigned long block, int count, errcode_t err); extern void (*test_io_cb_write_blk) (unsigned long block, int count, errcode_t err); -extern void (*test_io_cb_read_blk64) - (unsigned long long block, int count, errcode_t err); -extern void (*test_io_cb_write_blk64) - (unsigned long long block, int count, errcode_t err); extern void (*test_io_cb_set_blksize) (int blksize, errcode_t err); diff --git a/lib/ext2fs/ext2_types.h b/lib/ext2fs/ext2_types.h index 18d4f9bd..27277fa3 100644 --- a/lib/ext2fs/ext2_types.h +++ b/lib/ext2fs/ext2_types.h @@ -7,6 +7,14 @@ !defined(_EXT2_TYPES_H)) #define _EXT2_TYPES_H +#define __S8_TYPEDEF __signed__ char +#define __U8_TYPEDEF unsigned char +#define __S16_TYPEDEF __signed__ short +#define __U16_TYPEDEF unsigned short +#define __S32_TYPEDEF __signed__ int +#define __U32_TYPEDEF unsigned int +#define __S64_TYPEDEF __signed__ long long +#define __U64_TYPEDEF unsigned long long #ifdef __U8_TYPEDEF typedef __U8_TYPEDEF __u8; @@ -91,11 +99,11 @@ typedef __U64_TYPEDEF __u64; #if (4 == 8) typedef unsigned int __u64; #else -#if (8 == 8) -typedef unsigned long long __u64; -#else #if (4 == 8) typedef unsigned long __u64; +#else +#if (8 == 8) +typedef unsigned long long __u64; #endif /* SIZEOF_LONG_LONG == 8 */ #endif /* SIZEOF_LONG == 8 */ #endif /* SIZEOF_INT == 8 */ @@ -107,15 +115,15 @@ typedef __S64_TYPEDEF __s64; #if (4 == 8) typedef int __s64; #else +#if (4 == 8) +typedef long __s64; +#else #if (8 == 8) #if defined(__GNUC__) -typedef __signed__ long long __s64; +typedef __signed__ long long __s64; #else -typedef signed long long __s64; +typedef signed long long __s64; #endif /* __GNUC__ */ -#else -#if (4 == 8) -typedef long __s64; #endif /* SIZEOF_LONG_LONG == 8 */ #endif /* SIZEOF_LONG == 8 */ #endif /* SIZEOF_INT == 8 */ diff --git a/lib/ext2fs/ext2_types.h.in b/lib/ext2fs/ext2_types.h.in index 5b98f715..aa7ca3a9 100644 --- a/lib/ext2fs/ext2_types.h.in +++ b/lib/ext2fs/ext2_types.h.in @@ -92,11 +92,11 @@ typedef __U64_TYPEDEF __u64; #if (@SIZEOF_INT@ == 8) typedef unsigned int __u64; #else -#if (@SIZEOF_LONG_LONG@ == 8) -typedef unsigned long long __u64; -#else #if (@SIZEOF_LONG@ == 8) typedef unsigned long __u64; +#else +#if (@SIZEOF_LONG_LONG@ == 8) +typedef unsigned long long __u64; #endif /* SIZEOF_LONG_LONG == 8 */ #endif /* SIZEOF_LONG == 8 */ #endif /* SIZEOF_INT == 8 */ @@ -108,15 +108,15 @@ typedef __S64_TYPEDEF __s64; #if (@SIZEOF_INT@ == 8) typedef int __s64; #else +#if (@SIZEOF_LONG@ == 8) +typedef long __s64; +#else #if (@SIZEOF_LONG_LONG@ == 8) #if defined(__GNUC__) -typedef __signed__ long long __s64; +typedef __signed__ long long __s64; #else -typedef signed long long __s64; +typedef signed long long __s64; #endif /* __GNUC__ */ -#else -#if (@SIZEOF_LONG@ == 8) -typedef long __s64; #endif /* SIZEOF_LONG_LONG == 8 */ #endif /* SIZEOF_LONG == 8 */ #endif /* SIZEOF_INT == 8 */ diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index fb6b0b43..3573e854 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -30,6 +30,14 @@ extern "C" { #endif /* + * The Apple compiler in Xcode 4.3 fails when inlines are enabled in + * so disable them for that compiler. + */ +#if __APPLE_CC__ >= 5621 +#define NO_INLINE_FUNCS +#endif + +/* * Where the master copy of the superblock is located, and how big * superblocks are supposed to be. We define SUPERBLOCK_SIZE because * the size of the superblock structure is not necessarily trustworthy @@ -37,7 +45,7 @@ extern "C" { * 1032 bytes long). */ #define SUPERBLOCK_OFFSET 1024 -#define SUPERBLOCK_SIZE 1024 +#define SUPERBLOCK_SIZE 1024 /* * The last ext2fs revision level that this version of the library is @@ -64,20 +72,13 @@ extern "C" { #include <ext2fs/ext3_extents.h> #endif /* EXT2_FLAT_INCLUDES */ -#ifdef __CHECK_ENDIAN__ -#define __bitwise __attribute__((bitwise)) -#else -#define __bitwise -#endif - -typedef __u32 __bitwise ext2_ino_t; -typedef __u32 __bitwise blk_t; -typedef __u64 __bitwise blk64_t; -typedef __u32 __bitwise dgrp_t; -typedef __u32 __bitwise ext2_off_t; -typedef __u64 __bitwise ext2_off64_t; -typedef __s64 __bitwise e2_blkcnt_t; -typedef __u32 __bitwise ext2_dirhash_t; +typedef __u32 ext2_ino_t; +typedef __u32 blk_t; +typedef __u64 blk64_t; +typedef __u32 dgrp_t; +typedef __u32 ext2_off_t; +typedef __s64 e2_blkcnt_t; +typedef __u32 ext2_dirhash_t; #if EXT2_FLAT_INCLUDES #include "com_err.h" @@ -132,13 +133,6 @@ typedef struct ext2_struct_u32_iterate *badblocks_iterate; /* * ext2_dblist structure and abstractions (see dblist.c) */ -struct ext2_db_entry2 { - ext2_ino_t ino; - blk64_t blk; - e2_blkcnt_t blockcnt; -}; - -/* Ye Olde 32-bit version */ struct ext2_db_entry { ext2_ino_t ino; blk_t blk; @@ -187,10 +181,7 @@ typedef struct ext2_file *ext2_file_t; #define EXT2_FLAG_EXCLUSIVE 0x4000 #define EXT2_FLAG_SOFTSUPP_FEATURES 0x8000 #define EXT2_FLAG_NOFREE_ON_ERROR 0x10000 -#define EXT2_FLAG_64BITS 0x20000 -#define EXT2_FLAG_PRINT_PROGRESS 0x40000 #define EXT2_FLAG_DIRECT_IO 0x80000 -#define EXT2_FLAG_SKIP_MMP 0x100000 /* * Special flag in the ext2 inode i_flag field that means that this is @@ -200,12 +191,10 @@ typedef struct ext2_file *ext2_file_t; /* * Flags for mkjournal + * + * EXT2_MKJOURNAL_V1_SUPER Make a (deprecated) V1 journal superblock */ -#define EXT2_MKJOURNAL_V1_SUPER 0x0000001 /* create V1 superblock (deprecated) */ -#define EXT2_MKJOURNAL_LAZYINIT 0x0000002 /* don't zero journal inode before use*/ -#define EXT2_MKJOURNAL_NO_MNT_CHECK 0x0000004 /* don't check mount status */ - -struct opaque_ext2_group_desc; +#define EXT2_MKJOURNAL_V1_SUPER 0x0000001 struct struct_ext2_filsys { errcode_t magic; @@ -217,11 +206,10 @@ struct struct_ext2_filsys { int fragsize; dgrp_t group_desc_count; unsigned long desc_blocks; - struct opaque_ext2_group_desc * group_desc; - unsigned int inode_blocks_per_group; + struct ext2_group_desc * group_desc; + int inode_blocks_per_group; ext2fs_inode_bitmap inode_map; ext2fs_block_bitmap block_map; - /* XXX FIXME-64: not 64-bit safe, but not used? */ errcode_t (*get_blocks)(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks); errcode_t (*check_directory)(ext2_filsys fs, ext2_ino_t ino); errcode_t (*write_bitmaps)(ext2_filsys fs); @@ -236,13 +224,10 @@ struct struct_ext2_filsys { struct ext2_image_hdr * image_header; __u32 umask; time_t now; - int cluster_ratio_bits; - __u16 default_bitmap_type; - __u16 pad; /* * Reserved for future expansion */ - __u32 reserved[5]; + __u32 reserved[7]; /* * Reserved for the use of the calling application. @@ -261,18 +246,6 @@ struct struct_ext2_filsys { errcode_t (*get_alloc_block)(ext2_filsys fs, blk64_t goal, blk64_t *ret); void (*block_alloc_stats)(ext2_filsys fs, blk64_t blk, int inuse); - - /* - * Buffers for Multiple mount protection(MMP) block. - */ - void *mmp_buf; - void *mmp_cmp; - int mmp_fd; - - /* - * Time at which e2fsck last updated the MMP block. - */ - long mmp_last_written; }; #if EXT2_FLAT_INCLUDES @@ -282,13 +255,6 @@ struct struct_ext2_filsys { #endif /* - * 64-bit bitmap backend types - */ -#define EXT2FS_BMAP64_BITARRAY 1 -#define EXT2FS_BMAP64_RBTREE 2 -#define EXT2FS_BMAP64_AUTODIR 3 - -/* * Return flags for the block iterator functions */ #define BLOCK_CHANGED 1 @@ -566,97 +532,44 @@ 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_MMP|\ - EXT4_FEATURE_INCOMPAT_64BIT) + EXT4_FEATURE_INCOMPAT_FLEX_BG) #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_MMP|\ - EXT4_FEATURE_INCOMPAT_64BIT) + EXT4_FEATURE_INCOMPAT_FLEX_BG) #endif -#ifdef CONFIG_QUOTA #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\ EXT4_FEATURE_RO_COMPAT_HUGE_FILE|\ EXT2_FEATURE_RO_COMPAT_LARGE_FILE|\ EXT4_FEATURE_RO_COMPAT_DIR_NLINK|\ EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|\ - EXT4_FEATURE_RO_COMPAT_GDT_CSUM|\ - EXT4_FEATURE_RO_COMPAT_BIGALLOC|\ - EXT4_FEATURE_RO_COMPAT_QUOTA) -#else -#define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\ - EXT4_FEATURE_RO_COMPAT_HUGE_FILE|\ - EXT2_FEATURE_RO_COMPAT_LARGE_FILE|\ - EXT4_FEATURE_RO_COMPAT_DIR_NLINK|\ - EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|\ - EXT4_FEATURE_RO_COMPAT_GDT_CSUM|\ - EXT4_FEATURE_RO_COMPAT_BIGALLOC) -#endif + EXT4_FEATURE_RO_COMPAT_GDT_CSUM) /* * These features are only allowed if EXT2_FLAG_SOFTSUPP_FEATURES is passed * to ext2fs_openfs() */ #define EXT2_LIB_SOFTSUPP_INCOMPAT (0) -#define EXT2_LIB_SOFTSUPP_RO_COMPAT (EXT4_FEATURE_RO_COMPAT_REPLICA) - - -/* Translate a block number to a cluster number */ -#define EXT2FS_CLUSTER_RATIO(fs) (1 << (fs)->cluster_ratio_bits) -#define EXT2FS_CLUSTER_MASK(fs) (EXT2FS_CLUSTER_RATIO(fs) - 1) -#define EXT2FS_B2C(fs, blk) ((blk) >> (fs)->cluster_ratio_bits) -/* Translate a cluster number to a block number */ -#define EXT2FS_C2B(fs, cluster) ((cluster) << (fs)->cluster_ratio_bits) -/* Translate # of blks to # of clusters */ -#define EXT2FS_NUM_B2C(fs, blks) (((blks) + EXT2FS_CLUSTER_MASK(fs)) >> \ - (fs)->cluster_ratio_bits) - -#if defined(HAVE_FSTAT64) && !defined(__OSX_AVAILABLE_BUT_DEPRECATED) -typedef struct stat64 ext2fs_struct_stat; -#else -typedef struct stat ext2fs_struct_stat; -#endif - -/* - * For ext2fs_close2() and ext2fs_flush2(), this flag allows you to - * avoid the fsync call. - */ -#define EXT2_FLAG_FLUSH_NO_SYNC 1 +#define EXT2_LIB_SOFTSUPP_RO_COMPAT (0) /* * function prototypes */ -/* The LARGE_FILE feature should be set if we have stored files 2GB+ in size */ -static inline int ext2fs_needs_large_file_feature(unsigned long long file_size) -{ - return file_size >= 0x80000000ULL; -} - /* alloc.c */ 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, @@ -682,7 +595,6 @@ 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); @@ -747,10 +659,6 @@ extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs); extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs, const char *descr, ext2fs_block_bitmap *ret); -extern errcode_t ext2fs_allocate_subcluster_bitmap(ext2_filsys fs, - const char *descr, - ext2fs_block_bitmap *ret); -extern int ext2fs_get_bitmap_granularity(ext2fs_block_bitmap bitmap); extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs, const char *descr, ext2fs_inode_bitmap *ret); @@ -758,22 +666,14 @@ extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap, ext2_ino_t end, ext2_ino_t *oend); extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap, blk_t end, blk_t *oend); -extern errcode_t ext2fs_fudge_block_bitmap_end2(ext2fs_block_bitmap bitmap, - blk64_t end, blk64_t *oend); extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap); extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap); extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs); extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs); extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end, ext2fs_inode_bitmap bmap); -extern errcode_t ext2fs_resize_inode_bitmap2(__u64 new_end, - __u64 new_real_end, - ext2fs_inode_bitmap bmap); extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end, ext2fs_block_bitmap bmap); -extern errcode_t ext2fs_resize_block_bitmap2(__u64 new_end, - __u64 new_real_end, - ext2fs_block_bitmap bmap); extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1, ext2fs_block_bitmap bm2); extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1, @@ -781,88 +681,16 @@ extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1, extern errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap, ext2_ino_t start, unsigned int num, void *in); -extern errcode_t ext2fs_set_inode_bitmap_range2(ext2fs_inode_bitmap bmap, - __u64 start, size_t num, - void *in); extern errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap, ext2_ino_t start, unsigned int num, void *out); -extern errcode_t ext2fs_get_inode_bitmap_range2(ext2fs_inode_bitmap bmap, - __u64 start, size_t num, - void *out); extern errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap, blk_t start, unsigned int num, void *in); -extern errcode_t ext2fs_set_block_bitmap_range2(ext2fs_block_bitmap bmap, - blk64_t start, size_t num, - void *in); extern errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap, blk_t start, unsigned int num, void *out); -extern errcode_t ext2fs_get_block_bitmap_range2(ext2fs_block_bitmap bmap, - blk64_t start, size_t num, - void *out); - -/* blknum.c */ -extern dgrp_t ext2fs_group_of_blk2(ext2_filsys fs, blk64_t); -extern blk64_t ext2fs_group_first_block2(ext2_filsys fs, dgrp_t group); -extern blk64_t ext2fs_group_last_block2(ext2_filsys fs, dgrp_t group); -extern int ext2fs_group_blocks_count(ext2_filsys fs, dgrp_t group); -extern blk64_t ext2fs_inode_data_blocks2(ext2_filsys fs, - struct ext2_inode *inode); -extern blk64_t ext2fs_inode_i_blocks(ext2_filsys fs, - struct ext2_inode *inode); -extern blk64_t ext2fs_blocks_count(struct ext2_super_block *super); -extern void ext2fs_blocks_count_set(struct ext2_super_block *super, - blk64_t blk); -extern void ext2fs_blocks_count_add(struct ext2_super_block *super, - blk64_t blk); -extern blk64_t ext2fs_r_blocks_count(struct ext2_super_block *super); -extern void ext2fs_r_blocks_count_set(struct ext2_super_block *super, - blk64_t blk); -extern void ext2fs_r_blocks_count_add(struct ext2_super_block *super, - blk64_t blk); -extern blk64_t ext2fs_free_blocks_count(struct ext2_super_block *super); -extern void ext2fs_free_blocks_count_set(struct ext2_super_block *super, - blk64_t blk); -extern void ext2fs_free_blocks_count_add(struct ext2_super_block *super, - blk64_t blk); -/* Block group descriptor accessor functions */ -extern struct ext2_group_desc *ext2fs_group_desc(ext2_filsys fs, - struct opaque_ext2_group_desc *gdp, - dgrp_t group); -extern blk64_t ext2fs_block_bitmap_loc(ext2_filsys fs, dgrp_t group); -extern void ext2fs_block_bitmap_loc_set(ext2_filsys fs, dgrp_t group, - blk64_t blk); -extern blk64_t ext2fs_inode_bitmap_loc(ext2_filsys fs, dgrp_t group); -extern void ext2fs_inode_bitmap_loc_set(ext2_filsys fs, dgrp_t group, - blk64_t blk); -extern blk64_t ext2fs_inode_table_loc(ext2_filsys fs, dgrp_t group); -extern void ext2fs_inode_table_loc_set(ext2_filsys fs, dgrp_t group, - blk64_t blk); -extern __u32 ext2fs_bg_free_blocks_count(ext2_filsys fs, dgrp_t group); -extern void ext2fs_bg_free_blocks_count_set(ext2_filsys fs, dgrp_t group, - __u32 n); -extern __u32 ext2fs_bg_free_inodes_count(ext2_filsys fs, dgrp_t group); -extern void ext2fs_bg_free_inodes_count_set(ext2_filsys fs, dgrp_t group, - __u32 n); -extern __u32 ext2fs_bg_used_dirs_count(ext2_filsys fs, dgrp_t group); -extern void ext2fs_bg_used_dirs_count_set(ext2_filsys fs, dgrp_t group, - __u32 n); -extern __u32 ext2fs_bg_itable_unused(ext2_filsys fs, dgrp_t group); -extern void ext2fs_bg_itable_unused_set(ext2_filsys fs, dgrp_t group, - __u32 n); -extern __u16 ext2fs_bg_flags(ext2_filsys fs, dgrp_t group); -extern void ext2fs_bg_flags_zap(ext2_filsys fs, dgrp_t group); -extern int ext2fs_bg_flags_test(ext2_filsys fs, dgrp_t group, __u16 bg_flag); -extern void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags); -extern void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flags); -extern __u16 ext2fs_bg_checksum(ext2_filsys fs, dgrp_t group); -extern void ext2fs_bg_checksum_set(ext2_filsys fs, dgrp_t group, __u16 checksum); -extern blk64_t ext2fs_file_acl_block(ext2_filsys fs, - const struct ext2_inode *inode); -extern void ext2fs_file_acl_block_set(ext2_filsys fs, - struct ext2_inode *inode, blk64_t blk); + /* block.c */ extern errcode_t ext2fs_block_iterate(ext2_filsys fs, @@ -885,17 +713,6 @@ errcode_t ext2fs_block_iterate2(ext2_filsys fs, int ref_offset, void *priv_data), void *priv_data); -errcode_t ext2fs_block_iterate3(ext2_filsys fs, - ext2_ino_t ino, - int flags, - char *block_buf, - int (*func)(ext2_filsys fs, - blk64_t *blocknr, - e2_blkcnt_t blockcnt, - blk64_t ref_blk, - int ref_offset, - void *priv_data), - void *priv_data); /* bmap.c */ extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino, @@ -906,9 +723,6 @@ extern errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, char *block_buf, int bmap_flags, blk64_t block, int *ret_flags, blk64_t *phys_blk); -errcode_t ext2fs_map_cluster_block(ext2_filsys fs, ext2_ino_t ino, - struct ext2_inode *inode, blk64_t lblk, - blk64_t *pblk); #if 0 /* bmove.c */ @@ -923,16 +737,8 @@ extern errcode_t ext2fs_check_desc(ext2_filsys fs); /* closefs.c */ extern errcode_t ext2fs_close(ext2_filsys fs); -extern errcode_t ext2fs_close2(ext2_filsys fs, int flags); extern errcode_t ext2fs_flush(ext2_filsys fs); -extern errcode_t ext2fs_flush2(ext2_filsys fs, int flags); -extern int ext2fs_bg_has_super(ext2_filsys fs, dgrp_t 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_bg_has_super(ext2_filsys fs, int group_block); extern int ext2fs_super_and_bgd_loc(ext2_filsys fs, dgrp_t group, blk_t *ret_super_blk, @@ -941,15 +747,10 @@ extern int ext2fs_super_and_bgd_loc(ext2_filsys fs, int *ret_meta_bg); extern void ext2fs_update_dynamic_rev(ext2_filsys fs); -/* crc32c.c */ -extern __u32 ext2fs_crc32c_be(__u32 crc, unsigned char const *p, size_t len); -extern __u32 ext2fs_crc32c_le(__u32 crc, unsigned char const *p, size_t len); - /* csum.c */ extern void ext2fs_group_desc_csum_set(ext2_filsys fs, dgrp_t group); extern int ext2fs_group_desc_csum_verify(ext2_filsys fs, dgrp_t group); extern errcode_t ext2fs_set_gdt_csum(ext2_filsys fs); -extern __u16 ext2fs_group_desc_csum(ext2_filsys fs, dgrp_t group); /* dblist.c */ @@ -957,34 +758,20 @@ extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs); extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist); extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino, blk_t blk, int blockcnt); -extern errcode_t ext2fs_add_dir_block2(ext2_dblist dblist, ext2_ino_t ino, - blk64_t blk, e2_blkcnt_t blockcnt); extern void ext2fs_dblist_sort(ext2_dblist dblist, EXT2_QSORT_TYPE (*sortfunc)(const void *, const void *)); -extern void ext2fs_dblist_sort2(ext2_dblist dblist, - EXT2_QSORT_TYPE (*sortfunc)(const void *, - const void *)); extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist, int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info, void *priv_data), void *priv_data); -extern errcode_t ext2fs_dblist_iterate2(ext2_dblist dblist, - int (*func)(ext2_filsys fs, struct ext2_db_entry2 *db_info, - void *priv_data), - void *priv_data); extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino, blk_t blk, int blockcnt); -extern errcode_t ext2fs_set_dir_block2(ext2_dblist dblist, ext2_ino_t ino, - blk64_t blk, e2_blkcnt_t blockcnt); extern errcode_t ext2fs_copy_dblist(ext2_dblist src, ext2_dblist *dest); extern int ext2fs_dblist_count(ext2_dblist dblist); -extern blk64_t ext2fs_dblist_count2(ext2_dblist dblist); extern errcode_t ext2fs_dblist_get_last(ext2_dblist dblist, struct ext2_db_entry **entry); -extern errcode_t ext2fs_dblist_get_last2(ext2_dblist dblist, - struct ext2_db_entry2 **entry); extern errcode_t ext2fs_dblist_drop_last(ext2_dblist dblist); /* dblist_dir.c */ @@ -1006,14 +793,10 @@ 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, @@ -1062,18 +845,11 @@ 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); @@ -1085,7 +861,6 @@ extern errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino, extern void ext2fs_extent_free(ext2_extent_handle_t handle); extern errcode_t ext2fs_extent_get(ext2_extent_handle_t handle, int flags, struct ext2fs_extent *extent); -extern errcode_t ext2fs_extent_node_split(ext2_extent_handle_t handle); extern errcode_t ext2fs_extent_replace(ext2_extent_handle_t handle, int flags, struct ext2fs_extent *extent); extern errcode_t ext2fs_extent_insert(ext2_extent_handle_t handle, int flags, @@ -1098,9 +873,6 @@ extern errcode_t ext2fs_extent_get_info(ext2_extent_handle_t handle, struct ext2_extent_info *info); extern errcode_t ext2fs_extent_goto(ext2_extent_handle_t handle, blk64_t blk); -extern errcode_t ext2fs_extent_goto2(ext2_extent_handle_t handle, - int leaf_level, blk64_t blk); -extern errcode_t ext2fs_extent_fix_parents(ext2_extent_handle_t handle); /* fileio.c */ extern errcode_t ext2fs_file_open2(ext2_filsys fs, ext2_ino_t ino, @@ -1109,8 +881,6 @@ extern errcode_t ext2fs_file_open2(ext2_filsys fs, ext2_ino_t ino, extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino, int flags, ext2_file_t *ret); extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file); -struct ext2_inode *ext2fs_file_get_inode(ext2_file_t file); -extern ext2_ino_t ext2fs_file_get_inode_num(ext2_file_t file); extern errcode_t ext2fs_file_close(ext2_file_t file); extern errcode_t ext2fs_file_flush(ext2_file_t file); extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf, @@ -1124,7 +894,6 @@ extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset, errcode_t ext2fs_file_get_lsize(ext2_file_t file, __u64 *ret_size); extern ext2_off_t ext2fs_file_get_size(ext2_file_t file); extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size); -extern errcode_t ext2fs_file_set_size2(ext2_file_t file, ext2_off64_t size); /* finddev.c */ extern char *ext2fs_find_block_device(dev_t device); @@ -1174,42 +943,6 @@ extern errcode_t ext2fs_set_generic_bitmap_range(ext2fs_generic_bitmap bmap, errcode_t magic, __u32 start, __u32 num, void *in); -extern errcode_t ext2fs_find_first_zero_generic_bitmap(ext2fs_generic_bitmap bitmap, - __u32 start, __u32 end, - __u32 *out); - -/* gen_bitmap64.c */ - -/* Generate and print bitmap usage statistics */ -#define BMAP_STATS - -void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap); -errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic, - int type, __u64 start, __u64 end, - __u64 real_end, - const char *descr, - ext2fs_generic_bitmap *ret); -errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src, - ext2fs_generic_bitmap *dest); -void ext2fs_clear_generic_bmap(ext2fs_generic_bitmap bitmap); -errcode_t ext2fs_fudge_generic_bmap_end(ext2fs_generic_bitmap bitmap, - errcode_t neq, - __u64 end, __u64 *oend); -void ext2fs_set_generic_bmap_padding(ext2fs_generic_bitmap bmap); -errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap bmap, - __u64 new_end, - __u64 new_real_end); -errcode_t ext2fs_compare_generic_bmap(errcode_t neq, - ext2fs_generic_bitmap bm1, - ext2fs_generic_bitmap bm2); -errcode_t ext2fs_get_generic_bmap_range(ext2fs_generic_bitmap bmap, - __u64 start, unsigned int num, - void *out); -errcode_t ext2fs_set_generic_bmap_range(ext2fs_generic_bitmap bmap, - __u64 start, unsigned int num, - void *in); -errcode_t ext2fs_convert_subcluster_bitmap(ext2_filsys fs, - ext2fs_block_bitmap *bitmap); /* getsize.c */ extern errcode_t ext2fs_get_device_size(const char *file, int blocksize, @@ -1218,7 +951,6 @@ extern errcode_t ext2fs_get_device_size2(const char *file, int blocksize, blk64_t *retblocks); /* getsectsize.c */ -extern int ext2fs_get_dio_alignment(int fd); errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize); errcode_t ext2fs_get_device_phys_sectsize(const char *file, int *sectsize); @@ -1267,11 +999,6 @@ extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino, extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount); errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *); -/* inline.c */ - -extern errcode_t ext2fs_get_memalign(unsigned long size, - unsigned long align, void *ptr); - /* inode.c */ extern errcode_t ext2fs_flush_icache(ext2_filsys fs); extern errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan, @@ -1322,16 +1049,6 @@ extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags); extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags, char *mtpt, int mtlen); -/* punch.c */ -/* - * NOTE: This function removes from an inode the blocks "start", "end", and - * every block in between. - */ -extern errcode_t ext2fs_punch(ext2_filsys fs, ext2_ino_t ino, - struct ext2_inode *inode, - char *block_buf, blk64_t start, - blk64_t end); - /* namei.c */ extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name, int namelen, char *buf, ext2_ino_t *inode); @@ -1356,16 +1073,14 @@ 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 num_blocks, int flags, + __u32 size, int flags, char **ret_jsb); extern errcode_t ext2fs_add_journal_device(ext2_filsys fs, ext2_filsys journal_dev); -extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t num_blocks, +extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size, int flags); -extern int ext2fs_default_journal_size(__u64 num_blocks); +extern int ext2fs_default_journal_size(__u64 blocks); /* openfs.c */ extern errcode_t ext2fs_open(const char *name, int flags, int superblock, @@ -1375,8 +1090,6 @@ 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); @@ -1393,20 +1106,6 @@ errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name, errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name, ext2_ino_t ino, int flags); -/* symlink.c */ -errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino, - const char *name, char *target); - -/* mmp.c */ -errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf); -errcode_t ext2fs_mmp_write(ext2_filsys fs, blk64_t mmp_blk, void *buf); -errcode_t ext2fs_mmp_clear(ext2_filsys fs); -errcode_t ext2fs_mmp_init(ext2_filsys fs); -errcode_t ext2fs_mmp_start(ext2_filsys fs); -errcode_t ext2fs_mmp_update(ext2_filsys fs); -errcode_t ext2fs_mmp_stop(ext2_filsys fs); -unsigned ext2fs_mmp_new_seq(void); - /* read_bb.c */ extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs, ext2_badblocks_list *bb_list); @@ -1436,23 +1135,14 @@ extern void ext2fs_swap_ext_attr_entry(struct ext2_ext_attr_entry *to_entry, struct ext2_ext_attr_entry *from_entry); extern void ext2fs_swap_super(struct ext2_super_block * super); extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp); -extern void ext2fs_swap_group_desc2(ext2_filsys, struct ext2_group_desc *gdp); extern void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t, struct ext2_inode_large *f, int hostorder, int bufsize); extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t, struct ext2_inode *f, int hostorder); -extern void ext2fs_swap_mmp(struct mmp_struct *mmp); - -/* unix_io.c */ -extern int ext2fs_open_file(const char *pathname, int flags, mode_t mode); -extern int ext2fs_stat(const char *path, ext2fs_struct_stat *buf); -extern int ext2fs_fstat(int fd, ext2fs_struct_stat *buf); /* valid_blk.c */ extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode); -extern int ext2fs_inode_has_valid_blocks2(ext2_filsys fs, - struct ext2_inode *inode); /* version.c */ extern int ext2fs_parse_version_string(const char *ver_string); @@ -1466,13 +1156,9 @@ extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list, /* inline functions */ -#ifdef NO_INLINE_FUNCS extern errcode_t ext2fs_get_mem(unsigned long size, void *ptr); -extern errcode_t ext2fs_get_memzero(unsigned long size, void *ptr); -extern errcode_t ext2fs_get_array(unsigned long count, - unsigned long size, void *ptr); -extern errcode_t ext2fs_get_arrayzero(unsigned long count, - unsigned long size, void *ptr); +extern errcode_t ext2fs_get_memalign(unsigned long size, + unsigned long align, void *ptr); extern errcode_t ext2fs_free_mem(void *ptr); extern errcode_t ext2fs_resize_mem(unsigned long old_size, unsigned long size, void *ptr); @@ -1486,15 +1172,13 @@ extern void ext2fs_mark_ib_dirty(ext2_filsys fs); extern void ext2fs_mark_bb_dirty(ext2_filsys fs); extern int ext2fs_test_ib_dirty(ext2_filsys fs); extern int ext2fs_test_bb_dirty(ext2_filsys fs); -extern dgrp_t ext2fs_group_of_blk(ext2_filsys fs, blk_t blk); -extern dgrp_t ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino); +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); -extern __u64 ext2fs_div64_ceil(__u64 a, __u64 b); -#endif /* * The actual inlined functions definitions themselves... @@ -1506,21 +1190,17 @@ extern __u64 ext2fs_div64_ceil(__u64 a, __u64 b); #ifdef INCLUDE_INLINE_FUNCS #define _INLINE_ extern #else -#if (__STDC_VERSION__ >= 199901L) -#define _INLINE_ inline -#else #ifdef __GNUC__ #define _INLINE_ extern __inline__ #else /* For Watcom C */ #define _INLINE_ extern inline -#endif /* __GNUC__ */ -#endif /* __STDC_VERSION__ >= 199901L */ +#endif #endif #ifndef EXT2_CUSTOM_MEMORY_ROUTINES #include <string.h> /* - * Allocate memory. The 'ptr' arg must point to a pointer. + * Allocate memory */ _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr) { @@ -1533,41 +1213,42 @@ _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr) return 0; } -_INLINE_ errcode_t ext2fs_get_memzero(unsigned long size, void *ptr) +_INLINE_ errcode_t ext2fs_get_memalign(unsigned long size, + unsigned long align, void *ptr) { - void *pp; + errcode_t retval; - pp = malloc(size); - if (!pp) + if (align == 0) + align = 8; + +#if defined(__APPLE__) && defined(__MACH__) + /* MacOS 10.5, which we build for, doesn't have posix_memalign. + * The only option is valloc, but only use it if the requested + * alignment is larger than the alignment provided by malloc. + * The idea for this fix came from a patch on the macports website. + */ + *(void **) ptr = (align > 16) ? valloc(size) : malloc(size); + if (*(void **)ptr == NULL) return EXT2_ET_NO_MEMORY; - memset(pp, 0, size); - memcpy(ptr, &pp, sizeof(pp)); +#else + if ((retval = posix_memalign((void **) ptr, align, size))) { + if (retval == ENOMEM) + return EXT2_ET_NO_MEMORY; + return retval; + } +#endif return 0; } _INLINE_ errcode_t ext2fs_get_array(unsigned long count, unsigned long size, void *ptr) { if (count && (-1UL)/count<size) - return EXT2_ET_NO_MEMORY; + return EXT2_ET_NO_MEMORY; //maybe define EXT2_ET_OVERFLOW ? return ext2fs_get_mem(count*size, ptr); } -_INLINE_ errcode_t ext2fs_get_arrayzero(unsigned long count, - unsigned long size, void *ptr) -{ - void *pp; - - if (count && (-1UL)/count<size) - return EXT2_ET_NO_MEMORY; - pp = calloc(count, size); - if (!pp) - return EXT2_ET_NO_MEMORY; - memcpy(ptr, &pp, sizeof(pp)); - return 0; -} - /* - * Free memory. The 'ptr' arg must point to a pointer. + * Free memory */ _INLINE_ errcode_t ext2fs_free_mem(void *ptr) { @@ -1581,7 +1262,7 @@ _INLINE_ errcode_t ext2fs_free_mem(void *ptr) } /* - * Resize memory. The 'ptr' arg must point to a pointer. + * Resize memory */ _INLINE_ errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_size, unsigned long size, void *ptr) @@ -1682,14 +1363,16 @@ _INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs) /* * Return the group # of a block */ -_INLINE_ dgrp_t ext2fs_group_of_blk(ext2_filsys fs, blk_t blk) +_INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk) { - return ext2fs_group_of_blk2(fs, blk); + return (blk - fs->super->s_first_data_block) / + fs->super->s_blocks_per_group; } + /* * Return the group # of an inode number */ -_INLINE_ dgrp_t ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino) +_INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino) { return (ino - 1) / fs->super->s_inodes_per_group; } @@ -1699,7 +1382,8 @@ _INLINE_ dgrp_t ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino) */ _INLINE_ blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group) { - return (blk_t) ext2fs_group_first_block2(fs, group); + return fs->super->s_first_data_block + + (group * fs->super->s_blocks_per_group); } /* @@ -1707,13 +1391,17 @@ _INLINE_ blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group) */ _INLINE_ blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group) { - return (blk_t) ext2fs_group_last_block2(fs, 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) { - return (blk_t) ext2fs_inode_data_blocks2(fs, inode); + return inode->i_blocks - + (inode->i_file_acl ? fs->blocksize >> 9 : 0); } /* @@ -1725,14 +1413,6 @@ _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 diff --git a/lib/ext2fs/ext2fs.pc.in b/lib/ext2fs/ext2fs.pc.in index efac85e3..8db86635 100644 --- a/lib/ext2fs/ext2fs.pc.in +++ b/lib/ext2fs/ext2fs.pc.in @@ -7,5 +7,5 @@ Name: ext2fs Description: Ext2fs library Version: @E2FSPROGS_VERSION@ Requires.private: com_err -Cflags: -I${includedir}/ext2fs -I${includedir} +Cflags: -I${includedir}/ext2fs Libs: -L${libdir} -lext2fs diff --git a/lib/ext2fs/ext2fsP.h b/lib/ext2fs/ext2fsP.h index a88db93e..8772a4fc 100644 --- a/lib/ext2fs/ext2fsP.h +++ b/lib/ext2fs/ext2fsP.h @@ -11,8 +11,6 @@ #include "ext2fs.h" -#define EXT2FS_MAX_NESTED_LINKS 8 - /* * Badblocks list */ @@ -37,10 +35,10 @@ struct ext2_struct_u32_iterate { struct ext2_struct_dblist { int magic; ext2_filsys fs; - unsigned long long size; - unsigned long long count; + ext2_ino_t size; + ext2_ino_t count; int sorted; - struct ext2_db_entry2 * list; + struct ext2_db_entry * list; }; /* @@ -66,7 +64,7 @@ struct dir_context { */ struct ext2_inode_cache { void * buffer; - blk64_t buffer_blk; + blk_t buffer_blk; int cache_last; int cache_size; int refcount; @@ -81,67 +79,10 @@ struct ext2_inode_cache_ent { /* Function prototypes */ extern int ext2fs_process_dir_block(ext2_filsys fs, - blk64_t *blocknr, + blk_t *blocknr, e2_blkcnt_t blockcnt, - blk64_t ref_block, + blk_t ref_block, int ref_offset, void *priv_data); -/* Generic numeric progress meter */ - -struct ext2fs_numeric_progress_struct { - __u64 max; - int log_max; - int skip_progress; -}; - -extern void ext2fs_numeric_progress_init(ext2_filsys fs, - struct ext2fs_numeric_progress_struct * progress, - const char *label, __u64 max); -extern void ext2fs_numeric_progress_update(ext2_filsys fs, - struct ext2fs_numeric_progress_struct * progress, - __u64 val); -extern void ext2fs_numeric_progress_close(ext2_filsys fs, - struct ext2fs_numeric_progress_struct * progress, - const char *message); - -/* - * 64-bit bitmap support - */ - -extern errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic, - int type, __u64 start, __u64 end, - __u64 real_end, - const char * description, - ext2fs_generic_bitmap *bmap); - -extern void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap); - -extern errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src, - ext2fs_generic_bitmap *dest); - -extern errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap bmap, - __u64 new_end, - __u64 new_real_end); -extern errcode_t ext2fs_fudge_generic_bmap_end(ext2fs_generic_bitmap bitmap, - errcode_t neq, - __u64 end, __u64 *oend); -extern int ext2fs_mark_generic_bmap(ext2fs_generic_bitmap bitmap, - __u64 arg); -extern int ext2fs_unmark_generic_bmap(ext2fs_generic_bitmap bitmap, - __u64 arg); -extern int ext2fs_test_generic_bmap(ext2fs_generic_bitmap bitmap, - __u64 arg); -extern errcode_t ext2fs_set_generic_bmap_range(ext2fs_generic_bitmap bitmap, - __u64 start, unsigned int num, - void *in); -extern errcode_t ext2fs_get_generic_bmap_range(ext2fs_generic_bitmap bitmap, - __u64 start, unsigned int num, - void *out); -extern void ext2fs_warn_bitmap32(ext2fs_generic_bitmap bitmap,const char *func); - -extern int ext2fs_mem_is_zero(const char *mem, size_t len); -extern int ext2fs_file_block_offset_too_big(ext2_filsys fs, - struct ext2_inode *inode, - blk64_t offset); diff --git a/lib/ext2fs/ext_attr.c b/lib/ext2fs/ext_attr.c index ddcc89f7..358003ee 100644 --- a/lib/ext2fs/ext_attr.c +++ b/lib/ext2fs/ext_attr.c @@ -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_attr2(ext2_filsys fs, blk64_t block, void *buf) +errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf) { errcode_t retval; - retval = io_channel_read_blk64(fs->io, block, 1, buf); + retval = io_channel_read_blk(fs->io, block, 1, buf); if (retval) return retval; #ifdef WORDS_BIGENDIAN @@ -73,18 +73,13 @@ errcode_t ext2fs_read_ext_attr2(ext2_filsys fs, blk64_t block, void *buf) return 0; } -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 ext2fs_write_ext_attr(ext2_filsys fs, blk_t block, void *inbuf) { errcode_t retval; char *write_buf; -#ifdef WORDS_BIGENDIAN char *buf = NULL; +#ifdef WORDS_BIGENDIAN retval = ext2fs_get_mem(fs->blocksize, &buf); if (retval) return retval; @@ -93,24 +88,18 @@ errcode_t ext2fs_write_ext_attr2(ext2_filsys fs, blk64_t block, void *inbuf) #else write_buf = (char *) inbuf; #endif - retval = io_channel_write_blk64(fs->io, block, 1, write_buf); -#ifdef WORDS_BIGENDIAN - ext2fs_free_mem(&buf); -#endif + retval = io_channel_write_blk(fs->io, block, 1, write_buf); + if (buf) + ext2fs_free_mem(&buf); if (!retval) ext2fs_mark_changed(fs); 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_refcount2(ext2_filsys fs, blk64_t blk, +errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk, char *block_buf, int adjust, __u32 *newcount) { @@ -118,7 +107,7 @@ errcode_t ext2fs_adjust_ea_refcount2(ext2_filsys fs, blk64_t blk, struct ext2_ext_attr_header *header; char *buf = 0; - if ((blk >= ext2fs_blocks_count(fs->super)) || + if ((blk >= fs->super->s_blocks_count) || (blk < fs->super->s_first_data_block)) return EXT2_ET_BAD_EA_BLOCK_NUM; @@ -129,7 +118,7 @@ errcode_t ext2fs_adjust_ea_refcount2(ext2_filsys fs, blk64_t blk, block_buf = buf; } - retval = ext2fs_read_ext_attr2(fs, blk, block_buf); + retval = ext2fs_read_ext_attr(fs, blk, block_buf); if (retval) goto errout; @@ -138,7 +127,7 @@ errcode_t ext2fs_adjust_ea_refcount2(ext2_filsys fs, blk64_t blk, if (newcount) *newcount = header->h_refcount; - retval = ext2fs_write_ext_attr2(fs, blk, block_buf); + retval = ext2fs_write_ext_attr(fs, blk, block_buf); if (retval) goto errout; @@ -147,10 +136,3 @@ 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); -} diff --git a/lib/ext2fs/extent.c b/lib/ext2fs/extent.c index fc6c95b8..053ff158 100644 --- a/lib/ext2fs/extent.c +++ b/lib/ext2fs/extent.c @@ -53,7 +53,6 @@ struct ext2_extent_handle { ext2_filsys fs; ext2_ino_t ino; struct ext2_inode *inode; - struct ext2_inode inodebuf; int type; int level; int max_depth; @@ -159,13 +158,15 @@ errcode_t ext2fs_extent_header_verify(void *ptr, int size) /* * Begin functions to handle an inode's extent information */ -void ext2fs_extent_free(ext2_extent_handle_t handle) +extern void ext2fs_extent_free(ext2_extent_handle_t handle) { int i; if (!handle) return; + if (handle->inode) + ext2fs_free_mem(&handle->inode); if (handle->path) { for (i=1; i <= handle->max_depth; i++) { if (handle->path[i].buf) @@ -176,13 +177,13 @@ void ext2fs_extent_free(ext2_extent_handle_t handle) ext2fs_free_mem(&handle); } -errcode_t ext2fs_extent_open(ext2_filsys fs, ext2_ino_t ino, +extern errcode_t ext2fs_extent_open(ext2_filsys fs, ext2_ino_t ino, ext2_extent_handle_t *ret_handle) { return ext2fs_extent_open2(fs, ino, NULL, ret_handle); } -errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino, +extern errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, ext2_extent_handle_t *ret_handle) { @@ -202,13 +203,17 @@ errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino, return retval; memset(handle, 0, sizeof(struct ext2_extent_handle)); + retval = ext2fs_get_mem(sizeof(struct ext2_inode), &handle->inode); + if (retval) + goto errout; + handle->ino = ino; handle->fs = fs; if (inode) { - handle->inode = inode; - } else { - handle->inode = &handle->inodebuf; + memcpy(handle->inode, inode, sizeof(struct ext2_inode)); + } + else { retval = ext2fs_read_inode(fs, ino, handle->inode); if (retval) goto errout; @@ -253,8 +258,9 @@ errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino, handle->path[0].max_entries = ext2fs_le16_to_cpu(eh->eh_max); handle->path[0].curr = 0; handle->path[0].end_blk = - (EXT2_I_SIZE(handle->inode) + fs->blocksize - 1) >> - EXT2_BLOCK_SIZE_BITS(fs->super); + ((((__u64) handle->inode->i_size_high << 32) + + handle->inode->i_size + (fs->blocksize - 1)) + >> EXT2_BLOCK_SIZE_BITS(fs->super)); handle->path[0].visit_num = 1; handle->level = 0; handle->magic = EXT2_ET_MAGIC_EXTENT_HANDLE; @@ -279,7 +285,7 @@ errcode_t ext2fs_extent_get(ext2_extent_handle_t handle, struct ext3_extent_idx *ix = 0; struct ext3_extent *ex; errcode_t retval; - blk64_t blk; + blk_t blk; blk64_t end_blk; int orig_op, op; @@ -373,11 +379,9 @@ retry: case EXT2_EXTENT_ROOT: handle->level = 0; path = handle->path + handle->level; - /* fallthrough */ case EXT2_EXTENT_FIRST_SIB: path->left = path->entries; path->curr = 0; - /* fallthrough */ case EXT2_EXTENT_NEXT_SIB: if (path->left <= 0) return EXT2_ET_EXTENT_NO_NEXT; @@ -439,7 +443,7 @@ retry: (handle->fs->io != handle->fs->image_io)) memset(newpath->buf, 0, handle->fs->blocksize); else { - retval = io_channel_read_blk64(handle->fs->io, + retval = io_channel_read_blk(handle->fs->io, blk, 1, newpath->buf); if (retval) return retval; @@ -549,7 +553,7 @@ static errcode_t update_path(ext2_extent_handle_t handle) blk = ext2fs_le32_to_cpu(ix->ei_leaf) + ((__u64) ext2fs_le16_to_cpu(ix->ei_leaf_hi) << 32); - retval = io_channel_write_blk64(handle->fs->io, + retval = io_channel_write_blk(handle->fs->io, blk, 1, handle->path[handle->level].buf); } return retval; @@ -603,8 +607,8 @@ errcode_t ext2fs_extent_free_path(ext2_extent_path_t path) * If "blk" has no mapping (hole) then handle is left at last * extent before blk. */ -errcode_t ext2fs_extent_goto2(ext2_extent_handle_t handle, - int leaf_level, blk64_t blk) +static errcode_t extent_goto(ext2_extent_handle_t handle, + int leaf_level, blk64_t blk) { struct ext2fs_extent extent; errcode_t retval; @@ -693,7 +697,7 @@ errcode_t ext2fs_extent_goto2(ext2_extent_handle_t handle, errcode_t ext2fs_extent_goto(ext2_extent_handle_t handle, blk64_t blk) { - return ext2fs_extent_goto2(handle, 0, blk); + return extent_goto(handle, 0, blk); } /* @@ -705,14 +709,12 @@ errcode_t ext2fs_extent_goto(ext2_extent_handle_t handle, * Safe to call for any position in node; if not at the first entry, * will simply return. */ -errcode_t ext2fs_extent_fix_parents(ext2_extent_handle_t handle) +static errcode_t ext2fs_extent_fix_parents(ext2_extent_handle_t handle) { int retval = 0; - int orig_height; blk64_t start; struct extent_path *path; struct ext2fs_extent extent; - struct ext2_extent_info info; EXT2_CHECK_MAGIC(handle, EXT2_ET_MAGIC_EXTENT_HANDLE); @@ -733,10 +735,6 @@ errcode_t ext2fs_extent_fix_parents(ext2_extent_handle_t handle) /* modified node's start block */ start = extent.e_lblk; - if ((retval = ext2fs_extent_get_info(handle, &info))) - return retval; - orig_height = info.max_depth - info.curr_level; - /* traverse up until index not first, or startblk matches, or top */ while (handle->level > 0 && (path->left == path->entries - 1)) { @@ -755,7 +753,7 @@ errcode_t ext2fs_extent_fix_parents(ext2_extent_handle_t handle) } /* put handle back to where we started */ - retval = ext2fs_extent_goto2(handle, orig_height, start); + retval = ext2fs_extent_goto(handle, start); done: return retval; } @@ -818,10 +816,10 @@ errcode_t ext2fs_extent_replace(ext2_extent_handle_t handle, * * handle will be left pointing at original record. */ -errcode_t ext2fs_extent_node_split(ext2_extent_handle_t handle) +static errcode_t extent_node_split(ext2_extent_handle_t handle) { errcode_t retval = 0; - blk64_t new_node_pblk; + blk_t new_node_pblk; blk64_t new_node_start; blk64_t orig_lblk; blk64_t goal_blk = 0; @@ -873,12 +871,12 @@ errcode_t ext2fs_extent_node_split(ext2_extent_handle_t handle) goto done; goal_blk = extent.e_pblk; - retval = ext2fs_extent_node_split(handle); + retval = extent_node_split(handle); if (retval) goto done; /* get handle back to our original split position */ - retval = ext2fs_extent_goto2(handle, orig_height, orig_lblk); + retval = extent_goto(handle, orig_height, orig_lblk); if (retval) goto done; } @@ -933,9 +931,10 @@ errcode_t ext2fs_extent_node_split(ext2_extent_handle_t handle) if (log_flex) group = group & ~((1 << (log_flex)) - 1); - goal_blk = ext2fs_group_first_block2(handle->fs, group); + goal_blk = (group * handle->fs->super->s_blocks_per_group) + + handle->fs->super->s_first_data_block; } - retval = ext2fs_alloc_block2(handle->fs, goal_blk, block_buf, + retval = ext2fs_alloc_block(handle->fs, (blk_t) goal_blk, block_buf, &new_node_pblk); if (retval) goto done; @@ -963,8 +962,7 @@ errcode_t ext2fs_extent_node_split(ext2_extent_handle_t handle) new_node_start = ext2fs_le32_to_cpu(EXT_FIRST_INDEX(neweh)->ei_block); /* ...and write the new node block out to disk. */ - retval = io_channel_write_blk64(handle->fs->io, new_node_pblk, 1, - block_buf); + retval = io_channel_write_blk(handle->fs->io, new_node_pblk, 1, block_buf); if (retval) goto done; @@ -1026,13 +1024,12 @@ errcode_t ext2fs_extent_node_split(ext2_extent_handle_t handle) } /* get handle back to our original position */ - retval = ext2fs_extent_goto2(handle, orig_height, orig_lblk); + retval = extent_goto(handle, orig_height, orig_lblk); if (retval) goto done; /* new node hooked in, so update inode block count (do this here?) */ - handle->inode->i_blocks += (handle->fs->blocksize * - EXT2FS_CLUSTER_RATIO(handle->fs)) / 512; + handle->inode->i_blocks += handle->fs->blocksize / 512; retval = ext2fs_write_inode(handle->fs, handle->ino, handle->inode); if (retval) @@ -1077,7 +1074,7 @@ errcode_t ext2fs_extent_insert(ext2_extent_handle_t handle, int flags, printf("node full (level %d) - splitting\n", handle->level); #endif - retval = ext2fs_extent_node_split(handle); + retval = extent_node_split(handle); if (retval) return retval; path = handle->path + handle->level; @@ -1356,9 +1353,6 @@ errcode_t ext2fs_extent_set_bmap(ext2_extent_handle_t handle, &next_extent); if (retval) goto done; - retval = ext2fs_extent_fix_parents(handle); - if (retval) - goto done; } else retval = ext2fs_extent_insert(handle, EXT2_EXTENT_INSERT_AFTER, &newextent); @@ -1411,9 +1405,6 @@ errcode_t ext2fs_extent_set_bmap(ext2_extent_handle_t handle, retval = ext2fs_extent_replace(handle, 0, &extent); if (retval) goto done; - retval = ext2fs_extent_fix_parents(handle); - if (retval) - goto done; } else { __u32 orig_length; @@ -1451,7 +1442,7 @@ done: /* get handle back to its position */ if (orig_height > handle->max_depth) orig_height = handle->max_depth; /* In case we shortened the tree */ - ext2fs_extent_goto2(handle, orig_height, orig_lblk); + extent_goto(handle, orig_height, orig_lblk); return retval; } @@ -1512,13 +1503,10 @@ errcode_t ext2fs_extent_delete(ext2_extent_handle_t handle, int flags) return retval; retval = ext2fs_extent_delete(handle, flags); - handle->inode->i_blocks -= - (handle->fs->blocksize * - EXT2FS_CLUSTER_RATIO(handle->fs)) / 512; + handle->inode->i_blocks -= handle->fs->blocksize / 512; retval = ext2fs_write_inode(handle->fs, handle->ino, handle->inode); - ext2fs_block_alloc_stats2(handle->fs, - extent.e_pblk, -1); + ext2fs_block_alloc_stats(handle->fs, extent.e_pblk, -1); } } else { eh = (struct ext3_extent_header *) path->buf; @@ -1563,10 +1551,458 @@ errcode_t ext2fs_extent_get_info(ext2_extent_handle_t handle, } #ifdef DEBUG + +#include "ss/ss.h" + +#include "debugfs.h" + /* - * Override debugfs's prompt + * Hook in new commands into debugfs */ const char *debug_prog_name = "tst_extents"; +extern ss_request_table extent_cmds; +ss_request_table *extra_cmds = &extent_cmds; + +ext2_ino_t current_ino = 0; +ext2_extent_handle_t current_handle; + +int common_extent_args_process(int argc, char *argv[], int min_argc, + int max_argc, const char *cmd, + const char *usage, int flags) +{ + if (common_args_process(argc, argv, min_argc, max_argc, cmd, + usage, flags)) + return 1; + + if (!current_handle) { + com_err(cmd, 0, "Extent handle not open"); + return 1; + } + return 0; +} + +void do_inode(int argc, char *argv[]) +{ + ext2_ino_t inode; + int i; + struct ext3_extent_header *eh; + errcode_t retval; + + if (check_fs_open(argv[0])) + return; + + if (argc == 1) { + if (current_ino) + printf("Current inode is %d\n", current_ino); + else + printf("No current inode\n"); + return; + } + + if (common_inode_args_process(argc, argv, &inode, 0)) { + return; + } + + current_ino = 0; + + retval = ext2fs_extent_open(current_fs, inode, ¤t_handle); + if (retval) { + com_err(argv[1], retval, "while opening extent handle"); + return; + } + + current_ino = inode; + + printf("Loaded inode %d\n", current_ino); + + return; +} + +void generic_goto_node(char *cmd_name, int op) +{ + struct ext2fs_extent extent; + errcode_t retval; + + if (check_fs_open(cmd_name)) + return; + + if (!current_handle) { + com_err(cmd_name, 0, "Extent handle not open"); + return; + } + + retval = ext2fs_extent_get(current_handle, op, &extent); + if (retval) { + com_err(cmd_name, retval, 0); + return; + } + dbg_print_extent(0, &extent); +} + +void do_current_node(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_CURRENT); +} + +void do_root_node(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_ROOT); +} + +void do_last_leaf(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_LAST_LEAF); +} + +void do_first_sib(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_FIRST_SIB); +} + +void do_last_sib(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_LAST_SIB); +} + +void do_next_sib(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_NEXT_SIB); +} + +void do_prev_sib(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_PREV_SIB); +} + +void do_next_leaf(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_NEXT_LEAF); +} + +void do_prev_leaf(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_PREV_LEAF); +} + +void do_next(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_NEXT); +} + +void do_prev(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_PREV); +} + +void do_up(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_UP); +} + +void do_down(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_DOWN); +} + +void do_delete_node(int argc, char *argv[]) +{ + errcode_t retval; + int err; + + if (common_extent_args_process(argc, argv, 1, 1, "delete_node", + "", CHECK_FS_RW | CHECK_FS_BITMAPS)) + return; + + retval = ext2fs_extent_delete(current_handle, 0); + if (retval) { + com_err(argv[0], retval, 0); + return; + } + if (current_handle->path && current_handle->path[0].curr) + do_current_node(argc, argv); +} + +void do_replace_node(int argc, char *argv[]) +{ + const char *usage = "[--uninit] <lblk> <len> <pblk>"; + errcode_t retval; + struct ext2fs_extent extent; + int err; + + if (common_extent_args_process(argc, argv, 3, 5, "replace_node", + usage, CHECK_FS_RW | CHECK_FS_BITMAPS)) + return; + + extent.e_flags = 0; + + if (!strcmp(argv[1], "--uninit")) { + argc--; + argv++; + extent.e_flags |= EXT2_EXTENT_FLAGS_UNINIT; + } + + if (argc != 4) { + fprintf(stderr, "Usage: %s %s\n", argv[0], usage); + return; + } + extent.e_lblk = parse_ulong(argv[1], argv[0], "logical block", &err); + if (err) + return; + + extent.e_len = parse_ulong(argv[2], argv[0], "logical block", &err); + if (err) + return; + + extent.e_pblk = parse_ulong(argv[3], argv[0], "logical block", &err); + if (err) + return; + + retval = ext2fs_extent_replace(current_handle, 0, &extent); + if (retval) { + com_err(argv[0], retval, 0); + return; + } + do_current_node(argc, argv); +} + +void do_split_node(int argc, char *argv[]) +{ + errcode_t retval; + struct ext2fs_extent extent; + int err; + + if (common_extent_args_process(argc, argv, 1, 1, "split_node", + "", CHECK_FS_RW | CHECK_FS_BITMAPS)) + return; + + retval = extent_node_split(current_handle); + if (retval) { + com_err(argv[0], retval, 0); + return; + } + do_current_node(argc, argv); +} + +void do_insert_node(int argc, char *argv[]) +{ + const char *usage = "[--after] [--uninit] <lblk> <len> <pblk>"; + errcode_t retval; + struct ext2fs_extent extent; + char *cmd; + int err; + int flags = 0; + + if (common_extent_args_process(argc, argv, 3, 6, "insert_node", + usage, CHECK_FS_RW | CHECK_FS_BITMAPS)) + return; + + cmd = argv[0]; + + extent.e_flags = 0; + + while (argc > 2) { + if (!strcmp(argv[1], "--after")) { + argc--; + argv++; + flags |= EXT2_EXTENT_INSERT_AFTER; + continue; + } + if (!strcmp(argv[1], "--uninit")) { + argc--; + argv++; + extent.e_flags |= EXT2_EXTENT_FLAGS_UNINIT; + continue; + } + break; + } + + if (argc != 4) { + fprintf(stderr, "usage: %s %s\n", cmd, usage); + return; + } + + extent.e_lblk = parse_ulong(argv[1], cmd, + "logical block", &err); + if (err) + return; + + extent.e_len = parse_ulong(argv[2], cmd, + "length", &err); + if (err) + return; + + extent.e_pblk = parse_ulong(argv[3], cmd, + "pysical block", &err); + if (err) + return; + + retval = ext2fs_extent_insert(current_handle, flags, &extent); + if (retval) { + com_err(cmd, retval, 0); + return; + } + do_current_node(argc, argv); +} + +void do_set_bmap(int argc, char **argv) +{ + const char *usage = "[--uninit] <lblk> <pblk>"; + errcode_t retval; + blk_t logical; + blk_t physical; + char *cmd = argv[0]; + int flags = 0; + int err; + + if (common_extent_args_process(argc, argv, 3, 5, "set_bmap", + usage, CHECK_FS_RW | CHECK_FS_BITMAPS)) + return; + + if (argc > 2 && !strcmp(argv[1], "--uninit")) { + argc--; + argv++; + flags |= EXT2_EXTENT_SET_BMAP_UNINIT; + } + + if (argc != 3) { + fprintf(stderr, "Usage: %s %s\n", cmd, usage); + return; + } + + logical = parse_ulong(argv[1], cmd, + "logical block", &err); + if (err) + return; + + physical = parse_ulong(argv[2], cmd, + "physical block", &err); + if (err) + return; + + retval = ext2fs_extent_set_bmap(current_handle, logical, + (blk64_t) physical, flags); + if (retval) { + com_err(cmd, retval, 0); + return; + } + if (current_handle->path && current_handle->path[0].curr) + do_current_node(argc, argv); +} + +void do_print_all(int argc, char **argv) +{ + const char *usage = "[--leaf-only|--reverse|--reverse-leaf]"; + struct ext2fs_extent extent; + errcode_t retval; + errcode_t end_err = EXT2_ET_EXTENT_NO_NEXT; + int op = EXT2_EXTENT_NEXT; + int first_op = EXT2_EXTENT_ROOT; + + + if (common_extent_args_process(argc, argv, 1, 2, "print_all", + usage, 0)) + return; + + if (argc == 2) { + if (!strcmp(argv[1], "--leaf-only")) + op = EXT2_EXTENT_NEXT_LEAF; + else if (!strcmp(argv[1], "--reverse")) { + op = EXT2_EXTENT_PREV; + first_op = EXT2_EXTENT_LAST_LEAF; + end_err = EXT2_ET_EXTENT_NO_PREV; + } else if (!strcmp(argv[1], "--reverse-leaf")) { + op = EXT2_EXTENT_PREV_LEAF; + first_op = EXT2_EXTENT_LAST_LEAF; + end_err = EXT2_ET_EXTENT_NO_PREV; + } else { + fprintf(stderr, "Usage: %s %s\n", argv[0], usage); + return; + } + } + + retval = ext2fs_extent_get(current_handle, first_op, &extent); + if (retval) { + com_err(argv[0], retval, 0); + return; + } + dbg_print_extent(0, &extent); + + while (1) { + retval = ext2fs_extent_get(current_handle, op, &extent); + if (retval == end_err) + break; + + if (retval) { + com_err(argv[0], retval, 0); + return; + } + dbg_print_extent(0, &extent); + } +} + +void do_info(int argc, char **argv) +{ + struct ext2fs_extent extent; + struct ext2_extent_info info; + errcode_t retval; + + if (common_extent_args_process(argc, argv, 1, 1, "info", "", 0)) + return; + + retval = ext2fs_extent_get_info(current_handle, &info); + if (retval) { + com_err(argv[0], retval, 0); + return; + } + + retval = ext2fs_extent_get(current_handle, + EXT2_EXTENT_CURRENT, &extent); + if (retval) { + com_err(argv[0], retval, 0); + return; + } + + dbg_print_extent(0, &extent); + + printf("Current handle location: %d/%d (max: %d, bytes %d), level %d/%d\n", + info.curr_entry, info.num_entries, info.max_entries, + info.bytes_avail, info.curr_level, info.max_depth); + printf("\tmax lblk: %llu, max pblk: %llu\n", info.max_lblk, + info.max_pblk); + printf("\tmax_len: %u, max_uninit_len: %u\n", info.max_len, + info.max_uninit_len); +} + +void do_goto_block(int argc, char **argv) +{ + struct ext2fs_extent extent; + errcode_t retval; + int op = EXT2_EXTENT_NEXT_LEAF; + blk_t blk; + int level = 0; + + if (common_extent_args_process(argc, argv, 2, 3, "goto_block", + "block [level]", 0)) + return; + + if (strtoblk(argv[0], argv[1], &blk)) + return; + + if (argc == 3) + if (strtoblk(argv[0], argv[2], &level)) + return; + + retval = extent_goto(current_handle, level, (blk64_t) blk); + + if (retval) { + com_err(argv[0], retval, + "while trying to go to block %u, level %d", + blk, level); + return; + } + + generic_goto_node(argv[0], EXT2_EXTENT_CURRENT); +} #endif diff --git a/lib/ext2fs/extent_dbg.ct b/lib/ext2fs/extent_dbg.ct new file mode 100644 index 00000000..d0571f47 --- /dev/null +++ b/lib/ext2fs/extent_dbg.ct @@ -0,0 +1,74 @@ +# +# Copyright (C) 1993 Theodore Ts'o. This file may be redistributed +# under the terms of the GNU Public License. +# +command_table extent_cmds; + +request do_inode, "Open an inode", + inode; + +request do_current_node, "Current extent node", + current_node, current; + +request do_root_node, "Goto root extent", + root_node, root; + +request do_last_leaf, "Goto last leaf", + last_leaf; + +request do_first_sib, "Goto first sibling", + first_sibling, first_sib; + +request do_last_sib, "Goto last sibling", + last_sibling, last_sib; + +request do_next_sib, "Goto next sibling", + next_sibling, next_sib, ns; + +request do_prev_sib, "Goto previous sibling", + prev_sibling, prev_sib, ps; + +request do_next_leaf, "Goto next leaf", + next_leaf, nl; + +request do_prev_leaf, "Goto previous leaf", + prev_leaf, pl; + +request do_next, "Goto next node", + next, n; + +request do_prev, "Goto previous node", + previous, prev, p; + +request do_up, "Up node", + up_node, up, u; + +request do_down, "Down node", + down_node, down, d; + +request do_delete_node, "Delete node", + delete_node, delete; + +request do_insert_node, "Insert node", + insert_node, insert; + +request do_split_node, "Split node", + split_node, split; + +request do_set_bmap, "Set block mapping", + set_bmap; + +request do_replace_node, "Insert node", + replace_node, replace; + +request do_print_all, "Iterate over all nodes and print them", + print_all, all; + +request do_goto_block, "Goto extent containing specified block", + goto_block, goto; + +request do_info, "Print extent info", + info; + +end; + diff --git a/lib/ext2fs/fiemap.h b/lib/ext2fs/fiemap.h index 30bf5555..671decbd 100644 --- a/lib/ext2fs/fiemap.h +++ b/lib/ext2fs/fiemap.h @@ -34,10 +34,6 @@ struct fiemap { struct fiemap_extent fm_extents[0]; /* array of mapped extents (out) */ }; -#ifndef FS_IOC_FIEMAP -#define FS_IOC_FIEMAP _IOWR('f', 11, struct fiemap) -#endif - #define FIEMAP_MAX_OFFSET (~0ULL) #define FIEMAP_FLAG_SYNC 0x00000001 /* sync file data before map */ diff --git a/lib/ext2fs/fileio.c b/lib/ext2fs/fileio.c index 2e1b6824..834867e1 100644 --- a/lib/ext2fs/fileio.c +++ b/lib/ext2fs/fileio.c @@ -17,7 +17,6 @@ #include "ext2_fs.h" #include "ext2fs.h" -#include "ext2fsP.h" struct ext2_file { errcode_t magic; @@ -26,8 +25,8 @@ struct ext2_file { struct ext2_inode inode; int flags; __u64 pos; - blk64_t blockno; - blk64_t physblock; + blk_t blockno; + blk_t physblock; char *buf; }; @@ -97,24 +96,6 @@ ext2_filsys ext2fs_file_get_fs(ext2_file_t file) } /* - * This function returns the pointer to the inode of a file from the structure - */ -struct ext2_inode *ext2fs_file_get_inode(ext2_file_t file) -{ - if (file->magic != EXT2_ET_MAGIC_EXT2_FILE) - return NULL; - return &file->inode; -} - -/* This function returns the inode number from the structure */ -ext2_ino_t ext2fs_file_get_inode_num(ext2_file_t file) -{ - if (file->magic != EXT2_ET_MAGIC_EXT2_FILE) - return 0; - return file->ino; -} - -/* * This function flushes the dirty block buffer out to disk if * necessary. */ @@ -135,14 +116,15 @@ errcode_t ext2fs_file_flush(ext2_file_t file) * Allocate it. */ if (!file->physblock) { - retval = ext2fs_bmap2(fs, file->ino, &file->inode, + retval = ext2fs_bmap(fs, file->ino, &file->inode, BMAP_BUFFER, file->ino ? BMAP_ALLOC : 0, - file->blockno, 0, &file->physblock); + file->blockno, &file->physblock); if (retval) return retval; } - retval = io_channel_write_blk64(fs->io, file->physblock, 1, file->buf); + retval = io_channel_write_blk(fs->io, file->physblock, + 1, file->buf); if (retval) return retval; @@ -157,7 +139,7 @@ errcode_t ext2fs_file_flush(ext2_file_t file) */ static errcode_t sync_buffer_position(ext2_file_t file) { - blk64_t b; + blk_t b; errcode_t retval; b = file->pos / file->fs->blocksize; @@ -186,16 +168,16 @@ static errcode_t load_buffer(ext2_file_t file, int dontfill) errcode_t retval; if (!(file->flags & EXT2_FILE_BUF_VALID)) { - retval = ext2fs_bmap2(fs, file->ino, &file->inode, - BMAP_BUFFER, 0, file->blockno, 0, + retval = ext2fs_bmap(fs, file->ino, &file->inode, + BMAP_BUFFER, 0, file->blockno, &file->physblock); if (retval) return retval; if (!dontfill) { if (file->physblock) { - retval = io_channel_read_blk64(fs->io, - file->physblock, - 1, file->buf); + retval = io_channel_read_blk(fs->io, + file->physblock, + 1, file->buf); if (retval) return retval; } else @@ -297,20 +279,6 @@ errcode_t ext2fs_file_write(ext2_file_t file, const void *buf, if (retval) goto fail; - /* - * OK, the physical block hasn't been allocated yet. - * Allocate it. - */ - if (!file->physblock) { - retval = ext2fs_bmap2(fs, file->ino, &file->inode, - BMAP_BUFFER, - file->ino ? BMAP_ALLOC : 0, - file->blockno, 0, - &file->physblock); - if (retval) - goto fail; - } - file->flags |= EXT2_FILE_BUF_DIRTY; memcpy(file->buf+start, ptr, c); file->pos += c; @@ -320,15 +288,6 @@ errcode_t ext2fs_file_write(ext2_file_t file, const void *buf, } fail: - /* Update inode size */ - if (count != 0 && EXT2_I_SIZE(&file->inode) < file->pos) { - errcode_t rc; - - rc = ext2fs_file_set_size2(file, file->pos); - if (retval == 0) - retval = rc; - } - if (written) *written = count; return retval; @@ -393,106 +352,27 @@ ext2_off_t ext2fs_file_get_size(ext2_file_t file) return size; } -/* Zero the parts of the last block that are past EOF. */ -static errcode_t ext2fs_file_zero_past_offset(ext2_file_t file, - ext2_off64_t offset) -{ - ext2_filsys fs = file->fs; - char *b = NULL; - ext2_off64_t off = offset % fs->blocksize; - blk64_t blk; - int ret_flags; - errcode_t retval; - - if (off == 0) - return 0; - - retval = sync_buffer_position(file); - if (retval) - return retval; - - /* Is there an initialized block at the end? */ - retval = ext2fs_bmap2(fs, file->ino, NULL, NULL, 0, - offset / fs->blocksize, &ret_flags, &blk); - if (retval) - return retval; - if ((blk == 0) || (ret_flags & BMAP_RET_UNINIT)) - return 0; - - /* Zero to the end of the block */ - retval = ext2fs_get_mem(fs->blocksize, &b); - if (retval) - return retval; - - /* Read/zero/write block */ - retval = io_channel_read_blk64(fs->io, blk, 1, b); - if (retval) - goto out; - - memset(b + off, 0, fs->blocksize - off); - - retval = io_channel_write_blk64(fs->io, blk, 1, b); - if (retval) - goto out; - -out: - ext2fs_free_mem(&b); - return retval; -} - /* * This function sets the size of the file, truncating it if necessary * + * XXX still need to call truncate */ -errcode_t ext2fs_file_set_size2(ext2_file_t file, ext2_off64_t size) +errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size) { - ext2_off64_t old_size; errcode_t retval; - blk64_t old_truncate, truncate_block; - EXT2_CHECK_MAGIC(file, EXT2_ET_MAGIC_EXT2_FILE); - if (size && ext2fs_file_block_offset_too_big(file->fs, &file->inode, - (size - 1) / file->fs->blocksize)) - return EXT2_ET_FILE_TOO_BIG; - truncate_block = ((size + file->fs->blocksize - 1) >> - EXT2_BLOCK_SIZE_BITS(file->fs->super)); - old_size = EXT2_I_SIZE(&file->inode); - old_truncate = ((old_size + file->fs->blocksize - 1) >> - EXT2_BLOCK_SIZE_BITS(file->fs->super)); - - /* If we're writing a large file, set the large_file flag */ - if (LINUX_S_ISREG(file->inode.i_mode) && - ext2fs_needs_large_file_feature(EXT2_I_SIZE(&file->inode)) && - (!EXT2_HAS_RO_COMPAT_FEATURE(file->fs->super, - EXT2_FEATURE_RO_COMPAT_LARGE_FILE) || - file->fs->super->s_rev_level == EXT2_GOOD_OLD_REV)) { - file->fs->super->s_feature_ro_compat |= - EXT2_FEATURE_RO_COMPAT_LARGE_FILE; - ext2fs_update_dynamic_rev(file->fs); - ext2fs_mark_super_dirty(file->fs); - } - - file->inode.i_size = size & 0xffffffff; - file->inode.i_size_high = (size >> 32); + file->inode.i_size = size; + file->inode.i_size_high = 0; if (file->ino) { retval = ext2fs_write_inode(file->fs, file->ino, &file->inode); if (retval) return retval; } - retval = ext2fs_file_zero_past_offset(file, size); - if (retval) - return retval; - - if (truncate_block >= old_truncate) - return 0; - - return ext2fs_punch(file->fs, file->ino, &file->inode, 0, - truncate_block, ~0ULL); -} + /* + * XXX truncate inode if necessary + */ -errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size) -{ - return ext2fs_file_set_size2(file, size); + return 0; } diff --git a/lib/ext2fs/finddev.c b/lib/ext2fs/finddev.c index 88eb5cee..cc2029f2 100644 --- a/lib/ext2fs/finddev.c +++ b/lib/ext2fs/finddev.c @@ -33,7 +33,6 @@ #include "ext2_fs.h" #include "ext2fs.h" -#include "ext2fsP.h" struct dir_list { char *name; @@ -128,7 +127,6 @@ char *ext2fs_find_block_device(dev_t device) struct dir_list *list = 0, *new_list = 0; struct dir_list *current; char *ret_path = 0; - int level = 0; /* * Add the starting directories to search... @@ -155,9 +153,6 @@ char *ext2fs_find_block_device(dev_t device) if (list == 0) { list = new_list; new_list = 0; - /* Avoid infinite loop */ - if (++level >= EXT2FS_MAX_NESTED_LINKS) - break; } } free_dirlist(&list); diff --git a/lib/ext2fs/flushb.c b/lib/ext2fs/flushb.c index c4406fd1..394bb074 100644 --- a/lib/ext2fs/flushb.c +++ b/lib/ext2fs/flushb.c @@ -65,13 +65,17 @@ errcode_t ext2fs_sync_device(int fd, int flushb) #ifdef BLKFLSBUF if (ioctl (fd, BLKFLSBUF, 0) == 0) return 0; -#elif defined(__linux__) -#warning BLKFLSBUF not defined +#else +#ifdef __GNUC__ + #warning BLKFLSBUF not defined +#endif /* __GNUC__ */ #endif #ifdef FDFLUSH - return ioctl(fd, FDFLUSH, 0); /* In case this is a floppy */ -#elif defined(__linux__) -#warning FDFLUSH not defined + ioctl (fd, FDFLUSH, 0); /* In case this is a floppy */ +#else +#ifdef __GNUC__ + #warning FDFLUSH not defined +#endif /* __GNUC__ */ #endif } return 0; diff --git a/lib/ext2fs/freefs.c b/lib/ext2fs/freefs.c index 1e01ef5f..5c35bb68 100644 --- a/lib/ext2fs/freefs.c +++ b/lib/ext2fs/freefs.c @@ -42,8 +42,6 @@ void ext2fs_free(ext2_filsys fs) ext2fs_free_block_bitmap(fs->block_map); if (fs->inode_map) ext2fs_free_inode_bitmap(fs->inode_map); - if (fs->image_header) - ext2fs_free_mem(&fs->image_header); if (fs->badblocks) ext2fs_badblocks_list_free(fs->badblocks); @@ -55,11 +53,6 @@ void ext2fs_free(ext2_filsys fs) if (fs->icache) ext2fs_free_inode_cache(fs->icache); - if (fs->mmp_buf) - ext2fs_free_mem(&fs->mmp_buf); - if (fs->mmp_cmp) - ext2fs_free_mem(&fs->mmp_cmp); - fs->magic = 0; ext2fs_free_mem(&fs); diff --git a/lib/ext2fs/gen_bitmap.c b/lib/ext2fs/gen_bitmap.c index e4362345..42c9c7e4 100644 --- a/lib/ext2fs/gen_bitmap.c +++ b/lib/ext2fs/gen_bitmap.c @@ -25,7 +25,7 @@ #endif #include "ext2_fs.h" -#include "ext2fsP.h" +#include "ext2fs.h" struct ext2fs_struct_generic_bitmap { errcode_t magic; @@ -38,16 +38,6 @@ struct ext2fs_struct_generic_bitmap { __u32 reserved[7]; }; -#define EXT2FS_IS_32_BITMAP(bmap) \ - (((bmap)->magic == EXT2_ET_MAGIC_GENERIC_BITMAP) || \ - ((bmap)->magic == EXT2_ET_MAGIC_BLOCK_BITMAP) || \ - ((bmap)->magic == EXT2_ET_MAGIC_INODE_BITMAP)) - -#define EXT2FS_IS_64_BITMAP(bmap) \ - (((bmap)->magic == EXT2_ET_MAGIC_GENERIC_BITMAP64) || \ - ((bmap)->magic == EXT2_ET_MAGIC_BLOCK_BITMAP64) || \ - ((bmap)->magic == EXT2_ET_MAGIC_INODE_BITMAP64)) - /* * Used by previously inlined function, so we have to export this and * not change the function signature @@ -170,18 +160,6 @@ void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap) int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap, blk_t bitno) { - if (!EXT2FS_IS_32_BITMAP(bitmap)) { - if (EXT2FS_IS_64_BITMAP(bitmap)) { - ext2fs_warn_bitmap32(bitmap, __func__); - return ext2fs_test_generic_bmap(bitmap, bitno); - } -#ifndef OMIT_COM_ERR - com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, - "test_bitmap(%lu)", (unsigned long) bitno); -#endif - return 0; - } - if ((bitno < bitmap->start) || (bitno > bitmap->end)) { ext2fs_warn_bitmap2(bitmap, EXT2FS_TEST_ERROR, bitno); return 0; @@ -192,18 +170,6 @@ int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap, int ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap, __u32 bitno) { - if (!EXT2FS_IS_32_BITMAP(bitmap)) { - if (EXT2FS_IS_64_BITMAP(bitmap)) { - ext2fs_warn_bitmap32(bitmap, __func__); - return ext2fs_mark_generic_bmap(bitmap, bitno); - } -#ifndef OMIT_COM_ERR - com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, - "mark_bitmap(%lu)", (unsigned long) bitno); -#endif - return 0; - } - if ((bitno < bitmap->start) || (bitno > bitmap->end)) { ext2fs_warn_bitmap2(bitmap, EXT2FS_MARK_ERROR, bitno); return 0; @@ -214,18 +180,6 @@ int ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap, int ext2fs_unmark_generic_bitmap(ext2fs_generic_bitmap bitmap, blk_t bitno) { - if (!EXT2FS_IS_32_BITMAP(bitmap)) { - if (EXT2FS_IS_64_BITMAP(bitmap)) { - ext2fs_warn_bitmap32(bitmap, __func__); - return ext2fs_unmark_generic_bmap(bitmap, bitno); - } -#ifndef OMIT_COM_ERR - com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, - "mark_bitmap(%lu)", (unsigned long) bitno); -#endif - return 0; - } - if ((bitno < bitmap->start) || (bitno > bitmap->end)) { ext2fs_warn_bitmap2(bitmap, EXT2FS_UNMARK_ERROR, bitno); return 0; @@ -235,51 +189,18 @@ int ext2fs_unmark_generic_bitmap(ext2fs_generic_bitmap bitmap, __u32 ext2fs_get_generic_bitmap_start(ext2fs_generic_bitmap bitmap) { - if (!EXT2FS_IS_32_BITMAP(bitmap)) { - if (EXT2FS_IS_64_BITMAP(bitmap)) { - ext2fs_warn_bitmap32(bitmap, __func__); - return ext2fs_get_generic_bmap_start(bitmap); - } -#ifndef OMIT_COM_ERR - com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, - "get_bitmap_start"); -#endif - return 0; - } - return bitmap->start; } __u32 ext2fs_get_generic_bitmap_end(ext2fs_generic_bitmap bitmap) { - if (!EXT2FS_IS_32_BITMAP(bitmap)) { - if (EXT2FS_IS_64_BITMAP(bitmap)) { - ext2fs_warn_bitmap32(bitmap, __func__); - return ext2fs_get_generic_bmap_end(bitmap); - } -#ifndef OMIT_COM_ERR - com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, - "get_bitmap_end"); -#endif - return 0; - } return bitmap->end; } void ext2fs_clear_generic_bitmap(ext2fs_generic_bitmap bitmap) { - if (!EXT2FS_IS_32_BITMAP(bitmap)) { - if (EXT2FS_IS_64_BITMAP(bitmap)) { - ext2fs_warn_bitmap32(bitmap, __func__); - ext2fs_clear_generic_bmap(bitmap); - return; - } -#ifndef OMIT_COM_ERR - com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, - "clear_generic_bitmap"); -#endif + if (check_magic(bitmap)) return; - } memset(bitmap->bitmap, 0, (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1)); @@ -412,7 +333,7 @@ errcode_t ext2fs_set_generic_bitmap_range(ext2fs_generic_bitmap bmap, * Compare @mem to zero buffer by 256 bytes. * Return 1 if @mem is zeroed memory, otherwise return 0. */ -int ext2fs_mem_is_zero(const char *mem, size_t len) +static int mem_is_zero(const char *mem, size_t len) { static const char zero_buf[256]; @@ -500,33 +421,9 @@ static int ext2fs_test_clear_generic_bitmap_range(ext2fs_generic_bitmap bitmap, } /* Check whether all bytes are 0 */ - return ext2fs_mem_is_zero(ADDR + start_byte, len_byte); + return mem_is_zero(ADDR + start_byte, len_byte); } -errcode_t ext2fs_find_first_zero_generic_bitmap(ext2fs_generic_bitmap bitmap, - __u32 start, __u32 end, - __u32 *out) -{ - blk_t b; - - if (start < bitmap->start || end > bitmap->end || start > end) { - ext2fs_warn_bitmap2(bitmap, EXT2FS_TEST_ERROR, start); - return EINVAL; - } - - while (start <= end) { - b = ext2fs_test_bit(start - bitmap->start, bitmap->bitmap); - if (!b) { - *out = start; - return 0; - } - start++; - } - - return ENOENT; -} - - int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap, blk_t block, int num) { @@ -581,4 +478,3 @@ void ext2fs_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap, ext2fs_fast_clear_bit(block + i - bitmap->start, bitmap->bitmap); } - diff --git a/lib/ext2fs/gen_bitmap64.c b/lib/ext2fs/gen_bitmap64.c deleted file mode 100644 index 7f49fd9d..00000000 --- a/lib/ext2fs/gen_bitmap64.c +++ /dev/null @@ -1,849 +0,0 @@ -/* - * gen_bitmap64.c --- routines to read, write, and manipulate the new qinode and - * block bitmaps. - * - * Copyright (C) 2007, 2008 Theodore Ts'o. - * - * %Begin-Header% - * This file may be redistributed under the terms of the GNU Public - * License. - * %End-Header% - */ - -#include <stdio.h> -#include <string.h> -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <fcntl.h> -#include <time.h> -#include <errno.h> -#if HAVE_SYS_STAT_H -#include <sys/stat.h> -#endif -#if HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#endif - -#include "ext2_fs.h" -#include "ext2fsP.h" -#include "bmap64.h" - -/* - * Design of 64-bit bitmaps - * - * In order maintain ABI compatibility with programs that don't - * understand about 64-bit blocks/inodes, - * ext2fs_allocate_inode_bitmap() and ext2fs_allocate_block_bitmap() - * will create old-style bitmaps unless the application passes the - * flag EXT2_FLAG_64BITS to ext2fs_open(). If this flag is - * passed, then we know the application has been recompiled, so we can - * use the new-style bitmaps. If it is not passed, we have to return - * an error if trying to open a filesystem which needs 64-bit bitmaps. - * - * The new bitmaps use a new set of structure magic numbers, so that - * both the old-style and new-style interfaces can identify which - * version of the data structure was used. Both the old-style and - * new-style interfaces will support either type of bitmap, although - * of course 64-bit operation will only be possible when both the - * new-style interface and the new-style bitmap are used. - * - * For example, the new bitmap interfaces will check the structure - * magic numbers and so will be able to detect old-stype bitmap. If - * they see an old-style bitmap, they will pass it to the gen_bitmap.c - * functions for handling. The same will be true for the old - * interfaces as well. - * - * The new-style interfaces will have several different back-end - * implementations, so we can support different encodings that are - * appropriate for different applications. In general the default - * should be whatever makes sense, and what the application/library - * will use. However, e2fsck may need specialized implementations for - * its own uses. For example, when doing parent directory pointer - * loop detections in pass 3, the bitmap will *always* be sparse, so - * e2fsck can request an encoding which is optimized for that. - */ - -static void warn_bitmap(ext2fs_generic_bitmap bitmap, - int code, __u64 arg) -{ -#ifndef OMIT_COM_ERR - if (bitmap->description) - com_err(0, bitmap->base_error_code+code, - "#%llu for %s", arg, bitmap->description); - else - com_err(0, bitmap->base_error_code + code, "#%llu", arg); -#endif -} - -#ifdef BMAP_STATS_OPS -#define INC_STAT(map, name) map->stats.name -#else -#define INC_STAT(map, name) ;; -#endif - - -errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic, - int type, __u64 start, __u64 end, - __u64 real_end, - const char *descr, - ext2fs_generic_bitmap *ret) -{ - ext2fs_generic_bitmap bitmap; - struct ext2_bitmap_ops *ops; - ext2_ino_t num_dirs; - errcode_t retval; - - if (!type) - type = EXT2FS_BMAP64_BITARRAY; - - switch (type) { - case EXT2FS_BMAP64_BITARRAY: - ops = &ext2fs_blkmap64_bitarray; - break; - case EXT2FS_BMAP64_RBTREE: - ops = &ext2fs_blkmap64_rbtree; - break; - case EXT2FS_BMAP64_AUTODIR: - retval = ext2fs_get_num_dirs(fs, &num_dirs); - if (retval || num_dirs > (fs->super->s_inodes_count / 320)) - ops = &ext2fs_blkmap64_bitarray; - else - ops = &ext2fs_blkmap64_rbtree; - break; - default: - return EINVAL; - } - - retval = ext2fs_get_memzero(sizeof(struct ext2fs_struct_generic_bitmap), - &bitmap); - if (retval) - return retval; - -#ifdef BMAP_STATS - if (gettimeofday(&bitmap->stats.created, - (struct timezone *) NULL) == -1) { - perror("gettimeofday"); - ext2fs_free_mem(&bitmap); - return 1; - } - bitmap->stats.type = type; -#endif - - /* XXX factor out, repeated in copy_bmap */ - bitmap->magic = magic; - bitmap->fs = fs; - bitmap->start = start; - bitmap->end = end; - bitmap->real_end = real_end; - bitmap->bitmap_ops = ops; - bitmap->cluster_bits = 0; - switch (magic) { - case EXT2_ET_MAGIC_INODE_BITMAP64: - bitmap->base_error_code = EXT2_ET_BAD_INODE_MARK; - break; - case EXT2_ET_MAGIC_BLOCK_BITMAP64: - bitmap->base_error_code = EXT2_ET_BAD_BLOCK_MARK; - bitmap->cluster_bits = fs->cluster_ratio_bits; - break; - default: - bitmap->base_error_code = EXT2_ET_BAD_GENERIC_MARK; - } - if (descr) { - retval = ext2fs_get_mem(strlen(descr)+1, &bitmap->description); - if (retval) { - ext2fs_free_mem(&bitmap); - return retval; - } - strcpy(bitmap->description, descr); - } else - bitmap->description = 0; - - retval = bitmap->bitmap_ops->new_bmap(fs, bitmap); - if (retval) { - ext2fs_free_mem(&bitmap->description); - ext2fs_free_mem(&bitmap); - return retval; - } - - *ret = bitmap; - return 0; -} - -#ifdef BMAP_STATS -static void ext2fs_print_bmap_statistics(ext2fs_generic_bitmap bitmap) -{ - struct ext2_bmap_statistics *stats = &bitmap->stats; -#ifdef BMAP_STATS_OPS - float mark_seq_perc = 0.0, test_seq_perc = 0.0; - float mark_back_perc = 0.0, test_back_perc = 0.0; -#endif - double inuse; - struct timeval now; - -#ifdef BMAP_STATS_OPS - if (stats->test_count) { - test_seq_perc = ((float)stats->test_seq / - stats->test_count) * 100; - test_back_perc = ((float)stats->test_back / - stats->test_count) * 100; - } - - if (stats->mark_count) { - mark_seq_perc = ((float)stats->mark_seq / - stats->mark_count) * 100; - mark_back_perc = ((float)stats->mark_back / - stats->mark_count) * 100; - } -#endif - - if (gettimeofday(&now, (struct timezone *) NULL) == -1) { - perror("gettimeofday"); - return; - } - - inuse = (double) now.tv_sec + \ - (((double) now.tv_usec) * 0.000001); - inuse -= (double) stats->created.tv_sec + \ - (((double) stats->created.tv_usec) * 0.000001); - - fprintf(stderr, "\n[+] %s bitmap (type %d)\n", bitmap->description, - stats->type); - fprintf(stderr, "=================================================\n"); -#ifdef BMAP_STATS_OPS - fprintf(stderr, "%16llu bits long\n", - bitmap->real_end - bitmap->start); - fprintf(stderr, "%16lu copy_bmap\n%16lu resize_bmap\n", - stats->copy_count, stats->resize_count); - fprintf(stderr, "%16lu mark bmap\n%16lu unmark_bmap\n", - stats->mark_count, stats->unmark_count); - fprintf(stderr, "%16lu test_bmap\n%16lu mark_bmap_extent\n", - stats->test_count, stats->mark_ext_count); - fprintf(stderr, "%16lu unmark_bmap_extent\n" - "%16lu test_clear_bmap_extent\n", - stats->unmark_ext_count, stats->test_ext_count); - fprintf(stderr, "%16lu set_bmap_range\n%16lu set_bmap_range\n", - stats->set_range_count, stats->get_range_count); - fprintf(stderr, "%16lu clear_bmap\n%16lu contiguous bit test (%.2f%%)\n", - stats->clear_count, stats->test_seq, test_seq_perc); - fprintf(stderr, "%16lu contiguous bit mark (%.2f%%)\n" - "%16llu bits tested backwards (%.2f%%)\n", - stats->mark_seq, mark_seq_perc, - stats->test_back, test_back_perc); - fprintf(stderr, "%16llu bits marked backwards (%.2f%%)\n" - "%16.2f seconds in use\n", - stats->mark_back, mark_back_perc, inuse); -#endif /* BMAP_STATS_OPS */ -} -#endif - -void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap) -{ - if (!bmap) - return; - - if (EXT2FS_IS_32_BITMAP(bmap)) { - ext2fs_free_generic_bitmap(bmap); - return; - } - - if (!EXT2FS_IS_64_BITMAP(bmap)) - return; - -#ifdef BMAP_STATS - if (getenv("E2FSPROGS_BITMAP_STATS")) { - ext2fs_print_bmap_statistics(bmap); - bmap->bitmap_ops->print_stats(bmap); - } -#endif - - bmap->bitmap_ops->free_bmap(bmap); - - if (bmap->description) { - ext2fs_free_mem(&bmap->description); - bmap->description = 0; - } - bmap->magic = 0; - ext2fs_free_mem(&bmap); -} - -errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src, - ext2fs_generic_bitmap *dest) -{ - char *descr, *new_descr; - ext2fs_generic_bitmap new_bmap; - errcode_t retval; - - if (!src) - return EINVAL; - - if (EXT2FS_IS_32_BITMAP(src)) - return ext2fs_copy_generic_bitmap(src, dest); - - if (!EXT2FS_IS_64_BITMAP(src)) - return EINVAL; - - /* Allocate a new bitmap struct */ - retval = ext2fs_get_memzero(sizeof(struct ext2fs_struct_generic_bitmap), - &new_bmap); - if (retval) - return retval; - - -#ifdef BMAP_STATS_OPS - src->stats.copy_count++; -#endif -#ifdef BMAP_STATS - if (gettimeofday(&new_bmap->stats.created, - (struct timezone *) NULL) == -1) { - perror("gettimeofday"); - ext2fs_free_mem(&new_bmap); - return 1; - } - new_bmap->stats.type = src->stats.type; -#endif - - /* Copy all the high-level parts over */ - new_bmap->magic = src->magic; - new_bmap->fs = src->fs; - new_bmap->start = src->start; - new_bmap->end = src->end; - new_bmap->real_end = src->real_end; - new_bmap->bitmap_ops = src->bitmap_ops; - new_bmap->base_error_code = src->base_error_code; - new_bmap->cluster_bits = src->cluster_bits; - - descr = src->description; - if (descr) { - retval = ext2fs_get_mem(strlen(descr)+10, &new_descr); - if (retval) { - ext2fs_free_mem(&new_bmap); - return retval; - } - sprintf(new_descr, "copy of %s", descr); - new_bmap->description = new_descr; - } - - retval = src->bitmap_ops->copy_bmap(src, new_bmap); - if (retval) { - ext2fs_free_mem(&new_bmap->description); - ext2fs_free_mem(&new_bmap); - return retval; - } - - *dest = new_bmap; - - return 0; -} - -errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap bmap, - __u64 new_end, - __u64 new_real_end) -{ - if (!bmap) - return EINVAL; - - if (EXT2FS_IS_32_BITMAP(bmap)) - return ext2fs_resize_generic_bitmap(bmap->magic, new_end, - new_real_end, bmap); - - if (!EXT2FS_IS_64_BITMAP(bmap)) - return EINVAL; - - INC_STAT(bmap, resize_count); - - return bmap->bitmap_ops->resize_bmap(bmap, new_end, new_real_end); -} - -errcode_t ext2fs_fudge_generic_bmap_end(ext2fs_generic_bitmap bitmap, - errcode_t neq, - __u64 end, __u64 *oend) -{ - if (!bitmap) - return EINVAL; - - if (EXT2FS_IS_32_BITMAP(bitmap)) { - ext2_ino_t tmp_oend; - int retval; - - retval = ext2fs_fudge_generic_bitmap_end(bitmap, bitmap->magic, - neq, end, &tmp_oend); - if (oend) - *oend = tmp_oend; - return retval; - } - - if (!EXT2FS_IS_64_BITMAP(bitmap)) - return EINVAL; - - if (end > bitmap->real_end) - return neq; - if (oend) - *oend = bitmap->end; - bitmap->end = end; - return 0; -} - -__u64 ext2fs_get_generic_bmap_start(ext2fs_generic_bitmap bitmap) -{ - if (!bitmap) - return EINVAL; - - if (EXT2FS_IS_32_BITMAP(bitmap)) - return ext2fs_get_generic_bitmap_start(bitmap); - - if (!EXT2FS_IS_64_BITMAP(bitmap)) - return EINVAL; - - return bitmap->start; -} - -__u64 ext2fs_get_generic_bmap_end(ext2fs_generic_bitmap bitmap) -{ - if (!bitmap) - return EINVAL; - - if (EXT2FS_IS_32_BITMAP(bitmap)) - return ext2fs_get_generic_bitmap_end(bitmap); - - if (!EXT2FS_IS_64_BITMAP(bitmap)) - return EINVAL; - - return bitmap->end; -} - -void ext2fs_clear_generic_bmap(ext2fs_generic_bitmap bitmap) -{ - if (EXT2FS_IS_32_BITMAP(bitmap)) - ext2fs_clear_generic_bitmap(bitmap); - else - bitmap->bitmap_ops->clear_bmap (bitmap); -} - -int ext2fs_mark_generic_bmap(ext2fs_generic_bitmap bitmap, - __u64 arg) -{ - if (!bitmap) - return 0; - - if (EXT2FS_IS_32_BITMAP(bitmap)) { - if (arg & ~0xffffffffULL) { - ext2fs_warn_bitmap2(bitmap, - EXT2FS_MARK_ERROR, 0xffffffff); - return 0; - } - return ext2fs_mark_generic_bitmap(bitmap, arg); - } - - if (!EXT2FS_IS_64_BITMAP(bitmap)) - return 0; - - arg >>= bitmap->cluster_bits; - -#ifdef BMAP_STATS_OPS - if (arg == bitmap->stats.last_marked + 1) - bitmap->stats.mark_seq++; - if (arg < bitmap->stats.last_marked) - bitmap->stats.mark_back++; - bitmap->stats.last_marked = arg; - bitmap->stats.mark_count++; -#endif - - if ((arg < bitmap->start) || (arg > bitmap->end)) { - warn_bitmap(bitmap, EXT2FS_MARK_ERROR, arg); - return 0; - } - - return bitmap->bitmap_ops->mark_bmap(bitmap, arg); -} - -int ext2fs_unmark_generic_bmap(ext2fs_generic_bitmap bitmap, - __u64 arg) -{ - if (!bitmap) - return 0; - - if (EXT2FS_IS_32_BITMAP(bitmap)) { - if (arg & ~0xffffffffULL) { - ext2fs_warn_bitmap2(bitmap, EXT2FS_UNMARK_ERROR, - 0xffffffff); - return 0; - } - return ext2fs_unmark_generic_bitmap(bitmap, arg); - } - - if (!EXT2FS_IS_64_BITMAP(bitmap)) - return 0; - - arg >>= bitmap->cluster_bits; - - INC_STAT(bitmap, unmark_count); - - if ((arg < bitmap->start) || (arg > bitmap->end)) { - warn_bitmap(bitmap, EXT2FS_UNMARK_ERROR, arg); - return 0; - } - - return bitmap->bitmap_ops->unmark_bmap(bitmap, arg); -} - -int ext2fs_test_generic_bmap(ext2fs_generic_bitmap bitmap, - __u64 arg) -{ - if (!bitmap) - return 0; - - if (EXT2FS_IS_32_BITMAP(bitmap)) { - if (arg & ~0xffffffffULL) { - ext2fs_warn_bitmap2(bitmap, EXT2FS_TEST_ERROR, - 0xffffffff); - return 0; - } - return ext2fs_test_generic_bitmap(bitmap, arg); - } - - if (!EXT2FS_IS_64_BITMAP(bitmap)) - return 0; - - arg >>= bitmap->cluster_bits; - -#ifdef BMAP_STATS_OPS - bitmap->stats.test_count++; - if (arg == bitmap->stats.last_tested + 1) - bitmap->stats.test_seq++; - if (arg < bitmap->stats.last_tested) - bitmap->stats.test_back++; - bitmap->stats.last_tested = arg; -#endif - - if ((arg < bitmap->start) || (arg > bitmap->end)) { - warn_bitmap(bitmap, EXT2FS_TEST_ERROR, arg); - return 0; - } - - return bitmap->bitmap_ops->test_bmap(bitmap, arg); -} - -errcode_t ext2fs_set_generic_bmap_range(ext2fs_generic_bitmap bmap, - __u64 start, unsigned int num, - void *in) -{ - if (!bmap) - return EINVAL; - - if (EXT2FS_IS_32_BITMAP(bmap)) { - if ((start+num-1) & ~0xffffffffULL) { - ext2fs_warn_bitmap2(bmap, EXT2FS_UNMARK_ERROR, - 0xffffffff); - return EINVAL; - } - return ext2fs_set_generic_bitmap_range(bmap, bmap->magic, - start, num, in); - } - - if (!EXT2FS_IS_64_BITMAP(bmap)) - return EINVAL; - - INC_STAT(bmap, set_range_count); - - return bmap->bitmap_ops->set_bmap_range(bmap, start, num, in); -} - -errcode_t ext2fs_get_generic_bmap_range(ext2fs_generic_bitmap bmap, - __u64 start, unsigned int num, - void *out) -{ - if (!bmap) - return EINVAL; - - if (EXT2FS_IS_32_BITMAP(bmap)) { - if ((start+num-1) & ~0xffffffffULL) { - ext2fs_warn_bitmap2(bmap, - EXT2FS_UNMARK_ERROR, 0xffffffff); - return EINVAL; - } - return ext2fs_get_generic_bitmap_range(bmap, bmap->magic, - start, num, out); - } - - if (!EXT2FS_IS_64_BITMAP(bmap)) - return EINVAL; - - INC_STAT(bmap, get_range_count); - - return bmap->bitmap_ops->get_bmap_range(bmap, start, num, out); -} - -errcode_t ext2fs_compare_generic_bmap(errcode_t neq, - ext2fs_generic_bitmap bm1, - ext2fs_generic_bitmap bm2) -{ - blk64_t i; - - if (!bm1 || !bm2) - return EINVAL; - if (bm1->magic != bm2->magic) - return EINVAL; - - /* Now we know both bitmaps have the same magic */ - if (EXT2FS_IS_32_BITMAP(bm1)) - return ext2fs_compare_generic_bitmap(bm1->magic, neq, bm1, bm2); - - if (!EXT2FS_IS_64_BITMAP(bm1)) - return EINVAL; - - if ((bm1->start != bm2->start) || - (bm1->end != bm2->end)) - return neq; - - for (i = bm1->end - ((bm1->end - bm1->start) % 8); i <= bm1->end; i++) - if (ext2fs_test_generic_bmap(bm1, i) != - ext2fs_test_generic_bmap(bm2, i)) - return neq; - - return 0; -} - -void ext2fs_set_generic_bmap_padding(ext2fs_generic_bitmap bmap) -{ - __u64 start, num; - - if (EXT2FS_IS_32_BITMAP(bmap)) { - ext2fs_set_generic_bitmap_padding(bmap); - return; - } - - start = bmap->end + 1; - num = bmap->real_end - bmap->end; - bmap->bitmap_ops->mark_bmap_extent(bmap, start, num); - /* XXX ought to warn on error */ -} - -int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap bmap, - blk64_t block, unsigned int num) -{ - __u64 end = block + num; - - if (!bmap) - return EINVAL; - - if (num == 1) - return !ext2fs_test_generic_bmap((ext2fs_generic_bitmap) - bmap, block); - - if (EXT2FS_IS_32_BITMAP(bmap)) { - if ((block+num-1) & ~0xffffffffULL) { - ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bmap, - EXT2FS_UNMARK_ERROR, 0xffffffff); - return EINVAL; - } - return ext2fs_test_block_bitmap_range( - (ext2fs_generic_bitmap) bmap, block, num); - } - - if (!EXT2FS_IS_64_BITMAP(bmap)) - return EINVAL; - - INC_STAT(bmap, test_ext_count); - - /* convert to clusters if necessary */ - block >>= bmap->cluster_bits; - end += (1 << bmap->cluster_bits) - 1; - end >>= bmap->cluster_bits; - num = end - block; - - if ((block < bmap->start) || (block+num-1 > bmap->end)) { - ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST, block, - bmap->description); - return EINVAL; - } - - return bmap->bitmap_ops->test_clear_bmap_extent(bmap, block, num); -} - -void ext2fs_mark_block_bitmap_range2(ext2fs_block_bitmap bmap, - blk64_t block, unsigned int num) -{ - __u64 end = block + num; - - if (!bmap) - return; - - if (EXT2FS_IS_32_BITMAP(bmap)) { - if ((block+num-1) & ~0xffffffffULL) { - ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bmap, - EXT2FS_UNMARK_ERROR, 0xffffffff); - return; - } - ext2fs_mark_block_bitmap_range((ext2fs_generic_bitmap) bmap, - block, num); - } - - if (!EXT2FS_IS_64_BITMAP(bmap)) - return; - - INC_STAT(bmap, mark_ext_count); - - /* convert to clusters if necessary */ - block >>= bmap->cluster_bits; - end += (1 << bmap->cluster_bits) - 1; - end >>= bmap->cluster_bits; - num = end - block; - - if ((block < bmap->start) || (block+num-1 > bmap->end)) { - ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block, - bmap->description); - return; - } - - bmap->bitmap_ops->mark_bmap_extent(bmap, block, num); -} - -void ext2fs_unmark_block_bitmap_range2(ext2fs_block_bitmap bmap, - blk64_t block, unsigned int num) -{ - __u64 end = block + num; - - if (!bmap) - return; - - if (EXT2FS_IS_32_BITMAP(bmap)) { - if ((block+num-1) & ~0xffffffffULL) { - ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bmap, - EXT2FS_UNMARK_ERROR, 0xffffffff); - return; - } - ext2fs_unmark_block_bitmap_range((ext2fs_generic_bitmap) bmap, - block, num); - } - - if (!EXT2FS_IS_64_BITMAP(bmap)) - return; - - INC_STAT(bmap, unmark_ext_count); - - /* convert to clusters if necessary */ - block >>= bmap->cluster_bits; - end += (1 << bmap->cluster_bits) - 1; - end >>= bmap->cluster_bits; - num = end - block; - - if ((block < bmap->start) || (block+num-1 > bmap->end)) { - ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block, - bmap->description); - return; - } - - bmap->bitmap_ops->unmark_bmap_extent(bmap, block, num); -} - -void ext2fs_warn_bitmap32(ext2fs_generic_bitmap bitmap, const char *func) -{ -#ifndef OMIT_COM_ERR - if (bitmap && bitmap->description) - com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, - "called %s with 64-bit bitmap for %s", func, - bitmap->description); - else - com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, - "called %s with 64-bit bitmap", func); -#endif -} - -errcode_t ext2fs_convert_subcluster_bitmap(ext2_filsys fs, - ext2fs_block_bitmap *bitmap) -{ - ext2fs_block_bitmap cmap, bmap; - errcode_t retval; - blk64_t i, b_end, c_end; - int n, ratio; - - bmap = *bitmap; - - if (fs->cluster_ratio_bits == ext2fs_get_bitmap_granularity(bmap)) - return 0; /* Nothing to do */ - - retval = ext2fs_allocate_block_bitmap(fs, "converted cluster bitmap", - &cmap); - if (retval) - return retval; - - i = bmap->start; - b_end = bmap->end; - bmap->end = bmap->real_end; - c_end = cmap->end; - cmap->end = cmap->real_end; - n = 0; - ratio = 1 << fs->cluster_ratio_bits; - while (i < bmap->real_end) { - if (ext2fs_test_block_bitmap2(bmap, i)) { - ext2fs_mark_block_bitmap2(cmap, i); - i += ratio - n; - n = 0; - continue; - } - i++; n++; - if (n >= ratio) - n = 0; - } - bmap->end = b_end; - cmap->end = c_end; - ext2fs_free_block_bitmap(bmap); - *bitmap = cmap; - return 0; -} - -errcode_t ext2fs_find_first_zero_generic_bmap(ext2fs_generic_bitmap bitmap, - __u64 start, __u64 end, __u64 *out) -{ - int b; - - if (!bitmap) - return EINVAL; - - if (EXT2FS_IS_64_BITMAP(bitmap) && bitmap->bitmap_ops->find_first_zero) - return bitmap->bitmap_ops->find_first_zero(bitmap, start, - end, out); - - if (EXT2FS_IS_32_BITMAP(bitmap)) { - blk_t blk = 0; - errcode_t retval; - - if (((start) & ~0xffffffffULL) || - ((end) & ~0xffffffffULL)) { - ext2fs_warn_bitmap2(bitmap, EXT2FS_TEST_ERROR, start); - return EINVAL; - } - - retval = ext2fs_find_first_zero_generic_bitmap(bitmap, start, - end, &blk); - if (retval == 0) - *out = blk; - return retval; - } - - if (!EXT2FS_IS_64_BITMAP(bitmap)) - return EINVAL; - - start >>= bitmap->cluster_bits; - end >>= bitmap->cluster_bits; - - if (start < bitmap->start || end > bitmap->end || start > end) { - warn_bitmap(bitmap, EXT2FS_TEST_ERROR, start); - return EINVAL; - } - - while (start <= end) { - b = bitmap->bitmap_ops->test_bmap(bitmap, start); - if (!b) { - *out = start << bitmap->cluster_bits; - return 0; - } - start++; - } - - return ENOENT; -} diff --git a/lib/ext2fs/gen_crc32ctable.c b/lib/ext2fs/gen_crc32ctable.c deleted file mode 100644 index 9996e9d8..00000000 --- a/lib/ext2fs/gen_crc32ctable.c +++ /dev/null @@ -1,123 +0,0 @@ -#include <stdio.h> -#include "crc32c_defs.h" -#include <inttypes.h> - -#define ENTRIES_PER_LINE 4 - -#if CRC_LE_BITS <= 8 -#define LE_TABLE_SIZE (1 << CRC_LE_BITS) -#else -#define LE_TABLE_SIZE 256 -#endif - -#if CRC_BE_BITS <= 8 -#define BE_TABLE_SIZE (1 << CRC_BE_BITS) -#else -#define BE_TABLE_SIZE 256 -#endif - -static uint32_t crc32ctable_le[8][256]; -static uint32_t crc32ctable_be[8][256]; - -/** - * crc32cinit_le() - allocate and initialize LE table data - * - * crc is the crc of the byte i; other entries are filled in based on the - * fact that crctable[i^j] = crctable[i] ^ crctable[j]. - * - */ -static void crc32cinit_le(void) -{ - unsigned i, j; - uint32_t crc = 1; - - crc32ctable_le[0][0] = 0; - - for (i = LE_TABLE_SIZE >> 1; i; i >>= 1) { - crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); - for (j = 0; j < LE_TABLE_SIZE; j += 2 * i) - crc32ctable_le[0][i + j] = crc ^ crc32ctable_le[0][j]; - } - for (i = 0; i < LE_TABLE_SIZE; i++) { - crc = crc32ctable_le[0][i]; - for (j = 1; j < 8; j++) { - crc = crc32ctable_le[0][crc & 0xff] ^ (crc >> 8); - crc32ctable_le[j][i] = crc; - } - } -} - -/** - * crc32cinit_be() - allocate and initialize BE table data - */ -static void crc32cinit_be(void) -{ - unsigned i, j; - uint32_t crc = 0x80000000; - - crc32ctable_be[0][0] = 0; - - for (i = 1; i < BE_TABLE_SIZE; i <<= 1) { - crc = (crc << 1) ^ ((crc & 0x80000000) ? CRCPOLY_BE : 0); - for (j = 0; j < i; j++) - crc32ctable_be[0][i + j] = crc ^ crc32ctable_be[0][j]; - } - for (i = 0; i < BE_TABLE_SIZE; i++) { - crc = crc32ctable_be[0][i]; - for (j = 1; j < 8; j++) { - crc = crc32ctable_be[0][(crc >> 24) & 0xff] ^ - (crc << 8); - crc32ctable_be[j][i] = crc; - } - } -} - -static void output_table(uint32_t table[8][256], int len, char trans) -{ - int i, j; - - for (j = 0 ; j < 8; j++) { - printf("static const uint32_t t%d_%ce[] = {", j, trans); - for (i = 0; i < len - 1; i++) { - if ((i % ENTRIES_PER_LINE) == 0) - printf("\n"); - printf("to%ce(0x%8.8xL),", trans, table[j][i]); - if ((i % ENTRIES_PER_LINE) != (ENTRIES_PER_LINE - 1)) - printf(" "); - } - printf("to%ce(0x%8.8xL)};\n\n", trans, table[j][len - 1]); - - if (trans == 'l') { - if ((j+1)*8 >= CRC_LE_BITS) - break; - } else { - if ((j+1)*8 >= CRC_BE_BITS) - break; - } - } -} - -int main(int argc, char **argv) -{ - printf("/*\n"); - printf(" * crc32ctable.h - CRC32c tables\n"); - printf(" * this file is generated - do not edit\n"); - printf(" * # gen_crc32ctable > crc32c_table.h\n"); - printf(" * with\n"); - printf(" * CRC_LE_BITS = %d\n", CRC_LE_BITS); - printf(" * CRC_BE_BITS = %d\n", CRC_BE_BITS); - printf(" */\n"); - printf("#include <stdint.h>\n"); - - if (CRC_LE_BITS > 1) { - crc32cinit_le(); - output_table(crc32ctable_le, LE_TABLE_SIZE, 'l'); - } - - if (CRC_BE_BITS > 1) { - crc32cinit_be(); - output_table(crc32ctable_be, BE_TABLE_SIZE, 'b'); - } - - return 0; -} diff --git a/lib/ext2fs/get_pathname.c b/lib/ext2fs/get_pathname.c index 93a9ec81..7ac14db2 100644 --- a/lib/ext2fs/get_pathname.c +++ b/lib/ext2fs/get_pathname.c @@ -73,7 +73,7 @@ static errcode_t ext2fs_get_pathname_int(ext2_filsys fs, ext2_ino_t dir, char *buf, char **name) { struct get_pathname_struct gp; - char *parent_name = 0, *ret; + char *parent_name, *ret; errcode_t retval; if (dir == ino) { @@ -98,19 +98,7 @@ static errcode_t ext2fs_get_pathname_int(ext2_filsys fs, ext2_ino_t dir, gp.errcode = 0; retval = ext2fs_dir_iterate(fs, dir, 0, buf, get_pathname_proc, &gp); - if (retval == EXT2_ET_NO_DIRECTORY) { - char tmp[32]; - - if (ino) - snprintf(tmp, sizeof(tmp), "<%u>/<%u>", dir, ino); - else - snprintf(tmp, sizeof(tmp), "<%u>", dir); - retval = ext2fs_get_mem(strlen(tmp)+1, name); - if (retval) - goto cleanup; - strcpy(*name, tmp); - return 0; - } else if (retval) + if (retval) goto cleanup; if (gp.errcode) { retval = gp.errcode; @@ -143,11 +131,12 @@ static errcode_t ext2fs_get_pathname_int(ext2_filsys fs, ext2_ino_t dir, else strcat(ret, "???"); *name = ret; + ext2fs_free_mem(&parent_name); retval = 0; cleanup: - ext2fs_free_mem(&parent_name); - ext2fs_free_mem(&gp.name); + if (gp.name) + ext2fs_free_mem(&gp.name); return retval; } diff --git a/lib/ext2fs/getsectsize.c b/lib/ext2fs/getsectsize.c index c7ae6594..64f42a62 100644 --- a/lib/ext2fs/getsectsize.c +++ b/lib/ext2fs/getsectsize.c @@ -45,7 +45,11 @@ errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize) { int fd; - fd = ext2fs_open_file(file, O_RDONLY, 0); +#ifdef HAVE_OPEN64 + fd = open64(file, O_RDONLY); +#else + fd = open(file, O_RDONLY); +#endif if (fd < 0) return errno; @@ -61,39 +65,17 @@ errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize) } /* - * Return desired alignment for direct I/O - */ -int ext2fs_get_dio_alignment(int fd) -{ - int align = 0; - -#ifdef BLKSSZGET - if (ioctl(fd, BLKSSZGET, &align) < 0) - align = 0; -#endif - -#ifdef _SC_PAGESIZE - if (align <= 0) - align = sysconf(_SC_PAGESIZE); -#endif -#ifdef HAVE_GETPAGESIZE - if (align <= 0) - align = getpagesize(); -#endif - if (align <= 0) - align = 4096; - - return align; -} - -/* * Returns the physical sector size of a device */ errcode_t ext2fs_get_device_phys_sectsize(const char *file, int *sectsize) { int fd; - fd = ext2fs_open_file(file, O_RDONLY, 0); +#ifdef HAVE_OPEN64 + fd = open64(file, O_RDONLY); +#else + fd = open(file, O_RDONLY); +#endif if (fd < 0) return errno; diff --git a/lib/ext2fs/getsize.c b/lib/ext2fs/getsize.c index 2f4495ed..5ef0081b 100644 --- a/lib/ext2fs/getsize.c +++ b/lib/ext2fs/getsize.c @@ -139,13 +139,31 @@ static int valid_offset (int fd, ext2_loff_t offset) * Returns the number of blocks in a partition */ errcode_t ext2fs_get_device_size2(const char *file, int blocksize, - blk64_t *retblocks) + blk64_t *retblocks) { int fd, rc = 0; + int valid_blkgetsize64 = 1; +#ifdef __linux__ + struct utsname ut; +#endif unsigned long long size64; + unsigned long size; ext2_loff_t high, low; +#ifdef FDGETPRM + struct floppy_struct this_floppy; +#endif +#ifdef HAVE_SYS_DISKLABEL_H + int part; + struct disklabel lab; + struct partition *pp; + char ch; +#endif /* HAVE_SYS_DISKLABEL_H */ - fd = ext2fs_open_file(file, O_RDONLY, 0); +#ifdef HAVE_OPEN64 + fd = open64(file, O_RDONLY); +#else + fd = open(file, O_RDONLY); +#endif if (fd < 0) return errno; @@ -157,89 +175,73 @@ errcode_t ext2fs_get_device_size2(const char *file, int blocksize, #endif #ifdef BLKGETSIZE64 - { - int valid_blkgetsize64 = 1; #ifdef __linux__ - struct utsname ut; - - if ((uname(&ut) == 0) && - ((ut.release[0] == '2') && (ut.release[1] == '.') && - (ut.release[2] < '6') && (ut.release[3] == '.'))) - valid_blkgetsize64 = 0; + if ((uname(&ut) == 0) && + ((ut.release[0] == '2') && (ut.release[1] == '.') && + (ut.release[2] < '6') && (ut.release[3] == '.'))) + valid_blkgetsize64 = 0; #endif - if (valid_blkgetsize64 && - ioctl(fd, BLKGETSIZE64, &size64) >= 0) { - *retblocks = size64 / blocksize; - goto out; - } + if (valid_blkgetsize64 && + ioctl(fd, BLKGETSIZE64, &size64) >= 0) { + *retblocks = size64 / blocksize; + goto out; } -#endif /* BLKGETSIZE64 */ +#endif #ifdef BLKGETSIZE - { - unsigned long size; - - if (ioctl(fd, BLKGETSIZE, &size) >= 0) { - *retblocks = size / (blocksize / 512); - goto out; - } + if (ioctl(fd, BLKGETSIZE, &size) >= 0) { + *retblocks = size / (blocksize / 512); + goto out; } #endif #ifdef FDGETPRM - { - struct floppy_struct this_floppy; - - if (ioctl(fd, FDGETPRM, &this_floppy) >= 0) { - *retblocks = this_floppy.size / (blocksize / 512); - goto out; - } + if (ioctl(fd, FDGETPRM, &this_floppy) >= 0) { + *retblocks = this_floppy.size / (blocksize / 512); + goto out; } #endif #ifdef HAVE_SYS_DISKLABEL_H - { - int part; - struct disklabel lab; - struct partition *pp; - char ch; - #if defined(DIOCGMEDIASIZE) - { - off_t ms; - u_int bs; - if (ioctl(fd, DIOCGMEDIASIZE, &ms) >= 0) { - *retblocks = ms / blocksize; - goto out; - } - } + { + off_t ms; + u_int bs; + if (ioctl(fd, DIOCGMEDIASIZE, &ms) >= 0) { + *retblocks = ms / blocksize; + goto out; + } + } #elif defined(DIOCGDINFO) - /* old disklabel interface */ - part = strlen(file) - 1; - if (part >= 0) { - ch = file[part]; - if (isdigit(ch)) - part = 0; - else if (ch >= 'a' && ch <= 'h') - part = ch - 'a'; - else - part = -1; - } - if (part >= 0 && (ioctl(fd, DIOCGDINFO, (char *)&lab) >= 0)) { - pp = &lab.d_partitions[part]; - if (pp->p_size) { - *retblocks = pp->p_size / (blocksize / 512); - goto out; - } + /* old disklabel interface */ + part = strlen(file) - 1; + if (part >= 0) { + ch = file[part]; + if (isdigit(ch)) + part = 0; + else if (ch >= 'a' && ch <= 'h') + part = ch - 'a'; + else + part = -1; + } + if (part >= 0 && (ioctl(fd, DIOCGDINFO, (char *)&lab) >= 0)) { + pp = &lab.d_partitions[part]; + if (pp->p_size) { + *retblocks = pp->p_size / (blocksize / 512); + goto out; } -#endif /* defined(DIOCG*) */ } +#endif /* defined(DIOCG*) */ #endif /* HAVE_SYS_DISKLABEL_H */ { - ext2fs_struct_stat st; - - if (ext2fs_fstat(fd, &st) == 0) +#ifdef HAVE_FSTAT64 + struct stat64 st; + if (fstat64(fd, &st) == 0) +#else + struct stat st; + if (fstat(fd, &st) == 0) +#endif if (S_ISREG(st.st_mode)) { *retblocks = st.st_size / blocksize; goto out; @@ -252,9 +254,10 @@ errcode_t ext2fs_get_device_size2(const char *file, int blocksize, * find the size of the partition. */ low = 0; - for (high = 1024; valid_offset(fd, high); high *= 2) + for (high = 1024; valid_offset (fd, high); high *= 2) low = high; - while (low < high - 1) { + while (low < high - 1) + { const ext2_loff_t mid = (low + high) / 2; if (valid_offset (fd, mid)) @@ -262,7 +265,7 @@ errcode_t ext2fs_get_device_size2(const char *file, int blocksize, else high = mid; } - valid_offset(fd, 0); + valid_offset (fd, 0); size64 = low + 1; *retblocks = size64 / blocksize; out: diff --git a/lib/ext2fs/i_block.c b/lib/ext2fs/i_block.c index f36c3c47..822776df 100644 --- a/lib/ext2fs/i_block.c +++ b/lib/ext2fs/i_block.c @@ -31,20 +31,18 @@ errcode_t ext2fs_iblk_add_blocks(ext2_filsys fs, struct ext2_inode *inode, { unsigned long long b = inode->i_blocks; - if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE) - b += ((long long) inode->osd2.linux2.l_i_blocks_hi) << 32; - if (!(fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE) || !(inode->i_flags & EXT4_HUGE_FILE_FL)) num_blocks *= fs->blocksize / 512; - num_blocks *= EXT2FS_CLUSTER_RATIO(fs); b += num_blocks; - if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE) + if (fs->super->s_feature_ro_compat & + EXT4_FEATURE_RO_COMPAT_HUGE_FILE) { + b += ((long long) inode->osd2.linux2.l_i_blocks_hi) << 32; inode->osd2.linux2.l_i_blocks_hi = b >> 32; - else if (b > 0xFFFFFFFF) + } else if (b > 0xFFFFFFFF) return EOVERFLOW; inode->i_blocks = b & 0xFFFFFFFF; return 0; @@ -55,22 +53,21 @@ errcode_t ext2fs_iblk_sub_blocks(ext2_filsys fs, struct ext2_inode *inode, { unsigned long long b = inode->i_blocks; - if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE) - b += ((long long) inode->osd2.linux2.l_i_blocks_hi) << 32; - if (!(fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE) || !(inode->i_flags & EXT4_HUGE_FILE_FL)) num_blocks *= fs->blocksize / 512; - num_blocks *= EXT2FS_CLUSTER_RATIO(fs); if (num_blocks > b) return EOVERFLOW; b -= num_blocks; - if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE) + if (fs->super->s_feature_ro_compat & + EXT4_FEATURE_RO_COMPAT_HUGE_FILE) { + b += ((long long) inode->osd2.linux2.l_i_blocks_hi) << 32; inode->osd2.linux2.l_i_blocks_hi = b >> 32; + } inode->i_blocks = b & 0xFFFFFFFF; return 0; } @@ -81,7 +78,6 @@ errcode_t ext2fs_iblk_set(ext2_filsys fs, struct ext2_inode *inode, blk64_t b) EXT4_FEATURE_RO_COMPAT_HUGE_FILE) || !(inode->i_flags & EXT4_HUGE_FILE_FL)) b *= fs->blocksize / 512; - b *= EXT2FS_CLUSTER_RATIO(fs); inode->i_blocks = b & 0xFFFFFFFF; if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE) diff --git a/lib/ext2fs/icount.c b/lib/ext2fs/icount.c index f99824f8..a49f05fb 100644 --- a/lib/ext2fs/icount.c +++ b/lib/ext2fs/icount.c @@ -103,12 +103,12 @@ static errcode_t alloc_icount(ext2_filsys fs, int flags, ext2_icount_t *ret) return retval; memset(icount, 0, sizeof(struct ext2_icount)); - retval = ext2fs_allocate_inode_bitmap(fs, "icount", &icount->single); + retval = ext2fs_allocate_inode_bitmap(fs, 0, &icount->single); if (retval) goto errout; if (flags & EXT2_ICOUNT_OPT_INCREMENT) { - retval = ext2fs_allocate_inode_bitmap(fs, "icount_inc", + retval = ext2fs_allocate_inode_bitmap(fs, 0, &icount->multiple); if (retval) goto errout; @@ -179,7 +179,6 @@ errcode_t ext2fs_create_icount_tdb(ext2_filsys fs, char *tdb_dir, ext2_icount_t icount; errcode_t retval; char *fn, uuid[40]; - ext2_ino_t num_inodes; int fd; retval = alloc_icount(fs, flags, &icount); @@ -192,21 +191,9 @@ errcode_t ext2fs_create_icount_tdb(ext2_filsys fs, char *tdb_dir, uuid_unparse(fs->super->s_uuid, uuid); sprintf(fn, "%s/%s-icount-XXXXXX", tdb_dir, uuid); fd = mkstemp(fn); - if (fd < 0) - return fd; - - /* - * This is an overestimate of the size that we will need; the - * ideal value is the number of used inodes with a count - * greater than 1. OTOH the times when we really need this is - * with the backup programs that use lots of hard links, in - * which case the number of inodes in use approaches the ideal - * value. - */ - num_inodes = fs->super->s_inodes_count - fs->super->s_free_inodes_count; icount->tdb_fn = fn; - icount->tdb = tdb_open(fn, num_inodes, TDB_NOLOCK | TDB_NOSYNC, + icount->tdb = tdb_open(fn, 0, TDB_CLEAR_IF_FIRST, O_RDWR | O_CREAT | O_TRUNC, 0600); if (icount->tdb) { close(fd); @@ -352,7 +339,9 @@ static struct ext2_icount_el *insert_icount_el(ext2_icount_t icount, static struct ext2_icount_el *get_icount_el(ext2_icount_t icount, ext2_ino_t ino, int create) { + float range; int low, high, mid; + ext2_ino_t lowval, highval; if (!icount || !icount->list) return 0; @@ -374,7 +363,31 @@ static struct ext2_icount_el *get_icount_el(ext2_icount_t icount, low = 0; high = (int) icount->count-1; while (low <= high) { - mid = ((unsigned)low + (unsigned)high) >> 1; +#if 0 + mid = (low+high)/2; +#else + if (low == high) + mid = low; + else { + /* Interpolate for efficiency */ + lowval = icount->list[low].ino; + highval = icount->list[high].ino; + + if (ino < lowval) + range = 0; + else if (ino > highval) + range = 1; + else { + range = ((float) (ino - lowval)) / + (highval - lowval); + if (range > 0.9) + range = 0.9; + if (range < 0.1) + range = 0.1; + } + mid = low + ((int) (range * (high-low))); + } +#endif if (ino == icount->list[mid].ino) { icount->cursor = mid+1; return &icount->list[mid]; @@ -485,12 +498,12 @@ errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino, __u16 *ret) if (!ino || (ino > icount->num_inodes)) return EXT2_ET_INVALID_ARGUMENT; - if (ext2fs_test_inode_bitmap2(icount->single, ino)) { + if (ext2fs_test_inode_bitmap(icount->single, ino)) { *ret = 1; return 0; } if (icount->multiple && - !ext2fs_test_inode_bitmap2(icount->multiple, ino)) { + !ext2fs_test_inode_bitmap(icount->multiple, ino)) { *ret = 0; return 0; } @@ -509,7 +522,7 @@ errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino, if (!ino || (ino > icount->num_inodes)) return EXT2_ET_INVALID_ARGUMENT; - if (ext2fs_test_inode_bitmap2(icount->single, ino)) { + if (ext2fs_test_inode_bitmap(icount->single, ino)) { /* * If the existing count is 1, then we know there is * no entry in the list. @@ -517,14 +530,14 @@ errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino, if (set_inode_count(icount, ino, 2)) return EXT2_ET_NO_MEMORY; curr_value = 2; - ext2fs_unmark_inode_bitmap2(icount->single, ino); + ext2fs_unmark_inode_bitmap(icount->single, ino); } else if (icount->multiple) { /* * The count is either zero or greater than 1; if the * inode is set in icount->multiple, then there should * be an entry in the list, so we need to fix it. */ - if (ext2fs_test_inode_bitmap2(icount->multiple, ino)) { + if (ext2fs_test_inode_bitmap(icount->multiple, ino)) { get_inode_count(icount, ino, &curr_value); curr_value++; if (set_inode_count(icount, ino, curr_value)) @@ -534,7 +547,7 @@ errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino, * The count was zero; mark the single bitmap * and return. */ - ext2fs_mark_inode_bitmap2(icount->single, ino); + ext2fs_mark_inode_bitmap(icount->single, ino); if (ret) *ret = 1; return 0; @@ -550,7 +563,7 @@ errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino, return EXT2_ET_NO_MEMORY; } if (icount->multiple) - ext2fs_mark_inode_bitmap2(icount->multiple, ino); + ext2fs_mark_inode_bitmap(icount->multiple, ino); if (ret) *ret = icount_16_xlate(curr_value); return 0; @@ -566,10 +579,10 @@ errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino, EXT2_CHECK_MAGIC(icount, EXT2_ET_MAGIC_ICOUNT); - if (ext2fs_test_inode_bitmap2(icount->single, ino)) { - ext2fs_unmark_inode_bitmap2(icount->single, ino); + if (ext2fs_test_inode_bitmap(icount->single, ino)) { + ext2fs_unmark_inode_bitmap(icount->single, ino); if (icount->multiple) - ext2fs_unmark_inode_bitmap2(icount->multiple, ino); + ext2fs_unmark_inode_bitmap(icount->multiple, ino); else { set_inode_count(icount, ino, 0); } @@ -579,7 +592,7 @@ errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino, } if (icount->multiple && - !ext2fs_test_inode_bitmap2(icount->multiple, ino)) + !ext2fs_test_inode_bitmap(icount->multiple, ino)) return EXT2_ET_INVALID_ARGUMENT; get_inode_count(icount, ino, &curr_value); @@ -590,9 +603,9 @@ errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino, return EXT2_ET_NO_MEMORY; if (curr_value == 1) - ext2fs_mark_inode_bitmap2(icount->single, ino); + ext2fs_mark_inode_bitmap(icount->single, ino); if ((curr_value == 0) && icount->multiple) - ext2fs_unmark_inode_bitmap2(icount->multiple, ino); + ext2fs_unmark_inode_bitmap(icount->multiple, ino); if (ret) *ret = icount_16_xlate(curr_value); @@ -608,19 +621,19 @@ errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino, EXT2_CHECK_MAGIC(icount, EXT2_ET_MAGIC_ICOUNT); if (count == 1) { - ext2fs_mark_inode_bitmap2(icount->single, ino); + ext2fs_mark_inode_bitmap(icount->single, ino); if (icount->multiple) - ext2fs_unmark_inode_bitmap2(icount->multiple, ino); + ext2fs_unmark_inode_bitmap(icount->multiple, ino); return 0; } if (count == 0) { - ext2fs_unmark_inode_bitmap2(icount->single, ino); + ext2fs_unmark_inode_bitmap(icount->single, ino); if (icount->multiple) { /* * If the icount->multiple bitmap is enabled, * we can just clear both bitmaps and we're done */ - ext2fs_unmark_inode_bitmap2(icount->multiple, ino); + ext2fs_unmark_inode_bitmap(icount->multiple, ino); } else set_inode_count(icount, ino, 0); return 0; @@ -628,9 +641,9 @@ errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino, if (set_inode_count(icount, ino, count)) return EXT2_ET_NO_MEMORY; - ext2fs_unmark_inode_bitmap2(icount->single, ino); + ext2fs_unmark_inode_bitmap(icount->single, ino); if (icount->multiple) - ext2fs_mark_inode_bitmap2(icount->multiple, ino); + ext2fs_mark_inode_bitmap(icount->multiple, ino); return 0; } @@ -731,9 +744,9 @@ static void setup(void) initialize_ext2_error_table(); memset(¶m, 0, sizeof(param)); - ext2fs_blocks_count_set(¶m, 12000); + param.s_blocks_count = 12000; - retval = ext2fs_initialize("test fs", EXT2_FLAG_64BITS, ¶m, + retval = ext2fs_initialize("test fs", 0, ¶m, test_io_manager, &test_fs); if (retval) { com_err("setup", retval, diff --git a/lib/ext2fs/imager.c b/lib/ext2fs/imager.c index 5c7003a6..afa9a216 100644 --- a/lib/ext2fs/imager.c +++ b/lib/ext2fs/imager.c @@ -62,17 +62,16 @@ errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags) { unsigned int group, left, c, d; char *buf, *cp; - blk64_t blk; + blk_t blk; ssize_t actual; errcode_t retval; - off_t r; buf = malloc(fs->blocksize * BUF_BLOCKS); if (!buf) return ENOMEM; for (group = 0; group < fs->group_desc_count; group++) { - blk = ext2fs_inode_table_loc(fs, (unsigned)group); + blk = fs->group_desc[(unsigned)group].bg_inode_table; if (!blk) { retval = EXT2_ET_MISSING_INODE_TABLE; goto errout; @@ -82,7 +81,7 @@ errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags) c = BUF_BLOCKS; if (c > left) c = left; - retval = io_channel_read_blk64(fs->io, blk, c, buf); + retval = io_channel_read_blk(fs->io, blk, c, buf); if (retval) goto errout; cp = buf; @@ -97,11 +96,7 @@ errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags) blk++; left--; cp += fs->blocksize; - r = lseek(fd, fs->blocksize, SEEK_CUR); - if (r < 0) { - retval = errno; - goto errout; - } + lseek(fd, fs->blocksize, SEEK_CUR); continue; } /* Find non-zero blocks */ @@ -141,7 +136,7 @@ errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, { unsigned int group, c, left; char *buf; - blk64_t blk; + blk_t blk; ssize_t actual; errcode_t retval; @@ -150,7 +145,7 @@ errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, return ENOMEM; for (group = 0; group < fs->group_desc_count; group++) { - blk = ext2fs_inode_table_loc(fs, (unsigned)group); + blk = fs->group_desc[(unsigned)group].bg_inode_table; if (!blk) { retval = EXT2_ET_MISSING_INODE_TABLE; goto errout; @@ -169,7 +164,7 @@ errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, retval = EXT2_ET_SHORT_READ; goto errout; } - retval = io_channel_write_blk64(fs->io, blk, c, buf); + retval = io_channel_write_blk(fs->io, blk, c, buf); if (retval) goto errout; @@ -283,7 +278,7 @@ errout: errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags) { ext2fs_generic_bitmap bmap; - errcode_t retval; + errcode_t err, retval; ssize_t actual; __u32 itr, cnt, size; int c, total_size; @@ -296,6 +291,7 @@ errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags) return retval; } bmap = fs->inode_map; + err = EXT2_ET_MAGIC_INODE_BITMAP; itr = 1; cnt = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count; size = (EXT2_INODES_PER_GROUP(fs->super) / 8); @@ -306,6 +302,7 @@ errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags) return retval; } bmap = fs->block_map; + err = EXT2_ET_MAGIC_BLOCK_BITMAP; itr = fs->super->s_first_data_block; cnt = EXT2_BLOCKS_PER_GROUP(fs->super) * fs->group_desc_count; size = EXT2_BLOCKS_PER_GROUP(fs->super) / 8; @@ -317,8 +314,8 @@ errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags) if (size > (cnt >> 3)) size = (cnt >> 3); - retval = ext2fs_get_generic_bmap_range(bmap, itr, - size << 3, buf); + retval = ext2fs_get_generic_bitmap_range(bmap, + err, itr, size << 3, buf); if (retval) return retval; @@ -358,7 +355,7 @@ errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags) errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags) { ext2fs_generic_bitmap bmap; - errcode_t retval; + errcode_t err, retval; __u32 itr, cnt; char buf[1024]; unsigned int size; @@ -371,6 +368,7 @@ errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags) return retval; } bmap = fs->inode_map; + err = EXT2_ET_MAGIC_INODE_BITMAP; itr = 1; cnt = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count; size = (EXT2_INODES_PER_GROUP(fs->super) / 8); @@ -381,6 +379,7 @@ errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags) return retval; } bmap = fs->block_map; + err = EXT2_ET_MAGIC_BLOCK_BITMAP; itr = fs->super->s_first_data_block; cnt = EXT2_BLOCKS_PER_GROUP(fs->super) * fs->group_desc_count; size = EXT2_BLOCKS_PER_GROUP(fs->super) / 8; @@ -397,8 +396,8 @@ errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags) if (actual != (int) size) return EXT2_ET_SHORT_READ; - retval = ext2fs_set_generic_bmap_range(bmap, itr, - size << 3, buf); + retval = ext2fs_set_generic_bitmap_range(bmap, + err, itr, size << 3, buf); if (retval) return retval; diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c index a57ffcb5..32f075e7 100644 --- a/lib/ext2fs/initialize.c +++ b/lib/ext2fs/initialize.c @@ -46,6 +46,19 @@ #endif /* defined(__linux__) && defined(EXT2_OS_LINUX) */ /* + * Note we override the kernel include file's idea of what the default + * check interval (never) should be. It's a good idea to check at + * least *occasionally*, specially since servers will never rarely get + * to reboot, since Linux is so robust these days. :-) + * + * 180 days (six months) seems like a good value. + */ +#ifdef EXT2_DFL_CHECKINTERVAL +#undef EXT2_DFL_CHECKINTERVAL +#endif +#define EXT2_DFL_CHECKINTERVAL (86400L * 180L) + +/* * Calculate the number of GDT blocks to reserve for online filesystem growth. * The absolute maximum number of GDT blocks we can reserve is determined by * the number of block pointers that can fit into a single block. @@ -62,12 +75,8 @@ static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs) /* We set it at 1024x the current filesystem size, or * the upper block count limit (2^32), whichever is lower. */ - if (ext2fs_blocks_count(sb) < max_blocks / 1024) - max_blocks = ext2fs_blocks_count(sb) * 1024; - /* - * ext2fs_div64_ceil() is unnecessary because max_blocks is - * max _GDT_ blocks, which is limited to 32 bits. - */ + if (sb->s_blocks_count < max_blocks / 1024) + max_blocks = sb->s_blocks_count * 1024; 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)) @@ -87,22 +96,19 @@ errcode_t ext2fs_initialize(const char *name, int flags, ext2_filsys fs; errcode_t retval; struct ext2_super_block *super; + int frags_per_block; unsigned int rem; unsigned int overhead = 0; unsigned int ipg; dgrp_t i; - blk64_t free_blocks; blk_t numblocks; int rsv_gdt; int csum_flag; - int bigalloc_flag; int io_flags; - unsigned reserved_inos; char *buf = 0; char c; - double reserved_ratio; - if (!param || !ext2fs_blocks_count(param)) + if (!param || !param->s_blocks_count) return EXT2_ET_INVALID_ARGUMENT; retval = ext2fs_get_mem(sizeof(struct struct_ext2_filsys), &fs); @@ -113,15 +119,12 @@ errcode_t ext2fs_initialize(const char *name, int flags, fs->magic = EXT2_ET_MAGIC_EXT2FS_FILSYS; fs->flags = flags | EXT2_FLAG_RW; fs->umask = 022; - fs->default_bitmap_type = EXT2FS_BMAP64_RBTREE; #ifdef WORDS_BIGENDIAN fs->flags |= EXT2_FLAG_SWAP_BYTES; #endif io_flags = IO_FLAG_RW; if (flags & EXT2_FLAG_EXCLUSIVE) io_flags |= IO_FLAG_EXCLUSIVE; - if (flags & EXT2_FLAG_DIRECT_IO) - io_flags |= IO_FLAG_DIRECT_IO; retval = manager->open(name, io_flags, &fs->io); if (retval) goto cleanup; @@ -141,32 +144,18 @@ errcode_t ext2fs_initialize(const char *name, int flags, #define set_field(field, default) (super->field = param->field ? \ param->field : (default)) -#define assign_field(field) (super->field = param->field) super->s_magic = EXT2_SUPER_MAGIC; super->s_state = EXT2_VALID_FS; - bigalloc_flag = EXT2_HAS_RO_COMPAT_FEATURE(param, - EXT4_FEATURE_RO_COMPAT_BIGALLOC); - - assign_field(s_log_block_size); - - if (bigalloc_flag) { - set_field(s_log_cluster_size, super->s_log_block_size+4); - if (super->s_log_block_size > super->s_log_cluster_size) { - retval = EXT2_ET_INVALID_ARGUMENT; - goto cleanup; - } - } else - super->s_log_cluster_size = super->s_log_block_size; - - set_field(s_first_data_block, super->s_log_cluster_size ? 0 : 1); - set_field(s_max_mnt_count, 0); + set_field(s_log_block_size, 0); /* default blocksize: 1024 bytes */ + set_field(s_log_frag_size, 0); /* default fragsize: 1024 bytes */ + set_field(s_first_data_block, super->s_log_block_size ? 0 : 1); + set_field(s_max_mnt_count, EXT2_DFL_MAX_MNT_COUNT); set_field(s_errors, EXT2_ERRORS_DEFAULT); set_field(s_feature_compat, 0); set_field(s_feature_incompat, 0); set_field(s_feature_ro_compat, 0); - set_field(s_default_mount_opts, 0); set_field(s_first_meta_bg, 0); set_field(s_raid_stride, 0); /* default stride size: 0 */ set_field(s_raid_stripe_width, 0); /* default stripe width: 0 */ @@ -196,61 +185,28 @@ errcode_t ext2fs_initialize(const char *name, int flags, super->s_inode_size = EXT2_GOOD_OLD_INODE_SIZE; } - set_field(s_checkinterval, 0); + set_field(s_checkinterval, EXT2_DFL_CHECKINTERVAL); super->s_mkfs_time = super->s_lastcheck = fs->now ? fs->now : time(NULL); super->s_creator_os = CREATOR_OS; - fs->fragsize = fs->blocksize = EXT2_BLOCK_SIZE(super); - fs->cluster_ratio_bits = super->s_log_cluster_size - - super->s_log_block_size; + fs->blocksize = EXT2_BLOCK_SIZE(super); + fs->fragsize = EXT2_FRAG_SIZE(super); + frags_per_block = fs->blocksize / fs->fragsize; - if (bigalloc_flag) { - unsigned long long bpg; + /* default: (fs->blocksize*8) blocks/group, up to 2^16 (GDT limit) */ + set_field(s_blocks_per_group, fs->blocksize * 8); + if (super->s_blocks_per_group > EXT2_MAX_BLOCKS_PER_GROUP(super)) + super->s_blocks_per_group = EXT2_MAX_BLOCKS_PER_GROUP(super); + super->s_frags_per_group = super->s_blocks_per_group * frags_per_block; - if (param->s_blocks_per_group && - param->s_clusters_per_group && - ((param->s_clusters_per_group * EXT2FS_CLUSTER_RATIO(fs)) != - param->s_blocks_per_group)) { - retval = EXT2_ET_INVALID_ARGUMENT; - goto cleanup; - } - if (param->s_clusters_per_group) - assign_field(s_clusters_per_group); - else if (param->s_blocks_per_group) - super->s_clusters_per_group = - param->s_blocks_per_group / - EXT2FS_CLUSTER_RATIO(fs); - else if (super->s_log_cluster_size + 15 < 32) - super->s_clusters_per_group = fs->blocksize * 8; - else - super->s_clusters_per_group = (fs->blocksize - 1) * 8; - if (super->s_clusters_per_group > EXT2_MAX_CLUSTERS_PER_GROUP(super)) - super->s_clusters_per_group = EXT2_MAX_CLUSTERS_PER_GROUP(super); - bpg = EXT2FS_C2B(fs, - (unsigned long long) super->s_clusters_per_group); - if (bpg >= (((unsigned long long) 1) << 32)) { - retval = EXT2_ET_INVALID_ARGUMENT; - goto cleanup; - } - super->s_blocks_per_group = bpg; - } else { - set_field(s_blocks_per_group, fs->blocksize * 8); - if (super->s_blocks_per_group > EXT2_MAX_BLOCKS_PER_GROUP(super)) - super->s_blocks_per_group = EXT2_MAX_BLOCKS_PER_GROUP(super); - super->s_clusters_per_group = super->s_blocks_per_group; - } - - ext2fs_blocks_count_set(super, ext2fs_blocks_count(param) & - ~((blk64_t) EXT2FS_CLUSTER_MASK(fs))); - ext2fs_r_blocks_count_set(super, ext2fs_r_blocks_count(param)); - if (ext2fs_r_blocks_count(super) >= ext2fs_blocks_count(param)) { + super->s_blocks_count = param->s_blocks_count; + super->s_r_blocks_count = param->s_r_blocks_count; + if (super->s_r_blocks_count >= param->s_blocks_count) { retval = EXT2_ET_INVALID_ARGUMENT; goto cleanup; } - set_field(s_mmp_update_interval, 0); - /* * If we're creating an external journal device, we don't need * to bother with the rest. @@ -263,28 +219,18 @@ errcode_t ext2fs_initialize(const char *name, int flags, } retry: - fs->group_desc_count = (dgrp_t) ext2fs_div64_ceil( - ext2fs_blocks_count(super) - super->s_first_data_block, - 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; } - - set_field(s_desc_size, - super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ? - EXT2_MIN_DESC_SIZE_64BIT : 0); - fs->desc_blocks = ext2fs_div_ceil(fs->group_desc_count, EXT2_DESC_PER_BLOCK(super)); i = fs->blocksize >= 4096 ? 1 : 4096 / fs->blocksize; - - if (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT && - (ext2fs_blocks_count(super) / i) > (1ULL << 32)) - set_field(s_inodes_count, ~0U); - else - set_field(s_inodes_count, ext2fs_blocks_count(super) / i); + set_field(s_inodes_count, super->s_blocks_count / i); /* * Make sure we have at least EXT2_FIRST_INO + 1 inodes, so @@ -301,12 +247,12 @@ retry: */ ipg = ext2fs_div_ceil(super->s_inodes_count, fs->group_desc_count); if (ipg > fs->blocksize * 8) { - if (!bigalloc_flag && super->s_blocks_per_group >= 256) { + if (super->s_blocks_per_group >= 256) { /* Try again with slightly different parameters */ super->s_blocks_per_group -= 8; - ext2fs_blocks_count_set(super, - ext2fs_blocks_count(param)); - super->s_clusters_per_group = super->s_blocks_per_group; + super->s_blocks_count = param->s_blocks_count; + super->s_frags_per_group = super->s_blocks_per_group * + frags_per_block; goto retry; } else { retval = EXT2_ET_TOO_MANY_INODES; @@ -337,8 +283,6 @@ ipg_retry: * multiple of 8. This is needed to simplify the bitmap * splicing code. */ - if (super->s_inodes_per_group < 8) - super->s_inodes_per_group = 8; super->s_inodes_per_group &= ~7; fs->inode_blocks_per_group = (((super->s_inodes_per_group * EXT2_INODE_SIZE(super)) + @@ -394,24 +338,14 @@ ipg_retry: overhead = (int) (2 + fs->inode_blocks_per_group); if (ext2fs_bg_has_super(fs, fs->group_desc_count - 1)) overhead += 1 + fs->desc_blocks + super->s_reserved_gdt_blocks; - rem = ((ext2fs_blocks_count(super) - super->s_first_data_block) % + rem = ((super->s_blocks_count - super->s_first_data_block) % super->s_blocks_per_group); if ((fs->group_desc_count == 1) && rem && (rem < overhead)) { retval = EXT2_ET_TOOSMALL; goto cleanup; } if (rem && (rem < overhead+50)) { - ext2fs_blocks_count_set(super, ext2fs_blocks_count(super) - - rem); - /* - * If blocks count is changed, we need to recalculate - * reserved blocks count not to exceed 50%. - */ - reserved_ratio = 100.0 * ext2fs_r_blocks_count(param) / - ext2fs_blocks_count(param); - ext2fs_r_blocks_count_set(super, reserved_ratio * - ext2fs_blocks_count(super) / 100.0); - + super->s_blocks_count -= rem; goto retry; } @@ -427,7 +361,7 @@ ipg_retry: strcpy(buf, "block bitmap for "); strcat(buf, fs->device_name); - retval = ext2fs_allocate_subcluster_bitmap(fs, buf, &fs->block_map); + retval = ext2fs_allocate_block_bitmap(fs, buf, &fs->block_map); if (retval) goto cleanup; @@ -457,10 +391,9 @@ ipg_retry: * superblock and group descriptors (the inode tables and * bitmaps will be accounted for when allocated). */ - free_blocks = 0; + super->s_free_blocks_count = 0; csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(fs->super, EXT4_FEATURE_RO_COMPAT_GDT_CSUM); - reserved_inos = super->s_first_ino; for (i = 0; i < fs->group_desc_count; i++) { /* * Don't set the BLOCK_UNINIT group for the last group @@ -468,33 +401,25 @@ ipg_retry: */ if (csum_flag) { if (i != fs->group_desc_count - 1) - ext2fs_bg_flags_set(fs, i, - EXT2_BG_BLOCK_UNINIT); - ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_UNINIT); + fs->group_desc[i].bg_flags |= + EXT2_BG_BLOCK_UNINIT; + fs->group_desc[i].bg_flags |= EXT2_BG_INODE_UNINIT; numblocks = super->s_inodes_per_group; - if (reserved_inos) { - if (numblocks > reserved_inos) { - numblocks -= reserved_inos; - reserved_inos = 0; - } else { - reserved_inos -= numblocks; - numblocks = 0; - } - } - ext2fs_bg_itable_unused_set(fs, i, numblocks); + if (i == 0) + numblocks -= super->s_first_ino; + fs->group_desc[i].bg_itable_unused = numblocks; } numblocks = ext2fs_reserve_super_and_bgd(fs, i, fs->block_map); if (fs->super->s_log_groups_per_flex) numblocks += 2 + fs->inode_blocks_per_group; - free_blocks += numblocks; - ext2fs_bg_free_blocks_count_set(fs, i, numblocks); - ext2fs_bg_free_inodes_count_set(fs, i, fs->super->s_inodes_per_group); - ext2fs_bg_used_dirs_count_set(fs, i, 0); + super->s_free_blocks_count += numblocks; + fs->group_desc[i].bg_free_blocks_count = numblocks; + fs->group_desc[i].bg_free_inodes_count = + fs->super->s_inodes_per_group; + fs->group_desc[i].bg_used_dirs_count = 0; ext2fs_group_desc_csum_set(fs, i); } - free_blocks &= ~EXT2FS_CLUSTER_MASK(fs); - ext2fs_free_blocks_count_set(super, free_blocks); c = (char) 255; if (((int) c) == -1) { diff --git a/lib/ext2fs/inline.c b/lib/ext2fs/inline.c index 4d0f4ad1..f9be368b 100644 --- a/lib/ext2fs/inline.c +++ b/lib/ext2fs/inline.c @@ -11,9 +11,6 @@ * %End-Header% */ -#ifndef _XOPEN_SOURCE -#define _XOPEN_SOURCE 600 /* for posix_memalign() */ -#endif #include <stdio.h> #include <string.h> @@ -28,93 +25,8 @@ #if HAVE_SYS_TYPES_H #include <sys/types.h> #endif -#ifdef HAVE_MALLOC_H -#include <malloc.h> -#endif #include "ext2_fs.h" #define INCLUDE_INLINE_FUNCS #include "ext2fs.h" -/* - * We used to define this as an inline, but since we are now using - * autoconf-defined #ifdef's, we need to export this as a - * library-provided function exclusively. - */ -errcode_t ext2fs_get_memalign(unsigned long size, - unsigned long align, void *ptr) -{ - errcode_t retval; - void **p = ptr; - - if (align < 8) - align = 8; -#ifdef HAVE_POSIX_MEMALIGN - retval = posix_memalign(p, align, size); - if (retval) { - if (retval == ENOMEM) - return EXT2_ET_NO_MEMORY; - return retval; - } -#else -#ifdef HAVE_MEMALIGN - *p = memalign(align, size); - if (*p == NULL) { - if (errno) - return errno; - else - return EXT2_ET_NO_MEMORY; - } -#else -#ifdef HAVE_VALLOC - if (align > sizeof(long long)) - *p = valloc(size); - else -#endif - *p = malloc(size); - if ((unsigned long) *p & (align - 1)) { - free(*p); - *p = 0; - } - if (*p == 0) - return EXT2_ET_NO_MEMORY; -#endif -#endif - return 0; -} - -#ifdef DEBUG -static int isaligned(void *ptr, unsigned long align) -{ - return (((unsigned long) ptr & (align - 1)) == 0); -} - -static errcode_t test_memalign(unsigned long align) -{ - void *ptr = 0; - errcode_t retval; - - retval = ext2fs_get_memalign(32, align, &ptr); - if (!retval && !isaligned(ptr, align)) - retval = EINVAL; - free(ptr); - printf("tst_memalign(%lu) is %s\n", align, - retval ? error_message(retval) : "OK"); - return retval; -} - -int main(int argc, char **argv) -{ - int err = 0; - - if (test_memalign(4)) - err++; - if (test_memalign(32)) - err++; - if (test_memalign(1024)) - err++; - if (test_memalign(4096)) - err++; - return err; -} -#endif diff --git a/lib/ext2fs/inode.c b/lib/ext2fs/inode.c index d0b528cf..5088f9bb 100644 --- a/lib/ext2fs/inode.c +++ b/lib/ext2fs/inode.c @@ -33,7 +33,7 @@ struct ext2_struct_inode_scan { errcode_t magic; ext2_filsys fs; ext2_ino_t current_inode; - blk64_t current_block; + blk_t current_block; dgrp_t current_group; ext2_ino_t inodes_left; blk_t blocks_left; @@ -143,21 +143,21 @@ errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks, scan->current_group = 0; scan->groups_left = fs->group_desc_count - 1; scan->inode_buffer_blocks = buffer_blocks ? buffer_blocks : 8; - scan->current_block = ext2fs_inode_table_loc(scan->fs, - scan->current_group); + scan->current_block = scan->fs-> + group_desc[scan->current_group].bg_inode_table; scan->inodes_left = EXT2_INODES_PER_GROUP(scan->fs->super); scan->blocks_left = scan->fs->inode_blocks_per_group; if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { scan->inodes_left -= - ext2fs_bg_itable_unused(fs, scan->current_group); + fs->group_desc[scan->current_group].bg_itable_unused; scan->blocks_left = (scan->inodes_left + (fs->blocksize / scan->inode_size - 1)) * scan->inode_size / fs->blocksize; } - retval = io_channel_alloc_buf(fs->io, scan->inode_buffer_blocks, - &scan->inode_buffer); + retval = ext2fs_get_memalign(scan->inode_buffer_blocks * fs->blocksize, + fs->blocksize, &scan->inode_buffer); scan->done_group = 0; scan->done_group_data = 0; scan->bad_block_ptr = 0; @@ -232,8 +232,8 @@ static errcode_t get_next_blockgroup(ext2_inode_scan scan) scan->current_group++; scan->groups_left--; - scan->current_block = ext2fs_inode_table_loc(scan->fs, - scan->current_group); + scan->current_block =fs->group_desc[scan->current_group].bg_inode_table; + scan->current_inode = scan->current_group * EXT2_INODES_PER_GROUP(fs->super); @@ -243,7 +243,7 @@ static errcode_t get_next_blockgroup(ext2_inode_scan scan) if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { scan->inodes_left -= - ext2fs_bg_itable_unused(fs, scan->current_group); + fs->group_desc[scan->current_group].bg_itable_unused; scan->blocks_left = (scan->inodes_left + (fs->blocksize / scan->inode_size - 1)) * @@ -269,9 +269,9 @@ errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan, * increasing order. */ static errcode_t check_for_inode_bad_blocks(ext2_inode_scan scan, - blk64_t *num_blocks) + blk_t *num_blocks) { - blk64_t blk = scan->current_block; + blk_t blk = scan->current_block; badblocks_list bb = scan->fs->badblocks; /* @@ -328,7 +328,7 @@ static errcode_t check_for_inode_bad_blocks(ext2_inode_scan scan, */ static errcode_t get_next_blocks(ext2_inode_scan scan) { - blk64_t num_blocks; + blk_t num_blocks; errcode_t retval; /* @@ -364,7 +364,7 @@ static errcode_t get_next_blocks(ext2_inode_scan scan) memset(scan->inode_buffer, 0, (size_t) num_blocks * scan->fs->blocksize); } else { - retval = io_channel_read_blk64(scan->fs->io, + retval = io_channel_read_blk(scan->fs->io, scan->current_block, (int) num_blocks, scan->inode_buffer); @@ -434,8 +434,8 @@ errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan, ext2_ino_t *ino, * they can be done for block group #0. */ if ((scan->scan_flags & EXT2_SF_DO_LAZY) && - (ext2fs_bg_flags_test(scan->fs, scan->current_group, EXT2_BG_INODE_UNINIT) - )) + (scan->fs->group_desc[scan->current_group].bg_flags & + EXT2_BG_INODE_UNINIT)) goto force_new_group; if (scan->inodes_left == 0) goto force_new_group; @@ -522,8 +522,7 @@ errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino, errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode * inode, int bufsize) { - blk64_t block_nr; - unsigned long group, block, offset; + unsigned long group, block, block_nr, offset; char *ptr; errcode_t retval; int clen, i, inodes_per_block, length; @@ -532,9 +531,7 @@ errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino, EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); /* Check to see if user has an override function */ - if (fs->read_inode && - ((bufsize == sizeof(struct ext2_inode)) || - (EXT2_INODE_SIZE(fs->super) == sizeof(struct ext2_inode)))) { + if (fs->read_inode) { retval = (fs->read_inode)(fs, ino, inode); if (retval != EXT2_ET_CALLBACK_NOTHANDLED) return retval; @@ -571,9 +568,9 @@ errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino, offset = ((ino - 1) % EXT2_INODES_PER_GROUP(fs->super)) * EXT2_INODE_SIZE(fs->super); block = offset >> EXT2_BLOCK_SIZE_BITS(fs->super); - if (!ext2fs_inode_table_loc(fs, (unsigned) group)) + if (!fs->group_desc[(unsigned)group].bg_inode_table) return EXT2_ET_MISSING_INODE_TABLE; - block_nr = ext2fs_inode_table_loc(fs, group) + + block_nr = fs->group_desc[(unsigned)group].bg_inode_table + block; io = fs->io; } @@ -590,7 +587,7 @@ errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino, clen = fs->blocksize - offset; if (block_nr != fs->icache->buffer_blk) { - retval = io_channel_read_blk64(io, block_nr, 1, + retval = io_channel_read_blk(io, block_nr, 1, fs->icache->buffer); if (retval) return retval; @@ -631,8 +628,7 @@ errcode_t ext2fs_read_inode(ext2_filsys fs, ext2_ino_t ino, errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode * inode, int bufsize) { - blk64_t block_nr; - unsigned long group, block, offset; + unsigned long group, block, block_nr, offset; errcode_t retval = 0; struct ext2_inode_large temp_inode, *w_inode; char *ptr; @@ -673,10 +669,8 @@ errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino, if (length > (int) sizeof(struct ext2_inode_large)) { w_inode = malloc(length); - if (!w_inode) { - retval = ENOMEM; - goto errout; - } + if (!w_inode) + return ENOMEM; } else w_inode = &temp_inode; memset(w_inode, 0, length); @@ -693,11 +687,11 @@ errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino, offset = ((ino - 1) % EXT2_INODES_PER_GROUP(fs->super)) * EXT2_INODE_SIZE(fs->super); block = offset >> EXT2_BLOCK_SIZE_BITS(fs->super); - if (!ext2fs_inode_table_loc(fs, (unsigned) group)) { + if (!fs->group_desc[(unsigned) group].bg_inode_table) { retval = EXT2_ET_MISSING_INODE_TABLE; goto errout; } - block_nr = ext2fs_inode_table_loc(fs, (unsigned) group) + block; + block_nr = fs->group_desc[(unsigned) group].bg_inode_table + block; offset &= (EXT2_BLOCK_SIZE(fs->super) - 1); @@ -713,7 +707,7 @@ errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino, clen = fs->blocksize - offset; if (fs->icache->buffer_blk != block_nr) { - retval = io_channel_read_blk64(fs->io, block_nr, 1, + retval = io_channel_read_blk(fs->io, block_nr, 1, fs->icache->buffer); if (retval) goto errout; @@ -724,7 +718,7 @@ errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino, memcpy((char *) fs->icache->buffer + (unsigned) offset, ptr, clen); - retval = io_channel_write_blk64(fs->io, block_nr, 1, + retval = io_channel_write_blk(fs->io, block_nr, 1, fs->icache->buffer); if (retval) goto errout; diff --git a/lib/ext2fs/inode_io.c b/lib/ext2fs/inode_io.c index ced32448..4faaa487 100644 --- a/lib/ext2fs/inode_io.c +++ b/lib/ext2fs/inode_io.c @@ -163,10 +163,9 @@ static errcode_t inode_open(const char *name, int flags, io_channel *channel) return 0; cleanup: - if (io && io->name) - ext2fs_free_mem(&io->name); - if (data) + if (data) { ext2fs_free_mem(&data); + } if (io) ext2fs_free_mem(&io); return retval; diff --git a/lib/ext2fs/io_manager.c b/lib/ext2fs/io_manager.c index 116f2aea..6d0e2343 100644 --- a/lib/ext2fs/io_manager.c +++ b/lib/ext2fs/io_manager.c @@ -99,31 +99,3 @@ errcode_t io_channel_write_blk64(io_channel channel, unsigned long long block, return (channel->manager->write_blk)(channel, (unsigned long) block, count, data); } - -errcode_t io_channel_discard(io_channel channel, unsigned long long block, - unsigned long long count) -{ - EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); - - if (channel->manager->discard) - return (channel->manager->discard)(channel, block, count); - - return EXT2_ET_UNIMPLEMENTED; -} - -errcode_t io_channel_alloc_buf(io_channel io, int count, void *ptr) -{ - size_t size; - - if (count == 0) - size = io->block_size; - else if (count > 0) - size = io->block_size * count; - else - size = -count; - - if (io->align) - return ext2fs_get_memalign(size, io->align, ptr); - else - return ext2fs_get_mem(size, ptr); -} diff --git a/lib/ext2fs/irel.h b/lib/ext2fs/irel.h index 8aaa2d2b..9a4958be 100644 --- a/lib/ext2fs/irel.h +++ b/lib/ext2fs/irel.h @@ -10,7 +10,7 @@ */ struct ext2_inode_reference { - blk64_t block; + blk_t block; __u16 offset; }; diff --git a/lib/ext2fs/ismounted.c b/lib/ext2fs/ismounted.c index db80c460..2e9df4e0 100644 --- a/lib/ext2fs/ismounted.c +++ b/lib/ext2fs/ismounted.c @@ -20,13 +20,6 @@ #ifdef HAVE_LINUX_FD_H #include <linux/fd.h> #endif -#ifdef HAVE_LINUX_LOOP_H -#include <linux/loop.h> -#include <sys/ioctl.h> -#ifdef HAVE_LINUX_MAJOR_H -#include <linux/major.h> -#endif /* HAVE_LINUX_MAJOR_H */ -#endif /* HAVE_LINUX_LOOP_H */ #ifdef HAVE_MNTENT_H #include <mntent.h> #endif @@ -41,37 +34,7 @@ #include "ext2_fs.h" #include "ext2fs.h" -/* - * Check to see if a regular file is mounted. - * If /etc/mtab/ is a symlink of /proc/mounts, you will need the following check - * because the name in /proc/mounts is a loopback device not a regular file. - */ -static int check_loop_mounted(const char *mnt_fsname, dev_t mnt_rdev, - dev_t file_dev, ino_t file_ino) -{ -#if defined(HAVE_LINUX_LOOP_H) && defined(HAVE_LINUX_MAJOR_H) - struct loop_info64 loopinfo; - int loop_fd, ret; - - if (major(mnt_rdev) == LOOP_MAJOR) { - loop_fd = open(mnt_fsname, O_RDONLY); - if (loop_fd < 0) - return -1; - - ret = ioctl(loop_fd, LOOP_GET_STATUS64, &loopinfo); - close(loop_fd); - if (ret < 0) - return -1; - - if (file_dev == loopinfo.lo_device && - file_ino == loopinfo.lo_inode) - return 1; - } -#endif /* defined(HAVE_LINUX_LOOP_H) && defined(HAVE_LINUX_MAJOR_H) */ - return 0; -} - -#ifdef HAVE_SETMNTENT +#ifdef HAVE_MNTENT_H /* * Helper function which checks a file in /etc/mtab format to see if a * filesystem is mounted. Returns an error if the file doesn't exist @@ -89,15 +52,8 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file, int fd; *mount_flags = 0; - if ((f = setmntent (mtab_file, "r")) == NULL) { - if (errno == ENOENT) { - if (getenv("EXT2FS_NO_MTAB_OK")) - return 0; - else - return EXT2_ET_NO_MTAB_FILE; - } - return errno; - } + if ((f = setmntent (mtab_file, "r")) == NULL) + return (errno == ENOENT ? EXT2_NO_MTAB_FILE : errno); if (stat(file, &st_buf) == 0) { if (S_ISBLK(st_buf.st_mode)) { #ifndef __GNU__ /* The GNU hurd is broken with respect to stat devices */ @@ -118,10 +74,6 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file, #ifndef __GNU__ if (file_rdev && (file_rdev == st_buf.st_rdev)) break; - if (check_loop_mounted(mnt->mnt_fsname, - st_buf.st_rdev, file_dev, - file_ino) == 1) - break; #endif /* __GNU__ */ } else { if (file_dev && ((file_dev == st_buf.st_dev) && @@ -278,7 +230,7 @@ static errcode_t check_getmntinfo(const char *file, int *mount_flags, return 0; } #endif /* HAVE_GETMNTINFO */ -#endif /* HAVE_SETMNTENT */ +#endif /* HAVE_MNTENT_H */ /* * Check to see if we're dealing with the swap device. @@ -349,13 +301,15 @@ leave: errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags, char *mtpt, int mtlen) { + struct stat st_buf; errcode_t retval = 0; + int fd; if (is_swap_device(device)) { *mount_flags = EXT2_MF_MOUNTED | EXT2_MF_SWAP; strncpy(mtpt, "<swap>", mtlen); } else { -#ifdef HAVE_SETMNTENT +#ifdef HAVE_MNTENT_H retval = check_mntent(device, mount_flags, mtpt, mtlen); #else #ifdef HAVE_GETMNTINFO @@ -366,24 +320,21 @@ errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags, #endif *mount_flags = 0; #endif /* HAVE_GETMNTINFO */ -#endif /* HAVE_SETMNTENT */ +#endif /* HAVE_MNTENT_H */ } if (retval) return retval; #ifdef __linux__ /* This only works on Linux 2.6+ systems */ - { - struct stat st_buf; - - if (stat(device, &st_buf) == 0 && S_ISBLK(st_buf.st_mode)) { - int fd = open(device, O_RDONLY | O_EXCL); - - if (fd >= 0) - close(fd); - else if (errno == EBUSY) - *mount_flags |= EXT2_MF_BUSY; - } - } + if ((stat(device, &st_buf) != 0) || + !S_ISBLK(st_buf.st_mode)) + return 0; + fd = open(device, O_RDONLY | O_EXCL); + if (fd < 0) { + if (errno == EBUSY) + *mount_flags |= EXT2_MF_BUSY; + } else + close(fd); #endif return 0; diff --git a/lib/ext2fs/kernel-jbd.h b/lib/ext2fs/kernel-jbd.h index 059bf8fa..331b0e47 100644 --- a/lib/ext2fs/kernel-jbd.h +++ b/lib/ext2fs/kernel-jbd.h @@ -214,13 +214,13 @@ typedef struct journal_superblock_s #define JFS_HAS_COMPAT_FEATURE(j,mask) \ ((j)->j_format_version >= 2 && \ - ((j)->j_superblock->s_feature_compat & ext2fs_cpu_to_be32((mask)))) + ((j)->j_superblock->s_feature_compat & cpu_to_be32((mask)))) #define JFS_HAS_RO_COMPAT_FEATURE(j,mask) \ ((j)->j_format_version >= 2 && \ - ((j)->j_superblock->s_feature_ro_compat & ext2fs_cpu_to_be32((mask)))) + ((j)->j_superblock->s_feature_ro_compat & cpu_to_be32((mask)))) #define JFS_HAS_INCOMPAT_FEATURE(j,mask) \ ((j)->j_format_version >= 2 && \ - ((j)->j_superblock->s_feature_incompat & ext2fs_cpu_to_be32((mask)))) + ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask)))) #define JFS_FEATURE_COMPAT_CHECKSUM 0x00000001 @@ -234,8 +234,7 @@ typedef struct journal_superblock_s #define JFS_KNOWN_COMPAT_FEATURES 0 #define JFS_KNOWN_ROCOMPAT_FEATURES 0 #define JFS_KNOWN_INCOMPAT_FEATURES (JFS_FEATURE_INCOMPAT_REVOKE|\ - JFS_FEATURE_INCOMPAT_ASYNC_COMMIT|\ - JFS_FEATURE_INCOMPAT_64BIT) + JFS_FEATURE_INCOMPAT_ASYNC_COMMIT) #ifdef __KERNEL__ diff --git a/lib/ext2fs/kernel-list.h b/lib/ext2fs/kernel-list.h index 01f4f6b9..e07d06b6 100644 --- a/lib/ext2fs/kernel-list.h +++ b/lib/ext2fs/kernel-list.h @@ -17,6 +17,9 @@ struct list_head { #define LIST_HEAD_INIT(name) { &(name), &(name) } +#define LIST_HEAD(name) \ + struct list_head name = { &name, &name } + #define INIT_LIST_HEAD(ptr) do { \ (ptr)->next = (ptr); (ptr)->prev = (ptr); \ } while (0) diff --git a/lib/ext2fs/link.c b/lib/ext2fs/link.c index 8c5553c9..4cc8426a 100644 --- a/lib/ext2fs/link.c +++ b/lib/ext2fs/link.c @@ -41,9 +41,6 @@ static int link_proc(struct ext2_dir_entry *dirent, unsigned int rec_len, min_rec_len, curr_rec_len; int ret = 0; - if (ls->done) - return DIRENT_ABORT; - rec_len = EXT2_DIR_REC_LEN(ls->namelen); ls->err = ext2fs_get_rec_len(ls->fs, dirent, &curr_rec_len); @@ -55,9 +52,9 @@ static int link_proc(struct ext2_dir_entry *dirent, * if so, absorb it into this one. */ next = (struct ext2_dir_entry *) (buf + offset + curr_rec_len); - if ((offset + (int) curr_rec_len < blocksize - 8) && + if ((offset + curr_rec_len < blocksize - 8) && (next->inode == 0) && - (offset + (int) curr_rec_len + (int) next->rec_len <= blocksize)) { + (offset + curr_rec_len + next->rec_len <= blocksize)) { curr_rec_len += next->rec_len; ls->err = ext2fs_set_rec_len(ls->fs, curr_rec_len, dirent); if (ls->err) diff --git a/lib/ext2fs/llseek.c b/lib/ext2fs/llseek.c index 774d1d4d..7855590b 100644 --- a/lib/ext2fs/llseek.c +++ b/lib/ext2fs/llseek.c @@ -89,14 +89,17 @@ static ext2_loff_t my_llseek (int fd, ext2_loff_t offset, int origin) ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin) { -#if SIZEOF_OFF_T >= SIZEOF_LONG_LONG - return lseek (fd, offset, origin); -#else ext2_loff_t result; static int do_compat = 0; - if (do_compat) - goto fallback; + if ((sizeof(off_t) >= sizeof(ext2_loff_t)) || + (offset < ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1)))) + return lseek(fd, (off_t) offset, origin); + + if (do_compat) { + errno = EINVAL; + return -1; + } result = my_llseek (fd, offset, origin); if (result == -1 && errno == ENOSYS) { @@ -105,14 +108,9 @@ ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin) * which does not support the llseek system call */ do_compat++; - fallback: - if (offset < ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1))) - return lseek(fd, (off_t) offset, origin); errno = EINVAL; - return -1; } return result; -#endif } #else /* !linux */ diff --git a/lib/ext2fs/mkdir.c b/lib/ext2fs/mkdir.c index 9b6b7996..549ff6a3 100644 --- a/lib/ext2fs/mkdir.c +++ b/lib/ext2fs/mkdir.c @@ -33,12 +33,11 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, const char *name) { - ext2_extent_handle_t handle; errcode_t retval; struct ext2_inode parent_inode, inode; ext2_ino_t ino = inum; ext2_ino_t scratch_ino; - blk64_t blk; + blk_t blk; char *block = 0; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); @@ -56,7 +55,7 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, /* * Allocate a data block for the directory */ - retval = ext2fs_new_block2(fs, 0, 0, &blk); + retval = ext2fs_new_block(fs, 0, 0, &blk); if (retval) goto cleanup; @@ -84,10 +83,7 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, inode.i_mode = LINUX_S_IFDIR | (0777 & ~fs->umask); inode.i_uid = inode.i_gid = 0; ext2fs_iblk_set(fs, &inode, 1); - if (fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS) - inode.i_flags |= EXT4_EXTENTS_FL; - else - inode.i_block[0] = blk; + inode.i_block[0] = blk; inode.i_links_count = 2; inode.i_size = fs->blocksize; @@ -101,16 +97,6 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, if (retval) goto cleanup; - if (fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS) { - retval = ext2fs_extent_open2(fs, ino, &inode, &handle); - if (retval) - goto cleanup; - retval = ext2fs_extent_set_bmap(handle, 0, blk, 0); - ext2fs_extent_free(handle); - if (retval) - goto cleanup; - } - /* * Link the directory into the filesystem hierarchy */ @@ -142,7 +128,7 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, /* * Update accounting.... */ - ext2fs_block_alloc_stats2(fs, blk, +1); + ext2fs_block_alloc_stats(fs, blk, +1); ext2fs_inode_alloc_stats2(fs, ino, +1, 1); cleanup: diff --git a/lib/ext2fs/mkjournal.c b/lib/ext2fs/mkjournal.c index 02ffb97c..4a81f4b2 100644 --- a/lib/ext2fs/mkjournal.c +++ b/lib/ext2fs/mkjournal.c @@ -42,13 +42,13 @@ * returns it as an allocated block. */ errcode_t ext2fs_create_journal_superblock(ext2_filsys fs, - __u32 num_blocks, int flags, + __u32 size, int flags, char **ret_jsb) { errcode_t retval; journal_superblock_t *jsb; - if (num_blocks < 1024) + if (size < 1024) return EXT2_ET_JOURNAL_TOO_SMALL; if ((retval = ext2fs_get_mem(fs->blocksize, &jsb))) @@ -62,7 +62,7 @@ errcode_t ext2fs_create_journal_superblock(ext2_filsys fs, else jsb->s_header.h_blocktype = htonl(JFS_SUPERBLOCK_V2); jsb->s_blocksize = htonl(fs->blocksize); - jsb->s_maxlen = htonl(num_blocks); + jsb->s_maxlen = htonl(size); jsb->s_nr_users = htonl(1); jsb->s_first = htonl(1); jsb->s_sequence = htonl(1); @@ -90,21 +90,20 @@ errcode_t ext2fs_create_journal_superblock(ext2_filsys fs, * filesystems. */ static errcode_t write_journal_file(ext2_filsys fs, char *filename, - blk_t num_blocks, int flags) + blk_t size, int flags) { errcode_t retval; char *buf = 0; int fd, ret_size; blk_t i; - if ((retval = ext2fs_create_journal_superblock(fs, num_blocks, flags, - &buf))) + if ((retval = ext2fs_create_journal_superblock(fs, size, flags, &buf))) return retval; /* Open the device or journal file */ if ((fd = open(filename, O_WRONLY)) < 0) { retval = errno; - goto errfree; + goto errout; } /* Write the superblock out */ @@ -118,10 +117,7 @@ static errcode_t write_journal_file(ext2_filsys fs, char *filename, goto errout; memset(buf, 0, fs->blocksize); - if (flags & EXT2_MKJOURNAL_LAZYINIT) - goto success; - - for (i = 1; i < num_blocks; i++) { + for (i = 1; i < size; i++) { ret_size = write(fd, buf, fs->blocksize); if (ret_size < 0) { retval = errno; @@ -130,12 +126,10 @@ static errcode_t write_journal_file(ext2_filsys fs, char *filename, if (ret_size != (int) fs->blocksize) goto errout; } + close(fd); -success: retval = 0; errout: - close(fd); -errfree: ext2fs_free_mem(&buf); return retval; } @@ -151,8 +145,8 @@ errfree: * programs that check for memory leaks happy.) */ #define STRIDE_LENGTH 8 -errcode_t ext2fs_zero_blocks2(ext2_filsys fs, blk64_t blk, int num, - blk64_t *ret_blk, int *ret_count) +errcode_t ext2fs_zero_blocks(ext2_filsys fs, blk_t blk, int num, + blk_t *ret_blk, int *ret_count) { int j, count; static char *buf; @@ -185,7 +179,7 @@ errcode_t ext2fs_zero_blocks2(ext2_filsys fs, blk64_t blk, int num, if (count > STRIDE_LENGTH) count = STRIDE_LENGTH; } - retval = io_channel_write_blk64(fs->io, blk, count, buf); + retval = io_channel_write_blk(fs->io, blk, count, buf); if (retval) { if (ret_count) *ret_count = count; @@ -198,76 +192,56 @@ errcode_t ext2fs_zero_blocks2(ext2_filsys fs, blk64_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 */ struct mkjournal_struct { int num_blocks; int newblocks; - blk64_t goal; - blk64_t blk_to_zero; + blk_t goal; + blk_t blk_to_zero; int zero_count; - int flags; char *buf; errcode_t err; }; static int mkjournal_proc(ext2_filsys fs, - blk64_t *blocknr, - e2_blkcnt_t blockcnt, - blk64_t ref_block EXT2FS_ATTR((unused)), - int ref_offset EXT2FS_ATTR((unused)), - void *priv_data) + blk_t *blocknr, + e2_blkcnt_t blockcnt, + blk_t ref_block EXT2FS_ATTR((unused)), + int ref_offset EXT2FS_ATTR((unused)), + void *priv_data) { struct mkjournal_struct *es = (struct mkjournal_struct *) priv_data; - blk64_t new_blk; + blk_t new_blk; errcode_t retval; if (*blocknr) { es->goal = *blocknr; return 0; } - if (blockcnt && - (EXT2FS_B2C(fs, es->goal) == EXT2FS_B2C(fs, es->goal+1))) - new_blk = es->goal+1; - else { - es->goal &= ~EXT2FS_CLUSTER_MASK(fs); - retval = ext2fs_new_block2(fs, es->goal, 0, &new_blk); - if (retval) { - es->err = retval; - return BLOCK_ABORT; - } - ext2fs_block_alloc_stats2(fs, new_blk, +1); - es->newblocks++; + retval = ext2fs_new_block(fs, es->goal, 0, &new_blk); + if (retval) { + es->err = retval; + return BLOCK_ABORT; } if (blockcnt >= 0) es->num_blocks--; + es->newblocks++; retval = 0; if (blockcnt <= 0) - retval = io_channel_write_blk64(fs->io, new_blk, 1, es->buf); - else if (!(es->flags & EXT2_MKJOURNAL_LAZYINIT)) { + retval = io_channel_write_blk(fs->io, new_blk, 1, es->buf); + else { if (es->zero_count) { if ((es->blk_to_zero + es->zero_count == new_blk) && (es->zero_count < 1024)) es->zero_count++; else { - retval = ext2fs_zero_blocks2(fs, - es->blk_to_zero, - es->zero_count, - 0, 0); + retval = ext2fs_zero_blocks(fs, + es->blk_to_zero, + es->zero_count, + 0, 0); es->zero_count = 0; } } @@ -285,6 +259,7 @@ static int mkjournal_proc(ext2_filsys fs, return BLOCK_ABORT; } *blocknr = es->goal = new_blk; + ext2fs_block_alloc_stats(fs, new_blk, +1); if (es->num_blocks == 0) return (BLOCK_CHANGED | BLOCK_ABORT); @@ -297,41 +272,36 @@ static int mkjournal_proc(ext2_filsys fs, * This function creates a journal using direct I/O routines. */ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino, - blk_t num_blocks, int flags) + blk_t size, int flags) { char *buf; dgrp_t group, start, end, i, log_flex; errcode_t retval; struct ext2_inode inode; - unsigned long long inode_size; struct mkjournal_struct es; - if ((retval = ext2fs_create_journal_superblock(fs, num_blocks, flags, - &buf))) + if ((retval = ext2fs_create_journal_superblock(fs, size, flags, &buf))) return retval; if ((retval = ext2fs_read_bitmaps(fs))) - goto out2; + return retval; if ((retval = ext2fs_read_inode(fs, journal_ino, &inode))) - goto out2; + return retval; - if (inode.i_blocks > 0) { - retval = EEXIST; - goto out2; - } + if (inode.i_blocks > 0) + return EEXIST; - es.num_blocks = num_blocks; + es.num_blocks = size; es.newblocks = 0; es.buf = buf; es.err = 0; - es.flags = flags; es.zero_count = 0; if (fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS) { inode.i_flags |= EXT4_EXTENTS_FL; if ((retval = ext2fs_write_inode(fs, journal_ino, &inode))) - goto out2; + return retval; } /* @@ -339,13 +309,13 @@ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino, * the filesystem. Pick a group that has the largest number * of free blocks. */ - group = ext2fs_group_of_blk2(fs, (ext2fs_blocks_count(fs->super) - + group = ext2fs_group_of_blk(fs, (fs->super->s_blocks_count - fs->super->s_first_data_block) / 2); log_flex = 1 << fs->super->s_log_groups_per_flex; if (fs->super->s_log_groups_per_flex && (group > log_flex)) { group = group & ~(log_flex - 1); while ((group < fs->group_desc_count) && - ext2fs_bg_free_blocks_count(fs, group) == 0) + fs->group_desc[group].bg_free_blocks_count == 0) group++; if (group == fs->group_desc_count) group = 0; @@ -355,19 +325,21 @@ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino, end = ((group+1) < fs->group_desc_count) ? group+1 : group; group = start; for (i=start+1; i <= end; i++) - if (ext2fs_bg_free_blocks_count(fs, i) > - ext2fs_bg_free_blocks_count(fs, group)) + if (fs->group_desc[i].bg_free_blocks_count > + fs->group_desc[group].bg_free_blocks_count) group = i; - es.goal = ext2fs_group_first_block2(fs, group); - retval = ext2fs_block_iterate3(fs, journal_ino, BLOCK_FLAG_APPEND, + es.goal = (fs->super->s_blocks_per_group * group) + + fs->super->s_first_data_block; + + retval = ext2fs_block_iterate2(fs, journal_ino, BLOCK_FLAG_APPEND, 0, mkjournal_proc, &es); if (es.err) { retval = es.err; goto errout; } if (es.zero_count) { - retval = ext2fs_zero_blocks2(fs, es.blk_to_zero, + retval = ext2fs_zero_blocks(fs, es.blk_to_zero, es.zero_count, 0, 0); if (retval) goto errout; @@ -376,12 +348,7 @@ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino, if ((retval = ext2fs_read_inode(fs, journal_ino, &inode))) goto errout; - inode_size = (unsigned long long)fs->blocksize * num_blocks; - inode.i_size = inode_size & 0xFFFFFFFF; - inode.i_size_high = (inode_size >> 32) & 0xFFFFFFFF; - if (ext2fs_needs_large_file_feature(inode_size)) - fs->super->s_feature_ro_compat |= - EXT2_FEATURE_RO_COMPAT_LARGE_FILE; + inode.i_size += fs->blocksize * size; ext2fs_iblk_add_blocks(fs, &inode, es.newblocks); inode.i_mtime = inode.i_ctime = fs->now ? fs->now : time(0); inode.i_links_count = 1; @@ -392,14 +359,11 @@ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino, retval = 0; memcpy(fs->super->s_jnl_blocks, inode.i_block, EXT2_N_BLOCKS*4); - fs->super->s_jnl_blocks[15] = inode.i_size_high; fs->super->s_jnl_blocks[16] = inode.i_size; fs->super->s_jnl_backup_type = EXT3_JNL_BACKUP_BLOCKS; ext2fs_mark_super_dirty(fs); errout: - ext2fs_zero_blocks2(0, 0, 0, 0, 0); -out2: ext2fs_free_mem(&buf); return retval; } @@ -409,17 +373,17 @@ out2: * in the filesystem. For very small filesystems, it is not reasonable to * have a journal that fills more than half of the filesystem. */ -int ext2fs_default_journal_size(__u64 num_blocks) +int ext2fs_default_journal_size(__u64 blocks) { - if (num_blocks < 2048) + if (blocks < 2048) return -1; - if (num_blocks < 32768) + if (blocks < 32768) return (1024); - if (num_blocks < 256*1024) + if (blocks < 256*1024) return (4096); - if (num_blocks < 512*1024) + if (blocks < 512*1024) return (8192); - if (num_blocks < 1024*1024) + if (blocks < 1024*1024) return (16384); return 32768; } @@ -447,8 +411,7 @@ errcode_t ext2fs_add_journal_device(ext2_filsys fs, ext2_filsys journal_dev) start = 1; if (journal_dev->blocksize == 1024) start++; - if ((retval = io_channel_read_blk64(journal_dev->io, start, -1024, - buf))) + if ((retval = io_channel_read_blk(journal_dev->io, start, -1024, buf))) return retval; jsb = (journal_superblock_t *) buf; @@ -473,7 +436,7 @@ errcode_t ext2fs_add_journal_device(ext2_filsys fs, ext2_filsys journal_dev) } /* Writeback the journal superblock */ - if ((retval = io_channel_write_blk64(journal_dev->io, start, -1024, buf))) + if ((retval = io_channel_write_blk(journal_dev->io, start, -1024, buf))) return retval; fs->super->s_journal_inum = 0; @@ -490,26 +453,20 @@ errcode_t ext2fs_add_journal_device(ext2_filsys fs, ext2_filsys journal_dev) * POSIX routines if the filesystem is mounted, or using direct I/O * functions if it is not. */ -errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t num_blocks, int flags) +errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size, int flags) { errcode_t retval; ext2_ino_t journal_ino; struct stat st; char jfile[1024]; - int mount_flags; + int mount_flags, f; int fd = -1; - if (flags & EXT2_MKJOURNAL_NO_MNT_CHECK) - mount_flags = 0; - else if ((retval = ext2fs_check_mount_point(fs->device_name, - &mount_flags, - jfile, sizeof(jfile)-10))) + if ((retval = ext2fs_check_mount_point(fs->device_name, &mount_flags, + jfile, sizeof(jfile)-10))) return retval; if (mount_flags & EXT2_MF_MOUNTED) { -#if HAVE_EXT2_IOCTLS - int f = 0; -#endif strcat(jfile, "/.journal"); /* @@ -522,10 +479,9 @@ errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t num_blocks, int flags) #if HAVE_EXT2_IOCTLS fd = open(jfile, O_RDONLY); if (fd >= 0) { - retval = ioctl(fd, EXT2_IOC_SETFLAGS, &f); + f = 0; + ioctl(fd, EXT2_IOC_SETFLAGS, &f); close(fd); - if (retval) - return retval; } #endif #endif @@ -534,14 +490,7 @@ errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t num_blocks, int flags) if ((fd = open(jfile, O_CREAT|O_WRONLY, 0600)) < 0) return errno; - /* Note that we can't do lazy journal initialization for mounted - * filesystems, since the zero writing is also allocating the - * journal blocks. We could use fallocate, but not all kernels - * support that, and creating a journal on a mounted ext2 - * filesystems is extremely rare these days... Ignore it. */ - flags &= ~EXT2_MKJOURNAL_LAZYINIT; - - if ((retval = write_journal_file(fs, jfile, num_blocks, flags))) + if ((retval = write_journal_file(fs, jfile, size, flags))) goto errout; /* Get inode number of the journal file */ @@ -581,7 +530,7 @@ errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t num_blocks, int flags) } journal_ino = EXT2_JOURNAL_INO; if ((retval = write_journal_inode(fs, journal_ino, - num_blocks, flags))) + size, flags))) return retval; } @@ -594,7 +543,7 @@ errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t num_blocks, int flags) ext2fs_mark_super_dirty(fs); return 0; errout: - if (fd >= 0) + if (fd > 0) close(fd); return retval; } @@ -604,7 +553,7 @@ main(int argc, char **argv) { errcode_t retval; char *device_name; - ext2_filsys fs; + ext2_filsys fs; if (argc < 2) { fprintf(stderr, "Usage: %s filesystem\n", argv[0]); @@ -619,7 +568,7 @@ main(int argc, char **argv) exit(1); } - retval = ext2fs_add_journal_inode(fs, 1024, 0); + retval = ext2fs_add_journal_inode(fs, 1024); if (retval) { com_err(argv[0], retval, "while adding journal to %s", device_name); diff --git a/lib/ext2fs/mmp.c b/lib/ext2fs/mmp.c deleted file mode 100644 index a9eae504..00000000 --- a/lib/ext2fs/mmp.c +++ /dev/null @@ -1,397 +0,0 @@ -/* - * Helper functions for multiple mount protection (MMP). - * - * Copyright (C) 2011 Whamcloud, Inc. - * - * %Begin-Header% - * This file may be redistributed under the terms of the GNU Library - * General Public License, version 2. - * %End-Header% - */ - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - - -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <sys/time.h> - -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - -#include "ext2fs/ext2_fs.h" -#include "ext2fs/ext2fs.h" - -#ifndef O_DIRECT -#define O_DIRECT 0 -#endif - -errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf) -{ - struct mmp_struct *mmp_cmp; - errcode_t retval = 0; - - if ((mmp_blk <= fs->super->s_first_data_block) || - (mmp_blk >= ext2fs_blocks_count(fs->super))) - return EXT2_ET_MMP_BAD_BLOCK; - - /* ext2fs_open() reserves fd0,1,2 to avoid stdio collision, so checking - * mmp_fd <= 0 is OK to validate that the fd is valid. This opens its - * own fd to read the MMP block to ensure that it is using O_DIRECT, - * regardless of how the io_manager is doing reads, to avoid caching of - * the MMP block by the io_manager or the VM. It needs to be fresh. */ - if (fs->mmp_fd <= 0) { - fs->mmp_fd = open(fs->device_name, O_RDWR | O_DIRECT); - if (fs->mmp_fd < 0) { - retval = EXT2_ET_MMP_OPEN_DIRECT; - goto out; - } - } - - if (fs->mmp_cmp == NULL) { - int align = ext2fs_get_dio_alignment(fs->mmp_fd); - - retval = ext2fs_get_memalign(fs->blocksize, align, - &fs->mmp_cmp); - if (retval) - return retval; - } - - if ((blk64_t) ext2fs_llseek(fs->mmp_fd, mmp_blk * fs->blocksize, - SEEK_SET) != - mmp_blk * fs->blocksize) { - retval = EXT2_ET_LLSEEK_FAILED; - goto out; - } - - if (read(fs->mmp_fd, fs->mmp_cmp, fs->blocksize) != fs->blocksize) { - retval = EXT2_ET_SHORT_READ; - goto out; - } - - mmp_cmp = fs->mmp_cmp; -#ifdef WORDS_BIGENDIAN - ext2fs_swap_mmp(mmp_cmp); -#endif - - if (buf != NULL && buf != fs->mmp_cmp) - memcpy(buf, fs->mmp_cmp, fs->blocksize); - - if (mmp_cmp->mmp_magic != EXT4_MMP_MAGIC) { - retval = EXT2_ET_MMP_MAGIC_INVALID; - goto out; - } - -out: - return retval; -} - -errcode_t ext2fs_mmp_write(ext2_filsys fs, blk64_t mmp_blk, void *buf) -{ - struct mmp_struct *mmp_s = buf; - struct timeval tv; - errcode_t retval = 0; - - gettimeofday(&tv, 0); - mmp_s->mmp_time = tv.tv_sec; - fs->mmp_last_written = tv.tv_sec; - - if (fs->super->s_mmp_block < fs->super->s_first_data_block || - fs->super->s_mmp_block > ext2fs_blocks_count(fs->super)) - return EXT2_ET_MMP_BAD_BLOCK; - -#ifdef WORDS_BIGENDIAN - ext2fs_swap_mmp(mmp_s); -#endif - - /* I was tempted to make this use O_DIRECT and the mmp_fd, but - * this caused no end of grief, while leaving it as-is works. */ - retval = io_channel_write_blk64(fs->io, mmp_blk, -(int)sizeof(struct mmp_struct), buf); - -#ifdef WORDS_BIGENDIAN - ext2fs_swap_mmp(mmp_s); -#endif - - /* Make sure the block gets to disk quickly */ - io_channel_flush(fs->io); - return retval; -} - -#ifdef HAVE_SRANDOM -#define srand(x) srandom(x) -#define rand() random() -#endif - -unsigned ext2fs_mmp_new_seq(void) -{ - unsigned new_seq; - struct timeval tv; - - gettimeofday(&tv, 0); - srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec); - - gettimeofday(&tv, 0); - /* Crank the random number generator a few times */ - for (new_seq = (tv.tv_sec ^ tv.tv_usec) & 0x1F; new_seq > 0; new_seq--) - rand(); - - do { - new_seq = rand(); - } while (new_seq > EXT4_MMP_SEQ_MAX); - - return new_seq; -} - -static errcode_t ext2fs_mmp_reset(ext2_filsys fs) -{ - struct mmp_struct *mmp_s = NULL; - errcode_t retval = 0; - - if (fs->mmp_buf == NULL) { - retval = ext2fs_get_mem(fs->blocksize, &fs->mmp_buf); - if (retval) - goto out; - } - - memset(fs->mmp_buf, 0, fs->blocksize); - mmp_s = fs->mmp_buf; - - mmp_s->mmp_magic = EXT4_MMP_MAGIC; - mmp_s->mmp_seq = EXT4_MMP_SEQ_CLEAN; - mmp_s->mmp_time = 0; -#if _BSD_SOURCE || _XOPEN_SOURCE >= 500 - gethostname(mmp_s->mmp_nodename, sizeof(mmp_s->mmp_nodename)); -#else - mmp_s->mmp_nodename[0] = '\0'; -#endif - strncpy(mmp_s->mmp_bdevname, fs->device_name, - sizeof(mmp_s->mmp_bdevname)); - - mmp_s->mmp_check_interval = fs->super->s_mmp_update_interval; - if (mmp_s->mmp_check_interval < EXT4_MMP_MIN_CHECK_INTERVAL) - mmp_s->mmp_check_interval = EXT4_MMP_MIN_CHECK_INTERVAL; - - retval = ext2fs_mmp_write(fs, fs->super->s_mmp_block, fs->mmp_buf); -out: - return retval; -} - -errcode_t ext2fs_mmp_clear(ext2_filsys fs) -{ - errcode_t retval = 0; - - if (!(fs->flags & EXT2_FLAG_RW)) - return EXT2_ET_RO_FILSYS; - - retval = ext2fs_mmp_reset(fs); - - return retval; -} - -errcode_t ext2fs_mmp_init(ext2_filsys fs) -{ - struct ext2_super_block *sb = fs->super; - blk64_t mmp_block; - errcode_t retval; - - if (sb->s_mmp_update_interval == 0) - sb->s_mmp_update_interval = EXT4_MMP_UPDATE_INTERVAL; - /* This is probably excessively large, but who knows? */ - else if (sb->s_mmp_update_interval > EXT4_MMP_MAX_UPDATE_INTERVAL) - return EXT2_ET_INVALID_ARGUMENT; - - if (fs->mmp_buf == NULL) { - retval = ext2fs_get_mem(fs->blocksize, &fs->mmp_buf); - if (retval) - goto out; - } - - retval = ext2fs_alloc_block2(fs, 0, fs->mmp_buf, &mmp_block); - if (retval) - goto out; - - sb->s_mmp_block = mmp_block; - - retval = ext2fs_mmp_reset(fs); - if (retval) - goto out; - -out: - return retval; -} - -/* - * Make sure that the fs is not mounted or being fsck'ed while opening the fs. - */ -errcode_t ext2fs_mmp_start(ext2_filsys fs) -{ - struct mmp_struct *mmp_s; - unsigned seq; - unsigned int mmp_check_interval; - errcode_t retval = 0; - - if (fs->mmp_buf == NULL) { - retval = ext2fs_get_mem(fs->blocksize, &fs->mmp_buf); - if (retval) - goto mmp_error; - } - - retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, fs->mmp_buf); - if (retval) - goto mmp_error; - - mmp_s = fs->mmp_buf; - - mmp_check_interval = fs->super->s_mmp_update_interval; - if (mmp_check_interval < EXT4_MMP_MIN_CHECK_INTERVAL) - mmp_check_interval = EXT4_MMP_MIN_CHECK_INTERVAL; - - seq = mmp_s->mmp_seq; - if (seq == EXT4_MMP_SEQ_CLEAN) - goto clean_seq; - if (seq == EXT4_MMP_SEQ_FSCK) { - retval = EXT2_ET_MMP_FSCK_ON; - goto mmp_error; - } - - if (seq > EXT4_MMP_SEQ_FSCK) { - retval = EXT2_ET_MMP_UNKNOWN_SEQ; - goto mmp_error; - } - - /* - * If check_interval in MMP block is larger, use that instead of - * check_interval from the superblock. - */ - if (mmp_s->mmp_check_interval > mmp_check_interval) - mmp_check_interval = mmp_s->mmp_check_interval; - - sleep(2 * mmp_check_interval + 1); - - retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, fs->mmp_buf); - if (retval) - goto mmp_error; - - if (seq != mmp_s->mmp_seq) { - retval = EXT2_ET_MMP_FAILED; - goto mmp_error; - } - -clean_seq: - if (!(fs->flags & EXT2_FLAG_RW)) - goto mmp_error; - - mmp_s->mmp_seq = seq = ext2fs_mmp_new_seq(); -#if _BSD_SOURCE || _XOPEN_SOURCE >= 500 - gethostname(mmp_s->mmp_nodename, sizeof(mmp_s->mmp_nodename)); -#else - strcpy(mmp_s->mmp_nodename, "unknown host"); -#endif - strncpy(mmp_s->mmp_bdevname, fs->device_name, - sizeof(mmp_s->mmp_bdevname)); - - retval = ext2fs_mmp_write(fs, fs->super->s_mmp_block, fs->mmp_buf); - if (retval) - goto mmp_error; - - sleep(2 * mmp_check_interval + 1); - - retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, fs->mmp_buf); - if (retval) - goto mmp_error; - - if (seq != mmp_s->mmp_seq) { - retval = EXT2_ET_MMP_FAILED; - goto mmp_error; - } - - mmp_s->mmp_seq = EXT4_MMP_SEQ_FSCK; - retval = ext2fs_mmp_write(fs, fs->super->s_mmp_block, fs->mmp_buf); - if (retval) - goto mmp_error; - - return 0; - -mmp_error: - return retval; -} - -/* - * Clear the MMP usage in the filesystem. If this function returns an - * error EXT2_ET_MMP_CHANGE_ABORT it means the filesystem was modified - * by some other process while in use, and changes should be dropped, or - * risk filesystem corruption. - */ -errcode_t ext2fs_mmp_stop(ext2_filsys fs) -{ - struct mmp_struct *mmp, *mmp_cmp; - errcode_t retval = 0; - - if (!(fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_MMP) || - !(fs->flags & EXT2_FLAG_RW) || (fs->flags & EXT2_FLAG_SKIP_MMP)) - goto mmp_error; - - retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, fs->mmp_buf); - if (retval) - goto mmp_error; - - /* Check if the MMP block is not changed. */ - mmp = fs->mmp_buf; - mmp_cmp = fs->mmp_cmp; - if (memcmp(mmp, mmp_cmp, sizeof(*mmp_cmp))) { - retval = EXT2_ET_MMP_CHANGE_ABORT; - goto mmp_error; - } - - mmp_cmp->mmp_seq = EXT4_MMP_SEQ_CLEAN; - retval = ext2fs_mmp_write(fs, fs->super->s_mmp_block, fs->mmp_cmp); - -mmp_error: - if (fs->mmp_fd > 0) { - close(fs->mmp_fd); - fs->mmp_fd = -1; - } - - return retval; -} - -#define EXT2_MIN_MMP_UPDATE_INTERVAL 60 - -/* - * Update the on-disk mmp buffer, after checking that it hasn't been changed. - */ -errcode_t ext2fs_mmp_update(ext2_filsys fs) -{ - struct mmp_struct *mmp, *mmp_cmp; - struct timeval tv; - errcode_t retval = 0; - - if (!(fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_MMP) || - !(fs->flags & EXT2_FLAG_RW) || (fs->flags & EXT2_FLAG_SKIP_MMP)) - return 0; - - gettimeofday(&tv, 0); - if (tv.tv_sec - fs->mmp_last_written < EXT2_MIN_MMP_UPDATE_INTERVAL) - return 0; - - retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, NULL); - if (retval) - goto mmp_error; - - mmp = fs->mmp_buf; - mmp_cmp = fs->mmp_cmp; - - if (memcmp(mmp, mmp_cmp, sizeof(*mmp_cmp))) - return EXT2_ET_MMP_CHANGE_ABORT; - - mmp->mmp_time = tv.tv_sec; - mmp->mmp_seq = EXT4_MMP_SEQ_FSCK; - retval = ext2fs_mmp_write(fs, fs->super->s_mmp_block, fs->mmp_buf); - -mmp_error: - return retval; -} diff --git a/lib/ext2fs/namei.c b/lib/ext2fs/namei.c index dd710b89..22d2d2d2 100644 --- a/lib/ext2fs/namei.c +++ b/lib/ext2fs/namei.c @@ -19,7 +19,6 @@ #include "ext2_fs.h" #include "ext2fs.h" -#include "ext2fsP.h" static errcode_t open_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t base, const char *pathname, size_t pathlen, int follow, @@ -33,7 +32,6 @@ static errcode_t follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t dir, char *buffer = 0; errcode_t retval; struct ext2_inode ei; - blk64_t blk; #ifdef NAMEI_DEBUG printf("follow_link: root=%lu, dir=%lu, inode=%lu, lc=%d\n", @@ -46,19 +44,14 @@ static errcode_t follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t dir, *res_inode = inode; return 0; } - if (link_count++ >= EXT2FS_MAX_NESTED_LINKS) + if (link_count++ > 5) { return EXT2_ET_SYMLINK_LOOP; - + } if (ext2fs_inode_data_blocks(fs,&ei)) { - retval = ext2fs_bmap2(fs, inode, &ei, NULL, 0, 0, NULL, &blk); - if (retval) - return retval; - retval = ext2fs_get_mem(fs->blocksize, &buffer); if (retval) return retval; - - retval = io_channel_read_blk64(fs->io, blk, 1, buffer); + retval = io_channel_read_blk(fs->io, ei.i_block[0], 1, buffer); if (retval) { ext2fs_free_mem(&buffer); return retval; diff --git a/lib/ext2fs/newdir.c b/lib/ext2fs/newdir.c index bccaecdb..6bc57194 100644 --- a/lib/ext2fs/newdir.c +++ b/lib/ext2fs/newdir.c @@ -43,10 +43,8 @@ errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino, dir = (struct ext2_dir_entry *) buf; retval = ext2fs_set_rec_len(fs, fs->blocksize, dir); - if (retval) { - ext2fs_free_mem(&buf); + if (retval) return retval; - } if (dir_ino) { if (fs->super->s_feature_incompat & @@ -66,10 +64,8 @@ errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino, */ dir = (struct ext2_dir_entry *) (buf + dir->rec_len); retval = ext2fs_set_rec_len(fs, rec_len, dir); - if (retval) { - ext2fs_free_mem(&buf); + if (retval) return retval; - } dir->inode = parent_ino; dir->name_len = 2 | filetype; dir->name[0] = '.'; diff --git a/lib/ext2fs/nt_io.c b/lib/ext2fs/nt_io.c index a29e1d49..0f10543a 100644 --- a/lib/ext2fs/nt_io.c +++ b/lib/ext2fs/nt_io.c @@ -13,6 +13,7 @@ */ #ifdef HAVE_CONFIG_H +#include "config.h" #endif diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c index 45b3627e..d638da03 100644 --- a/lib/ext2fs/openfs.c +++ b/lib/ext2fs/openfs.c @@ -22,9 +22,6 @@ #if HAVE_SYS_TYPES_H #include <sys/types.h> #endif -#ifdef HAVE_ERRNO_H -#include <errno.h> -#endif #include "ext2_fs.h" @@ -32,12 +29,11 @@ #include "ext2fs.h" #include "e2image.h" -blk64_t ext2fs_descriptor_block_loc2(ext2_filsys fs, blk64_t group_block, - dgrp_t i) +blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block, dgrp_t i) { int bg; int has_super = 0; - blk64_t ret_blk; + int ret_blk; if (!(fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) || (i < fs->super->s_first_meta_bg)) @@ -46,7 +42,7 @@ blk64_t ext2fs_descriptor_block_loc2(ext2_filsys fs, blk64_t group_block, bg = EXT2_DESC_PER_BLOCK(fs->super) * i; if (ext2fs_bg_has_super(fs, bg)) has_super = 1; - ret_blk = ext2fs_group_first_block2(fs, bg) + has_super; + 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 @@ -57,16 +53,11 @@ blk64_t ext2fs_descriptor_block_loc2(ext2_filsys fs, blk64_t group_block, */ if (group_block != fs->super->s_first_data_block && ((ret_blk + fs->super->s_blocks_per_group) < - ext2fs_blocks_count(fs->super))) + fs->super->s_blocks_count)) ret_blk += fs->super->s_blocks_per_group; 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) @@ -85,9 +76,6 @@ errcode_t ext2fs_open(const char *name, int flags, int superblock, * EXT2_FLAG_FORCE - Open the filesystem even if some of the * features aren't supported. * EXT2_FLAG_JOURNAL_DEV_OK - Open an ext3 journal device - * EXT2_FLAG_SKIP_MMP - Open without multi-mount protection check. - * EXT2_FLAG_64BITS - Allow 64-bit bitfields (needed for large - * filesystems) */ errcode_t ext2fs_open2(const char *name, const char *io_options, int flags, int superblock, @@ -98,11 +86,10 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, errcode_t retval; unsigned long i, first_meta_bg; __u32 features; - unsigned int blocks_per_group, io_flags; - blk64_t group_block, blk; + int groups_per_block, blocks_per_group, io_flags; + blk_t group_block, blk; char *dest, *cp; #ifdef WORDS_BIGENDIAN - unsigned int groups_per_block; struct ext2_group_desc *gdp; int j; #endif @@ -144,7 +131,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, goto cleanup; fs->image_io = fs->io; fs->io->app_data = fs; - retval = io_channel_alloc_buf(fs->io, -SUPERBLOCK_SIZE, &fs->super); + retval = ext2fs_get_memalign(SUPERBLOCK_SIZE, 512, &fs->super); if (retval) goto cleanup; if (flags & EXT2_FLAG_IMAGE_FILE) { @@ -221,7 +208,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, features = fs->super->s_feature_incompat; #ifdef EXT2_LIB_SOFTSUPP_INCOMPAT if (flags & EXT2_FLAG_SOFTSUPP_FEATURES) - features &= ~EXT2_LIB_SOFTSUPP_INCOMPAT; + features &= !EXT2_LIB_SOFTSUPP_INCOMPAT; #endif if (features & ~EXT2_LIB_FEATURE_INCOMPAT_SUPP) { retval = EXT2_ET_UNSUPP_FEATURE; @@ -231,7 +218,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, features = fs->super->s_feature_ro_compat; #ifdef EXT2_LIB_SOFTSUPP_RO_COMPAT if (flags & EXT2_FLAG_SOFTSUPP_FEATURES) - features &= ~EXT2_LIB_SOFTSUPP_RO_COMPAT; + features &= !EXT2_LIB_SOFTSUPP_RO_COMPAT; #endif if ((flags & EXT2_FLAG_RW) && (features & ~EXT2_LIB_FEATURE_RO_COMPAT_SUPP)) { @@ -252,36 +239,12 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, retval = EXT2_ET_CORRUPT_SUPERBLOCK; goto cleanup; } - - /* - * bigalloc requires cluster-aware bitfield operations, which at the - * moment means we need EXT2_FLAG_64BITS. - */ - if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, - EXT4_FEATURE_RO_COMPAT_BIGALLOC) && - !(flags & EXT2_FLAG_64BITS)) { - retval = EXT2_ET_CANT_USE_LEGACY_BITMAPS; - goto cleanup; - } - - if (!EXT2_HAS_RO_COMPAT_FEATURE(fs->super, - EXT4_FEATURE_RO_COMPAT_BIGALLOC) && - (fs->super->s_log_block_size != fs->super->s_log_cluster_size)) { - retval = EXT2_ET_CORRUPT_SUPERBLOCK; - goto cleanup; - } - fs->fragsize = fs->blocksize = EXT2_BLOCK_SIZE(fs->super); + fs->blocksize = EXT2_BLOCK_SIZE(fs->super); if (EXT2_INODE_SIZE(fs->super) < EXT2_GOOD_OLD_INODE_SIZE) { retval = EXT2_ET_CORRUPT_SUPERBLOCK; goto cleanup; } - fs->cluster_ratio_bits = fs->super->s_log_cluster_size - - fs->super->s_log_block_size; - if (EXT2_BLOCKS_PER_GROUP(fs->super) != - EXT2_CLUSTERS_PER_GROUP(fs->super) << fs->cluster_ratio_bits) { - retval = EXT2_ET_CORRUPT_SUPERBLOCK; - goto cleanup; - } + fs->fragsize = EXT2_FRAG_SIZE(fs->super); fs->inode_blocks_per_group = ((EXT2_INODES_PER_GROUP(fs->super) * EXT2_INODE_SIZE(fs->super) + EXT2_BLOCK_SIZE(fs->super) - 1) / @@ -321,18 +284,18 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, blocks_per_group > EXT2_MAX_BLOCKS_PER_GROUP(fs->super) || fs->inode_blocks_per_group > EXT2_MAX_INODES_PER_GROUP(fs->super) || EXT2_DESC_PER_BLOCK(fs->super) == 0 || - fs->super->s_first_data_block >= ext2fs_blocks_count(fs->super)) { + fs->super->s_first_data_block >= fs->super->s_blocks_count) { retval = EXT2_ET_CORRUPT_SUPERBLOCK; goto cleanup; } - fs->group_desc_count = ext2fs_div64_ceil(ext2fs_blocks_count(fs->super) - - fs->super->s_first_data_block, - blocks_per_group); - if (fs->group_desc_count * EXT2_INODES_PER_GROUP(fs->super) != - fs->super->s_inodes_count) { - retval = EXT2_ET_CORRUPT_SUPERBLOCK; + fs->group_desc_count = ext2fs_div_ceil(fs->super->s_blocks_count - + fs->super->s_first_data_block, + blocks_per_group); + if (fs->group_desc_count * EXT2_INODES_PER_GROUP(fs->super) != + fs->super->s_inodes_count) { + retval = EXT2_ET_CORRUPT_SUPERBLOCK; goto cleanup; - } + } fs->desc_blocks = ext2fs_div_ceil(fs->group_desc_count, EXT2_DESC_PER_BLOCK(fs->super)); retval = ext2fs_get_array(fs->desc_blocks, fs->blocksize, @@ -341,12 +304,8 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, goto cleanup; if (!group_block) group_block = fs->super->s_first_data_block; - if (group_block == 0 && fs->blocksize == 1024) - group_block = 1; /* Deal with 1024 blocksize && bigalloc */ dest = (char *) fs->group_desc; -#ifdef WORDS_BIGENDIAN groups_per_block = EXT2_DESC_PER_BLOCK(fs->super); -#endif if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) first_meta_bg = fs->super->s_first_meta_bg; else @@ -358,24 +317,20 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, goto cleanup; #ifdef WORDS_BIGENDIAN gdp = (struct ext2_group_desc *) dest; - for (j=0; j < groups_per_block*first_meta_bg; j++) { - gdp = ext2fs_group_desc(fs, fs->group_desc, j); - ext2fs_swap_group_desc2(fs, gdp); - } + for (j=0; j < groups_per_block*first_meta_bg; j++) + ext2fs_swap_group_desc(gdp++); #endif dest += fs->blocksize*first_meta_bg; } for (i=first_meta_bg ; i < fs->desc_blocks; i++) { - blk = ext2fs_descriptor_block_loc2(fs, group_block, i); - retval = io_channel_read_blk64(fs->io, blk, 1, dest); + blk = ext2fs_descriptor_block_loc(fs, group_block, i); + retval = io_channel_read_blk(fs->io, blk, 1, dest); if (retval) goto cleanup; #ifdef WORDS_BIGENDIAN - for (j=0; j < groups_per_block; j++) { - gdp = ext2fs_group_desc(fs, fs->group_desc, - i * groups_per_block + j); - ext2fs_swap_group_desc2(fs, gdp); - } + gdp = (struct ext2_group_desc *) dest; + for (j=0; j < groups_per_block; j++) + ext2fs_swap_group_desc(gdp++); #endif dest += fs->blocksize; } @@ -388,34 +343,18 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, */ if (superblock > 1 && EXT2_HAS_RO_COMPAT_FEATURE(fs->super, EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { - dgrp_t group; - - for (group = 0; group < fs->group_desc_count; group++) { - ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT); - ext2fs_bg_flags_clear(fs, group, EXT2_BG_INODE_UNINIT); - ext2fs_bg_itable_unused_set(fs, group, 0); - /* The checksum will be reset later, but fix it here - * anyway to avoid printing a lot of spurious errors. */ - ext2fs_group_desc_csum_set(fs, group); - } - if (fs->flags & EXT2_FLAG_RW) - ext2fs_mark_super_dirty(fs); - } - - if ((fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_MMP) && - !(flags & EXT2_FLAG_SKIP_MMP) && - (flags & (EXT2_FLAG_RW | EXT2_FLAG_EXCLUSIVE))) { - retval = ext2fs_mmp_start(fs); - if (retval) { - fs->flags |= EXT2_FLAG_SKIP_MMP; /* just do cleanup */ - ext2fs_mmp_stop(fs); - goto cleanup; + struct ext2_group_desc *gd; + for (i = 0, gd = fs->group_desc; i < fs->group_desc_count; + i++, gd++) { + gd->bg_flags &= ~EXT2_BG_BLOCK_UNINIT; + gd->bg_flags &= ~EXT2_BG_INODE_UNINIT; + gd->bg_itable_unused = 0; } + ext2fs_mark_super_dirty(fs); } fs->flags &= ~EXT2_FLAG_NOFREE_ON_ERROR; *ret_fs = fs; - return 0; cleanup: if (flags & EXT2_FLAG_NOFREE_ON_ERROR) @@ -450,20 +389,8 @@ errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io) errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io) { - errcode_t err; - if ((fs->flags & EXT2_FLAG_IMAGE_FILE) == 0) return EXT2_ET_NOT_IMAGE_FILE; - err = io_channel_set_blksize(new_io, fs->blocksize); - if (err) - return err; - if ((new_io == fs->image_io) || (new_io == fs->io)) - return 0; - if ((fs->image_io != fs->io) && - fs->image_io) - io_channel_close(fs->image_io); - if (fs->io) - io_channel_close(fs->io); fs->io = fs->image_io = new_io; fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_RW | EXT2_FLAG_BB_DIRTY | EXT2_FLAG_IB_DIRTY; diff --git a/lib/ext2fs/progress.c b/lib/ext2fs/progress.c deleted file mode 100644 index ad6a3d4d..00000000 --- a/lib/ext2fs/progress.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - * progress.c - Numeric progress meter - * - * Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, - * 2003, 2004, 2005 by Theodore Ts'o. - * - * %Begin-Header% - * This file may be redistributed under the terms of the GNU Public - * License. - * %End-Header% - */ - -#include "ext2fs.h" -#include "ext2fsP.h" - -#include <time.h> - -static char spaces[80], backspaces[80]; -static time_t last_update; - -static int int_log10(unsigned int arg) -{ - int l; - - for (l=0; arg ; l++) - arg = arg / 10; - return l; -} - -void ext2fs_numeric_progress_init(ext2_filsys fs, - struct ext2fs_numeric_progress_struct * progress, - const char *label, __u64 max) -{ - /* - * The PRINT_PROGRESS flag turns on or off ALL - * progress-related messages, whereas the SKIP_PROGRESS - * environment variable prints the start and end messages but - * not the numeric countdown in the middle. - */ - if (!(fs->flags & EXT2_FLAG_PRINT_PROGRESS)) - return; - - memset(spaces, ' ', sizeof(spaces)-1); - spaces[sizeof(spaces)-1] = 0; - memset(backspaces, '\b', sizeof(backspaces)-1); - backspaces[sizeof(backspaces)-1] = 0; - - memset(progress, 0, sizeof(*progress)); - if (getenv("E2FSPROGS_SKIP_PROGRESS")) - progress->skip_progress++; - - - /* - * Figure out how many digits we need - */ - progress->max = max; - progress->log_max = int_log10(max); - - if (label) { - fputs(label, stdout); - fflush(stdout); - } - last_update = 0; -} - -void ext2fs_numeric_progress_update(ext2_filsys fs, - struct ext2fs_numeric_progress_struct * progress, - __u64 val) -{ - time_t now; - - if (!(fs->flags & EXT2_FLAG_PRINT_PROGRESS)) - return; - if (progress->skip_progress) - return; - now = time(0); - if (now == last_update) - return; - last_update = now; - - printf("%*llu/%*llu", progress->log_max, val, - progress->log_max, progress->max); - fprintf(stdout, "%.*s", (2*progress->log_max)+1, backspaces); -} - -void ext2fs_numeric_progress_close(ext2_filsys fs, - struct ext2fs_numeric_progress_struct * progress, - const char *message) -{ - if (!(fs->flags & EXT2_FLAG_PRINT_PROGRESS)) - return; - fprintf(stdout, "%.*s", (2*progress->log_max)+1, spaces); - fprintf(stdout, "%.*s", (2*progress->log_max)+1, backspaces); - if (message) - fputs(message, stdout); -} diff --git a/lib/ext2fs/punch.c b/lib/ext2fs/punch.c deleted file mode 100644 index adfcdecb..00000000 --- a/lib/ext2fs/punch.c +++ /dev/null @@ -1,447 +0,0 @@ -/* - * punch.c --- deallocate blocks allocated to an inode - * - * Copyright (C) 2010 Theodore Ts'o. - * - * %Begin-Header% - * This file may be redistributed under the terms of the GNU Library - * General Public License, version 2. - * %End-Header% - */ - -#include <stdio.h> -#include <string.h> -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <errno.h> - -#include "ext2_fs.h" -#include "ext2fs.h" - -#undef PUNCH_DEBUG - -/* - * This function returns 1 if the specified block is all zeros - */ -static int check_zero_block(char *buf, int blocksize) -{ - char *cp = buf; - int left = blocksize; - - while (left > 0) { - if (*cp++) - return 0; - left--; - } - return 1; -} - -/* - * This clever recursive function handles i_blocks[] as well as - * indirect, double indirect, and triple indirect blocks. It iterates - * over the entries in the i_blocks array or indirect blocks, and for - * each one, will recursively handle any indirect blocks and then - * frees and deallocates the blocks. - */ -static errcode_t ind_punch(ext2_filsys fs, struct ext2_inode *inode, - char *block_buf, blk_t *p, int level, - blk_t start, blk_t count, int max) -{ - errcode_t retval; - blk_t b; - int i; - blk64_t offset, incr; - int freed = 0; - -#ifdef PUNCH_DEBUG - printf("Entering ind_punch, level %d, start %u, count %u, " - "max %d\n", level, start, count, max); -#endif - incr = 1ULL << ((EXT2_BLOCK_SIZE_BITS(fs->super)-2)*level); - for (i=0, offset=0; i < max; i++, p++, offset += incr) { - if (offset >= start + count) - break; - if (*p == 0 || (offset+incr) <= start) - continue; - b = *p; - if (level > 0) { - blk_t start2; -#ifdef PUNCH_DEBUG - printf("Reading indirect block %u\n", b); -#endif - retval = ext2fs_read_ind_block(fs, b, block_buf); - if (retval) - return retval; - start2 = (start > offset) ? start - offset : 0; - retval = ind_punch(fs, inode, block_buf + fs->blocksize, - (blk_t *) block_buf, level - 1, - start2, count - offset, - fs->blocksize >> 2); - if (retval) - return retval; - retval = ext2fs_write_ind_block(fs, b, block_buf); - if (retval) - return retval; - if (!check_zero_block(block_buf, fs->blocksize)) - continue; - } -#ifdef PUNCH_DEBUG - printf("Freeing block %u (offset %llu)\n", b, offset); -#endif - ext2fs_block_alloc_stats(fs, b, -1); - *p = 0; - freed++; - } -#ifdef PUNCH_DEBUG - printf("Freed %d blocks\n", freed); -#endif - return ext2fs_iblk_sub_blocks(fs, inode, freed); -} - -static errcode_t ext2fs_punch_ind(ext2_filsys fs, struct ext2_inode *inode, - char *block_buf, blk_t start, blk_t count) -{ - errcode_t retval; - char *buf = 0; - int level; - int num = EXT2_NDIR_BLOCKS; - blk_t *bp = inode->i_block; - blk_t addr_per_block; - blk64_t max = EXT2_NDIR_BLOCKS; - - if (!block_buf) { - retval = ext2fs_get_array(3, fs->blocksize, &buf); - if (retval) - return retval; - block_buf = buf; - } - - addr_per_block = (blk_t) fs->blocksize >> 2; - - for (level = 0; level < 4; level++, max *= (blk64_t)addr_per_block) { -#ifdef PUNCH_DEBUG - printf("Main loop level %d, start %u count %u " - "max %llu num %d\n", level, start, count, max, num); -#endif - if (start < max) { - retval = ind_punch(fs, inode, block_buf, bp, level, - start, count, num); - if (retval) - goto errout; - if (count > max) - count -= max - start; - else - break; - start = 0; - } else - start -= max; - bp += num; - if (level == 0) { - num = 1; - max = 1; - } - } - retval = 0; -errout: - if (buf) - ext2fs_free_mem(&buf); - return retval; -} - -#ifdef PUNCH_DEBUG - -#define dbg_printf(f, a...) printf(f, ## a) - -static void dbg_print_extent(char *desc, struct ext2fs_extent *extent) -{ - if (desc) - printf("%s: ", desc); - printf("extent: lblk %llu--%llu, len %u, pblk %llu, flags: ", - extent->e_lblk, extent->e_lblk + extent->e_len - 1, - extent->e_len, extent->e_pblk); - if (extent->e_flags & EXT2_EXTENT_FLAGS_LEAF) - fputs("LEAF ", stdout); - if (extent->e_flags & EXT2_EXTENT_FLAGS_UNINIT) - fputs("UNINIT ", stdout); - if (extent->e_flags & EXT2_EXTENT_FLAGS_SECOND_VISIT) - fputs("2ND_VISIT ", stdout); - if (!extent->e_flags) - fputs("(none)", stdout); - fputc('\n', stdout); - -} -#else -#define dbg_print_extent(desc, ex) do { } while (0) -#define dbg_printf(f, a...) do { } while (0) -#endif - -/* Free a range of blocks, respecting cluster boundaries */ -static errcode_t punch_extent_blocks(ext2_filsys fs, ext2_ino_t ino, - struct ext2_inode *inode, - blk64_t lfree_start, blk64_t free_start, - __u32 free_count, int *freed) -{ - blk64_t pblk; - int freed_now = 0; - __u32 cluster_freed; - errcode_t retval = 0; - - /* No bigalloc? Just free each block. */ - if (EXT2FS_CLUSTER_RATIO(fs) == 1) { - *freed += free_count; - while (free_count-- > 0) - ext2fs_block_alloc_stats2(fs, free_start++, -1); - return retval; - } - - /* - * Try to free up to the next cluster boundary. We assume that all - * blocks in a logical cluster map to blocks from the same physical - * cluster, and that the offsets within the [pl]clusters match. - */ - if (free_start & EXT2FS_CLUSTER_MASK(fs)) { - retval = ext2fs_map_cluster_block(fs, ino, inode, - lfree_start, &pblk); - if (retval) - goto errout; - if (!pblk) { - ext2fs_block_alloc_stats2(fs, free_start, -1); - freed_now++; - } - cluster_freed = EXT2FS_CLUSTER_RATIO(fs) - - (free_start & EXT2FS_CLUSTER_MASK(fs)); - if (cluster_freed > free_count) - cluster_freed = free_count; - free_count -= cluster_freed; - free_start += cluster_freed; - lfree_start += cluster_freed; - } - - /* Free whole clusters from the middle of the range. */ - while (free_count > 0 && free_count >= EXT2FS_CLUSTER_RATIO(fs)) { - ext2fs_block_alloc_stats2(fs, free_start, -1); - freed_now++; - cluster_freed = EXT2FS_CLUSTER_RATIO(fs); - free_count -= cluster_freed; - free_start += cluster_freed; - lfree_start += cluster_freed; - } - - /* Try to free the last cluster. */ - if (free_count > 0) { - retval = ext2fs_map_cluster_block(fs, ino, inode, - lfree_start, &pblk); - if (retval) - goto errout; - if (!pblk) { - ext2fs_block_alloc_stats2(fs, free_start, -1); - freed_now++; - } - } - -errout: - *freed += freed_now; - return retval; -} - -static errcode_t ext2fs_punch_extent(ext2_filsys fs, ext2_ino_t ino, - struct ext2_inode *inode, - blk64_t start, blk64_t end) -{ - ext2_extent_handle_t handle = 0; - struct ext2fs_extent extent; - errcode_t retval; - blk64_t free_start, next, lfree_start; - __u32 free_count, newlen; - int freed = 0; - int op; - - retval = ext2fs_extent_open2(fs, ino, inode, &handle); - if (retval) - return retval; - /* - * Find the extent closest to the start of the punch range. We don't - * check the return value because _goto() sets the current node to the - * next-lowest extent if 'start' is in a hole, and doesn't set a - * current node if there was a real error reading the extent tree. - * In that case, _get() will error out. - * - * Note: If _get() returns 'no current node', that simply means that - * there aren't any blocks mapped past this point in the file, so we're - * done. - */ - ext2fs_extent_goto(handle, start); - retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, &extent); - if (retval == EXT2_ET_NO_CURRENT_NODE) { - retval = 0; - goto errout; - } else if (retval) - goto errout; - while (1) { - op = EXT2_EXTENT_NEXT_LEAF; - dbg_print_extent("main loop", &extent); - next = extent.e_lblk + extent.e_len; - dbg_printf("start %llu, end %llu, next %llu\n", - (unsigned long long) start, - (unsigned long long) end, - (unsigned long long) next); - if (start <= extent.e_lblk) { - if (end < extent.e_lblk) - goto next_extent; - dbg_printf("Case #%d\n", 1); - /* Start of deleted region before extent; - adjust beginning of extent */ - free_start = extent.e_pblk; - lfree_start = extent.e_lblk; - if (next > end) - free_count = end - extent.e_lblk + 1; - else - free_count = extent.e_len; - extent.e_len -= free_count; - extent.e_lblk += free_count; - extent.e_pblk += free_count; - } else if (end >= next-1) { - if (start >= next) - break; - /* End of deleted region after extent; - adjust end of extent */ - dbg_printf("Case #%d\n", 2); - newlen = start - extent.e_lblk; - free_start = extent.e_pblk + newlen; - lfree_start = extent.e_lblk + newlen; - free_count = extent.e_len - newlen; - extent.e_len = newlen; - } else { - struct ext2fs_extent newex; - - dbg_printf("Case #%d\n", 3); - /* The hard case; we need to split the extent */ - newex.e_pblk = extent.e_pblk + - (end + 1 - extent.e_lblk); - newex.e_lblk = end + 1; - newex.e_len = next - end - 1; - newex.e_flags = extent.e_flags; - - extent.e_len = start - extent.e_lblk; - free_start = extent.e_pblk + extent.e_len; - lfree_start = extent.e_lblk + extent.e_len; - free_count = end - start + 1; - - dbg_print_extent("inserting", &newex); - retval = ext2fs_extent_insert(handle, - EXT2_EXTENT_INSERT_AFTER, &newex); - if (retval) - goto errout; - /* Now pointing at inserted extent; so go back */ - retval = ext2fs_extent_get(handle, - EXT2_EXTENT_PREV_LEAF, - &newex); - if (retval) - goto errout; - } - if (extent.e_len) { - dbg_print_extent("replacing", &extent); - retval = ext2fs_extent_replace(handle, 0, &extent); - } else { - struct ext2fs_extent newex; - blk64_t old_lblk, next_lblk; - dbg_printf("deleting current extent%s\n", ""); - - /* - * Save the location of the next leaf, then slip - * back to the current extent. - */ - retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, - &newex); - if (retval) - goto errout; - old_lblk = newex.e_lblk; - - retval = ext2fs_extent_get(handle, - EXT2_EXTENT_NEXT_LEAF, - &newex); - if (retval == EXT2_ET_EXTENT_NO_NEXT) - next_lblk = old_lblk; - else if (retval) - goto errout; - else - next_lblk = newex.e_lblk; - - retval = ext2fs_extent_goto(handle, old_lblk); - if (retval) - goto errout; - - /* Now delete the extent. */ - retval = ext2fs_extent_delete(handle, 0); - if (retval) - goto errout; - - /* Jump forward to the next extent. */ - ext2fs_extent_goto(handle, next_lblk); - op = EXT2_EXTENT_CURRENT; - } - if (retval) - goto errout; - dbg_printf("Free start %llu, free count = %u\n", - free_start, free_count); - retval = punch_extent_blocks(fs, ino, inode, lfree_start, - free_start, free_count, &freed); - if (retval) - goto errout; - next_extent: - retval = ext2fs_extent_get(handle, op, - &extent); - if (retval == EXT2_ET_EXTENT_NO_NEXT || - retval == EXT2_ET_NO_CURRENT_NODE) - break; - if (retval) - goto errout; - } - dbg_printf("Freed %d blocks\n", freed); - retval = ext2fs_iblk_sub_blocks(fs, inode, freed); -errout: - ext2fs_extent_free(handle); - return retval; -} - -/* - * Deallocate all logical blocks starting at start to end, inclusive. - * If end is ~0, then this is effectively truncate. - */ -errcode_t ext2fs_punch(ext2_filsys fs, ext2_ino_t ino, - struct ext2_inode *inode, - char *block_buf, blk64_t start, - blk64_t end) -{ - errcode_t retval; - struct ext2_inode inode_buf; - - if (start > end) - return EINVAL; - - /* Read inode structure if necessary */ - if (!inode) { - retval = ext2fs_read_inode(fs, ino, &inode_buf); - if (retval) - return retval; - inode = &inode_buf; - } - if (inode->i_flags & EXT4_EXTENTS_FL) - retval = ext2fs_punch_extent(fs, ino, inode, start, end); - else { - blk_t count; - - if (start > ~0U) - return 0; - if (end > ~0U) - end = ~0U; - count = ((end - start + 1) < ~0U) ? (end - start + 1) : ~0U; - retval = ext2fs_punch_ind(fs, inode, block_buf, - (blk_t) start, count); - } - if (retval) - return retval; - - return ext2fs_write_inode(fs, ino, inode); -} diff --git a/lib/ext2fs/qcow2.c b/lib/ext2fs/qcow2.c deleted file mode 100644 index 9d56ae58..00000000 --- a/lib/ext2fs/qcow2.c +++ /dev/null @@ -1,255 +0,0 @@ -/* - * qcow2.c --- Functions to generate qcow2 formatted disk images. This - * format is used originally by QEMU for virtual machines, and stores the - * filesystem data on disk in a packed format to avoid creating sparse - * image files that need lots of seeking to read and write. - * - * The qcow2 format supports zlib compression, but that is not yet - * implemented. - * - * It is possible to directly mount a qcow2 image using qemu-nbd: - * - * [root]# modprobe nbd max_part=63 - * [root]# qemu-nbd -c /dev/nbd0 image.img - * [root]# mount /dev/nbd0p1 /mnt/qemu - * - * Format details at http://people.gnome.org/~markmc/qcow-image-format.html - * - * Copyright (C) 2010 Red Hat, Inc., Lukas Czerner <lczerner@redhat.com> - * - * %Begin-Header% - * This file may be redistributed under the terms of the GNU Public - * License. - * %End-Header% - */ - -#define _LARGEFILE_SOURCE -#define _LARGEFILE64_SOURCE - -#include <fcntl.h> -#include <grp.h> -#include <pwd.h> -#include <stdio.h> -#ifdef HAVE_STDLIB_H -#include <stdlib.h> -#endif -#include <string.h> -#include <time.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <assert.h> - -#include "ext2fs/ext2fs.h" -#include "qcow2.h" - -/* Functions for converting qcow2 image into raw image */ - -struct ext2_qcow2_hdr *qcow2_read_header(int fd) -{ - void *buffer = NULL; - struct ext2_qcow2_hdr *hdr = NULL; - size_t size; - errcode_t ret; - - ret = ext2fs_get_mem(sizeof(struct ext2_qcow2_hdr), &buffer); - if (ret) - return NULL; - memset(buffer, 0, sizeof(struct ext2_qcow2_hdr)); - - if (ext2fs_llseek(fd, 0, SEEK_SET < 0)) { - ext2fs_free_mem(&buffer); - return NULL; - } - - size = read(fd, buffer, sizeof(struct ext2_qcow2_hdr)); - if (size != sizeof(struct ext2_qcow2_hdr)) { - ext2fs_free_mem(&buffer); - return NULL; - } - - hdr = (struct ext2_qcow2_hdr *)(buffer); - - if ((ext2fs_be32_to_cpu(hdr->magic) != QCOW_MAGIC) || - (ext2fs_be32_to_cpu(hdr->version) != 2)) { - ext2fs_free_mem(&hdr); - return NULL; - } - - return hdr; -} - -static int qcow2_read_l1_table(struct ext2_qcow2_image *img) -{ - int fd = img->fd; - size_t size, l1_size = img->l1_size * sizeof(blk64_t); - blk64_t *table; - errcode_t ret; - - ret = ext2fs_get_memzero(l1_size, &table); - if (ret) - return ret; - - if (ext2fs_llseek(fd, img->l1_offset, SEEK_SET) < 0) { - ext2fs_free_mem(&table); - return errno; - } - - size = read(fd, table, l1_size); - if (size != l1_size) { - ext2fs_free_mem(&table); - return errno; - } - - img->l1_table = table; - - return 0; -} - -static int qcow2_read_l2_table(struct ext2_qcow2_image *img, - ext2_off64_t offset, blk64_t **l2_table) -{ - int fd = img->fd; - size_t size; - - assert(*l2_table); - - if (ext2fs_llseek(fd, offset, SEEK_SET) < 0) - return errno; - - size = read(fd, *l2_table, img->cluster_size); - if (size != img->cluster_size) - return errno; - - return 0; -} - -static int qcow2_copy_data(int fdin, int fdout, ext2_off64_t off_in, - ext2_off64_t off_out, void *buf, size_t count) -{ - size_t size; - - assert(buf); - - if (ext2fs_llseek(fdout, off_out, SEEK_SET) < 0) - return errno; - - if (ext2fs_llseek(fdin, off_in, SEEK_SET) < 0) - return errno; - - size = read(fdin, buf, count); - if (size != count) - return errno; - - size = write(fdout, buf, count); - if (size != count) - return errno; - - return 0; -} - - -int qcow2_write_raw_image(int qcow2_fd, int raw_fd, - struct ext2_qcow2_hdr *hdr) -{ - struct ext2_qcow2_image img; - errcode_t ret = 0; - unsigned int l1_index, l2_index; - ext2_off64_t offset; - blk64_t *l1_table, *l2_table = NULL; - void *copy_buf = NULL; - size_t size; - - if (hdr->crypt_method) - return -QCOW_ENCRYPTED; - - img.fd = qcow2_fd; - img.hdr = hdr; - img.l2_cache = NULL; - img.l1_table = NULL; - img.cluster_bits = ext2fs_be32_to_cpu(hdr->cluster_bits); - img.cluster_size = 1 << img.cluster_bits; - img.l1_size = ext2fs_be32_to_cpu(hdr->l1_size); - img.l1_offset = ext2fs_be64_to_cpu(hdr->l1_table_offset); - img.l2_size = 1 << (img.cluster_bits - 3); - img.image_size = ext2fs_be64_to_cpu(hdr->size); - - - ret = ext2fs_get_memzero(img.cluster_size, &l2_table); - if (ret) - goto out; - - ret = ext2fs_get_memzero(1 << img.cluster_bits, ©_buf); - if (ret) - goto out; - - if (ext2fs_llseek(raw_fd, 0, SEEK_SET) < 0) { - ret = errno; - goto out; - } - - ret = qcow2_read_l1_table(&img); - if (ret) - goto out; - - l1_table = img.l1_table; - /* Walk through l1 table */ - for (l1_index = 0; l1_index < img.l1_size; l1_index++) { - ext2_off64_t off_out; - - offset = ext2fs_be64_to_cpu(l1_table[l1_index]) & - ~QCOW_OFLAG_COPIED; - - if ((offset > img.image_size) || - (offset <= 0)) - continue; - - if (offset & QCOW_OFLAG_COMPRESSED) { - ret = -QCOW_COMPRESSED; - goto out; - } - - ret = qcow2_read_l2_table(&img, offset, &l2_table); - if (ret) - break; - - /* Walk through l2 table and copy data blocks into raw image */ - for (l2_index = 0; l2_index < img.l2_size; l2_index++) { - offset = ext2fs_be64_to_cpu(l2_table[l2_index]) & - ~QCOW_OFLAG_COPIED; - - if (offset == 0) - continue; - - off_out = (l1_index * img.l2_size) + - l2_index; - off_out <<= img.cluster_bits; - ret = qcow2_copy_data(qcow2_fd, raw_fd, offset, - off_out, copy_buf, img.cluster_size); - if (ret) - goto out; - } - } - - /* Resize the output image to the filesystem size */ - if (ext2fs_llseek(raw_fd, img.image_size - 1, SEEK_SET) < 0) - return errno; - - ((char *)copy_buf)[0] = 0; - size = write(raw_fd, copy_buf, 1); - if (size != 1) { - ret = errno; - goto out; - } - -out: - if (copy_buf) - ext2fs_free_mem(©_buf); - if (img.l1_table) - ext2fs_free_mem(&img.l1_table); - if (l2_table) - ext2fs_free_mem(&l2_table); - return ret; -} diff --git a/lib/ext2fs/qcow2.h b/lib/ext2fs/qcow2.h deleted file mode 100644 index 81e0ec93..00000000 --- a/lib/ext2fs/qcow2.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * qcow2.h --- structures and function prototypes for qcow2.c to generate - * qcow2 formatted disk images. This format is used originally by QEMU - * for virtual machines, and stores the filesystem data on disk in a - * packed format to avoid creating sparse image files that need lots of - * seeking to read and write. - * - * The qcow2 format supports zlib compression, but that is not yet - * implemented. - * - * It is possible to directly mount a qcow2 image using qemu-nbd: - * - * [root]# modprobe nbd max_part=63 - * [root]# qemu-nbd -c /dev/nbd0 image.img - * [root]# mount /dev/nbd0p1 /mnt/qemu - * - * Format details at http://people.gnome.org/~markmc/qcow-image-format.html - * - * Copyright (C) 2010 Red Hat, Inc., Lukas Czerner <lczerner@redhat.com> - * - * %Begin-Header% - * This file may be redistributed under the terms of the GNU Public - * License. - * %End-Header% - */ - -/* Number of l2 tables in memory before writeback */ -#define L2_CACHE_PREALLOC 512 - - -#define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb) -#define QCOW_VERSION 2 -#define QCOW_OFLAG_COPIED (1LL << 63) -#define QCOW_OFLAG_COMPRESSED (1LL << 62) - -#define QCOW_COMPRESSED 1 -#define QCOW_ENCRYPTED 2 - -struct ext2_qcow2_hdr { - __u32 magic; - __u32 version; - - __u64 backing_file_offset; - __u32 backing_file_size; - - __u32 cluster_bits; - __u64 size; - __u32 crypt_method; - - __u32 l1_size; - __u64 l1_table_offset; - - __u64 refcount_table_offset; - __u32 refcount_table_clusters; - - __u32 nb_snapshots; - __u64 snapshots_offset; -}; - -typedef struct ext2_qcow2_l2_table L2_CACHE_HEAD; - -struct ext2_qcow2_l2_table { - __u32 l1_index; - __u64 offset; - __u64 *data; - L2_CACHE_HEAD *next; -}; - -struct ext2_qcow2_l2_cache { - L2_CACHE_HEAD *used_head; - L2_CACHE_HEAD *used_tail; - L2_CACHE_HEAD *free_head; - __u32 free; - __u32 count; - __u64 next_offset; -}; - -struct ext2_qcow2_refcount { - __u64 *refcount_table; - __u64 refcount_table_offset; - __u64 refcount_block_offset; - - __u32 refcount_table_clusters; - __u32 refcount_table_index; - __u32 refcount_block_index; - - __u16 *refcount_block; -}; - -struct ext2_qcow2_image { - int fd; - struct ext2_qcow2_hdr *hdr; - struct ext2_qcow2_l2_cache *l2_cache; - struct ext2_qcow2_refcount refcount; - __u32 cluster_size; - __u32 cluster_bits; - __u32 l1_size; - __u32 l2_size; - - __u64 *l1_table; - __u64 l2_offset; - __u64 l1_offset; - __u64 image_size; -}; - -/* Function prototypes */ - -/* qcow2.c */ - -/* Functions for converting qcow2 image into raw image */ -struct ext2_qcow2_hdr *qcow2_read_header(int); -int qcow2_write_raw_image(int, int, struct ext2_qcow2_hdr *); - diff --git a/lib/ext2fs/rbtree.c b/lib/ext2fs/rbtree.c deleted file mode 100644 index 94393030..00000000 --- a/lib/ext2fs/rbtree.c +++ /dev/null @@ -1,451 +0,0 @@ -/* - Red Black Trees - (C) 1999 Andrea Arcangeli <andrea@suse.de> - (C) 2002 David Woodhouse <dwmw2@infradead.org> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - linux/lib/rbtree.c -*/ - -#include "rbtree.h" - -static void __rb_rotate_left(struct rb_node *node, struct rb_root *root) -{ - struct rb_node *right = node->rb_right; - struct rb_node *parent = ext2fs_rb_parent(node); - - if ((node->rb_right = right->rb_left)) - ext2fs_rb_set_parent(right->rb_left, node); - right->rb_left = node; - - ext2fs_rb_set_parent(right, parent); - - if (parent) - { - if (node == parent->rb_left) - parent->rb_left = right; - else - parent->rb_right = right; - } - else - root->rb_node = right; - ext2fs_rb_set_parent(node, right); -} - -static void __rb_rotate_right(struct rb_node *node, struct rb_root *root) -{ - struct rb_node *left = node->rb_left; - struct rb_node *parent = ext2fs_rb_parent(node); - - if ((node->rb_left = left->rb_right)) - ext2fs_rb_set_parent(left->rb_right, node); - left->rb_right = node; - - ext2fs_rb_set_parent(left, parent); - - if (parent) - { - if (node == parent->rb_right) - parent->rb_right = left; - else - parent->rb_left = left; - } - else - root->rb_node = left; - ext2fs_rb_set_parent(node, left); -} - -void ext2fs_rb_insert_color(struct rb_node *node, struct rb_root *root) -{ - struct rb_node *parent, *gparent; - - while ((parent = ext2fs_rb_parent(node)) && ext2fs_rb_is_red(parent)) - { - gparent = ext2fs_rb_parent(parent); - - if (parent == gparent->rb_left) - { - { - register struct rb_node *uncle = gparent->rb_right; - if (uncle && ext2fs_rb_is_red(uncle)) - { - ext2fs_rb_set_black(uncle); - ext2fs_rb_set_black(parent); - ext2fs_rb_set_red(gparent); - node = gparent; - continue; - } - } - - if (parent->rb_right == node) - { - register struct rb_node *tmp; - __rb_rotate_left(parent, root); - tmp = parent; - parent = node; - node = tmp; - } - - ext2fs_rb_set_black(parent); - ext2fs_rb_set_red(gparent); - __rb_rotate_right(gparent, root); - } else { - { - register struct rb_node *uncle = gparent->rb_left; - if (uncle && ext2fs_rb_is_red(uncle)) - { - ext2fs_rb_set_black(uncle); - ext2fs_rb_set_black(parent); - ext2fs_rb_set_red(gparent); - node = gparent; - continue; - } - } - - if (parent->rb_left == node) - { - register struct rb_node *tmp; - __rb_rotate_right(parent, root); - tmp = parent; - parent = node; - node = tmp; - } - - ext2fs_rb_set_black(parent); - ext2fs_rb_set_red(gparent); - __rb_rotate_left(gparent, root); - } - } - - ext2fs_rb_set_black(root->rb_node); -} - -static void __rb_erase_color(struct rb_node *node, struct rb_node *parent, - struct rb_root *root) -{ - struct rb_node *other; - - while ((!node || ext2fs_rb_is_black(node)) && node != root->rb_node) - { - if (parent->rb_left == node) - { - other = parent->rb_right; - if (ext2fs_rb_is_red(other)) - { - ext2fs_rb_set_black(other); - ext2fs_rb_set_red(parent); - __rb_rotate_left(parent, root); - other = parent->rb_right; - } - if ((!other->rb_left || ext2fs_rb_is_black(other->rb_left)) && - (!other->rb_right || ext2fs_rb_is_black(other->rb_right))) - { - ext2fs_rb_set_red(other); - node = parent; - parent = ext2fs_rb_parent(node); - } - else - { - if (!other->rb_right || ext2fs_rb_is_black(other->rb_right)) - { - ext2fs_rb_set_black(other->rb_left); - ext2fs_rb_set_red(other); - __rb_rotate_right(other, root); - other = parent->rb_right; - } - ext2fs_rb_set_color(other, ext2fs_rb_color(parent)); - ext2fs_rb_set_black(parent); - ext2fs_rb_set_black(other->rb_right); - __rb_rotate_left(parent, root); - node = root->rb_node; - break; - } - } - else - { - other = parent->rb_left; - if (ext2fs_rb_is_red(other)) - { - ext2fs_rb_set_black(other); - ext2fs_rb_set_red(parent); - __rb_rotate_right(parent, root); - other = parent->rb_left; - } - if ((!other->rb_left || ext2fs_rb_is_black(other->rb_left)) && - (!other->rb_right || ext2fs_rb_is_black(other->rb_right))) - { - ext2fs_rb_set_red(other); - node = parent; - parent = ext2fs_rb_parent(node); - } - else - { - if (!other->rb_left || ext2fs_rb_is_black(other->rb_left)) - { - ext2fs_rb_set_black(other->rb_right); - ext2fs_rb_set_red(other); - __rb_rotate_left(other, root); - other = parent->rb_left; - } - ext2fs_rb_set_color(other, ext2fs_rb_color(parent)); - ext2fs_rb_set_black(parent); - ext2fs_rb_set_black(other->rb_left); - __rb_rotate_right(parent, root); - node = root->rb_node; - break; - } - } - } - if (node) - ext2fs_rb_set_black(node); -} - -void ext2fs_rb_erase(struct rb_node *node, struct rb_root *root) -{ - struct rb_node *child, *parent; - int color; - - if (!node->rb_left) - child = node->rb_right; - else if (!node->rb_right) - child = node->rb_left; - else - { - struct rb_node *old = node, *left; - - node = node->rb_right; - while ((left = node->rb_left) != NULL) - node = left; - - if (ext2fs_rb_parent(old)) { - if (ext2fs_rb_parent(old)->rb_left == old) - ext2fs_rb_parent(old)->rb_left = node; - else - ext2fs_rb_parent(old)->rb_right = node; - } else - root->rb_node = node; - - child = node->rb_right; - parent = ext2fs_rb_parent(node); - color = ext2fs_rb_color(node); - - if (parent == old) { - parent = node; - } else { - if (child) - ext2fs_rb_set_parent(child, parent); - parent->rb_left = child; - - node->rb_right = old->rb_right; - ext2fs_rb_set_parent(old->rb_right, node); - } - - node->rb_parent_color = old->rb_parent_color; - node->rb_left = old->rb_left; - ext2fs_rb_set_parent(old->rb_left, node); - - goto color; - } - - parent = ext2fs_rb_parent(node); - color = ext2fs_rb_color(node); - - if (child) - ext2fs_rb_set_parent(child, parent); - if (parent) - { - if (parent->rb_left == node) - parent->rb_left = child; - else - parent->rb_right = child; - } - else - root->rb_node = child; - - color: - if (color == RB_BLACK) - __rb_erase_color(child, parent, root); -} - -static void ext2fs_rb_augment_path(struct rb_node *node, rb_augment_f func, void *data) -{ - struct rb_node *parent; - -up: - func(node, data); - parent = ext2fs_rb_parent(node); - if (!parent) - return; - - if (node == parent->rb_left && parent->rb_right) - func(parent->rb_right, data); - else if (parent->rb_left) - func(parent->rb_left, data); - - node = parent; - goto up; -} - -/* - * after inserting @node into the tree, update the tree to account for - * both the new entry and any damage done by rebalance - */ -void ext2fs_rb_augment_insert(struct rb_node *node, rb_augment_f func, void *data) -{ - if (node->rb_left) - node = node->rb_left; - else if (node->rb_right) - node = node->rb_right; - - ext2fs_rb_augment_path(node, func, data); -} - -/* - * before removing the node, find the deepest node on the rebalance path - * that will still be there after @node gets removed - */ -struct rb_node *ext2fs_rb_augment_erase_begin(struct rb_node *node) -{ - struct rb_node *deepest; - - if (!node->rb_right && !node->rb_left) - deepest = ext2fs_rb_parent(node); - else if (!node->rb_right) - deepest = node->rb_left; - else if (!node->rb_left) - deepest = node->rb_right; - else { - deepest = ext2fs_rb_next(node); - if (deepest->rb_right) - deepest = deepest->rb_right; - else if (ext2fs_rb_parent(deepest) != node) - deepest = ext2fs_rb_parent(deepest); - } - - return deepest; -} - -/* - * after removal, update the tree to account for the removed entry - * and any rebalance damage. - */ -void ext2fs_rb_augment_erase_end(struct rb_node *node, rb_augment_f func, void *data) -{ - if (node) - ext2fs_rb_augment_path(node, func, data); -} - -/* - * This function returns the first node (in sort order) of the tree. - */ -struct rb_node *ext2fs_rb_first(const struct rb_root *root) -{ - struct rb_node *n; - - n = root->rb_node; - if (!n) - return NULL; - while (n->rb_left) - n = n->rb_left; - return n; -} - -struct rb_node *ext2fs_rb_last(const struct rb_root *root) -{ - struct rb_node *n; - - n = root->rb_node; - if (!n) - return NULL; - while (n->rb_right) - n = n->rb_right; - return n; -} - -struct rb_node *ext2fs_rb_next(struct rb_node *node) -{ - struct rb_node *parent; - - if (ext2fs_rb_parent(node) == node) - return NULL; - - /* If we have a right-hand child, go down and then left as far - as we can. */ - if (node->rb_right) { - node = node->rb_right; - while (node->rb_left) - node=node->rb_left; - return (struct rb_node *)node; - } - - /* No right-hand children. Everything down and left is - smaller than us, so any 'next' node must be in the general - direction of our parent. Go up the tree; any time the - ancestor is a right-hand child of its parent, keep going - up. First time it's a left-hand child of its parent, said - parent is our 'next' node. */ - while ((parent = ext2fs_rb_parent(node)) && node == parent->rb_right) - node = parent; - - return parent; -} - -struct rb_node *ext2fs_rb_prev(struct rb_node *node) -{ - struct rb_node *parent; - - if (ext2fs_rb_parent(node) == node) - return NULL; - - /* If we have a left-hand child, go down and then right as far - as we can. */ - if (node->rb_left) { - node = node->rb_left; - while (node->rb_right) - node=node->rb_right; - return (struct rb_node *)node; - } - - /* No left-hand children. Go up till we find an ancestor which - is a right-hand child of its parent */ - while ((parent = ext2fs_rb_parent(node)) && node == parent->rb_left) - node = parent; - - return parent; -} - -void ext2fs_rb_replace_node(struct rb_node *victim, struct rb_node *new, - struct rb_root *root) -{ - struct rb_node *parent = ext2fs_rb_parent(victim); - - /* Set the surrounding nodes to point to the replacement */ - if (parent) { - if (victim == parent->rb_left) - parent->rb_left = new; - else - parent->rb_right = new; - } else { - root->rb_node = new; - } - if (victim->rb_left) - ext2fs_rb_set_parent(victim->rb_left, new); - if (victim->rb_right) - ext2fs_rb_set_parent(victim->rb_right, new); - - /* Copy the pointers/colour from the victim to the replacement */ - *new = *victim; -} diff --git a/lib/ext2fs/rbtree.h b/lib/ext2fs/rbtree.h deleted file mode 100644 index 3b0b0784..00000000 --- a/lib/ext2fs/rbtree.h +++ /dev/null @@ -1,180 +0,0 @@ -/* - Red Black Trees - (C) 1999 Andrea Arcangeli <andrea@suse.de> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - linux/include/linux/rbtree.h - - To use rbtrees you'll have to implement your own insert and search cores. - This will avoid us to use callbacks and to drop drammatically performances. - I know it's not the cleaner way, but in C (not in C++) to get - performances and genericity... - - Some example of insert and search follows here. The search is a plain - normal search over an ordered tree. The insert instead must be implemented - in two steps: First, the code must insert the element in order as a red leaf - in the tree, and then the support library function rb_insert_color() must - be called. Such function will do the not trivial work to rebalance the - rbtree, if necessary. - ------------------------------------------------------------------------ -static inline struct page * rb_search_page_cache(struct inode * inode, - unsigned long offset) -{ - struct rb_node * n = inode->i_rb_page_cache.rb_node; - struct page * page; - - while (n) - { - page = rb_entry(n, struct page, rb_page_cache); - - if (offset < page->offset) - n = n->rb_left; - else if (offset > page->offset) - n = n->rb_right; - else - return page; - } - return NULL; -} - -static inline struct page * __rb_insert_page_cache(struct inode * inode, - unsigned long offset, - struct rb_node * node) -{ - struct rb_node ** p = &inode->i_rb_page_cache.rb_node; - struct rb_node * parent = NULL; - struct page * page; - - while (*p) - { - parent = *p; - page = rb_entry(parent, struct page, rb_page_cache); - - if (offset < page->offset) - p = &(*p)->rb_left; - else if (offset > page->offset) - p = &(*p)->rb_right; - else - return page; - } - - rb_link_node(node, parent, p); - - return NULL; -} - -static inline struct page * rb_insert_page_cache(struct inode * inode, - unsigned long offset, - struct rb_node * node) -{ - struct page * ret; - if ((ret = __rb_insert_page_cache(inode, offset, node))) - goto out; - rb_insert_color(node, &inode->i_rb_page_cache); - out: - return ret; -} ------------------------------------------------------------------------ -*/ - -#ifndef _LINUX_RBTREE_H -#define _LINUX_RBTREE_H - -#include <stdlib.h> - -#undef offsetof -#ifdef __compiler_offsetof -#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER) -#else -#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) -#endif - -#define container_of(ptr, type, member) ({ \ - const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) - -struct rb_node -{ - unsigned long rb_parent_color; -#define RB_RED 0 -#define RB_BLACK 1 - struct rb_node *rb_right; - struct rb_node *rb_left; -} __attribute__((aligned(sizeof(long)))); - /* The alignment might seem pointless, but allegedly CRIS needs it */ - -struct rb_root -{ - struct rb_node *rb_node; -}; - - -#define ext2fs_rb_parent(r) ((struct rb_node *)((r)->rb_parent_color & ~3)) -#define ext2fs_rb_color(r) ((r)->rb_parent_color & 1) -#define ext2fs_rb_is_red(r) (!ext2fs_rb_color(r)) -#define ext2fs_rb_is_black(r) ext2fs_rb_color(r) -#define ext2fs_rb_set_red(r) do { (r)->rb_parent_color &= ~1; } while (0) -#define ext2fs_rb_set_black(r) do { (r)->rb_parent_color |= 1; } while (0) - -static inline void ext2fs_rb_set_parent(struct rb_node *rb, struct rb_node *p) -{ - rb->rb_parent_color = (rb->rb_parent_color & 3) | (unsigned long)p; -} -static inline void ext2fs_rb_set_color(struct rb_node *rb, int color) -{ - rb->rb_parent_color = (rb->rb_parent_color & ~1) | color; -} - -#define RB_ROOT (struct rb_root) { NULL, } -#define ext2fs_rb_entry(ptr, type, member) container_of(ptr, type, member) - -#define EXT2FS_RB_EMPTY_ROOT(root) ((root)->rb_node == NULL) -#define EXT2FS_RB_EMPTY_NODE(node) (ext2fs_rb_parent(node) == node) -#define EXT2FS_RB_CLEAR_NODE(node) (ext2fs_rb_set_parent(node, node)) - -extern void ext2fs_rb_insert_color(struct rb_node *, struct rb_root *); -extern void ext2fs_rb_erase(struct rb_node *, struct rb_root *); - -typedef void (*rb_augment_f)(struct rb_node *node, void *data); - -extern void ext2fs_rb_augment_insert(struct rb_node *node, - rb_augment_f func, void *data); -extern struct rb_node *ext2fs_rb_augment_erase_begin(struct rb_node *node); -extern void ext2fs_rb_augment_erase_end(struct rb_node *node, - rb_augment_f func, void *data); - -/* Find logical next and previous nodes in a tree */ -extern struct rb_node *ext2fs_rb_next(struct rb_node *); -extern struct rb_node *ext2fs_rb_prev(struct rb_node *); -extern struct rb_node *ext2fs_rb_first(const struct rb_root *); -extern struct rb_node *ext2fs_rb_last(const struct rb_root *); - -/* Fast replacement of a single node without remove/rebalance/add/rebalance */ -extern void ext2fs_rb_replace_node(struct rb_node *victim, struct rb_node *new, - struct rb_root *root); - -static inline void ext2fs_rb_link_node(struct rb_node * node, - struct rb_node * parent, - struct rb_node ** rb_link) -{ - node->rb_parent_color = (unsigned long )parent; - node->rb_left = node->rb_right = NULL; - - *rb_link = node; -} - -#endif /* _LINUX_RBTREE_H */ diff --git a/lib/ext2fs/read_bb.c b/lib/ext2fs/read_bb.c index e5d63227..33167840 100644 --- a/lib/ext2fs/read_bb.c +++ b/lib/ext2fs/read_bb.c @@ -49,7 +49,7 @@ static int mark_bad_block(ext2_filsys fs, blk_t *block_nr, return 0; if ((*block_nr < fs->super->s_first_data_block) || - (*block_nr >= ext2fs_blocks_count(fs->super))) + (*block_nr >= fs->super->s_blocks_count)) return 0; /* Ignore illegal blocks */ rb->err = ext2fs_badblocks_list_add(rb->bb_list, *block_nr); diff --git a/lib/ext2fs/read_bb_file.c b/lib/ext2fs/read_bb_file.c index 89c567bb..0ca76045 100644 --- a/lib/ext2fs/read_bb_file.c +++ b/lib/ext2fs/read_bb_file.c @@ -38,7 +38,7 @@ errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f, void *priv_data)) { errcode_t retval; - blk64_t blockno; + blk_t blockno; int count; char buf[128]; @@ -54,15 +54,12 @@ errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f, while (!feof (f)) { if (fgets(buf, sizeof(buf), f) == NULL) break; - count = sscanf(buf, "%llu", &blockno); + count = sscanf(buf, "%u", &blockno); if (count <= 0) continue; - /* Badblocks isn't going to be updated for 64bit */ - if (blockno >> 32) - return EOVERFLOW; if (fs && ((blockno < fs->super->s_first_data_block) || - (blockno >= ext2fs_blocks_count(fs->super)))) { + (blockno >= fs->super->s_blocks_count))) { if (invalid) (invalid)(fs, blockno, buf, priv_data); continue; diff --git a/lib/ext2fs/res_gdt.c b/lib/ext2fs/res_gdt.c index acce650d..424d8671 100644 --- a/lib/ext2fs/res_gdt.c +++ b/lib/ext2fs/res_gdt.c @@ -65,9 +65,8 @@ errcode_t ext2fs_create_resize_inode(ext2_filsys fs) struct ext2_inode inode; __u32 *dindir_buf, *gdt_buf; unsigned long long apb, inode_size; - /* FIXME-64 - can't deal with extents */ blk_t dindir_blk, rsv_off, gdt_off, gdt_blk; - int dindir_dirty = 0, inode_dirty = 0, sb_blk = 0; + int dindir_dirty = 0, inode_dirty = 0; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); @@ -75,22 +74,13 @@ errcode_t ext2fs_create_resize_inode(ext2_filsys fs) retval = ext2fs_get_array(2, fs->blocksize, &dindir_buf); if (retval) - return retval; + goto out_free; gdt_buf = (__u32 *)((char *)dindir_buf + fs->blocksize); retval = ext2fs_read_inode(fs, EXT2_RESIZE_INO, &inode); if (retval) goto out_free; - /* - * File systems with a blocksize of 1024 and bigalloc have - * sb->s_first_data_block of 0; yet the superblock is still at - * block #1. We compensate for it here. - */ - sb_blk = sb->s_first_data_block; - if (fs->blocksize == 1024 && sb_blk == 0) - sb_blk = 1; - /* Maximum possible file size (we donly use the dindirect blocks) */ apb = EXT2_ADDR_PER_BLOCK(sb); if ((dindir_blk = inode.i_block[EXT2_DIND_BLOCK])) { @@ -101,7 +91,7 @@ errcode_t ext2fs_create_resize_inode(ext2_filsys fs) if (retval) goto out_inode; } else { - blk_t goal = sb_blk + fs->desc_blocks + + blk_t goal = sb->s_first_data_block + fs->desc_blocks + sb->s_reserved_gdt_blocks + 2 + fs->inode_blocks_per_group; @@ -129,7 +119,7 @@ errcode_t ext2fs_create_resize_inode(ext2_filsys fs) } for (rsv_off = 0, gdt_off = fs->desc_blocks, - gdt_blk = sb_blk + 1 + fs->desc_blocks; + gdt_blk = sb->s_first_data_block + 1 + fs->desc_blocks; rsv_off < sb->s_reserved_gdt_blocks; rsv_off++, gdt_off++, gdt_blk++) { unsigned int three = 1, five = 5, seven = 7; diff --git a/lib/ext2fs/rw_bitmaps.c b/lib/ext2fs/rw_bitmaps.c index eacf86a5..4e77a8f1 100644 --- a/lib/ext2fs/rw_bitmaps.c +++ b/lib/ext2fs/rw_bitmaps.c @@ -34,10 +34,10 @@ static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block) int block_nbytes, inode_nbytes; unsigned int nbits; errcode_t retval; - char *block_buf = NULL, *inode_buf = NULL; + char *block_buf, *inode_buf; int csum_flag = 0; - blk64_t blk; - blk64_t blk_itr = EXT2FS_B2C(fs, fs->super->s_first_data_block); + blk_t blk; + blk_t blk_itr = fs->super->s_first_data_block; ext2_ino_t ino_itr = 1; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); @@ -51,18 +51,20 @@ static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block) inode_nbytes = block_nbytes = 0; if (do_block) { - block_nbytes = EXT2_CLUSTERS_PER_GROUP(fs->super) / 8; - retval = io_channel_alloc_buf(fs->io, 0, &block_buf); + block_nbytes = EXT2_BLOCKS_PER_GROUP(fs->super) / 8; + retval = ext2fs_get_memalign(fs->blocksize, fs->blocksize, + &block_buf); if (retval) - goto errout; + return retval; memset(block_buf, 0xff, fs->blocksize); } if (do_inode) { inode_nbytes = (size_t) ((EXT2_INODES_PER_GROUP(fs->super)+7) / 8); - retval = io_channel_alloc_buf(fs->io, 0, &inode_buf); + retval = ext2fs_get_memalign(fs->blocksize, fs->blocksize, + &inode_buf); if (retval) - goto errout; + return retval; memset(inode_buf, 0xff, fs->blocksize); } @@ -70,33 +72,30 @@ static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block) if (!do_block) goto skip_block_bitmap; - if (csum_flag && ext2fs_bg_flags_test(fs, i, EXT2_BG_BLOCK_UNINIT) - ) + if (csum_flag && fs->group_desc[i].bg_flags & + EXT2_BG_BLOCK_UNINIT) goto skip_this_block_bitmap; - retval = ext2fs_get_block_bitmap_range2(fs->block_map, + retval = ext2fs_get_block_bitmap_range(fs->block_map, blk_itr, block_nbytes << 3, block_buf); if (retval) - goto errout; + return retval; if (i == fs->group_desc_count - 1) { /* Force bitmap padding for the last group */ - nbits = EXT2FS_NUM_B2C(fs, - ((ext2fs_blocks_count(fs->super) - - (__u64) fs->super->s_first_data_block) - % (__u64) EXT2_BLOCKS_PER_GROUP(fs->super))); + nbits = ((fs->super->s_blocks_count + - fs->super->s_first_data_block) + % EXT2_BLOCKS_PER_GROUP(fs->super)); if (nbits) for (j = nbits; j < fs->blocksize * 8; j++) ext2fs_set_bit(j, block_buf); } - blk = ext2fs_block_bitmap_loc(fs, i); + blk = fs->group_desc[i].bg_block_bitmap; if (blk) { - retval = io_channel_write_blk64(fs->io, blk, 1, - block_buf); - if (retval) { - retval = EXT2_ET_BLOCK_BITMAP_WRITE; - goto errout; - } + retval = io_channel_write_blk(fs->io, blk, 1, + block_buf); + if (retval) + return EXT2_ET_BLOCK_BITMAP_WRITE; } skip_this_block_bitmap: blk_itr += block_nbytes << 3; @@ -105,23 +104,21 @@ static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block) if (!do_inode) continue; - if (csum_flag && ext2fs_bg_flags_test(fs, i, EXT2_BG_INODE_UNINIT) - ) + if (csum_flag && fs->group_desc[i].bg_flags & + EXT2_BG_INODE_UNINIT) goto skip_this_inode_bitmap; - retval = ext2fs_get_inode_bitmap_range2(fs->inode_map, + retval = ext2fs_get_inode_bitmap_range(fs->inode_map, ino_itr, inode_nbytes << 3, inode_buf); if (retval) - goto errout; + return retval; - blk = ext2fs_inode_bitmap_loc(fs, i); + blk = fs->group_desc[i].bg_inode_bitmap; if (blk) { - retval = io_channel_write_blk64(fs->io, blk, 1, + retval = io_channel_write_blk(fs->io, blk, 1, inode_buf); - if (retval) { - retval = EXT2_ET_INODE_BITMAP_WRITE; - goto errout; - } + if (retval) + return EXT2_ET_INODE_BITMAP_WRITE; } skip_this_inode_bitmap: ino_itr += inode_nbytes << 3; @@ -136,12 +133,6 @@ static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block) ext2fs_free_mem(&inode_buf); } return 0; -errout: - if (inode_buf) - ext2fs_free_mem(&inode_buf); - if (block_buf) - ext2fs_free_mem(&block_buf); - return retval; } static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block) @@ -150,22 +141,19 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block) char *block_bitmap = 0, *inode_bitmap = 0; char *buf; errcode_t retval; - int block_nbytes = EXT2_CLUSTERS_PER_GROUP(fs->super) / 8; + int block_nbytes = EXT2_BLOCKS_PER_GROUP(fs->super) / 8; int inode_nbytes = EXT2_INODES_PER_GROUP(fs->super) / 8; int csum_flag = 0; + int do_image = fs->flags & EXT2_FLAG_IMAGE_FILE; unsigned int cnt; - blk64_t blk; - blk64_t blk_itr = EXT2FS_B2C(fs, fs->super->s_first_data_block); - blk64_t blk_cnt; + blk_t blk; + blk_t blk_itr = fs->super->s_first_data_block; + blk_t blk_cnt; ext2_ino_t ino_itr = 1; ext2_ino_t ino_cnt; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); - if ((block_nbytes > (int) fs->blocksize) || - (inode_nbytes > (int) fs->blocksize)) - return EXT2_ET_CORRUPT_SUPERBLOCK; - fs->write_bitmaps = ext2fs_write_bitmaps; if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, @@ -183,7 +171,13 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block) retval = ext2fs_allocate_block_bitmap(fs, buf, &fs->block_map); if (retval) goto cleanup; - retval = io_channel_alloc_buf(fs->io, 0, &block_bitmap); + if (do_image) + retval = ext2fs_get_mem(fs->blocksize, &block_bitmap); + else + retval = ext2fs_get_memalign((unsigned) block_nbytes, + fs->blocksize, + &block_bitmap); + if (retval) goto cleanup; } else @@ -196,7 +190,8 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block) retval = ext2fs_allocate_inode_bitmap(fs, buf, &fs->inode_map); if (retval) goto cleanup; - retval = io_channel_alloc_buf(fs->io, 0, &inode_bitmap); + retval = ext2fs_get_mem(do_image ? fs->blocksize : + (unsigned) inode_nbytes, &inode_bitmap); if (retval) goto cleanup; } else @@ -207,14 +202,14 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block) blk = (fs->image_header->offset_inodemap / fs->blocksize); ino_cnt = fs->super->s_inodes_count; while (inode_nbytes > 0) { - retval = io_channel_read_blk64(fs->image_io, blk++, + retval = io_channel_read_blk(fs->image_io, blk++, 1, inode_bitmap); if (retval) goto cleanup; cnt = fs->blocksize << 3; if (cnt > ino_cnt) cnt = ino_cnt; - retval = ext2fs_set_inode_bitmap_range2(fs->inode_map, + retval = ext2fs_set_inode_bitmap_range(fs->inode_map, ino_itr, cnt, inode_bitmap); if (retval) goto cleanup; @@ -224,17 +219,17 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block) } blk = (fs->image_header->offset_blockmap / fs->blocksize); - blk_cnt = (blk64_t)EXT2_CLUSTERS_PER_GROUP(fs->super) * + blk_cnt = EXT2_BLOCKS_PER_GROUP(fs->super) * fs->group_desc_count; while (block_nbytes > 0) { - retval = io_channel_read_blk64(fs->image_io, blk++, + retval = io_channel_read_blk(fs->image_io, blk++, 1, block_bitmap); if (retval) goto cleanup; cnt = fs->blocksize << 3; if (cnt > blk_cnt) cnt = blk_cnt; - retval = ext2fs_set_block_bitmap_range2(fs->block_map, + retval = ext2fs_set_block_bitmap_range(fs->block_map, blk_itr, cnt, block_bitmap); if (retval) goto cleanup; @@ -247,14 +242,14 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block) for (i = 0; i < fs->group_desc_count; i++) { if (block_bitmap) { - blk = ext2fs_block_bitmap_loc(fs, i); - if (csum_flag && - ext2fs_bg_flags_test(fs, i, EXT2_BG_BLOCK_UNINIT) && + blk = fs->group_desc[i].bg_block_bitmap; + if (csum_flag && fs->group_desc[i].bg_flags & + EXT2_BG_BLOCK_UNINIT && ext2fs_group_desc_csum_verify(fs, i)) blk = 0; if (blk) { - retval = io_channel_read_blk64(fs->io, blk, - 1, block_bitmap); + retval = io_channel_read_blk(fs->io, blk, + -block_nbytes, block_bitmap); if (retval) { retval = EXT2_ET_BLOCK_BITMAP_READ; goto cleanup; @@ -262,21 +257,21 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block) } else memset(block_bitmap, 0, block_nbytes); cnt = block_nbytes << 3; - retval = ext2fs_set_block_bitmap_range2(fs->block_map, + retval = ext2fs_set_block_bitmap_range(fs->block_map, blk_itr, cnt, block_bitmap); if (retval) goto cleanup; blk_itr += block_nbytes << 3; } if (inode_bitmap) { - blk = ext2fs_inode_bitmap_loc(fs, i); - if (csum_flag && - ext2fs_bg_flags_test(fs, i, EXT2_BG_INODE_UNINIT) && + blk = fs->group_desc[i].bg_inode_bitmap; + if (csum_flag && fs->group_desc[i].bg_flags & + EXT2_BG_INODE_UNINIT && ext2fs_group_desc_csum_verify(fs, i)) blk = 0; if (blk) { - retval = io_channel_read_blk64(fs->io, blk, - 1, inode_bitmap); + retval = io_channel_read_blk(fs->io, blk, + -inode_nbytes, inode_bitmap); if (retval) { retval = EXT2_ET_INODE_BITMAP_READ; goto cleanup; @@ -284,7 +279,7 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block) } else memset(inode_bitmap, 0, inode_nbytes); cnt = inode_nbytes << 3; - retval = ext2fs_set_inode_bitmap_range2(fs->inode_map, + retval = ext2fs_set_inode_bitmap_range(fs->inode_map, ino_itr, cnt, inode_bitmap); if (retval) goto cleanup; diff --git a/lib/ext2fs/sparse.c b/lib/ext2fs/sparse.c new file mode 100644 index 00000000..63c11f61 --- /dev/null +++ b/lib/ext2fs/sparse.c @@ -0,0 +1,78 @@ +/* + * sparse.c --- find the groups in an ext2 filesystem with metadata backups + * + * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. + * Copyright (C) 2002 Andreas Dilger. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include <stdio.h> + +#include "ext2_fs.h" +#include "ext2fsP.h" + +static int test_root(int a, int b) +{ + if (a == 0) + return 1; + while (1) { + if (a == 1) + return 1; + if (a % b) + return 0; + a = a / b; + } +} + +int ext2fs_bg_has_super(ext2_filsys fs, int group_block) +{ + if (!(fs->super->s_feature_ro_compat & + EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) + return 1; + + if (test_root(group_block, 3) || (test_root(group_block, 5)) || + test_root(group_block, 7)) + return 1; + + return 0; +} + +/* + * Iterate through the groups which hold BACKUP superblock/GDT copies in an + * ext3 filesystem. The counters should be initialized to 1, 5, and 7 before + * calling this for the first time. In a sparse filesystem it will be the + * sequence of powers of 3, 5, and 7: 1, 3, 5, 7, 9, 25, 27, 49, 81, ... + * For a non-sparse filesystem it will be every group: 1, 2, 3, 4, ... + */ +unsigned int ext2fs_list_backups(ext2_filsys fs, unsigned int *three, + unsigned int *five, unsigned int *seven) +{ + unsigned int *min = three; + int mult = 3; + unsigned int ret; + + if (!(fs->super->s_feature_ro_compat & + EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) { + ret = *min; + *min += 1; + return ret; + } + + if (*five < *min) { + min = five; + mult = 5; + } + if (*seven < *min) { + min = seven; + mult = 7; + } + + ret = *min; + *min *= mult; + + return ret; +} diff --git a/lib/ext2fs/swapfs.c b/lib/ext2fs/swapfs.c index 46d60ef4..12427e0a 100644 --- a/lib/ext2fs/swapfs.c +++ b/lib/ext2fs/swapfs.c @@ -31,9 +31,9 @@ void ext2fs_swap_super(struct ext2_super_block * sb) sb->s_free_inodes_count = ext2fs_swab32(sb->s_free_inodes_count); sb->s_first_data_block = ext2fs_swab32(sb->s_first_data_block); sb->s_log_block_size = ext2fs_swab32(sb->s_log_block_size); - sb->s_log_cluster_size = ext2fs_swab32(sb->s_log_cluster_size); + sb->s_log_frag_size = ext2fs_swab32(sb->s_log_frag_size); sb->s_blocks_per_group = ext2fs_swab32(sb->s_blocks_per_group); - sb->s_clusters_per_group = ext2fs_swab32(sb->s_clusters_per_group); + sb->s_frags_per_group = ext2fs_swab32(sb->s_frags_per_group); sb->s_inodes_per_group = ext2fs_swab32(sb->s_inodes_per_group); sb->s_mtime = ext2fs_swab32(sb->s_mtime); sb->s_wtime = ext2fs_swab32(sb->s_wtime); @@ -70,41 +70,32 @@ void ext2fs_swap_super(struct ext2_super_block * sb) sb->s_min_extra_isize = ext2fs_swab16(sb->s_min_extra_isize); sb->s_want_extra_isize = ext2fs_swab16(sb->s_want_extra_isize); sb->s_flags = ext2fs_swab32(sb->s_flags); - sb->s_mmp_update_interval = ext2fs_swab16(sb->s_mmp_update_interval); - sb->s_mmp_block = ext2fs_swab64(sb->s_mmp_block); sb->s_kbytes_written = ext2fs_swab64(sb->s_kbytes_written); sb->s_snapshot_inum = ext2fs_swab32(sb->s_snapshot_inum); sb->s_snapshot_id = ext2fs_swab32(sb->s_snapshot_id); sb->s_snapshot_r_blocks_count = ext2fs_swab64(sb->s_snapshot_r_blocks_count); sb->s_snapshot_list = ext2fs_swab32(sb->s_snapshot_list); - sb->s_usr_quota_inum = ext2fs_swab32(sb->s_usr_quota_inum); - sb->s_grp_quota_inum = ext2fs_swab32(sb->s_grp_quota_inum); - sb->s_overhead_blocks = ext2fs_swab32(sb->s_overhead_blocks); - sb->s_checksum = ext2fs_swab32(sb->s_checksum); for (i=0; i < 4; i++) sb->s_hash_seed[i] = ext2fs_swab32(sb->s_hash_seed[i]); /* if journal backup is for a valid extent-based journal... */ - if (ext2fs_extent_header_verify(sb->s_jnl_blocks, - sizeof(sb->s_jnl_blocks)) == 0) { - /* ... swap only the journal i_size and i_size_high, - * and the extent data is not swapped on read */ - i = 15; - } else { - /* direct/indirect journal: swap it all */ - i = 0; + if (!ext2fs_extent_header_verify(sb->s_jnl_blocks, + sizeof(sb->s_jnl_blocks))) { + /* ... swap only the journal i_size */ + sb->s_jnl_blocks[16] = ext2fs_swab32(sb->s_jnl_blocks[16]); + /* and the extent data is not swapped on read */ + return; } - for (; i < 17; i++) + + /* direct/indirect journal: swap it all */ + for (i=0; i < 17; i++) sb->s_jnl_blocks[i] = ext2fs_swab32(sb->s_jnl_blocks[i]); } -void ext2fs_swap_group_desc2(ext2_filsys fs, struct ext2_group_desc *gdp) +void ext2fs_swap_group_desc(struct ext2_group_desc *gdp) { - struct ext4_group_desc *gdp4 = (struct ext4_group_desc *)gdp; - - /* Do the 32-bit parts first */ gdp->bg_block_bitmap = ext2fs_swab32(gdp->bg_block_bitmap); gdp->bg_inode_bitmap = ext2fs_swab32(gdp->bg_inode_bitmap); gdp->bg_inode_table = ext2fs_swab32(gdp->bg_inode_table); @@ -112,41 +103,10 @@ void ext2fs_swap_group_desc2(ext2_filsys fs, struct ext2_group_desc *gdp) gdp->bg_free_inodes_count = ext2fs_swab16(gdp->bg_free_inodes_count); gdp->bg_used_dirs_count = ext2fs_swab16(gdp->bg_used_dirs_count); gdp->bg_flags = ext2fs_swab16(gdp->bg_flags); - gdp->bg_exclude_bitmap_lo = ext2fs_swab32(gdp->bg_exclude_bitmap_lo); - gdp->bg_block_bitmap_csum_lo = - ext2fs_swab16(gdp->bg_block_bitmap_csum_lo); - gdp->bg_inode_bitmap_csum_lo = - ext2fs_swab16(gdp->bg_inode_bitmap_csum_lo); gdp->bg_itable_unused = ext2fs_swab16(gdp->bg_itable_unused); gdp->bg_checksum = ext2fs_swab16(gdp->bg_checksum); - /* If we're 32-bit, we're done */ - if (fs == NULL || EXT2_DESC_SIZE(fs->super) < EXT2_MIN_DESC_SIZE_64BIT) - return; - - /* Swap the 64-bit parts */ - gdp4->bg_block_bitmap_hi = ext2fs_swab32(gdp4->bg_block_bitmap_hi); - gdp4->bg_inode_bitmap_hi = ext2fs_swab32(gdp4->bg_inode_bitmap_hi); - gdp4->bg_inode_table_hi = ext2fs_swab32(gdp4->bg_inode_table_hi); - gdp4->bg_free_blocks_count_hi = - ext2fs_swab16(gdp4->bg_free_blocks_count_hi); - gdp4->bg_free_inodes_count_hi = - ext2fs_swab16(gdp4->bg_free_inodes_count_hi); - gdp4->bg_used_dirs_count_hi = - ext2fs_swab16(gdp4->bg_used_dirs_count_hi); - gdp4->bg_itable_unused_hi = ext2fs_swab16(gdp4->bg_itable_unused_hi); - gdp4->bg_exclude_bitmap_hi = ext2fs_swab16(gdp4->bg_exclude_bitmap_hi); - gdp4->bg_block_bitmap_csum_hi = - ext2fs_swab16(gdp4->bg_block_bitmap_csum_hi); - gdp4->bg_inode_bitmap_csum_hi = - ext2fs_swab16(gdp4->bg_inode_bitmap_csum_hi); -} - -void ext2fs_swap_group_desc(struct ext2_group_desc *gdp) -{ - ext2fs_swap_group_desc2(0, gdp); } - void ext2fs_swap_ext_attr_header(struct ext2_ext_attr_header *to_header, struct ext2_ext_attr_header *from_header) { @@ -258,8 +218,8 @@ void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t, ext2fs_swab16 (f->osd2.linux2.l_i_uid_high); t->osd2.linux2.l_i_gid_high = ext2fs_swab16 (f->osd2.linux2.l_i_gid_high); - t->osd2.linux2.l_i_checksum_lo = - ext2fs_swab16(f->osd2.linux2.l_i_checksum_lo); + t->osd2.linux2.l_i_reserved2 = + ext2fs_swab32(f->osd2.linux2.l_i_reserved2); break; case EXT2_OS_HURD: t->osd1.hurd1.h_i_translator = @@ -293,21 +253,6 @@ void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t, return; } - if (extra_isize >= 4) - t->i_checksum_hi = ext2fs_swab16(f->i_checksum_hi); - if (extra_isize >= 8) - t->i_ctime_extra = ext2fs_swab32(f->i_ctime_extra); - if (extra_isize >= 12) - t->i_mtime_extra = ext2fs_swab32(f->i_mtime_extra); - if (extra_isize >= 16) - t->i_atime_extra = ext2fs_swab32(f->i_atime_extra); - if (extra_isize >= 20) - t->i_crtime = ext2fs_swab32(f->i_crtime); - if (extra_isize >= 24) - t->i_crtime_extra = ext2fs_swab32(f->i_crtime_extra); - if (extra_isize >= 28) - t->i_version_hi = ext2fs_swab32(f->i_version_hi); - i = sizeof(struct ext2_inode) + extra_isize + sizeof(__u32); if (bufsize < (int) i) return; /* no space for EA magic */ @@ -341,12 +286,4 @@ void ext2fs_swap_inode(ext2_filsys fs, struct ext2_inode *t, sizeof(struct ext2_inode)); } -void ext2fs_swap_mmp(struct mmp_struct *mmp) -{ - mmp->mmp_magic = ext2fs_swab32(mmp->mmp_magic); - mmp->mmp_seq = ext2fs_swab32(mmp->mmp_seq); - mmp->mmp_time = ext2fs_swab64(mmp->mmp_time); - mmp->mmp_check_interval = ext2fs_swab16(mmp->mmp_check_interval); -} - #endif diff --git a/lib/ext2fs/symlink.c b/lib/ext2fs/symlink.c deleted file mode 100644 index 4478dffe..00000000 --- a/lib/ext2fs/symlink.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * symlink.c --- make a symlink in the filesystem, based on mkdir.c - * - * Copyright (c) 2012, Intel Corporation. - * All Rights Reserved. - * - * %Begin-Header% - * This file may be redistributed under the terms of the GNU Library - * General Public License, version 2. - * %End-Header% - */ - -#include <stdio.h> -#include <string.h> -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <fcntl.h> -#include <time.h> -#if HAVE_SYS_STAT_H -#include <sys/stat.h> -#endif -#if HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif - -#include "ext2_fs.h" -#include "ext2fs.h" - -errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino, - const char *name, char *target) -{ - ext2_extent_handle_t handle; - errcode_t retval; - struct ext2_inode inode; - ext2_ino_t scratch_ino; - blk64_t blk; - int fastlink; - unsigned int target_len; - char *block_buf = 0; - - EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); - - /* The Linux kernel doesn't allow for links longer than a block */ - target_len = strlen(target); - if (target_len > fs->blocksize) { - retval = EXT2_ET_INVALID_ARGUMENT; - goto cleanup; - } - - /* - * Allocate a data block for slow links - */ - fastlink = (target_len < sizeof(inode.i_block)); - if (!fastlink) { - retval = ext2fs_new_block2(fs, 0, 0, &blk); - if (retval) - goto cleanup; - retval = ext2fs_get_mem(fs->blocksize, &block_buf); - if (retval) - goto cleanup; - } - - /* - * Allocate an inode, if necessary - */ - if (!ino) { - retval = ext2fs_new_inode(fs, parent, LINUX_S_IFLNK | 0755, - 0, &ino); - if (retval) - goto cleanup; - } - - /* - * Create the inode structure.... - */ - memset(&inode, 0, sizeof(struct ext2_inode)); - inode.i_mode = LINUX_S_IFLNK | 0777; - inode.i_uid = inode.i_gid = 0; - ext2fs_iblk_set(fs, &inode, fastlink ? 0 : 1); - inode.i_links_count = 1; - inode.i_size = target_len; - /* The time fields are set by ext2fs_write_new_inode() */ - - if (fastlink) { - /* Fast symlinks, target stored in inode */ - strcpy((char *)&inode.i_block, target); - } else { - /* Slow symlinks, target stored in the first block */ - memset(block_buf, 0, fs->blocksize); - strcpy(block_buf, target); - if (fs->super->s_feature_incompat & - EXT3_FEATURE_INCOMPAT_EXTENTS) { - /* - * The extent bmap is setup after the inode and block - * have been written out below. - */ - inode.i_flags |= EXT4_EXTENTS_FL; - } - } - - /* - * Write out the inode and inode data block. The inode generation - * number is assigned by write_new_inode, which means that the - * operations using ino must come after it. - */ - retval = ext2fs_write_new_inode(fs, ino, &inode); - if (retval) - goto cleanup; - - if (!fastlink) { - retval = ext2fs_bmap2(fs, ino, &inode, NULL, BMAP_SET, 0, NULL, - &blk); - if (retval) - goto cleanup; - - retval = io_channel_write_blk64(fs->io, blk, 1, block_buf); - if (retval) - goto cleanup; - } - - /* - * Link the symlink into the filesystem hierarchy - */ - if (name) { - retval = ext2fs_lookup(fs, parent, name, strlen(name), 0, - &scratch_ino); - if (!retval) { - retval = EXT2_ET_FILE_EXISTS; - goto cleanup; - } - if (retval != EXT2_ET_FILE_NOT_FOUND) - goto cleanup; - retval = ext2fs_link(fs, parent, name, ino, EXT2_FT_SYMLINK); - if (retval) - goto cleanup; - } - - /* - * Update accounting.... - */ - if (!fastlink) - ext2fs_block_alloc_stats2(fs, blk, +1); - ext2fs_inode_alloc_stats2(fs, ino, +1, 0); - -cleanup: - if (block_buf) - ext2fs_free_mem(&block_buf); - return retval; -} diff --git a/lib/ext2fs/tdb.c b/lib/ext2fs/tdb.c index 869c4057..0c82a248 100644 --- a/lib/ext2fs/tdb.c +++ b/lib/ext2fs/tdb.c @@ -107,12 +107,14 @@ typedef int bool; #include "tdb.h" -static TDB_DATA tdb_null; - #ifndef u32 #define u32 unsigned #endif +#ifndef HAVE_GETPAGESIZE +#define getpagesize() 0x2000 +#endif + typedef u32 tdb_len_t; typedef u32 tdb_off_t; @@ -1747,7 +1749,7 @@ static int transaction_sync(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction: fsync failed\n")); return -1; } -#if defined(HAVE_MSYNC) && defined(MS_SYNC) +#ifdef MS_SYNC if (tdb->map_ptr) { tdb_off_t moffset = offset & ~(tdb->page_size-1); if (msync(moffset + (char *)tdb->map_ptr, @@ -3055,6 +3057,8 @@ int tdb_printfreelist(struct tdb_context *tdb) /* file: tdb.c */ +TDB_DATA tdb_null; + /* non-blocking increment of the tdb sequence number if the tdb has been opened using the TDB_SEQNUM flag @@ -3706,17 +3710,17 @@ void tdb_enable_seqnum(struct tdb_context *tdb) static struct tdb_context *tdbs = NULL; -/* This is from a hash algorithm suggested by Rogier Wolff */ +/* This is based on the hash algorithm from gdbm */ static unsigned int default_tdb_hash(TDB_DATA *key) { u32 value; /* Used to compute the hash value. */ u32 i; /* Used to cycle through random values. */ /* Set the initial value from the key size. */ - for (value = 0, i=0; i < key->dsize; i++) - value = value * 256 + key->dptr[i] + (value >> 24) * 241; + for (value = 0x238F13AF * key->dsize, i=0; i < key->dsize; i++) + value = (value + (key->dptr[i] << (i*5 % 24))); - return value; + return (1103515243 * value + 12345); } @@ -3834,7 +3838,7 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags, tdb->hash_fn = hash_fn ? hash_fn : default_tdb_hash; /* cache the page size */ - tdb->page_size = sysconf(_SC_PAGESIZE); + tdb->page_size = getpagesize(); if (tdb->page_size <= 0) { tdb->page_size = 0x2000; } diff --git a/lib/ext2fs/tdb.h b/lib/ext2fs/tdb.h index 732ef0ec..bfcd9436 100644 --- a/lib/ext2fs/tdb.h +++ b/lib/ext2fs/tdb.h @@ -206,6 +206,8 @@ void tdb_dump_all(struct tdb_context *tdb); int tdb_printfreelist(struct tdb_context *tdb); int tdb_validate_freelist(struct tdb_context *tdb, int *pnum_entries); +extern TDB_DATA tdb_null; + #ifdef __cplusplus } #endif diff --git a/lib/ext2fs/test_io.c b/lib/ext2fs/test_io.c index d79c6d58..8d887a86 100644 --- a/lib/ext2fs/test_io.c +++ b/lib/ext2fs/test_io.c @@ -9,12 +9,6 @@ * %End-Header% */ -#if HAVE_SECURE_GETENV -#define _GNU_SOURCE -#endif -#if HAVE_SECURE_GETENV -#define _GNU_SOURCE -#endif #include <stdio.h> #include <string.h> #if HAVE_UNISTD_H @@ -79,8 +73,7 @@ static errcode_t test_write_byte(io_channel channel, unsigned long offset, static errcode_t test_set_option(io_channel channel, const char *option, const char *arg); static errcode_t test_get_stats(io_channel channel, io_stats *stats); -static errcode_t test_discard(io_channel channel, unsigned long long block, - unsigned long long count); + static struct struct_io_manager struct_test_manager = { EXT2_ET_MAGIC_IO_MANAGER, @@ -96,7 +89,6 @@ static struct struct_io_manager struct_test_manager = { test_get_stats, test_read_blk64, test_write_blk64, - test_discard, }; io_manager test_io_manager = &struct_test_manager; @@ -128,7 +120,6 @@ void (*test_io_cb_write_byte) #define TEST_FLAG_FLUSH 0x08 #define TEST_FLAG_DUMP 0x10 #define TEST_FLAG_SET_OPTION 0x20 -#define TEST_FLAG_DISCARD 0x40 static void test_dump_block(io_channel channel, struct test_private_data *data, @@ -178,9 +169,7 @@ static char *safe_getenv(const char *arg) #endif #endif -#if defined(HAVE_SECURE_GETENV) - return secure_getenv(arg); -#elif defined(HAVE___SECURE_GETENV) +#ifdef HAVE___SECURE_GETENV return __secure_getenv(arg); #else return getenv(arg); @@ -198,12 +187,14 @@ static errcode_t test_open(const char *name, int flags, io_channel *channel) return EXT2_ET_BAD_DEVICE_NAME; retval = ext2fs_get_mem(sizeof(struct struct_io_channel), &io); if (retval) - goto cleanup; + return retval; memset(io, 0, sizeof(struct struct_io_channel)); io->magic = EXT2_ET_MAGIC_IO_CHANNEL; retval = ext2fs_get_mem(sizeof(struct test_private_data), &data); - if (retval) + if (retval) { + retval = EXT2_ET_NO_MEMORY; goto cleanup; + } io->manager = test_io_manager; retval = ext2fs_get_mem(strlen(name)+1, &io->name); if (retval) @@ -254,9 +245,6 @@ static errcode_t test_open(const char *name, int flags, io_channel *channel) if ((value = safe_getenv("TEST_IO_WRITE_ABORT")) != NULL) data->write_abort_count = strtoul(value, NULL, 0); - if (data->real) - io->align = data->real->align; - *channel = io; return 0; @@ -302,10 +290,8 @@ static errcode_t test_set_blksize(io_channel channel, int blksize) data = (struct test_private_data *) channel->private_data; EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL); - if (data->real) { + if (data->real) retval = io_channel_set_blksize(data->real, blksize); - channel->align = data->real->align; - } if (data->set_blksize) data->set_blksize(blksize, retval); if (data->flags & TEST_FLAG_SET_BLKSIZE) @@ -509,22 +495,3 @@ static errcode_t test_get_stats(io_channel channel, io_stats *stats) } return retval; } - -static errcode_t test_discard(io_channel channel, unsigned long long block, - unsigned long long count) -{ - struct test_private_data *data; - errcode_t retval = 0; - - EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); - data = (struct test_private_data *) channel->private_data; - EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL); - - if (data->real) - retval = io_channel_discard(data->real, block, count); - if (data->flags & TEST_FLAG_DISCARD) - fprintf(data->outfile, - "Test_io: discard(%llu, %llu) returned %s\n", - block, count, retval ? error_message(retval) : "OK"); - return retval; -} diff --git a/lib/ext2fs/tst_badblocks.c b/lib/ext2fs/tst_badblocks.c index 717b95b9..82090b1c 100644 --- a/lib/ext2fs/tst_badblocks.c +++ b/lib/ext2fs/tst_badblocks.c @@ -227,7 +227,7 @@ int file_test_invalid(badblocks_list bb) fs->super = malloc(SUPERBLOCK_SIZE); memset(fs->super, 0, SUPERBLOCK_SIZE); fs->super->s_first_data_block = 1; - ext2fs_blocks_count_set(fs->super, 100); + fs->super->s_blocks_count = 100; f = tmpfile(); if (!f) { diff --git a/lib/ext2fs/tst_bitmaps.c b/lib/ext2fs/tst_bitmaps.c deleted file mode 100644 index d433e77d..00000000 --- a/lib/ext2fs/tst_bitmaps.c +++ /dev/null @@ -1,652 +0,0 @@ -/* - * tst_bitmaps.c - * - * Copyright (C) 2011 Theodore Ts'o. - * - * %Begin-Header% - * This file may be redistributed under the terms of the GNU Library - * General Public License, version 2. - * %End-Header% - */ - -#include <unistd.h> -#include <stdlib.h> -#include <stdio.h> -#ifdef HAVE_GETOPT_H -#include <getopt.h> -#endif -#include <string.h> -#include <fcntl.h> -#include <time.h> -#include <sys/stat.h> -#include <sys/types.h> -#include "ss/ss.h" - -#include "ext2_fs.h" -#include "ext2fs.h" -#include "ext2fsP.h" - -extern ss_request_table tst_bitmaps_cmds; - -static char subsystem_name[] = "tst_bitmaps"; -static char version[] = "1.0"; - -ext2_filsys test_fs; -int exit_status = 0; - -static int source_file(const char *cmd_file, int sci_idx) -{ - FILE *f; - char buf[256]; - char *cp; - int retval; - int noecho; - - if (strcmp(cmd_file, "-") == 0) - f = stdin; - else { - f = fopen(cmd_file, "r"); - if (!f) { - perror(cmd_file); - exit(1); - } - } - fflush(stdout); - fflush(stderr); - setbuf(stdout, NULL); - setbuf(stderr, NULL); - while (!feof(f)) { - if (fgets(buf, sizeof(buf), f) == NULL) - break; - if (buf[0] == '#') - continue; - noecho = 0; - if (buf[0] == '-') { - noecho = 1; - buf[0] = ' '; - } - cp = strchr(buf, '\n'); - if (cp) - *cp = 0; - cp = strchr(buf, '\r'); - if (cp) - *cp = 0; - if (!noecho) - printf("%s: %s\n", subsystem_name, buf); - retval = ss_execute_line(sci_idx, buf); - if (retval) { - ss_perror(sci_idx, retval, buf); - exit_status++; - } - } - return exit_status; -} - - -/* - * This function resets the libc getopt() function, which keeps - * internal state. Bad design! Stupid libc API designers! No - * biscuit! - * - * BSD-derived getopt() functions require that optind be reset to 1 in - * order to reset getopt() state. This used to be generally accepted - * way of resetting getopt(). However, glibc's getopt() - * has additional getopt() state beyond optind, and requires that - * optind be set zero to reset its state. So the unfortunate state of - * affairs is that BSD-derived versions of getopt() misbehave if - * optind is set to 0 in order to reset getopt(), and glibc's getopt() - * will core dump if optind is set 1 in order to reset getopt(). - * - * More modern versions of BSD require that optreset be set to 1 in - * order to reset getopt(). Sigh. Standards, anyone? - * - * We hide the hair here. - */ -void reset_getopt(void) -{ -#if defined(__GLIBC__) || defined(__linux__) - optind = 0; -#else - optind = 1; -#endif -#ifdef HAVE_OPTRESET - optreset = 1; /* Makes BSD getopt happy */ -#endif -} - -/* - * This function will convert a string to an unsigned long, printing - * an error message if it fails, and returning success or failure in err. - */ -unsigned long parse_ulong(const char *str, const char *cmd, - const char *descr, int *err) -{ - char *tmp; - unsigned long ret; - - ret = strtoul(str, &tmp, 0); - if (*tmp == 0) { - if (err) - *err = 0; - return ret; - } - com_err(cmd, 0, "Bad %s - %s", descr, str); - if (err) - *err = 1; - else - exit(1); - return 0; -} - - -int check_fs_open(char *name) -{ - if (!test_fs) { - com_err(name, 0, "Filesystem not open"); - return 1; - } - return 0; -} - -static void setup_filesystem(const char *name, - unsigned int blocks, unsigned int inodes, - unsigned int type, int flags) -{ - struct ext2_super_block param; - errcode_t retval; - - memset(¶m, 0, sizeof(param)); - ext2fs_blocks_count_set(¶m, blocks); - param.s_inodes_count = inodes; - - retval = ext2fs_initialize("test fs", flags, ¶m, - test_io_manager, &test_fs); - - if (retval) { - com_err(name, retval, "while initializing filesystem"); - return; - } - test_fs->default_bitmap_type = type; - ext2fs_free_block_bitmap(test_fs->block_map); - test_fs->block_map = 0; - ext2fs_free_inode_bitmap(test_fs->inode_map); - test_fs->inode_map = 0; - retval = ext2fs_allocate_block_bitmap(test_fs, "block bitmap", - &test_fs->block_map); - if (retval) { - com_err(name, retval, "while allocating block bitmap"); - goto errout; - } - retval = ext2fs_allocate_inode_bitmap(test_fs, "inode bitmap", - &test_fs->inode_map); - if (retval) { - com_err(name, retval, "while allocating inode bitmap"); - goto errout; - } - return; - -errout: - ext2fs_close(test_fs); - test_fs = 0; -} - -void setup_cmd(int argc, char **argv) -{ - int c, err; - unsigned int blocks = 128; - unsigned int inodes = 0; - unsigned int type = EXT2FS_BMAP64_BITARRAY; - int flags = EXT2_FLAG_64BITS; - - if (test_fs) { - ext2fs_close(test_fs); - test_fs = 0; - } - - reset_getopt(); - while ((c = getopt(argc, argv, "b:i:lt:")) != EOF) { - switch (c) { - case 'b': - blocks = parse_ulong(optarg, argv[0], - "number of blocks", &err); - if (err) - return; - break; - case 'i': - inodes = parse_ulong(optarg, argv[0], - "number of blocks", &err); - if (err) - return; - break; - case 'l': /* Legacy bitmaps */ - flags = 0; - break; - case 't': - type = parse_ulong(optarg, argv[0], - "bitmap backend type", &err); - if (err) - return; - break; - default: - fprintf(stderr, "%s: usage: setup [-b blocks] " - "[-i inodes] [-t type]\n", argv[0]); - return; - } - } - setup_filesystem(argv[0], blocks, inodes, type, flags); -} - -void close_cmd(int argc, char **argv) -{ - if (check_fs_open(argv[0])) - return; - - ext2fs_close(test_fs); - test_fs = 0; -} - - -void dump_bitmap(ext2fs_generic_bitmap bmap, unsigned int start, unsigned num) -{ - unsigned char *buf; - errcode_t retval; - int i, len = (num - start + 7) / 8; - - buf = malloc(len); - if (!buf) { - com_err("dump_bitmap", 0, "couldn't allocate buffer"); - return; - } - memset(buf, 0, len); - retval = ext2fs_get_generic_bmap_range(bmap, (__u64) start, num, buf); - if (retval) { - com_err("dump_bitmap", retval, - "while calling ext2fs_generic_bmap_range"); - free(buf); - return; - } - for (i=0; i < len; i++) - printf("%02x", buf[i]); - printf("\n"); - printf("bits set: %u\n", ext2fs_bitcount(buf, len)); - free(buf); -} - -void dump_inode_bitmap_cmd(int argc, char **argv) -{ - if (check_fs_open(argv[0])) - return; - - printf("inode bitmap: "); - dump_bitmap(test_fs->inode_map, 1, test_fs->super->s_inodes_count); -} - -void dump_block_bitmap_cmd(int argc, char **argv) -{ - if (check_fs_open(argv[0])) - return; - - printf("block bitmap: "); - dump_bitmap(test_fs->block_map, test_fs->super->s_first_data_block, - test_fs->super->s_blocks_count); -} - -void do_setb(int argc, char *argv[]) -{ - unsigned int block, num; - int err; - int test_result, op_result; - - if (check_fs_open(argv[0])) - return; - - if (argc != 2 && argc != 3) { - com_err(argv[0], 0, "Usage: setb <block> [num]"); - return; - } - - block = parse_ulong(argv[1], argv[0], "block", &err); - if (err) - return; - - if (argc == 3) { - num = parse_ulong(argv[2], argv[0], "num", &err); - if (err) - return; - - ext2fs_mark_block_bitmap_range2(test_fs->block_map, - block, num); - printf("Marking blocks %u to %u\n", block, block + num - 1); - return; - } - - test_result = ext2fs_test_block_bitmap2(test_fs->block_map, block); - op_result = ext2fs_mark_block_bitmap2(test_fs->block_map, block); - printf("Setting block %u, was %s before\n", block, op_result ? - "set" : "clear"); - if (!test_result != !op_result) - com_err(argv[0], 0, "*ERROR* test_result different! (%d, %d)", - test_result, op_result); -} - -void do_clearb(int argc, char *argv[]) -{ - unsigned int block, num; - int err; - int test_result, op_result; - - if (check_fs_open(argv[0])) - return; - - if (argc != 2 && argc != 3) { - com_err(argv[0], 0, "Usage: clearb <block> [num]"); - return; - } - - block = parse_ulong(argv[1], argv[0], "block", &err); - if (err) - return; - - if (argc == 3) { - num = parse_ulong(argv[2], argv[0], "num", &err); - if (err) - return; - - ext2fs_unmark_block_bitmap_range2(test_fs->block_map, - block, num); - printf("Clearing blocks %u to %u\n", block, block + num - 1); - return; - } - - test_result = ext2fs_test_block_bitmap2(test_fs->block_map, block); - op_result = ext2fs_unmark_block_bitmap2(test_fs->block_map, block); - printf("Clearing block %u, was %s before\n", block, op_result ? - "set" : "clear"); - if (!test_result != !op_result) - com_err(argv[0], 0, "*ERROR* test_result different! (%d, %d)", - test_result, op_result); -} - -void do_testb(int argc, char *argv[]) -{ - unsigned int block, num; - int err; - int test_result; - - if (check_fs_open(argv[0])) - return; - - if (argc != 2 && argc != 3) { - com_err(argv[0], 0, "Usage: testb <block> [num]"); - return; - } - - block = parse_ulong(argv[1], argv[0], "block", &err); - if (err) - return; - - if (argc == 3) { - num = parse_ulong(argv[2], argv[0], "num", &err); - if (err) - return; - - test_result = - ext2fs_test_block_bitmap_range2(test_fs->block_map, - block, num); - printf("Blocks %u to %u are %sall clear.\n", - block, block + num - 1, test_result ? "" : "NOT "); - return; - } - - test_result = ext2fs_test_block_bitmap2(test_fs->block_map, block); - printf("Block %u is %s\n", block, test_result ? "set" : "clear"); -} - -void do_ffzb(int argc, char *argv[]) -{ - unsigned int start, end; - int err; - errcode_t retval; - blk64_t out; - - if (check_fs_open(argv[0])) - return; - - if (argc != 3 && argc != 3) { - com_err(argv[0], 0, "Usage: ffzb <start> <end>"); - return; - } - - start = parse_ulong(argv[1], argv[0], "start", &err); - if (err) - return; - - end = parse_ulong(argv[2], argv[0], "end", &err); - if (err) - return; - - retval = ext2fs_find_first_zero_block_bitmap2(test_fs->block_map, - start, end, &out); - if (retval) { - printf("ext2fs_find_first_zero_block_bitmap2() returned %s\n", - error_message(retval)); - return; - } - printf("First unmarked block is %llu\n", out); -} - - -void do_zerob(int argc, char *argv[]) -{ - if (check_fs_open(argv[0])) - return; - - printf("Clearing block bitmap.\n"); - ext2fs_clear_block_bitmap(test_fs->block_map); -} - -void do_seti(int argc, char *argv[]) -{ - unsigned int inode; - int err; - int test_result, op_result; - - if (check_fs_open(argv[0])) - return; - - if (argc != 2) { - com_err(argv[0], 0, "Usage: seti <inode>"); - return; - } - - inode = parse_ulong(argv[1], argv[0], "inode", &err); - if (err) - return; - - test_result = ext2fs_test_inode_bitmap2(test_fs->inode_map, inode); - op_result = ext2fs_mark_inode_bitmap2(test_fs->inode_map, inode); - printf("Setting inode %u, was %s before\n", inode, op_result ? - "set" : "clear"); - if (!test_result != !op_result) { - com_err(argv[0], 0, "*ERROR* test_result different! (%d, %d)", - test_result, op_result); - exit_status++; - } -} - -void do_cleari(int argc, char *argv[]) -{ - unsigned int inode; - int err; - int test_result, op_result; - - if (check_fs_open(argv[0])) - return; - - if (argc != 2) { - com_err(argv[0], 0, "Usage: clearb <inode>"); - return; - } - - inode = parse_ulong(argv[1], argv[0], "inode", &err); - if (err) - return; - - test_result = ext2fs_test_inode_bitmap2(test_fs->inode_map, inode); - op_result = ext2fs_unmark_inode_bitmap2(test_fs->inode_map, inode); - printf("Clearing inode %u, was %s before\n", inode, op_result ? - "set" : "clear"); - if (!test_result != !op_result) { - com_err(argv[0], 0, "*ERROR* test_result different! (%d, %d)", - test_result, op_result); - exit_status++; - } -} - -void do_testi(int argc, char *argv[]) -{ - unsigned int inode; - int err; - int test_result; - - if (check_fs_open(argv[0])) - return; - - if (argc != 2) { - com_err(argv[0], 0, "Usage: testb <inode>"); - return; - } - - inode = parse_ulong(argv[1], argv[0], "inode", &err); - if (err) - return; - - test_result = ext2fs_test_inode_bitmap2(test_fs->inode_map, inode); - printf("Inode %u is %s\n", inode, test_result ? "set" : "clear"); -} - -void do_ffzi(int argc, char *argv[]) -{ - unsigned int start, end; - int err; - errcode_t retval; - ext2_ino_t out; - - if (check_fs_open(argv[0])) - return; - - if (argc != 3 && argc != 3) { - com_err(argv[0], 0, "Usage: ffzi <start> <end>"); - return; - } - - start = parse_ulong(argv[1], argv[0], "start", &err); - if (err) - return; - - end = parse_ulong(argv[2], argv[0], "end", &err); - if (err) - return; - - retval = ext2fs_find_first_zero_inode_bitmap2(test_fs->inode_map, - start, end, &out); - if (retval) { - printf("ext2fs_find_first_zero_inode_bitmap2() returned %s\n", - error_message(retval)); - return; - } - printf("First unmarked inode is %u\n", out); -} - - -void do_zeroi(int argc, char *argv[]) -{ - if (check_fs_open(argv[0])) - return; - - printf("Clearing inode bitmap.\n"); - ext2fs_clear_inode_bitmap(test_fs->inode_map); -} - -int main(int argc, char **argv) -{ - unsigned int blocks = 128; - unsigned int inodes = 0; - unsigned int type = EXT2FS_BMAP64_BITARRAY; - int c, err, code; - char *request = (char *)NULL; - char *cmd_file = 0; - int sci_idx; - int flags = EXT2_FLAG_64BITS; - - add_error_table(&et_ss_error_table); - add_error_table(&et_ext2_error_table); - while ((c = getopt (argc, argv, "b:i:lt:R:f:")) != EOF) { - switch (c) { - case 'b': - blocks = parse_ulong(optarg, argv[0], - "number of blocks", &err); - if (err) - exit(1); - break; - case 'i': - inodes = parse_ulong(optarg, argv[0], - "number of blocks", &err); - if (err) - exit(1); - break; - case 'l': /* Legacy bitmaps */ - flags = 0; - break; - case 't': - type = parse_ulong(optarg, argv[0], - "bitmap backend type", &err); - if (err) - exit(1); - break; - case 'R': - request = optarg; - break; - case 'f': - cmd_file = optarg; - break; - default: - com_err(argv[0], 0, "Usage: %s [-R request] " - "[-f cmd_file]", subsystem_name); - exit(1); - } - } - - sci_idx = ss_create_invocation(subsystem_name, version, - (char *)NULL, &tst_bitmaps_cmds, &code); - if (code) { - ss_perror(sci_idx, code, "creating invocation"); - exit(1); - } - - (void) ss_add_request_table (sci_idx, &ss_std_requests, 1, &code); - if (code) { - ss_perror(sci_idx, code, "adding standard requests"); - exit (1); - } - - printf("%s %s. Type '?' for a list of commands.\n\n", - subsystem_name, version); - - setup_filesystem(argv[0], blocks, inodes, type, flags); - - if (request) { - code = ss_execute_line(sci_idx, request); - if (code) { - ss_perror(sci_idx, code, request); - exit_status++; - } - } else if (cmd_file) { - exit_status = source_file(cmd_file, sci_idx); - } else { - ss_listen(sci_idx); - } - - exit(exit_status); -} - diff --git a/lib/ext2fs/tst_bitmaps_cmd.ct b/lib/ext2fs/tst_bitmaps_cmd.ct deleted file mode 100644 index 1e1e5d34..00000000 --- a/lib/ext2fs/tst_bitmaps_cmd.ct +++ /dev/null @@ -1,45 +0,0 @@ -command_table tst_bitmaps_cmds; - -request setup_cmd, "Setup file system", - setup; - -request close_cmd, "Close file system", - close; - -request dump_inode_bitmap_cmd, "Dump the inode bitmap", - dump_inode_bitmap, dump_ib; - -request dump_block_bitmap_cmd, "Dump the block bitmap", - dump_block_bitmap, dump_bb; - -request do_setb, "Set block", - set_block, setb; - -request do_clearb, "Clear block", - clear_block, clearb; - -request do_testb, "Test block", - test_block, testb; - -request do_ffzb, "Find first zero block", - find_first_zero_block, ffzb; - -request do_zerob, "Clear block bitmap", - clear_block_bitmap, zerob; - -request do_seti, "Set inode", - set_inode, seti; - -request do_cleari, "Clear inode", - clear_inode, cleari; - -request do_testi, "Test inode", - test_inode, testi; - -request do_ffzi, "Find first zero inode", - find_first_zero_inode, ffzi; - -request do_zeroi, "Clear inode bitmap", - clear_inode_bitmap, zeroi; - -end; diff --git a/lib/ext2fs/tst_bitmaps_cmds b/lib/ext2fs/tst_bitmaps_cmds deleted file mode 100644 index 31e2a600..00000000 --- a/lib/ext2fs/tst_bitmaps_cmds +++ /dev/null @@ -1,99 +0,0 @@ -setb 12 -setb 12 -clearb 12 -clearb 12 -setb 12 -setb 14 -setb 16 -testb 13 -testb 15 -testb 12 -testb 14 -setb 13 -setb 15 -testb 12 -testb 11 -testb 15 -testb 16 -dump_bb -ffzb 11 16 -ffzb 12 16 -ffzb 12 20 -clearb 13 -ffzb 12 20 -setb 13 -clearb 12 7 -testb 12 7 -setb 15 -testb 12 7 -clearb 15 -testb 12 7 -setb 12 7 -dump_bb -seti 2 -seti 5 -seti 4 -seti 3 -seti 4 -seti 5 -testi 6 -testi 1 -dump_ib -ffzi 1 6 -ffzi 2 5 -ffzi 2 6 -cleari 4 -ffzi 2 6 -zeroi -testi 5 -seti 5 -seti 5 -cleari 5 -cleari 5 -testi 17 -testi 6 -testi 4 -clearb 7 12 -dump_bb -setb 1 -dump_bb -setb 2 -dump_bb -setb 3 -dump_bb -setb 4 -dump_bb -setb 5 -dump_bb -setb 6 -dump_bb -setb 7 -dump_bb -setb 8 -dump_bb -setb 10 -setb 12 -setb 14 -setb 17 -setb 19 -setb 24 -setb 26 -setb 27 -setb 30 -setb 31 -setb 32 -setb 35 -setb 39 -setb 40 -setb 44 -setb 46 -setb 47 -setb 49 -setb 51 -setb 52 -clearb 2 -clearb 3 -clearb 7 -dump_bb -quit - diff --git a/lib/ext2fs/tst_bitmaps_exp b/lib/ext2fs/tst_bitmaps_exp deleted file mode 100644 index 2d62b66d..00000000 --- a/lib/ext2fs/tst_bitmaps_exp +++ /dev/null @@ -1,211 +0,0 @@ -tst_bitmaps 1.0. Type '?' for a list of commands. - -tst_bitmaps: setb 12 -Setting block 12, was clear before -tst_bitmaps: setb 12 -Setting block 12, was set before -tst_bitmaps: clearb 12 -Clearing block 12, was set before -tst_bitmaps: clearb 12 -Clearing block 12, was clear before -tst_bitmaps: setb 12 -Setting block 12, was clear before -tst_bitmaps: setb 14 -Setting block 14, was clear before -tst_bitmaps: setb 16 -Setting block 16, was clear before -tst_bitmaps: testb 13 -Block 13 is clear -tst_bitmaps: testb 15 -Block 15 is clear -tst_bitmaps: testb 12 -Block 12 is set -tst_bitmaps: testb 14 -Block 14 is set -tst_bitmaps: setb 13 -Setting block 13, was clear before -tst_bitmaps: setb 15 -Setting block 15, was clear before -tst_bitmaps: testb 12 -Block 12 is set -tst_bitmaps: testb 11 -Block 11 is clear -tst_bitmaps: testb 15 -Block 15 is set -tst_bitmaps: testb 16 -Block 16 is set -tst_bitmaps: dump_bb -block bitmap: 00f80000000000000000000000000000 -bits set: 5 -tst_bitmaps: ffzb 11 16 -First unmarked block is 11 -tst_bitmaps: ffzb 12 16 -ext2fs_find_first_zero_block_bitmap2() returned No such file or directory -tst_bitmaps: ffzb 12 20 -First unmarked block is 17 -tst_bitmaps: clearb 13 -Clearing block 13, was set before -tst_bitmaps: ffzb 12 20 -First unmarked block is 13 -tst_bitmaps: setb 13 -Setting block 13, was clear before -tst_bitmaps: clearb 12 7 -Clearing blocks 12 to 18 -tst_bitmaps: testb 12 7 -Blocks 12 to 18 are all clear. -tst_bitmaps: setb 15 -Setting block 15, was clear before -tst_bitmaps: testb 12 7 -Blocks 12 to 18 are NOT all clear. -tst_bitmaps: clearb 15 -Clearing block 15, was set before -tst_bitmaps: testb 12 7 -Blocks 12 to 18 are all clear. -tst_bitmaps: setb 12 7 -Marking blocks 12 to 18 -tst_bitmaps: dump_bb -block bitmap: 00f80300000000000000000000000000 -bits set: 7 -tst_bitmaps: seti 2 -Setting inode 2, was clear before -tst_bitmaps: seti 5 -Setting inode 5, was clear before -tst_bitmaps: seti 4 -Setting inode 4, was clear before -tst_bitmaps: seti 3 -Setting inode 3, was clear before -tst_bitmaps: seti 4 -Setting inode 4, was set before -tst_bitmaps: seti 5 -Setting inode 5, was set before -tst_bitmaps: testi 6 -Inode 6 is clear -tst_bitmaps: testi 1 -Inode 1 is clear -tst_bitmaps: dump_ib -inode bitmap: 1e000000 -bits set: 4 -tst_bitmaps: ffzi 1 6 -First unmarked inode is 1 -tst_bitmaps: ffzi 2 5 -ext2fs_find_first_zero_inode_bitmap2() returned No such file or directory -tst_bitmaps: ffzi 2 6 -First unmarked inode is 6 -tst_bitmaps: cleari 4 -Clearing inode 4, was set before -tst_bitmaps: ffzi 2 6 -First unmarked inode is 4 -tst_bitmaps: zeroi -Clearing inode bitmap. -tst_bitmaps: testi 5 -Inode 5 is clear -tst_bitmaps: seti 5 -Setting inode 5, was clear before -tst_bitmaps: seti 5 -Setting inode 5, was set before -tst_bitmaps: cleari 5 -Clearing inode 5, was set before -tst_bitmaps: cleari 5 -Clearing inode 5, was clear before -tst_bitmaps: testi 17 -Inode 17 is clear -tst_bitmaps: testi 6 -Inode 6 is clear -tst_bitmaps: testi 4 -Inode 4 is clear -tst_bitmaps: clearb 7 12 -Clearing blocks 7 to 18 -tst_bitmaps: dump_bb -block bitmap: 00000000000000000000000000000000 -bits set: 0 -tst_bitmaps: setb 1 -Setting block 1, was clear before -tst_bitmaps: dump_bb -block bitmap: 01000000000000000000000000000000 -bits set: 1 -tst_bitmaps: setb 2 -Setting block 2, was clear before -tst_bitmaps: dump_bb -block bitmap: 03000000000000000000000000000000 -bits set: 2 -tst_bitmaps: setb 3 -Setting block 3, was clear before -tst_bitmaps: dump_bb -block bitmap: 07000000000000000000000000000000 -bits set: 3 -tst_bitmaps: setb 4 -Setting block 4, was clear before -tst_bitmaps: dump_bb -block bitmap: 0f000000000000000000000000000000 -bits set: 4 -tst_bitmaps: setb 5 -Setting block 5, was clear before -tst_bitmaps: dump_bb -block bitmap: 1f000000000000000000000000000000 -bits set: 5 -tst_bitmaps: setb 6 -Setting block 6, was clear before -tst_bitmaps: dump_bb -block bitmap: 3f000000000000000000000000000000 -bits set: 6 -tst_bitmaps: setb 7 -Setting block 7, was clear before -tst_bitmaps: dump_bb -block bitmap: 7f000000000000000000000000000000 -bits set: 7 -tst_bitmaps: setb 8 -Setting block 8, was clear before -tst_bitmaps: dump_bb -block bitmap: ff000000000000000000000000000000 -bits set: 8 -tst_bitmaps: setb 10 -Setting block 10, was clear before -tst_bitmaps: setb 12 -Setting block 12, was clear before -tst_bitmaps: setb 14 -Setting block 14, was clear before -tst_bitmaps: setb 17 -Setting block 17, was clear before -tst_bitmaps: setb 19 -Setting block 19, was clear before -tst_bitmaps: setb 24 -Setting block 24, was clear before -tst_bitmaps: setb 26 -Setting block 26, was clear before -tst_bitmaps: setb 27 -Setting block 27, was clear before -tst_bitmaps: setb 30 -Setting block 30, was clear before -tst_bitmaps: setb 31 -Setting block 31, was clear before -tst_bitmaps: setb 32 -Setting block 32, was clear before -tst_bitmaps: setb 35 -Setting block 35, was clear before -tst_bitmaps: setb 39 -Setting block 39, was clear before -tst_bitmaps: setb 40 -Setting block 40, was clear before -tst_bitmaps: setb 44 -Setting block 44, was clear before -tst_bitmaps: setb 46 -Setting block 46, was clear before -tst_bitmaps: setb 47 -Setting block 47, was clear before -tst_bitmaps: setb 49 -Setting block 49, was clear before -tst_bitmaps: setb 51 -Setting block 51, was clear before -tst_bitmaps: setb 52 -Setting block 52, was clear before -tst_bitmaps: clearb 2 -Clearing block 2, was set before -tst_bitmaps: clearb 3 -Clearing block 3, was set before -tst_bitmaps: clearb 7 -Clearing block 7, was set before -tst_bitmaps: dump_bb -block bitmap: b92a85e6c4680d000000000000000000 -bits set: 25 -tst_bitmaps: quit -tst_bitmaps: diff --git a/lib/ext2fs/tst_bitops.c b/lib/ext2fs/tst_bitops.c index b64735cd..f57a2e46 100644 --- a/lib/ext2fs/tst_bitops.c +++ b/lib/ext2fs/tst_bitops.c @@ -169,125 +169,5 @@ int main(int argc, char **argv) printf("ext2fs_fast_set_bit big_test successful\n"); - /* Repeat foregoing tests for 64-bit bitops */ - - /* Test test_bit */ - for (i=0,j=0; i < size; i++) { - if (ext2fs_test_bit64(i, bitarray)) { - if (bits_list[j] == i) { - j++; - } else { - printf("64-bit: Bit %d set, not expected\n", - i); - exit(1); - } - } else { - if (bits_list[j] == i) { - printf("64-bit: " - "Expected bit %d to be clear.\n", i); - exit(1); - } - } - } - printf("64-bit: ext2fs_test_bit appears to be correct\n"); - - /* Test ext2fs_set_bit */ - memset(testarray, 0, sizeof(testarray)); - for (i=0; bits_list[i] > 0; i++) { - ext2fs_set_bit64(bits_list[i], testarray); - } - if (memcmp(testarray, bitarray, sizeof(testarray)) == 0) { - printf("64-bit: ext2fs_set_bit test succeeded.\n"); - } else { - printf("64-bit: ext2fs_set_bit test failed.\n"); - for (i=0; i < sizeof(testarray); i++) { - printf("%02x ", testarray[i]); - } - printf("\n"); - exit(1); - } - for (i=0; bits_list[i] > 0; i++) { - ext2fs_clear_bit64(bits_list[i], testarray); - } - for (i=0; i < sizeof(testarray); i++) { - if (testarray[i]) { - printf("64-bit: ext2fs_clear_bit failed, " - "testarray[%d] is %d\n", i, testarray[i]); - exit(1); - } - } - printf("64-bit: ext2fs_clear_bit test succeed.\n"); - - /* Do bigarray test */ - bigarray = malloc(1 << 29); - if (!bigarray) { - fprintf(stderr, "Failed to allocate scratch memory!\n"); - exit(1); - } - - bigarray[BIG_TEST_BIT >> 3] = 0; - - ext2fs_set_bit64(BIG_TEST_BIT, bigarray); - printf("64-bit: big bit number (%u) test: %d, expected %d\n", - BIG_TEST_BIT, bigarray[BIG_TEST_BIT >> 3], - (1 << (BIG_TEST_BIT & 7))); - if (bigarray[BIG_TEST_BIT >> 3] != (1 << (BIG_TEST_BIT & 7))) - exit(1); - - ext2fs_clear_bit64(BIG_TEST_BIT, bigarray); - - printf("64-bit: big bit number (%u) test: %d, expected 0\n", - BIG_TEST_BIT, - bigarray[BIG_TEST_BIT >> 3]); - if (bigarray[BIG_TEST_BIT >> 3] != 0) - exit(1); - - printf("64-bit: ext2fs_set_bit big_test successful\n"); - - /* Now test ext2fs_fast_set_bit */ - memset(testarray, 0, sizeof(testarray)); - for (i=0; bits_list[i] > 0; i++) { - ext2fs_fast_set_bit64(bits_list[i], testarray); - } - if (memcmp(testarray, bitarray, sizeof(testarray)) == 0) { - printf("64-bit: ext2fs_fast_set_bit test succeeded.\n"); - } else { - printf("64-bit: ext2fs_fast_set_bit test failed.\n"); - for (i=0; i < sizeof(testarray); i++) { - printf("%02x ", testarray[i]); - } - printf("\n"); - exit(1); - } - for (i=0; bits_list[i] > 0; i++) { - ext2fs_clear_bit64(bits_list[i], testarray); - } - for (i=0; i < sizeof(testarray); i++) { - if (testarray[i]) { - printf("64-bit: ext2fs_clear_bit failed, " - "testarray[%d] is %d\n", i, testarray[i]); - exit(1); - } - } - printf("64-bit: ext2fs_clear_bit test succeed.\n"); - - bigarray[BIG_TEST_BIT >> 3] = 0; - - ext2fs_fast_set_bit64(BIG_TEST_BIT, bigarray); - printf("64-bit: big bit number (%u) test: %d, expected %d\n", - BIG_TEST_BIT, bigarray[BIG_TEST_BIT >> 3], - (1 << (BIG_TEST_BIT & 7))); - if (bigarray[BIG_TEST_BIT >> 3] != (1 << (BIG_TEST_BIT & 7))) - exit(1); - - ext2fs_fast_clear_bit64(BIG_TEST_BIT, bigarray); - - printf("64-bit: big bit number (%u) test: %d, expected 0\n", - BIG_TEST_BIT, bigarray[BIG_TEST_BIT >> 3]); - if (bigarray[BIG_TEST_BIT >> 3] != 0) - exit(1); - - printf("64-bit: ext2fs_fast_set_bit big_test successful\n"); - exit(0); } diff --git a/lib/ext2fs/tst_fs_struct.c b/lib/ext2fs/tst_fs_struct.c deleted file mode 100644 index 6f44df18..00000000 --- a/lib/ext2fs/tst_fs_struct.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * This testing program checks the offset of the ext2_filsys structure - * - * Copyright (C) 2007 by Theodore Ts'o. - * - * %Begin-Header% - * This file may be redistributed under the terms of the GNU Library - * General Public License, version 2. - * %End-Header% - */ - -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> - -#include "ext2fs.h" - -struct struct_ext2_filsys fs; - -#ifndef offsetof -#define offsetof(type, member) __builtin_offsetof (type, member) -#endif -#define check_field(x) cur_offset = do_field(#x, sizeof(fs.x), \ - offsetof(struct struct_ext2_filsys, x), \ - cur_offset) - -static int do_field(const char *field, size_t size, int offset, int cur_offset) -{ - if (offset != cur_offset) { - printf("\t(padding %d bytes?)\n", offset - cur_offset); - } - printf("%8d %-30s %3u\n", offset, field, (unsigned) size); - return offset + size; -} - -int main(int argc, char **argv) -{ -#if (__GNUC__ >= 4) - int cur_offset = 0; - - printf("%8s %-30s %3s\n", "offset", "field", "size"); - check_field(magic); - check_field(io); - check_field(flags); - check_field(device_name); - check_field(super); - check_field(blocksize); - check_field(fragsize); - check_field(group_desc_count); - check_field(desc_blocks); - check_field(group_desc); - check_field(inode_blocks_per_group); - check_field(inode_map); - check_field(block_map); - check_field(get_blocks); - check_field(check_directory); - check_field(write_bitmaps); - check_field(read_inode); - check_field(write_inode); - check_field(badblocks); - check_field(dblist); - check_field(stride); - check_field(orig_super); - check_field(image_header); - check_field(umask); - check_field(now); - check_field(cluster_ratio_bits); - check_field(reserved); - check_field(priv_data); - check_field(icache); - check_field(image_io); - check_field(get_alloc_block); - check_field(block_alloc_stats); - check_field(mmp_buf); - check_field(mmp_cmp); - check_field(mmp_fd); - check_field(mmp_last_written); - printf("Ending offset is %d\n\n", cur_offset); -#endif - exit(0); -} diff --git a/lib/ext2fs/tst_inode_size.c b/lib/ext2fs/tst_inode_size.c deleted file mode 100644 index 3f0ab82c..00000000 --- a/lib/ext2fs/tst_inode_size.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * This testing program makes sure the ext2_inode structure is 1024 bytes long - * - * Copyright (C) 2007 by Theodore Ts'o. - * - * %Begin-Header% - * This file may be redistributed under the terms of the GNU Library - * General Public License, version 2. - * %End-Header% - */ - -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> - -#include "ext2_fs.h" - -struct ext2_inode_large inode; - -#ifndef offsetof -#define offsetof(type, member) __builtin_offsetof(type, member) -#endif - -#define check_field(x, s) cur_offset = do_field(#x, s, sizeof(inode.x), \ - offsetof(struct ext2_inode_large, x), \ - cur_offset) - -static int do_field(const char *field, unsigned size, unsigned cur_size, - unsigned offset, unsigned cur_offset) -{ - if (size != cur_size) { - printf("error: %s size %u should be %u\n", - field, cur_size, size); - exit(1); - } - if (offset != cur_offset) { - printf("error: %s offset %u should be %u\n", - field, cur_offset, offset); - exit(1); - } - printf("%8d %-30s %3u\n", offset, field, (unsigned) size); - return offset + size; -} - -int main(int argc, char **argv) -{ -#if (__GNUC__ >= 4) - int cur_offset = 0; - - printf("%8s %-30s %3s\n", "offset", "field", "size"); - check_field(i_mode, 2); - check_field(i_uid, 2); - check_field(i_size, 4); - check_field(i_atime, 4); - check_field(i_ctime, 4); - check_field(i_mtime, 4); - check_field(i_dtime, 4); - check_field(i_gid, 2); - check_field(i_links_count, 2); - check_field(i_blocks, 4); - check_field(i_flags, 4); - check_field(osd1.linux1.l_i_version, 4); - check_field(i_block, 15 * 4); - check_field(i_generation, 4); - check_field(i_file_acl, 4); - check_field(i_size_high, 4); - check_field(i_faddr, 4); - check_field(osd2.linux2.l_i_blocks_hi, 2); - check_field(osd2.linux2.l_i_file_acl_high, 2); - check_field(osd2.linux2.l_i_uid_high, 2); - check_field(osd2.linux2.l_i_gid_high, 2); - check_field(osd2.linux2.l_i_checksum_lo, 2); - check_field(osd2.linux2.l_i_reserved, 2); - do_field("Small inode end", 0, 0, cur_offset, 128); - check_field(i_extra_isize, 2); - check_field(i_checksum_hi, 2); - check_field(i_ctime_extra, 4); - check_field(i_mtime_extra, 4); - check_field(i_atime_extra, 4); - check_field(i_crtime, 4); - check_field(i_crtime_extra, 4); - check_field(i_version_hi, 4); - /* This size will change as new fields are added */ - do_field("Large inode end", 0, 0, cur_offset, sizeof(inode)); -#endif - return 0; -} diff --git a/lib/ext2fs/tst_iscan.c b/lib/ext2fs/tst_iscan.c index efeeb772..443b1b45 100644 --- a/lib/ext2fs/tst_iscan.c +++ b/lib/ext2fs/tst_iscan.c @@ -25,7 +25,7 @@ #include "ext2_fs.h" #include "ext2fs.h" -blk64_t test_vec[] = { 8, 12, 24, 34, 43, 44, 100, 0 }; +blk_t test_vec[] = { 8, 12, 24, 34, 43, 44, 100, 0 }; ext2_filsys test_fs; ext2fs_block_bitmap bad_block_map, touched_map; @@ -35,7 +35,7 @@ badblocks_list test_badblocks; int first_no_comma = 1; int failed = 0; -static void iscan_test_read_blk64(unsigned long long block, int count, errcode_t err) +static void test_read_blk(unsigned long block, int count, errcode_t err) { int i; @@ -45,25 +45,20 @@ static void iscan_test_read_blk64(unsigned long long block, int count, errcode_t printf(", "); if (count > 1) - printf("%llu-%llu", block, block+count-1); + printf("%lu-%lu", block, block+count-1); else - printf("%llu", block); + printf("%lu", block); for (i=0; i < count; i++, block++) { - if (ext2fs_test_block_bitmap2(touched_map, block)) { - printf("\nDuplicate block?!? --- %llu\n", block); + if (ext2fs_test_block_bitmap(touched_map, block)) { + printf("\nDuplicate block?!? --- %lu\n", block); failed++; first_no_comma = 1; } - ext2fs_mark_block_bitmap2(touched_map, block); + ext2fs_mark_block_bitmap(touched_map, block); } } -static void iscan_test_read_blk(unsigned long block, int count, errcode_t err) -{ - iscan_test_read_blk64(block, count, err); -} - /* * Setup the variables for doing the inode scan test. */ @@ -76,13 +71,12 @@ static void setup(void) initialize_ext2_error_table(); memset(¶m, 0, sizeof(param)); - ext2fs_blocks_count_set(¶m, 12000); + param.s_blocks_count = 12000; - test_io_cb_read_blk = iscan_test_read_blk; - test_io_cb_read_blk64 = iscan_test_read_blk64; + test_io_cb_read_blk = test_read_blk; - retval = ext2fs_initialize("test fs", EXT2_FLAG_64BITS, ¶m, + retval = ext2fs_initialize("test fs", 0, ¶m, test_io_manager, &test_fs); if (retval) { com_err("setup", retval, @@ -129,7 +123,7 @@ static void setup(void) "while adding test vector %d", i); exit(1); } - ext2fs_mark_block_bitmap2(bad_block_map, test_vec[i]); + ext2fs_mark_block_bitmap(bad_block_map, test_vec[i]); } test_fs->badblocks = test_badblocks; } @@ -158,7 +152,7 @@ static void iterate(void) while (ino) { retval = ext2fs_get_next_inode(scan, &ino, &inode); if (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE) { - ext2fs_mark_inode_bitmap2(bad_inode_map, ino); + ext2fs_mark_inode_bitmap(bad_inode_map, ino); continue; } if (retval) { @@ -177,30 +171,30 @@ static void iterate(void) static void check_map(void) { int i, j, first=1; - blk64_t blk; + unsigned long blk; for (i=0; test_vec[i]; i++) { - if (ext2fs_test_block_bitmap2(touched_map, test_vec[i])) { - printf("Bad block was touched --- %llu\n", test_vec[i]); + if (ext2fs_test_block_bitmap(touched_map, test_vec[i])) { + printf("Bad block was touched --- %u\n", test_vec[i]); failed++; first_no_comma = 1; } - ext2fs_mark_block_bitmap2(touched_map, test_vec[i]); + ext2fs_mark_block_bitmap(touched_map, test_vec[i]); } for (i = 0; i < test_fs->group_desc_count; i++) { - for (j=0, blk = ext2fs_inode_table_loc(test_fs, i); + for (j=0, blk = test_fs->group_desc[i].bg_inode_table; j < test_fs->inode_blocks_per_group; j++, blk++) { - if (!ext2fs_test_block_bitmap2(touched_map, blk) && - !ext2fs_test_block_bitmap2(bad_block_map, blk)) { - printf("Missing block --- %llu\n", blk); + if (!ext2fs_test_block_bitmap(touched_map, blk) && + !ext2fs_test_block_bitmap(bad_block_map, blk)) { + printf("Missing block --- %lu\n", blk); failed++; } } } printf("Bad inodes: "); for (i=1; i <= test_fs->super->s_inodes_count; i++) { - if (ext2fs_test_inode_bitmap2(bad_inode_map, i)) { + if (ext2fs_test_inode_bitmap(bad_inode_map, i)) { if (first) first = 0; else diff --git a/lib/ext2fs/tst_super_size.c b/lib/ext2fs/tst_super_size.c index eef5a630..eb9114f1 100644 --- a/lib/ext2fs/tst_super_size.c +++ b/lib/ext2fs/tst_super_size.c @@ -20,123 +20,123 @@ struct sb_struct sb; -#ifndef offsetof -#define offsetof(type, member) __builtin_offsetof (type, member) -#endif +int verbose = 0; -#define check_field(x, s) cur_offset = do_field(#x, s, sizeof(sb.x), \ - offsetof(struct sb_struct, x), \ - cur_offset) +#define offsetof(type, member) __builtin_offsetof (type, member) +#define check_field(x) cur_offset = do_field(#x, sizeof(sb.x), \ + offsetof(struct sb_struct, x), \ + cur_offset) -static int do_field(const char *field, unsigned size, unsigned cur_size, - unsigned offset, unsigned cur_offset) +static int do_field(const char *field, size_t size, int offset, int cur_offset) { - if (size != cur_size) { - printf("error: %s size %u should be %u\n", - field, cur_size, size); - exit(1); - } if (offset != cur_offset) { - printf("error: %s offset %u should be %u\n", - field, cur_offset, offset); + printf("Warning! Unexpected offset at %s\n", field); exit(1); } - printf("%8d %-30s %3u\n", offset, field, size); + printf("%8d %-30s %3u\n", offset, field, (unsigned) size); return offset + size; } -int main(int argc, char **argv) +void check_superblock_fields() { #if (__GNUC__ >= 4) int cur_offset = 0; printf("%8s %-30s %3s\n", "offset", "field", "size"); - check_field(s_inodes_count, 4); - check_field(s_blocks_count, 4); - check_field(s_r_blocks_count, 4); - check_field(s_free_blocks_count, 4); - check_field(s_free_inodes_count, 4); - check_field(s_first_data_block, 4); - check_field(s_log_block_size, 4); - check_field(s_log_cluster_size, 4); - check_field(s_blocks_per_group, 4); - check_field(s_clusters_per_group, 4); - check_field(s_inodes_per_group, 4); - check_field(s_mtime, 4); - check_field(s_wtime, 4); - check_field(s_mnt_count, 2); - check_field(s_max_mnt_count, 2); - check_field(s_magic, 2); - check_field(s_state, 2); - check_field(s_errors, 2); - check_field(s_minor_rev_level, 2); - check_field(s_lastcheck, 4); - check_field(s_checkinterval, 4); - check_field(s_creator_os, 4); - check_field(s_rev_level, 4); - check_field(s_def_resuid, 2); - check_field(s_def_resgid, 2); - check_field(s_first_ino, 4); - check_field(s_inode_size, 2); - check_field(s_block_group_nr, 2); - check_field(s_feature_compat, 4); - check_field(s_feature_incompat, 4); - check_field(s_feature_ro_compat, 4); - check_field(s_uuid, 16); - check_field(s_volume_name, 16); - check_field(s_last_mounted, 64); - check_field(s_algorithm_usage_bitmap, 4); - check_field(s_prealloc_blocks, 1); - check_field(s_prealloc_dir_blocks, 1); - check_field(s_reserved_gdt_blocks, 2); - check_field(s_journal_uuid, 16); - check_field(s_journal_inum, 4); - check_field(s_journal_dev, 4); - check_field(s_last_orphan, 4); - check_field(s_hash_seed, 4 * 4); - check_field(s_def_hash_version, 1); - check_field(s_jnl_backup_type, 1); - check_field(s_desc_size, 2); - check_field(s_default_mount_opts, 4); - check_field(s_first_meta_bg, 4); - check_field(s_mkfs_time, 4); - check_field(s_jnl_blocks, 17 * 4); - check_field(s_blocks_count_hi, 4); - check_field(s_r_blocks_count_hi, 4); - check_field(s_free_blocks_hi, 4); - check_field(s_min_extra_isize, 2); - check_field(s_want_extra_isize, 2); - check_field(s_flags, 4); - check_field(s_raid_stride, 2); - check_field(s_mmp_update_interval, 2); - check_field(s_mmp_block, 8); - check_field(s_raid_stripe_width, 4); - check_field(s_log_groups_per_flex, 1); - check_field(s_reserved_char_pad, 1); - check_field(s_reserved_pad, 2); - check_field(s_kbytes_written, 8); - check_field(s_snapshot_inum, 4); - check_field(s_snapshot_id, 4); - check_field(s_snapshot_r_blocks_count, 8); - check_field(s_snapshot_list, 4); - check_field(s_error_count, 4); - check_field(s_first_error_time, 4); - check_field(s_first_error_ino, 4); - check_field(s_first_error_block, 8); - check_field(s_first_error_func, 32); - check_field(s_first_error_line, 4); - check_field(s_last_error_time, 4); - check_field(s_last_error_ino, 4); - check_field(s_last_error_line, 4); - check_field(s_last_error_block, 8); - check_field(s_last_error_func, 32); - check_field(s_mount_opts, 64); - check_field(s_usr_quota_inum, 4); - check_field(s_grp_quota_inum, 4); - check_field(s_overhead_blocks, 4); - check_field(s_reserved, 108 * 4); - check_field(s_checksum, 4); - do_field("Superblock end", 0, 0, cur_offset, 1024); + check_field(s_inodes_count); + check_field(s_blocks_count); + check_field(s_r_blocks_count); + check_field(s_free_blocks_count); + check_field(s_free_inodes_count); + check_field(s_first_data_block); + check_field(s_log_block_size); + check_field(s_log_frag_size); + check_field(s_blocks_per_group); + check_field(s_frags_per_group); + check_field(s_inodes_per_group); + check_field(s_mtime); + check_field(s_wtime); + check_field(s_mnt_count); + check_field(s_max_mnt_count); + check_field(s_magic); + check_field(s_state); + check_field(s_errors); + check_field(s_minor_rev_level); + check_field(s_lastcheck); + check_field(s_checkinterval); + check_field(s_creator_os); + check_field(s_rev_level); + check_field(s_def_resuid); + check_field(s_def_resgid); + check_field(s_first_ino); + check_field(s_inode_size); + check_field(s_block_group_nr); + check_field(s_feature_compat); + check_field(s_feature_incompat); + check_field(s_feature_ro_compat); + check_field(s_uuid); + check_field(s_volume_name); + check_field(s_last_mounted); + check_field(s_algorithm_usage_bitmap); + check_field(s_prealloc_blocks); + check_field(s_prealloc_dir_blocks); + check_field(s_reserved_gdt_blocks); + check_field(s_journal_uuid); + check_field(s_journal_inum); + check_field(s_journal_dev); + check_field(s_last_orphan); + check_field(s_hash_seed); + check_field(s_def_hash_version); + check_field(s_jnl_backup_type); + check_field(s_desc_size); + check_field(s_default_mount_opts); + check_field(s_first_meta_bg); + check_field(s_mkfs_time); + check_field(s_jnl_blocks); + check_field(s_blocks_count_hi); + check_field(s_r_blocks_count_hi); + check_field(s_free_blocks_hi); + check_field(s_min_extra_isize); + check_field(s_want_extra_isize); + check_field(s_flags); + check_field(s_raid_stride); + check_field(s_mmp_interval); + check_field(s_mmp_block); + check_field(s_raid_stripe_width); + check_field(s_log_groups_per_flex); + check_field(s_reserved_char_pad); + check_field(s_reserved_pad); + check_field(s_kbytes_written); + check_field(s_snapshot_inum); + check_field(s_snapshot_id); + check_field(s_snapshot_r_blocks_count); + check_field(s_snapshot_list); + check_field(s_error_count); + check_field(s_first_error_time); + check_field(s_first_error_ino); + check_field(s_first_error_block); + check_field(s_first_error_func); + check_field(s_first_error_line); + check_field(s_last_error_time); + check_field(s_last_error_ino); + check_field(s_last_error_line); + check_field(s_last_error_block); + check_field(s_last_error_func); + check_field(s_mount_opts); + check_field(s_reserved); + printf("Ending offset is %d\n\n", cur_offset); #endif - return 0; +} + + +int main(int argc, char **argv) +{ + int s = sizeof(struct sb_struct); + + check_superblock_fields(); + printf("Size of struct %s is %d\n", sb_struct_name, s); + if (s != 1024) { + exit(1); + } + exit(0); } diff --git a/lib/ext2fs/undo_io.c b/lib/ext2fs/undo_io.c index df55abf3..7cf88684 100644 --- a/lib/ext2fs/undo_io.c +++ b/lib/ext2fs/undo_io.c @@ -73,10 +73,6 @@ 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, @@ -86,7 +82,6 @@ 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, @@ -98,10 +93,7 @@ static struct struct_io_manager struct_undo_manager = { undo_write_blk, undo_flush, undo_write_byte, - undo_set_option, - undo_get_stats, - undo_read_blk64, - undo_write_blk64, + undo_set_option }; io_manager undo_io_manager = &struct_undo_manager; @@ -148,7 +140,7 @@ static errcode_t write_file_system_identity(io_channel undo_channel, block_size = channel->block_size; io_channel_set_blksize(channel, SUPERBLOCK_OFFSET); - retval = io_channel_read_blk64(channel, 1, -SUPERBLOCK_SIZE, &super); + retval = io_channel_read_blk(channel, 1, -SUPERBLOCK_SIZE, &super); if (retval) goto err_out; @@ -198,17 +190,17 @@ static errcode_t write_block_size(TDB_CONTEXT *tdb, int block_size) } static errcode_t undo_write_tdb(io_channel channel, - unsigned long long block, int count) + unsigned long block, int count) { int size, sz; - unsigned long long block_num, backing_blk_num; + unsigned 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 long end_block; + unsigned long end_block; data = (struct undo_private_data *) channel->private_data; @@ -274,7 +266,7 @@ static errcode_t undo_write_tdb(io_channel channel, sz = count / channel->block_size; else sz = -count; - retval = io_channel_read_blk64(data->real, backing_blk_num, + retval = io_channel_read_blk(data->real, backing_blk_num, sz, read_ptr); if (retval) { if (retval != EXT2_ET_SHORT_READ) { @@ -293,7 +285,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 %lld data %x and size %d\n", + printf("Printing with key %ld data %x and size %d\n", block_num, tdb_data.dptr, tdb_data.dsize); @@ -357,7 +349,7 @@ static errcode_t undo_open(const char *name, int flags, io_channel *channel) return EXT2_ET_BAD_DEVICE_NAME; retval = ext2fs_get_mem(sizeof(struct struct_io_channel), &io); if (retval) - goto cleanup; + return retval; memset(io, 0, sizeof(struct struct_io_channel)); io->magic = EXT2_ET_MAGIC_IO_CHANNEL; retval = ext2fs_get_mem(sizeof(struct undo_private_data), &data); @@ -400,14 +392,13 @@ static errcode_t undo_open(const char *name, int flags, io_channel *channel) * setup err handler for read so that we know * when the backing manager fails do short read */ - if (data->real) - undo_err_handler_init(data->real); + undo_err_handler_init(data->real); *channel = io; return 0; cleanup: - if (data && data->real) + if (data->real) io_channel_close(data->real); if (data) ext2fs_free_mem(&data); @@ -464,7 +455,7 @@ static errcode_t undo_set_blksize(io_channel channel, int blksize) return retval; } -static errcode_t undo_read_blk64(io_channel channel, unsigned long long block, +static errcode_t undo_read_blk(io_channel channel, unsigned long block, int count, void *buf) { errcode_t retval = 0; @@ -475,18 +466,12 @@ static errcode_t undo_read_blk64(io_channel channel, unsigned long long block, EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL); if (data->real) - retval = io_channel_read_blk64(data->real, block, count, buf); + retval = io_channel_read_blk(data->real, block, count, buf); return retval; } -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, +static errcode_t undo_write_blk(io_channel channel, unsigned long block, int count, const void *buf) { struct undo_private_data *data; @@ -502,17 +487,11 @@ static errcode_t undo_write_blk64(io_channel channel, unsigned long long block, if (retval) return retval; if (data->real) - retval = io_channel_write_blk64(data->real, block, count, buf); + retval = io_channel_write_blk(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) { @@ -605,18 +584,3 @@ 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 = 0; - 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; -} diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c index 419564fe..5bf2c925 100644 --- a/lib/ext2fs/unix_io.c +++ b/lib/ext2fs/unix_io.c @@ -17,9 +17,7 @@ #define _LARGEFILE_SOURCE #define _LARGEFILE64_SOURCE -#ifndef _GNU_SOURCE #define _GNU_SOURCE -#endif #include <stdio.h> #include <string.h> @@ -49,14 +47,15 @@ #if HAVE_SYS_RESOURCE_H #include <sys/resource.h> #endif -#if HAVE_LINUX_FALLOC_H -#include <linux/falloc.h> -#endif #if defined(__linux__) && defined(_IO) && !defined(BLKROGET) #define BLKROGET _IO(0x12, 94) /* Get read-only status (0 = read_write). */ #endif +#if defined(__linux__) && defined(_IO) && !defined(BLKSSZGET) +#define BLKSSZGET _IO(0x12,104)/* get block device sector size */ +#endif + #undef ALIGN_DEBUG #include "ext2_fs.h" @@ -70,11 +69,11 @@ if ((struct)->magic != (code)) return (code) struct unix_cache { - char *buf; - unsigned long long block; - int access_time; - unsigned dirty:1; - unsigned in_use:1; + char *buf; + unsigned long block; + int access_time; + unsigned dirty:1; + unsigned in_use:1; }; #define CACHE_SIZE 8 @@ -116,8 +115,6 @@ static errcode_t unix_read_blk64(io_channel channel, unsigned long long block, int count, void *data); static errcode_t unix_write_blk64(io_channel channel, unsigned long long block, int count, const void *data); -static errcode_t unix_discard(io_channel channel, unsigned long long block, - unsigned long long count); static struct struct_io_manager struct_unix_manager = { EXT2_ET_MAGIC_IO_MANAGER, @@ -133,7 +130,6 @@ static struct struct_io_manager struct_unix_manager = { unix_get_stats, unix_read_blk64, unix_write_blk64, - unix_discard, }; io_manager unix_io_manager = &struct_unix_manager; @@ -160,13 +156,12 @@ static errcode_t unix_get_stats(io_channel channel, io_stats *stats) static errcode_t raw_read_blk(io_channel channel, struct unix_private_data *data, unsigned long long block, - int count, void *bufv) + int count, void *buf) { errcode_t retval; ssize_t size; ext2_loff_t location; int actual = 0; - unsigned char *buf = bufv; size = (count < 0) ? -count : count * channel->block_size; data->io_stats.bytes_read += size; @@ -175,9 +170,8 @@ static errcode_t raw_read_blk(io_channel channel, retval = errno ? errno : EXT2_ET_LLSEEK_FAILED; goto error_out; } - if ((channel->align == 0) || - (IS_ALIGNED(buf, channel->align) && - IS_ALIGNED(size, channel->align))) { + if ((data->align == 0) || + ((IS_ALIGNED(buf, data->align)) && IS_ALIGNED(size, data->align))) { actual = read(data->dev, buf, size); if (actual != size) { short_read: @@ -222,13 +216,12 @@ error_out: static errcode_t raw_write_blk(io_channel channel, struct unix_private_data *data, unsigned long long block, - int count, const void *bufv) + int count, const void *buf) { ssize_t size; ext2_loff_t location; int actual = 0; errcode_t retval; - const unsigned char *buf = bufv; if (count == 1) size = channel->block_size; @@ -246,9 +239,8 @@ static errcode_t raw_write_blk(io_channel channel, goto error_out; } - if ((channel->align == 0) || - (IS_ALIGNED(buf, channel->align) && - IS_ALIGNED(size, channel->align))) { + if ((data->align == 0) || + ((IS_ALIGNED(buf, data->align)) && IS_ALIGNED(size, data->align))) { actual = write(data->dev, buf, size); if (actual != size) { short_write: @@ -315,14 +307,16 @@ static errcode_t alloc_cache(io_channel channel, cache->in_use = 0; if (cache->buf) ext2fs_free_mem(&cache->buf); - retval = io_channel_alloc_buf(channel, 0, &cache->buf); + retval = ext2fs_get_memalign(channel->block_size, + data->align, &cache->buf); if (retval) return retval; } - if (channel->align) { + if (data->align) { if (data->bounce) ext2fs_free_mem(&data->bounce); - retval = io_channel_alloc_buf(channel, 0, &data->bounce); + retval = ext2fs_get_memalign(channel->block_size, data->align, + &data->bounce); } return retval; } @@ -428,44 +422,6 @@ static errcode_t flush_cached_blocks(io_channel channel, } #endif /* NO_IO_CACHE */ -#ifdef __linux__ -#ifndef BLKDISCARDZEROES -#define BLKDISCARDZEROES _IO(0x12,124) -#endif -#endif - -int ext2fs_open_file(const char *pathname, int flags, mode_t mode) -{ - if (mode) -#if defined(HAVE_OPEN64) && !defined(__OSX_AVAILABLE_BUT_DEPRECATED) - return open64(pathname, flags, mode); - else - return open64(pathname, flags); -#else - return open(pathname, flags, mode); - else - return open(pathname, flags); -#endif -} - -int ext2fs_stat(const char *path, ext2fs_struct_stat *buf) -{ -#if defined(HAVE_FSTAT64) && !defined(__OSX_AVAILABLE_BUT_DEPRECATED) - return stat64(path, buf); -#else - return stat(path, buf); -#endif -} - -int ext2fs_fstat(int fd, ext2fs_struct_stat *buf) -{ -#if defined(HAVE_FSTAT64) && !defined(__OSX_AVAILABLE_BUT_DEPRECATED) - return fstat64(fd, buf); -#else - return fstat(fd, buf); -#endif -} - static errcode_t unix_open(const char *name, int flags, io_channel *channel) { io_channel io = NULL; @@ -473,7 +429,7 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel) errcode_t retval; int open_flags; int f_nocache = 0; - ext2fs_struct_stat st; + struct stat st; #ifdef __linux__ struct utsname ut; #endif @@ -482,7 +438,7 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel) return EXT2_ET_BAD_DEVICE_NAME; retval = ext2fs_get_mem(sizeof(struct struct_io_channel), &io); if (retval) - goto cleanup; + return retval; memset(io, 0, sizeof(struct struct_io_channel)); io->magic = EXT2_ET_MAGIC_IO_CHANNEL; retval = ext2fs_get_mem(sizeof(struct unix_private_data), &data); @@ -504,29 +460,28 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel) memset(data, 0, sizeof(struct unix_private_data)); data->magic = EXT2_ET_MAGIC_UNIX_IO_CHANNEL; data->io_stats.num_fields = 2; - data->dev = -1; open_flags = (flags & IO_FLAG_RW) ? O_RDWR : O_RDONLY; if (flags & IO_FLAG_EXCLUSIVE) open_flags |= O_EXCL; -#if defined(O_DIRECT) - if (flags & IO_FLAG_DIRECT_IO) { - open_flags |= O_DIRECT; - io->align = ext2fs_get_dio_alignment(data->dev); - } -#elif defined(F_NOCACHE) - if (flags & IO_FLAG_DIRECT_IO) { + if (flags & IO_FLAG_DIRECT_IO) +#if !defined(O_DIRECT) && defined(F_NOCACHE) f_nocache = F_NOCACHE; - io->align = 4096; - } +#else + open_flags |= O_DIRECT; #endif data->flags = flags; - data->dev = ext2fs_open_file(io->name, open_flags, 0); +#ifdef HAVE_OPEN64 + data->dev = open64(io->name, open_flags); +#else + data->dev = open(io->name, open_flags); +#endif if (data->dev < 0) { retval = errno; goto cleanup; } + if (f_nocache) { if (fcntl(data->dev, f_nocache, 1) < 0) { retval = errno; @@ -534,26 +489,10 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel) } } - /* - * If the device is really a block device, then set the - * appropriate flag, otherwise we can set DISCARD_ZEROES flag - * because we are going to use punch hole instead of discard - * and if it succeed, subsequent read from sparse area returns - * zero. - */ - if (ext2fs_stat(io->name, &st) == 0) { - if (S_ISBLK(st.st_mode)) - io->flags |= CHANNEL_FLAGS_BLOCK_DEVICE; - else - io->flags |= CHANNEL_FLAGS_DISCARD_ZEROES; - } - -#ifdef BLKDISCARDZEROES - { - int zeroes = 0; - if (ioctl(data->dev, BLKDISCARDZEROES, &zeroes) == 0 && - zeroes) - io->flags |= CHANNEL_FLAGS_DISCARD_ZEROES; +#ifdef BLKSSZGET + if (flags & IO_FLAG_DIRECT_IO) { + if (ioctl(data->dev, BLKSSZGET, &data->align) != 0) + data->align = io->block_size; } #endif @@ -562,8 +501,7 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel) * Some operating systems require that the buffers be aligned, * regardless of O_DIRECT */ - if (!io->align) - io->align = 512; + data->align = 512; #endif @@ -578,6 +516,7 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel) /* Is the block device actually writable? */ error = ioctl(data->dev, BLKROGET, &readonly); if (!error && readonly) { + close(data->dev); retval = EPERM; goto cleanup; } @@ -604,7 +543,7 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel) (ut.release[2] == '4') && (ut.release[3] == '.') && (ut.release[4] == '1') && (ut.release[5] >= '0') && (ut.release[5] < '8')) && - (ext2fs_stat(io->name, &st) == 0) && + (fstat(data->dev, &st) == 0) && (S_ISBLK(st.st_mode))) { struct rlimit rlim; @@ -623,17 +562,11 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel) cleanup: if (data) { - if (data->dev >= 0) - close(data->dev); free_cache(data); ext2fs_free_mem(&data); } - if (io) { - if (io->name) { - ext2fs_free_mem(&io->name); - } + if (io) ext2fs_free_mem(&io); - } return retval; } @@ -844,7 +777,7 @@ static errcode_t unix_write_byte(io_channel channel, unsigned long offset, data = (struct unix_private_data *) channel->private_data; EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL); - if (channel->align != 0) { + if (data->align != 0) { #ifdef ALIGN_DEBUG printf("unix_write_byte: O_DIRECT fallback\n"); #endif @@ -913,52 +846,3 @@ static errcode_t unix_set_option(io_channel channel, const char *option, } return EXT2_ET_INVALID_ARGUMENT; } - -#if defined(__linux__) && !defined(BLKDISCARD) -#define BLKDISCARD _IO(0x12,119) -#endif - -static errcode_t unix_discard(io_channel channel, unsigned long long block, - unsigned long long count) -{ - struct unix_private_data *data; - int ret; - - EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); - data = (struct unix_private_data *) channel->private_data; - EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL); - - if (channel->flags & CHANNEL_FLAGS_BLOCK_DEVICE) { -#ifdef BLKDISCARD - __uint64_t range[2]; - - range[0] = (__uint64_t)(block) * channel->block_size; - range[1] = (__uint64_t)(count) * channel->block_size; - - ret = ioctl(data->dev, BLKDISCARD, &range); -#else - goto unimplemented; -#endif - } else { -#if defined(HAVE_FALLOCATE) && defined(FALLOC_FL_PUNCH_HOLE) - /* - * If we are not on block device, try to use punch hole - * to reclaim free space. - */ - ret = fallocate(data->dev, - FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, - (off_t)(block) * channel->block_size, - (off_t)(count) * channel->block_size); -#else - goto unimplemented; -#endif - } - if (ret < 0) { - if (errno == EOPNOTSUPP) - goto unimplemented; - return errno; - } - return 0; -unimplemented: - return EXT2_ET_UNIMPLEMENTED; -} diff --git a/lib/ext2fs/valid_blk.c b/lib/ext2fs/valid_blk.c index 7c3defc7..32ac9e60 100644 --- a/lib/ext2fs/valid_blk.c +++ b/lib/ext2fs/valid_blk.c @@ -23,7 +23,7 @@ * This function returns 1 if the inode's block entries actually * contain block entries. */ -int ext2fs_inode_has_valid_blocks2(ext2_filsys fs, struct ext2_inode *inode) +int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode) { /* * Only directories, regular files, and some symbolic links @@ -38,7 +38,7 @@ int ext2fs_inode_has_valid_blocks2(ext2_filsys fs, struct ext2_inode *inode) * target is stored in the block entries. */ if (LINUX_S_ISLNK (inode->i_mode)) { - if (ext2fs_file_acl_block(fs, inode) == 0) { + if (inode->i_file_acl == 0) { /* With no EA block, we can rely on i_blocks */ if (inode->i_blocks == 0) return 0; @@ -53,8 +53,3 @@ int ext2fs_inode_has_valid_blocks2(ext2_filsys fs, struct ext2_inode *inode) } return 1; } - -int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode) -{ - return ext2fs_inode_has_valid_blocks2(NULL, inode); -} |
