summaryrefslogtreecommitdiff
path: root/lib/ext2fs/extent.c
AgeCommit message (Collapse)AuthorFilesLines
2011-09-18Shorten compile commands run by the build systemTheodore Ts'o1-0/+1
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-16e2fsprogs: annotate intentional fallthroughs in case statementsEric Sandeen1-0/+2
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-07-08misc: use EXT2_I_SIZE() consistently to get sizeAndreas Dilger1-3/+2
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>
2010-07-22libext2fs: Don't make a copy of the inode in ext2fs_extent_open2()Theodore Ts'o1-9/+4
Previously, ext2fs_extent_open2() copied the passed-in inode structure into the extent handle, and the extent functions modified the copy of the inode structure if necessary due to extent splits, etc. Change ext2fs_extent_open2() so that the extent functions use the inode structure passed into ext2fs_extent_open2(). Otherwise the passed-in inode structure could become out of date due to changes made by the extent functions. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-07-20tst_extents: Fix 64-bit bugs in do_goto_block()Theodore Ts'o1-6/+8
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-06-13libext2fs: More random 64-bit fixes, lots of block_iterate3Valerie Aurora Henson1-3/+3
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-06-07Merge branch 'maint' into nextTheodore Ts'o1-2/+2
Conflicts: e2fsck/journal.c e2fsck/pass1.c e2fsck/pass2.c misc/mke2fs.c
2010-05-17libe2p, libext2fs: Update file copyright permission states to match COPYINGTheodore Ts'o1-2/+2
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>
2009-10-25Convert ext2fs_block_alloc_stats() calls to block_alloc_stats2()Valerie Aurora Henson1-1/+2
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-09-07Convert to use io_channel_read_blk64() and io_channel_write_blk64()Valerie Aurora Henson1-3/+4
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-07-19libext2fs: Avoid creating unneeded new extents in ext2fs_extent_set_bmap()Theodore Ts'o1-25/+93
Avoiding inserting a new extent if it is possible to merge the new block to the beginning or the end of the previous or next extent. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-07-19libext2fs: Improve debugging printf's in extent.cTheodore Ts'o1-8/+51
Comment out less common debugging printf's, and fix some type warnings. Add high-level debugging printf's for ext2fs_extent_goto(), ext2fs_extent_insert(), ext2fs_extent_delete(), ext2fs_extent_replace() Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-07-19libext2fs: Fix regression in ext2fs_extent_set_bmap()Theodore Ts'o1-4/+5
Commit 0dc291611 introduced a regression when unmapping the first block in an extent. This caused e2fsck -fD to corrupt large directories if the directory has to shrink by more than one block. The problem was set_bmap should only go to a next leaf when setting a first block in an extent, and not when it is unmapping the first block in an extent. Addresses-Debian-Bug: #537510 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-07-12libext2fs: Fix minor gcc -Wall warningsTheodore Ts'o1-1/+0
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-07-10libext2fs: Make ext2fs_extent_set_bmap() more robust against ENOSPCTheodore Ts'o1-13/+33
In the case where we ext2fs_extent_set_bmap() is replacing the block mapping at the beginning of an already-existing extent, insert a new extent if necessary before shrinking an existing extent, to avoid data loss if the disk is full. This mostly addresses the problem described in Red Hat Bugzilla's statistics are still wrong, but at least the files on the filesystem are not corrupted. If there is a failure during the inode_scan_and_fix pass, the simplest thing to do may be to tell the user to run e2fsck -fy. Addresses-Red-Hat-Bug: #510379 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-07-07libext2fs: reset handle after inserting new extentEric Sandeen1-0/+4
Commit 53422e moved the new extent insertion in ext2fs_extent_set_bmap() prior to the modification of the original extent, but the insert function left the handle pointing to the new extent. This left us modifying the -new- extent, instead of the original one, and winding up with a corrupt extent tree something like: BLOCKS: (0-1):588791-588792, (0):588791 We need to move back to the previous extent prior to modification, if we inserted a new one. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2009-06-17libext2fs: write only core inode in update_path()Eric Sandeen1-7/+6
The ext2_extent_handle only has a struct ext2_inode allocated on it, and the same amount copied into it in that same function, but in update_path() we're possibly writing out more than that - for example 256 bytes, from that address. This causes uninitialized memory to get written to disk, overwriting the parts of the inode past the osd2 member (the end of the smaller structure). Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-06-15libext2fs: Fix memory leak in the extents handling functionTheodore Ts'o1-1/+1
Each time an extent handle is opened and closed, if the inode has an extent tree which does not fit in the inode's i_block structure, a filesystem block buffer was not getting released. Since e2fsck opens an extent handle for every inode using extents, this can translate to a very large amount of memory getting lost. Thanks to Henrik 'Mauritz' Johnson for discovering and pointing out this leak, which he ran into while running the "rdump" command in debugfs. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-05-28libext2fs: add ext2fs_extent_open2number96521-7/+19
The patch below adds a function, ext2fs_extent_open2(), that behaves as ext2fs_extent_open(), but will use the user-supplied inode structure when opening an extent instead of reading the inode from disk. It also changes several of the calls to extent_open() to use this enhancement. Signed-off-by: Nic Case <number9652@yahoo.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-05-25resize2fs: fix ENOSPC corruption caseEric Sandeen1-5/+6
http://people.redhat.com/esandeen/livecd-creator-imagefile.bz2 contains an image (for now) which, when resized to 578639, corrupts the filesystem. This is a bit crazy, I guess, because the fs currently has only 1 free block, but still, we should be graceful about the failure. Perhaps it would make sense to check the requested valuea against the minimum value resize2fs would compute for "-P" and fail (at least without a force). But in any case, this exposed 2 bugs when moving that one block required an extent split, which is what hit the ENOSPC. For starters, ext2fs_extent_set_bmap() in the "(re/un)mapping last block in extent" case was replacing the old extent before the new one was created; when the new extent creation failed, it left us in an inconsistent state. Simply changing the order of the two should fix this problem. Next, ext2fs_extent_insert was calling ext2fs_extent_delete() on *any* error, including one caused by failure to allocate a new block to split the node to hold that extent ... the handle was left unchanged, and we deleted the -original- extent. As a quick fix for this, just don't do the delete if we fail the split, though this may need to be smarter. I don't think we have terribly consistent behavior about where a handle is left on various errors. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2009-03-08remove useless if-before-free testsJim Meyering1-2/+1
In case you're wondering about whether this change is safe from a portability standpoint, fear not. This has been beaten to death in other forums. Here are a few threads: http://thread.gmane.org/gmane.comp.version-control.git/74187 http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/12712 http://thread.gmane.org/gmane.emacs.devel/98144 http://thread.gmane.org/gmane.comp.lib.glibc.alpha/13092 There has been debate about whether it's a good idea from a performance standpoint, too, but imho you'll have a hard time finding an instance where this sort of change induces a measurable performance penalty. If you do, please let me know. Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2008-12-25e2fsck: Fix an unhandled corruption case in scan_extent_node()Theodore Ts'o1-1/+3
A corrupted interior node in an extent tree would cause e2fsck to crash with the error message: Error1: Corrupt extent header on inode 107192 Aborted (core dumped) Handle this and related failures when scanning an inode's extent tree more robustly. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-08-27Remove trailing whitespace for the entire source treeTheodore Ts'o1-3/+3
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-08-27libext2fs: Fix ext2fs_bmap() to work with extents and BMAP_ALLOCTheodore Ts'o1-1/+4
Fix bugs with extents support when allocating blocks. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-08-22ext2fs_extent_set_bmap(): Avoid creating extra extents for resize2fsTheodore Ts'o1-5/+7
When resize2fs moves blocks belonging to an inode, it will call ext2fs_extent_set_bmap() for logical blocks 0, 1, 2, 3, ... Optimize for this calling pattern so we don't end up creating a separate extent for each block. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-08-22ext2fs_extent_set_bmap(): fix bug when replacing a single block extentTheodore Ts'o1-2/+1
When replacing a single block extent, make sure we set or clear the uninitialized extent flag as requested by the caller. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-08-22Fix ext2fs_extent_set_bmap() when setting a block before the first extentTheodore Ts'o1-1/+3
When setting a logical block which is before the first extent in the extent tree, make sure the new extent goes in front, at the very beginning of the extent tree. This fixes a bug where previously the new extent would be inserted out of order in this case. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-08-16libext2fs : Fix memory leaks in ext2fs_extent_open()Manish Katiyar1-3/+5
Memory allocated for the ext2_extent_handle is not getting freed from all the return paths in case of error. Below patch fixes it. Signed-off-by: "Manish Katiyar" <mkatiyar@gmail.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2008-07-18e2fsprogs: Fix tst_extents output on bigendian machine.Aneesh Kumar K.V1-5/+15
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2008-07-13Remove gcc-specific varargs macro in extent.cTheodore Ts'o1-24/+57
Use "#ifdef DEBUG // printf... // #endif" instead of dbg_printf(). Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-06-23libext2fs: Don't include ss/ss.h except when debuggingTheodore Ts'o1-1/+2
extent.c should only try to include ss/ssh.h when it is compiled with -DDEBUG. Otherwise it's not necessary and it breaks the Debian MIPS build (and the Debian MIPS build only) because it tries to build libext2fs without building libss as part of a MIPS-specific build rule. Addresses-Debian-Bug: #487675 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-06-07Fix gcc -Wall warnings in libext2fsTheodore Ts'o1-14/+13
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-06-02Teach ext2fs_extent_delete() to remove an empty extent node from the treeEric Sandeen1-7/+24
ext2fs_extent_delete() will also update the parent node and decrement the inode block count. Passing in the EXT2_EXTENT_DELETE_KEEP_EMPTY flag will allow the empty node to remain. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2008-06-02libext2fs: add new function ext2fs_extent_set_bmap()Eric Sandeen1-53/+356
Allows unmapping or remapping single mapped logical blocks, and mapping currently unmapped blocks. Also implements ext2fs_extent_fix_parents() to fix parent index logical starts, if the first index of a node changes its logical start block. Currently this can result in unnecessary new single-block extents; I think perhaps ext2fs_extent_insert should grow a flag to request merging with a nearby extent? Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2008-06-02Teach ext2fs_extent_insert() to split the current node if necessaryEric Sandeen1-3/+12
If ext2fs_extent_insert finds that the requested node for insertion is full, it will currently fail. With this patch it will split as necessary to make room, unless an EXT2_EXTENT_INSERT_NOSPLIT flag is passed to it. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2008-06-02libext2fs: Teach extent.c how to split nodesEric Sandeen1-0/+251
When called for a given handle, the new function extent_node_split() will split the current node such that half of the node's entries will be moved to a new tree block. The parent will then be updated to point to the (now smaller) original node as well as the new node. If the root node is requested to be split, it will move all entries out to a new node, and leave a single entry in the root pointing to that new node. If the reqested split node's parent is full it will recursively split up to the root to make room for the new node's insertion. If you ask to split a non-root node with only one entry, it will refuse (we'd have an empty node otherwise). It also updates the i_blocks count when a new block has successfully been connected to the tree. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2008-06-02ext2fs_extent_open: If the inode is empty, initialize the extent treeTheodore Ts'o1-3/+18
If the inode's i_block[] array is completely empty, create an empty extent tree in the in-core inode and set the EXT4_EXTENT_FL inode flag. This makes it easy to create a new inode using extents. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-06-01ext2fs_extent_replace: Support uninit extents and check validity of e_lenTheodore Ts'o1-5/+34
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-05-14fix extent_goto for non-0 leaf levelsEric Sandeen1-6/+21
The logic for stopping at the right level in extent_goto was wrong, so if you asked it to go to any level other than 0 (the leaf level) it would fail. Also add this argument to the tst_extents goto command to test it. (I thought this was a failure in my split code but it was this helper that was causing problems...) Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2008-04-17Make extent_goto() deterministic when logical block not foundEric Sandeen1-1/+12
Make sure that extent_goto() leaves us at the last extent prior to the requested logical block, if the logical block requested lands in a hole. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2008-04-17Fix ext2fs_extent_insert when at last extent in nodeEric Sandeen1-1/+1
ext2fs_extent_insert() only did a memmove if path->left was > 0, but if we are at the last extent in the node, path->left == 0, and this node must be moved before the current extent is replaced with the newly inserted node. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2008-04-17print a bit more info for the tst_extents info commandEric Sandeen1-0/+10
Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-03-20Fix ext2fs_extent_get for uninit leaf extentsEric Sandeen1-2/+2
The ext2fs_extent_get() function was not OR-ing together UNINIT and LEAF flags in the case where an extent was both; so if we had an extent which was both uniint and leaf, pass1 would bail out where depth == max_depth but was not marked as leaf, and e2fsck (from the next branch) would abort with: e2fsck 1.40.8 (13-Mar-2008) Pass 1: Checking inodes, blocks, and sizes Error1: No 'down' extent Aborted Also, if the error is encountered again, print the inode number to aid debugging until it's properly handled, at least. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-03-17Fix miscellaneous gcc -Wall warningsTheodore Ts'o1-10/+9
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-03-14libext2fs: Fix fencepost error in ext2fs_extent_insert()Theodore Ts'o1-1/+2
ext2fs_extent_insert() was copying n-1 of the existing extents when moving things down to make room for the new extent. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-03-13libext2fs: Fix ext2fs_extent_delete() to always point at a valid entryTheodore Ts'o1-0/+4
When deleting the last entry in a node, back up the current pointer so it is always pointing at a valid entry. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-02-22Add missing shift for ei_leaf_hiValerie Clement1-1/+1
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-02-22Add missing free in ext2fs_extent_free()Valerie Clement1-0/+1
handle->path should be freed in ext2fs_extent_free() Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-02-18Add support for extents to libext2fsTheodore Ts'o1-0/+1144
Initial implemenation of extents support in libext2fs Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>