Commit Graph

54 Commits (dcb8e1fa0452a3d31b678351c2297ad0255d3e4b)

Author SHA1 Message Date
Darrick J. Wong 2ed0adbce6 libext2fs: store checksum seed in superblock
Allow the filesystem to store the metadata checksum seed in the
superblock and add an incompat feature to say that we're using it.
This enables tune2fs to change the UUID on a mounted metadata_csum
FS without having to (racy!) rewrite all disk metadata.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2016-03-06 20:08:52 -05:00
Darrick J. Wong 77b3e98718 libext2fs: clean up feature test macros with predicate functions
Create separate predicate functions to test/set/clear feature flags,
thereby replacing the wordy old macros.  Furthermore, clean out the
places where we open-coded feature tests.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-10-24 00:34:09 -04:00
Darrick J. Wong c0ff3a21b6 libext2fs: set BLOCK_UNINIT for non-last blockgroups if all blocks are free
Set BLOCK_UNINIT in any group whose blocks are all unused, so long as
it isn't the last group.  This helps us speed up future e2fsck runs
and mounts because we don't need to read or checksum block bitmaps for
these groups.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-11-17 17:46:13 -05:00
Darrick J. Wong 2432a41a58 libext2fs: fix problems with LE<->BE conversions on BE platforms
Fix more problems that I found when testing on ppc64:

- Inode swap cut and paste error leads to immutable inodes being
  detected as inlinedata inodes, leading to e2fsck incorrectly barfing
  on i_block[] contents.

- Superblock csum/verify must be aware of the fs->super byte order
  when checking for metadata_csum feature flag.  (Hint: in _openfs(),
  fs->super is in LE order for the first csum verification)

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-08-24 22:01:36 -04:00
Theodore Ts'o 71715a5a9a Merge branch 'maint' into next 2014-04-20 08:31:24 -04:00
Andreas Dilger d8f401b135 fix miscellaneous build warnings
Fix various unused variable and use-uninitialized warnings.

Add generated files into .gitignore.

Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2014-04-14 12:22:42 -04:00
Theodore Ts'o d887b93701 libext2fs: make ext2fs_group_desc_csum return 0 if meta_csum not enabled
Addresses-Coverity-Id: #1147784

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2014-01-07 09:10:24 -05:00
Theodore Ts'o 2ffccc82c4 Merge branch 'maint' into next
Conflicts:
	lib/ext2fs/csum.c
2013-12-26 00:30:56 -05:00
Theodore Ts'o b3c2a63813 libext2fs: checksum bg descriptors larger than 64 bytes
Currently the ext4 block group descriptor is 64 bytes.  In case we
need to support larger block group descriptors in the future, teach
ext2fs_group_desc_csum() to checksum parts of the block group
descriptors that libext2fs doesn't yet understand.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-12-24 23:19:07 -05:00
Andreas Dilger 2bc3041754 debugfs, e2fsck: fix s_desc_size handling
The s_desc_size in the superblock specifies the group descriptor
size in bytes, but in various places the EXT4_FEATURE_INCOMPAT_64BIT
flag implies that the descriptor size is EXT2_MIN_DESC_SIZE_64BIT
(64 bytes) instead of checking the actual size.  In other places,
the s_desc_size field is used without checking for INCOMPAT_64BIT.

In the case of ext2fs_group_desc() the s_desc_size was being ignored,
and assumed to be sizeof(struct ext4_group_desc), which would result
in garbage for any but the first group descriptor.  Similarly, in
ext2fs_group_desc_csum() and print_csum() they assumed that the
maximum group descriptor size was sizeof(struct ext4_group_desc).
Fix these functions to use the actual superblock s_desc_size if
INCOMPAT_64BIT.

Conversely, in ext2fs_swap_group_desc2() s_desc_size was used
without checking for INCOMPAT_64BIT being set.

The e2fsprogs behaviour is different than that of the kernel,
which always checks INCOMPAT_64BIT, and only uses s_desc_size to
determine the offset of group descriptors and what range of bytes
to checksum.

Allow specifying the s_desc_size field at mke2fs time with the
"-E desc_size=NNN" option.  Allow a power-of-two s_desc_size
value up to s_blocksize if INCOMPAT_64BIT is specified.  This
is not expected to be used by regular users at this time, so it
is not currently documented in the mke2fs usage or man page.

Add m_desc_size_128, f_desc_size_128, and f_desc_bad test cases to
verify mke2fs and e2fsck handling of larger group descriptor sizes.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-12-24 22:50:19 -05:00
Theodore Ts'o 894eaf8506 libext2fs: fix gcc -Wall nits
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-05-19 22:12:36 -04:00
Andreas Dilger 1b8c4c1b45 build: quiet build warnings for "gcc -Wall"
Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-01-27 22:31:03 -05:00
Theodore Ts'o b9b5e43ea8 Merge branch 'maint' into next
Conflicts:
	RELEASE-NOTES
	debian/changelog
	lib/ext2fs/crc32c.c
	lib/ext2fs/rw_bitmaps.c
	resize/resize2fs.c
	version.h
2013-01-01 18:50:26 -05:00
Andreas Dilger f797cf3e37 tests: don't consider "make check" a compiler error
In a number of places, the output format from "make check" is
incorrectly interpreted as compiler warning output (triggered by
the presence of colons and parenthesis in the output).  Convert
these lines to similar output that does not trigger false build
warnings.

In the case of the tst_uuid.c program, the "ctime()" output was
difficult to change, but in fact it is better to actually compare
the time-based UUID against wallclock time instead of just printing
the formatted time as a string, so this test is improved.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-12-29 17:13:24 -05:00
Theodore Ts'o 97fac35094 libext2fs: when checking the inode's checksum, allow an all-zero inode
When the kernel writes an inode where all of the other inodes in in
the inode table (itable) block are unused, it skips reading the itable
block from disk, and instead uses an all zeros block.  This can cause
e2fsck to complain when it iterates over the inodes using
ext2fs_get_next_inode() since the inode apparently has an invalid
checksum.  Normally the inode won't be returned at all if it is at the
end of the block group's part of the inode table, thanks to the
bg_itable_unused field.  But it's possible for this situation to
happen earlier in the inode table block.

Fix this by changing ext2fs_inode_csum_verify() to allow the inode to
be all zero's; if the checksum fails, and the inode is all zero's,
treat it as a valid checksum.

Reported-by: Tao Ma <boyu.tm@taobao.com>
Reported-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2012-08-02 20:47:46 -04:00
Darrick J. Wong a9620d8b30 libext2fs: add checksum to MMP block
Calculate and verify a checksum of the MMP block.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-08-02 20:47:45 -04:00
Darrick J. Wong 5b58dc2304 libext2fs: block group checksum should use metadata_csum algorithm
Change the block group algorithm to use the same algorithm as the rest
of the metadata_csum.  This mostly involves providing a helper
function to tell if group descriptors should have checksums set or
verified, and modifying the gdt checksum code to use the correct
algorithm.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-08-02 20:47:45 -04:00
Darrick J. Wong 1eedf3e52c libext2fs: record the checksum algorithm in use in the superblock
Record the type of checksum algorithm we're using for metadata in the
superblock, in case we ever want/need to change the algorithm.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-08-02 20:47:44 -04:00
Darrick J. Wong d4ca3e40ca libext2fs: calculate and verify superblock checksums
Calculate and verify the superblock checksums.  Each copy of the
superblock records the number of the group it's in and the FS UUID, so
we can simply checksum the whole block.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-08-02 20:47:44 -04:00
Darrick J. Wong 39f5659ae3 libext2fs: verify and calculate extended attribute block checksums
Calculate and verify the checksum for separate (i.e. not in the inode)
extended attribute blocks; the checksum lives in the header.

[ Merged in change from Tao so that we always use the fs checksum seed
  for the xattr blocks. ]

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Tao Ma <boyu.mt@taobao.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-08-02 20:47:44 -04:00
Darrick J. Wong 81683c6a32 libext2fs: add checksums to the end of directory leaf nodes
Introduce small structures for recording directory tree checksums, and
some API changes to support writing out directory blocks with
checksums.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-08-02 17:27:43 -04:00
Darrick J. Wong dc96de09d7 libext2fs: add dx_root/dx_node checksum calculation and verification helpers
Verify and calculate checksums of htree internal node blocks.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-07-30 19:22:04 -04:00
Darrick J. Wong 41275efeee libext2fs: verify and calculate extent tree block checksums
Verify and calculate extent tree block checksums when processing
filesystems.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-07-30 19:14:04 -04:00
Darrick J. Wong e7dc95c677 libext2fs: create the block bitmap checksum
Calculate and verify the block bitmap checksum.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-07-30 19:04:04 -04:00
Darrick J. Wong a80ea34023 libext2fs: create the inode bitmap checksum
Provide a field in the block group descriptor to store inode bitmap
checksum, and some helper functions to calculate and verify it.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-07-30 18:56:04 -04:00
Darrick J. Wong 37d82b6a95 libext2fs: add inode checksum support
This patch adds the ability for the libext2fs functions to read and
write the inode checksum.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-07-30 18:46:04 -04:00
Theodore Ts'o f3ce48a4b6 libext2fs: remove debugging printf from ext2fs_group_desc_csum
This reduces the number of C library symbols needed by boot loader
systems such as yaboot.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2012-07-30 17:39:25 -04:00
Theodore Ts'o 87141781aa dumpe2fs: print the expected block group checksum if it is incorrect
This helps to diagnose problems caused by incorrect block group
checksums.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2012-03-15 12:13:25 -04:00
Theodore Ts'o d1154eb460 Shorten compile commands run by the build system
The DEFS line in MCONFIG had gotten so long that it exceeded 4k, and
this was starting to cause some tools heartburn.  It also made "make
V=1" almost useless, since trying to following the individual commands
run by make was lost in the noise of all of the defines.

So fix this by putting the configure-generated defines in lib/config.h
and the directory pathnames to lib/dirpaths.h.

In addition, clean up some vestigal defines in configure.in and in the
Makefiles to further shorten the cc command lines.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-18 17:34:37 -04:00
Theodore Ts'o d32c915abf libext2fs: Fix gcc -Wall warnings
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-07-07 13:50:22 -04:00
Theodore Ts'o 562f264243 Merge branch 'maint' into next
Conflicts:
	lib/ext2fs/block.c
	lib/ext2fs/csum.c
	resize/main.c
2010-12-20 10:06:58 -05:00
Eric Sandeen c816ecb204 e2fsprogs: fix type-punning warnings
Flags used during RHEL/Fedora builds lead to a couple type-punning
warnings:

  recovery.c: In function 'do_one_pass':
  recovery.c:539: warning: dereferencing type-punned pointer will break strict-aliasing rules
  ./csum.c: In function 'print_csum':
  ./csum.c:170: warning: dereferencing type-punned pointer will break strict-aliasing rules

The two changes below fix this up.

Note that the csum test binary output changes slightly, but this does
not break any tests.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2010-12-16 17:15:30 -05:00
Theodore Ts'o 97d26ce9e3 Merge branch 'maint' into next
Conflicts:
	e2fsck/journal.c
	e2fsck/pass1.c
	e2fsck/pass2.c
	misc/mke2fs.c
2010-06-07 12:42:40 -04:00
Theodore Ts'o 543547a52a libe2p, libext2fs: Update file copyright permission states to match COPYING
The top-level COPYING file states that the e2p and ext2fs libraries
are available under the LGPLv2.  The files were incorrectly labelled.
Alex Thomas/Luster has been consulted wrt to the ext3_extents.h file;
the rest of the files were primarily authored by Theodore Ts'o.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-05-17 23:04:39 -04:00
Theodore Ts'o 1d18a55c52 libext2fs: Fix byte swapping bugs
The 64-bit patches broke compiles on big endian systems.  In addition
the block group checksum test was failing, due to bugs in both the
test case and the checksum code itself.  This commit addresses these
problems.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-02-15 09:51:28 -05:00
Theodore Ts'o cf828f1a72 libext2fs: Byte-swap 64-bit block group descriptors
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-25 21:46:01 -04:00
Valerie Aurora Henson d7cca6b06f Convert to use block group accessor functions
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()

Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-25 21:43:47 -04:00
Eric Sandeen e633b58ac7 libext2fs: clean up ext2fs_bg_flags_ interfaces
The ext2fs_bg_flag* functions were confusing.

Currently we have this:

void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group,__u16 bg_flags);

(_set (unused) sets exactly bg_flags; _clear clears all and ignores bg_flags)

and these, which can twiddle individual bits in bg_flags:

void ext2fs_bg_flag_set(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
void ext2fs_bg_flag_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flag);

A better interface, after the patch below, is just:

ext2fs_bg_flags_zap(fs, group) /* zeros bg_flags */
ext2fs_bg_flags_set(fs, group, flags) /* adds flags to bg_flags */
ext2fs_bg_flags_clear(fs, group, flags) /* clears flags in bg_flags */

and remove the original ext2fs_bg_flags_set / ext2fs_bg_flags_clear.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-25 21:41:32 -04:00
Valerie Aurora Henson 4efbac6fed Convert uses of super->s_*_blocks_count to ext2fs_*_blocks_count()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-09-07 20:46:34 -04:00
Valerie Aurora Henson 8f82ef9860 Convert libext2fs to 64-bit bitmap interface
(Includes fixes from Nick Dokos)

Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-08-05 00:27:10 -04:00
Theodore Ts'o 470e737a87 libext2fs: Move test code for csum.c inline instead of in a separate file
Move the test code which is used to build the tst_csum progam from
tst_csum into csum.c under an #ifdef DEBUG to simplify things and to
avoid compile problems caused by not having a prototype for
ext2fs_group_desc_csum().

Addresses-Sourceforge-Bug: #2484331

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-05-29 11:01:22 -04:00
Theodore Ts'o 0eeec8ac61 Fix compiling under diet libc
Some recent changes had caused diet libc support to bitrot.  Fix up
missing header files and other portability fixups needed for dietlibc.
(Many of these changes also improve general portability.)

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-09-12 09:10:39 -04:00
Theodore Ts'o efc6f628e1 Remove trailing whitespace for the entire source tree
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-08-27 23:07:54 -04:00
Theodore Ts'o c4dcb1c10a libext2fs: Fix namespace leakage of crc16 functions
Rename crc16 to ext2fs_crc16, and make crc16_table static, since
there's not reason it should be exposed at all.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-08-24 22:44:33 -04:00
Theodore Ts'o 4729455f0a libext2fs: Don't check the group checksum when !GDT_CSUM
ext2fs_group_desc_csum_verify() is always checking the bg_checksum (to
make sure it is zero) even when the GDT_CSUM feature is not present.
This is normally OK, but apparently there are filesystems in the wild
where this field has not be initialized to zero.

Addresses-Debian-Bug: #490637

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-07-13 19:03:59 -04:00
Theodore Ts'o 8895f43a60 Fix gcc -Wall warnings in libext2fs
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-06-07 11:53:56 -04:00
Theodore Ts'o 5711ed297b Transfer responsibility of setting the *_UNINIT flags to libext2fs
Mke2fs used to have special case, ugly code in
setup_lazy_bg/setup_uninit_bg flag which set the flags based on all
sorts of special cases.  Change it so that it is done in libext2fs,
and fix mke2fs to use alloc_stats functions which will take care of
clearing the *_UNINIT flags automatically as needed.

This is preparatory work to make the flex_bg allocation patch much
cleaner.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-04-21 01:39:23 -04:00
Theodore Ts'o 16b851cdae Remove LAZY_BG feature
This simplifies the code, and using the uninit_bg with the inode table
lazily initialized is just as good.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-04-20 23:33:34 -04:00
Theodore Ts'o 456e989270 ext2fs_set_gdt_csum: Remove setting of BLOCK_UNINIT
This function tried to set BLOCK_UNINIT based on the return value of
ext2fs_super_and_bgd_loc.  That's not something that works once we
start allowing flex_bg since the block group metadata might not be
located in the blockgroup itself.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-04-20 18:31:53 -04:00
Theodore Ts'o 3c5556ed4a ext2fs_set_gdt_csum: Remove bogus setting of ITABLE_ZEROED
It used to be the case that ext2fs_set_gdt_csum set the ITABLE_ZEROED
flag if the INODE_UNINIT is not set.  This assumed that the only
caller of ext2fs_set_gdt_csum was e2fsck (which was not true), and
that e2fsck would take care of zeroing the inode table (whic was also
not true).

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-04-20 18:31:53 -04:00