summaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)AuthorFilesLines
2011-09-30libext2fs: Always swab the MMP block on big-endian systems machinesDarrick J. Wong1-9/+6
The MMP code in libext2fs tries to gate MMP block swab'ing with this test: if (fs->super->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC)) However, EXT2FS_ENABLE_SWAPFS never seems to be defined anywhere (all possible existed, the field fs->super->s_magic is always in host byteorder, so the test always fails. So, we can change the #ifdef to WORDS_BIGENDIAN (which is conditionally defined on BE platforms) and get rid of the broken if test. Signed-off-by: Darrick J. Wong <djwong@us.ibm.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-30libext2fs: Fix various bugs from the metadata checksum integrationDarrick J. Wong3-13/+11
Fix several minor errors in structure definitions, the byteswap code, and Makefiles that result from merging the crc32c and initial parts of the metadata checksumming patchset. Signed-off-by: Darrick J. Wong <djwong@us.ibm.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-28libext2fs: use ext2fs byte swap functions for portabilityTheodore Ts'o1-4/+5
The functions htole32(), le32toh(), be32toh(), htobe32() aren't defined in all environments. Use the ext2fs byte swap functions for portability. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-28libquota: use ext2fs byte swapping functions for portabilityTheodore Ts'o4-65/+69
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-25ext2fs: add multi-mount protection (INCOMPAT_MMP)Andreas Dilger12-19/+559
Multi-mount protection is feature that allows mke2fs, e2fsck, and others to detect if the filesystem is mounted on a remote node (on SAN disks) and avoid corrupting the filesystem. For e2fsprogs this means that it checks the MMP block to see if the filesystem is in use, and marks the filesystem busy while e2fsck is running on the system. This is useful on SAN disks that are shared between high-availability servers, or accessible by multiple nodes that aren't in HA pairs. MMP isn't intended to serve as a primary HA exclusion mechanism, but as a failsafe to protect against user, software, or hardware errors. There is no requirement that e2fsck updates the MMP block at regular intervals, but e2fsck does this occasionally to provide useful information to the sysadmin in case of a detected conflict. For the kernel (since Linux 3.0) MMP adds a "heartbeat" mechanism to periodically write to disk (every few seconds by default) to notify other nodes that the filesystem is still in use and unsafe to modify. Originally-by: Kalpak Shah <kalpak@clusterfs.com> Signed-off-by: Johann Lombardi <johann@whamcloud.com> Signed-off-by: Andreas Dilger <adilger@whamcloud.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-24misc: quiet minor compiler errorsAndreas Dilger4-13/+18
Several compiler errors are quieted: - zero-length gnu_printf format string - unused variable - uninitalized variable (though it isn't actually used for anything) - fixed a bug in ext2fs_stat() if stat64() does not exist Signed-off-by: Andreas Dilger <adilger@whamcloud.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-24libext2fs: add flag to ext2fs_flush() and ext2fs_close() to avoid fsyncRichard W.M. Jones2-3/+23
This adds new APIs: ext2fs_flush2 and ext2fs_close2 which take an extra 'int flags' parameter. This allows us to pass in an EXT2_FLAG_FLUSH_NO_SYNC flag which avoids fsync'ing the filesystem when closing it. For the case we have in mind where we are just constructing a throwaway ext2 filesystem in a file in order to boot a VM, this saves over 5 seconds during the boot process and avoids many unnecessary disk writes. Existing code using ext2fs_flush and ext2fs_close remains unaffected by this change. Signed-off-by: Richard W.M. Jones <rjones@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-19libquota: only build a static libraryTheodore Ts'o1-19/+19
Since the libquota library has namespace contamination issues, don't build a shared library and link against it statically. Don't include it as part of the Debian packages. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-18Shorten compile commands run by the build systemTheodore Ts'o164-149/+1028
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-16libext2: Fix leaks in write_bitmaps on error returnsEric Sandeen1-9/+19
block_buf and/or inode_buf may not be properly freed on an error return. Create a new errout: target to free them as needed in error conditions. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16e2fsprogs: Fix some error cleanup path bugsEric Sandeen6-11/+11
In inode_open(), if the allocation of &io fails, we go to cleanup and dereference io to test io->name, which is a bug. Similarly in undo_open() if allocation of &data fails, we go to cleanup and dereference data to test data->real. In the test_open() case we explicitly set retval to the only possible error return from ext2fs_get_mem(), so remove that for tidiness. The other changes just make make earlier returns go through the error goto for consistency. In many cases we returned directly from the first error, but "goto cleanup" etc for every subsequent error. In some cases this leads to "impossible" tests such as: if (ptr) ext2fs_free_mem(&ptr) on paths where ptr cannot be null because we would have returned directly earlier, and Coverity flags this. This isn't really indicative of an error in most cases, but I think it can be clearer to always exit through the error goto if it's used later in the function. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16libe2p: reach unreachable codeEric Sandeen1-3/+4
The EOPNOTSUPP case is unreachable, being outside a set of: #if ... return; #else ... return; #endif Fix this up so that if neither HAVE_CHFLAGS nor HAVE_EXT2_IOCTLS applies, we set EOPNOTSUPP. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16e2fsprogs: annotate intentional fallthroughs in case statementsEric Sandeen5-0/+10
Using the /* fallthrough */ comment lets Coverity (and humans) know that we really do want to fall through in these case statements. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16libext2fs: Potential null ptr deref in undo_err_handler_initEric Sandeen1-1/+2
In the !undo_io_backing_manager case, undo_err_handler_init will be passed a null data->real, which will be dereferenced. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16libext2: move buf variable completely under ifdefEric Sandeen1-3/+4
If !WORDS_BIGENDIAN, it is pointless to test whether buf is NULL, because it is initialized to NULL and never changed. This makes Coverity complain, so we can just move all handling of "buf" under the #ifdef. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16libext2: Fix EXT2_LIB_SOFTSUPP maskingEric Sandeen1-2/+2
EXT2_LIB_SOFTSUPP_INCOMPAT_* are supposed to be bitmasks of features which can be opened even though they are under development. The intent is that these are masked out of the features list, so that they will be ignored on open. However, the code does a logical not vs. a bitwise not: features &= !EXT2_LIB_SOFTSUPP_INCOMPAT; which will not have the desired effect... Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16libext2s: fix swapfs.c so it builds on big endian systemsTheodore Ts'o2-11/+27
Also cleaned up ext2_fs.h, and improved the byte swapping code so the extra fields in the large inode are properly byte swapped. Addresses-Debian-Bug: #641838 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-16libquota: indicate in the ELF library image that it requires libext2fsTheodore Ts'o1-1/+1
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-16debugfs: add 64-bit support to the set_field commandsTheodore Ts'o3-3/+3
The set_fields commands (set_super_value, set_inode_field, set_block_group) now handle fields which store in split fields on ext4's on-disk format. For example, the superblock fields s_blocks_count and s_blocks_count_hi. The user can either set the low or high part of the field via "blocks_count_lo" or "blocks_count_hi", or both parts can be set via "blocks_count". Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-16libext2fs: add metadata checksum and snapshot feature flagsTheodore Ts'o6-12/+47
Reserve EXT4_FEATURE_RO_COMPAT_METADATA_CSUM and EXT2_FEATURE_COMPAT_EXCLUDE_BITMAP. Also reserve fields in the superblock and the inode for the checksums. In the block group descriptor, reserve the exclude bitmap field for the snapshot feature, and checksums for the inode and block allocation bitmaps. With this commit, the metadata checksum and exclude bitmap features should have reserved all of the fields they need in ext4's on-disk format. This commit also fixes an a missing byte swap for s_overhead_blocks. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Cc: Darrick J. Wong <djwong@us.ibm.com> Cc: Amir Goldstein <amir73il@gmail.com>
2011-09-16libext2fs: remove redundant last-group check in ext2fs_check_desc()Eric Sandeen1-2/+0
ext2fs_group_last_block2() already properly calculates the last block in the last group, so there is no need to special-case this after the call. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16e2fsprogs: add ext2fs_group_blocks_count helperEric Sandeen4-17/+22
Code to count the number of blocks in the last partial group is cut and pasted around the e2fsprogs codebase a few times. Making this a helper function should improve matters. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16libext2fs: fix size check in tst_inode_sizeTheodore Ts'o2-1/+2
Also add run tst_inode_size automaically from "make check" Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-16Merge branch 'maint' into nextTheodore Ts'o5-5/+18
2011-09-15e2fsprogs: Use punch hole as "discard" on regular filesLukas Czerner2-8/+46
If e2fsprogs tools (mke2fs, e2fsck) is run on regular file instead of on block device, we can use punch hole instead of regular discard command which would not work on regular file anyway. This gives us several advantages. First of all when e2fsck is run with '-E discard' parameter it will punch out all ununsed space from the image, hence trimming down the file system image. And secondly, when creating an file system on regular file (with '-E discard' which is default), we can use punch hole to clear the file content, hence we can skip inode table initialization, because reads from sparse area returns zeros. This will result in faster file system creation (without the need to specify lazy_itable_init) and smaller images. This commit also fixes some tests that would fail due to mke2fs showing discard progress, hence the output would differ. Signed-off-by: Lukas Czerner <lczerner@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-15e2fsprogs: create open() and stat() helpersLukas Czerner4-22/+44
In many places we are using #ifdef HAVE_OPEN64 to determine if we can use open64() but that's ugly. This commit creates two new helpers ext2fs_open_file() for open() and ext2fs_stat() for stat(). Also we need new typedef ext2fs_struct_stat for struct stat. Signed-off-by: Lukas Czerner <lczerner@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-15libext2fs: Add crc32c implementation for metadata checksummingDarrick J. Wong5-2/+1345
Add a slicing-by-8 CRC32c implementation for metadata checksumming. Adapted from Bob Pearson's kernel patch. Also added a self-test mechanism so we can verify that the crc32c implementation is working correctly. Signed-off-by: Darrick J. Wong <djwong@us.ibm.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-15libext2fs: fix the range validation in bitmap_range2 funcsAmir Goldstein1-5/+5
The condition ((start+num) & ~0xffffffffULL) in bitmap_range2 and generic_bmap_range funcs in get_bitmap64.c was wrong and inconsistent with the condition (start+num-1 > bmap->real_end) in generic_bitmap_range funcs in get_bitmap.c. I got the following error from tune2fs on a 16TB fs: Illegal block number passed to ext2fs_unmark_block_bitmap #4294967295 for block bitmap for 16TB.img tune2fs: Invalid argument while reading bitmaps Fix to condition to ((start+num-1) & ~0xffffffffULL), because the bit (start+num) is not going to be changed by the funcs. Signed-off-by: Amir Goldstein <amir73il@users.sf.net> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-15libext2fs: fix binary and source compatibility with the dump programTheodore Ts'o4-4/+17
The dump program relies on fs->frag_size and the EXT2_FRAGS_PER_BLOCK() macro. Kind of silly for it to do so, but it's part of the kludgy way the dump program (which was originally written for the BSD FFS was ported over to support ext2/3.) Given how it makes assumptions about the ext2/3/4 file system being similar to the BSD FFS, it's a bit of a miracle it works for ext4 --- or at least appears to work... Addresses-Debian-Bug: #636418 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-15libe2p: fix bug so that MNTOPT_ options can be successfully parsedTheodore Ts'o1-1/+1
Thanks to Israel G. Lugo for pointing this out. Addresses-Debian-Bug: #641667 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-14libquota: fix "make install" so it works in with a VPATH build directoryTheodore Ts'o1-2/+2
Also fix up the name of the header file which we are installing so it is correct. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-14libext2fs: add new test: tst_inode_sizeTheodore Ts'o2-1/+87
This test makes sure the size of the ext2_inode is what we expect Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-14resize2fs: add support for new in-kernel online resize ioctlYongqiang Yang1-0/+1
This is needed to support online resizing for > 32-bit file systems Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-08-31e2fsck: add support for checking the built-in quota filesAditya Kali1-1/+2
This patch adds support for doing quota accounting during full e2fsck scan if the 'quota' feature was set on the superblock. If user-visible quota inodes are in use, they will be hidden and converted to the reserved quota inodes. Signed-off-by: Aditya Kali <adityakali@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-08-31e2fsprogs: add quota library to e2fsprogsAditya Kali14-0/+2585
This patch adds the quota library (ported form Jan Kara's quota-tools) in e2fsprogs in order to make quotas as a first class supported feature in Ext4. This patch also provides interface in lib/quota/mkquota.h that will be used by mke2fs, tune2fs, e2fsck, etc. to initialize and update quota files. This first version of the quota library does not support reading existing quota files. This support will be added in the near future. Thanks to Jan Kara for his work on quota-tools. Most of the files in this patch are taken as-is from quota tools and were simply modified to work with libext2fs in e2fsprogs. Signed-off-by: Aditya Kali <adityakali@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-08-31libext2fs: fix binary search for the icount and badblocks storesTheodore Ts'o2-26/+2
Remove the interpolation because there is a bug in icount which can cause a core dump if calculated range gets turned into a NaN and then do an out-of-bounds array access. We could fix this with some more tests, but the complexity is such that nuking all of the interpolation code will be faster than fixing the interpolation. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-08-10libext2fs: copy cluster_bits in ext2fs_copy_generic_bmapEric Sandeen1-0/+1
The f_lotsbad regression test was failing on some systems with: Restarting e2fsck from the beginning... Pass 1: Checking inodes, blocks, and sizes +Illegal block number passed to ext2fs_test_block_bitmap #0 for in-use block map Pass 2: Checking directory structure Entry 'termcap' in / (2) has deleted/unused inode 12. Clear? yes Running with valgrind (./test_script --valgrind f_lotsbad) we see: +==31409== Conditional jump or move depends on uninitialised value(s) +==31409== at 0x42927A: ext2fs_test_generic_bmap (gen_bitmap64.c:378) among others. Looking at gen_bitmap64.c: 376: arg >>= bitmap->cluster_bits; 377: 378: if ((arg < bitmap->start) || (arg > bitmap->end)) { A little more debugging showed that it was actually bitmap->cluster_bits which was uninitialized, because it never gets copied over in ext2fs_copy_generic_bmap() Patch below resolves the issue. Reported-by: Andreas Dilger <adilger@whamcloud.com> Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-07-09libext2fs: fix block iterator when the callback function modifies an extentTheodore Ts'o1-0/+11
If the callback interator modifies a block in the middle of an extent during a call to the block iterator, causing the extent to be split, ext2_block_iterate3() will end up calling the callback function twice for some number of blocks. Fix this. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-07-08misc: use EXT2_I_SIZE() consistently to get sizeAndreas Dilger2-5/+3
Use the EXT2_I_SIZE() macro consistently to access the inode size. The i_size/i_size_high combination is open coded in several places. Signed-off-by: Andreas Dilger <adilger@whamcloud.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-07-07libext2fs: don't hang in ext2fs_new_block2() on a full bigalloc file systemTheodore Ts'o1-0/+2
Prevent ext2fs_new_block2() from looping forever when a bigalloc file system is full. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-07-07libext2fs: teach ext2fs_bmap2() about bigallocTheodore Ts'o1-2/+44
This allows debugfs's write command to work correctly on bigalloc file systems. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-07-07libext2fs: move ext2fs_bmap2()'s the extent handling to a separate functionTheodore Ts'o1-54/+68
Separate the extent handling to a separate function to make BMAP_ALLOC processing more efficient. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-07-07libext2fs: teach ext2fs_block_alloc_stats2() about bigallocTheodore Ts'o1-1/+2
Change ext2fs_block_alloc_stats2() so that when a cluster is allocated, the free blocks counter in the superblock is appropriately decremented by the cluster size. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-07-07libext2fs: replace missing flexbg initialization in flexbg_offsetTheodore Ts'o1-0/+2
Commit 25567a7b0fa9 accidentally removed the initialization for flexbg and flexbg_size, which affected ext2fs_allocate_group_table() and ext2fs_allocate_tables(). Replace them. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-07-07libext2fs: Fix gcc -Wall warningsTheodore Ts'o9-20/+29
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-07-05libext2fs: fix 64-bit support in ext2fs_bmap2()Theodore Ts'o1-3/+9
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-07-05libext2fs: fix 64-bit support in ext2fs_{read,write}_inode_full()Theodore Ts'o1-2/+4
This fixes a problem where reading or writing inodes located after the 4GB boundary would fail. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-07-05e2fsck, libext2fs: support for bigalloc file systems with a blocksize of 1024Theodore Ts'o5-38/+56
Filesystems with a blocksize of 1024 have the superblock starting at block #1. However, the first data block in the superblock is 0 to simplify the cluster calculations. So we must compensate for this in a number of places, mostly in the ext2fs library, but also in e2fsck. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-06-19libext2fs: fix makefile dependency problemTheodore Ts'o1-2/+14
lib/ext2fs/Makefile.in had a buggy entry for blkmap64_ba.c in $(SRCS), which caused this source file to not have a valid Makefile dependency entry, so blkmap64_ba.o would not get rebuilt when it needed to be. Also updated the Makefile dependency for the misc directory while we're at it. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-06-16mke2fs, e2fsck: fix i_blocks handling for bigalloc file systemsTheodore Ts'o3-2/+5
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>