summaryrefslogtreecommitdiff
path: root/e2fsck/unix.c
AgeCommit message (Collapse)AuthorFilesLines
2011-12-18e2fsck: use different bitmap types as appropriateTheodore Ts'o1-0/+4
Now that we have multiple backend implementations of the bitmap code, this commit teaches e2fsck to use either the most appropriate backend for each use case. Since we don't know for sure if we will get it all right, the default choices can be overridden via e2fsck.conf. The various definitions are shown here, with the current defaults (which may change as we add more bitmap implementations and as learn what works better). ; EXT2FS_BAMP64_BITARRAY is 1 ; EXT2FS_BMAP64_RBTREE is 2 ; EXT2FS_BMAP64_AUTODIR is 3 [bitmaps] inode_used_map = 2 ; pass1 inode_dir_map = 3 ; pass1 inode_reg_map = 2 ; pass1 block_found_map = 2 ; pass1 inode_bad_map = 2 ; pass1 inode_imagic_map = 2 ; pass1 block_dup_map = 2 ; pass1 block_ea_map = 2 ; pass1 inode_link_info = 2 ; pass1 inode_dup_map = 2 ; pass1b inode_done_map = 3 ; pass3 inode_loop_detect = 3 ; pass3 fs_bitmaps = 2 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-11-14libquota: cleanup libquota codeAditya Kali1-3/+3
This patch cleans up the quota code as suggested in previous reviews. This includes * remove BUG_ON()s and 'exit()' calls from library code * remove calls to malloc/free and instead use ext2fs_get/free_mem functions. * lib/quota/common.c file in not needed anymore and is removed. * rename exported functions to start with quota_ (ex: init_quota_context --> quota_init_context) * better error handling in quota library Signed-off-by: Aditya Kali <adityakali@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-10-09Fix more spelling errors found by translators and add pluralizationTheodore Ts'o1-2/+4
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-10-05Pass the gettext() function to libcom_errTheodore Ts'o1-0/+1
For those e2fsprogs programs which use libcom_err and are internationalized, pass the gettext() function to libcom_err during program initialization. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-30e2fsck: zero ctx->fs after freeing fs when restarting due to MMPDarrick J. Wong1-0/+1
If MMP is enabled and e2fsck determines that it needs to restart itself on account of various MMP conditions, it will close the current fs and jump back to the start of fs checking. However, closing fs also frees it, which means that we need to set ctx->fs to NULL to prevent subsequent open code from accessing the old deleted pointer. Signed-off-by: Darrick J. Wong <djwong@us.ibm.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-25ext2fs: add multi-mount protection (INCOMPAT_MMP)Andreas Dilger1-1/+100
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-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: Don't try to close an fd which is negativeEric Sandeen1-5/+6
These reflect either file descriptors which aren't tested for failure, or closures of fd's which may have failed. In setup_tdb(), test for failure of mkstemp and return without trying to open the file (again). In reserve_stdio_fds, rather than closing the "extra" fd == 3 due to the way the loop is written, just don't go that far by using while (fd <= 2). In logsave, it forks and retries forever if open fails, but at least make coverity happy by explicitly not trying to close a negative file descriptor. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-08-31e2fsck: add support for checking the built-in quota filesAditya Kali1-0/+17
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-11e2fsck: catch termination signals and print information about themTheodore Ts'o1-0/+1
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-06-16e2fsck: fix mysterious "FILE SYSTEM WAS MODIFIED" with no changesTheodore Ts'o1-0/+31
Commit 2a77a784a3 (firest released in e2fsprogs 1.33) compared superblock summary free blocks and inode counts with the allocation bitmap counts before starting the file system check proper, and if they differed, set the superblock and marked it as dirty. If no other file systme changes were required, this would cause a "*** FILE SYSTEM WAS MODIFIED ***" message without any explanation of what e2fsck had changed. We fix this by only setting the superblock summary free block/inodes counts if we are skipping a full check, and in non-preen mode, e2fsck will now print an explicit message stating how the superblock had been updated. In a full check, any updates to the superblock free blocks/inodes fields will be noted in pass5. This change requires changing a few test results (essentially reversing the changes made in commit 2a77a784a3). Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-06-11ext2fs: Handle internal journal over 2^32 bytesAndreas Dilger1-1/+2
The write_journal_inode() code is only setting the low 32-bit i_size for the journal size, even though it is possible to specify a journal up to 10M blocks in size. Trying to create a journal larger than 2GB will succeed, but an immediate e2fsck would fail. Store i_size_high for the journal inode when creating it, and load it upon access. Use s_jnl_blocks[15] to store the journal i_size_high backup. This field is currently unused, as EXT2_N_BLOCKS is 15, so it is using s_jnl_blocks[0..14], and i_size is in s_jnl_blocks[16]. Rename the "size" argument "num_blocks" for the journal creation functions to clarify this parameter is in units of filesystem blocks and not bytes. Signed-off-by: Andreas Dilger <adilger@whamcloud.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-05-07Merge branch 'maint' into nextTheodore Ts'o1-1/+1
2011-05-07e2fsck: make the "fs is mounted; continue?" prompt more paranoidTheodore Ts'o1-1/+1
A user received the "file system is mounted; do you really want to continue" prompt, and then instead of typing "n" for no, forgot that he hadn't declined to continuation question, and typed the up-arrow key, which in his locale, the 'A' in "^[[A" was interpreted as "yes", and he lost data. This was clearly the user's fault, but to make e2fsck a bit safer against user stupidity/carelessness, we will change the "fs is mounted; continue?" prompt to default to no, and treat the escape character (along with the return and space characters, currently) as a request for the default answer. Addresses-Debian-Bug: #619859 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-12-16Merge branch 'master' into nextTheodore Ts'o1-1/+9
Conflicts: e2fsck/e2fsck.h e2fsck/unix.c
2010-12-13Merge branch 'maint' into nextTheodore Ts'o1-1/+19
Conflicts: e2fsck/pass4.c misc/dumpe2fs.c resize/online.c
2010-12-06e2fsck: add an option which causes it to only do a journal replayBernd Schubert1-0/+11
As recently discussed on linux-ext4@vger.kernel.org add an option to e2fsck to allow to replay the journal only. That will allow scripts, such as pacemakers 'Filesystem' RA to first replay the journal and if that sets an error state from the journal replay, further check for that error (dumpe2fh -h | grep "Filesystem state:") and if that shows and error to refuse to mount. It also allows automatic e2fsck scripts to first replay the journal and on a second run after the real pass1 to passX checks to test for the return code. Signed-off-by: Bernd Schubert <bschubert@ddn.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2010-12-06e2fsck: Do blkid interpretation on the external journal specifierTheodore Ts'o1-1/+8
If the user specifies "e2fsck -j UUID=XXX", e2fsck should do blkid interpretation, since e2fsck does it with the base file system name. So from the sake of consistency and user convenience, we should do it here too. Addresses-Debian-Bug: #559315 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-11-22e2fsck: Discard free data and inode blocks.Lukas Czerner1-1/+9
In Pass 5 when we are checking block and inode bitmaps we have great opportunity to discard free space and unused inodes on the device, because bitmaps has just been verified as valid. This commit takes advantage of this opportunity and discards both, all free space and unused inodes. I have added new set of options, 'nodiscard' and 'discard'. When the underlying devices does not support discard, or discard ends with an error, or when any kind of error occurs on the filesystem, no further discard attempt will be made and the e2fsck will behave as it would with nodiscard option provided. As an addition, when there is any not-yet-zeroed inode table and discard zeroes data, then inode table is marked as zeroed. Signed-off-by: Lukas Czerner <lczerner@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2010-09-24Merge branch 'maint' into nextTheodore Ts'o1-0/+2
Conflicts: configure configure.in lib/ext2fs/ext2fs.h misc/mke2fs.c
2010-09-19e2fsck: Improve error message when device name misspelledJan Kara1-0/+2
When a device name is misspelled, we output the full text about specifying alternate superblock. This is slightly misleading because when the device cannot be open because of ENOENT, this certainly won't help. So just print that device does not exist and exit. Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2010-07-19Merge branch 'maint' into nextTheodore Ts'o1-0/+4
Conflicts: resize/extent.c
2010-07-05e2fsck: Add missing ext2fs_close() call when going back to original superblockTheodore Ts'o1-0/+2
In the case where the original superblock and the backup superblock are both invalid in some way, e2fsck will try to go back to the orignal superblock. To do that, it must close the attempted open using the backup superblock first (since otherwise the exclusive open will prevent the subsequent open from succeding). Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-07-05Add superblock fields which track first and most recent fs errorsTheodore Ts'o1-0/+2
Add superblock fields which track where and when the first and most recent file system errors occured. These fields are displayed by dumpe2fs and cleared by e2fsck. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-06-13e2fsck: Fix up to be 64-bit block number safeValerie Aurora Henson1-6/+7
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>
2010-06-07Merge branch 'maint' into nextTheodore Ts'o1-5/+13
Conflicts: e2fsck/journal.c e2fsck/pass1.c e2fsck/pass2.c misc/mke2fs.c
2010-05-17e2fsck: Don't set the group descriptor checksums if the fsck was cancelledTheodore Ts'o1-1/+2
It's a bad idea to set the checksums if e2fsck is aborted by the user, and it often causes an error message, "Inode bitmap not loaded while setting block group checksum info". Addresses-Launchpad-Bug: #582035 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-05-13e2fsck: Skip time-based checks if the time looks insane or broken_system_clockTheodore Ts'o1-4/+11
There are broken embedded devices that have system clocks that always reset to January 1, 1970 whenever they boot (even if no power is lost). There are also systems that have super cheap clock crystals that can be very inaccurate. So if the option broken_system_clock is given, disable all time based checks. E2fsck will also try to detect incorrect system clock times, and automatically mark the system clock as insane. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-03-15Merge branch 'maint' into nextTheodore Ts'o1-10/+25
2010-03-15e2fsck: Don't blow up if the physical device is too bigTheodore Ts'o1-6/+6
If the user grows a partition bigger than 2**32 blocks, e2fsprogs 1.41.x is not going to be able to support resizing the filesystem, since it doesn't have > 2**32 block support. However, e2fsck should still work, so the system administrator doesn't get stuck. Addresses-Launchpad-Bug: #521648 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-03-15e2fsck: Make the "filesystem is mounted" message more scaryTheodore Ts'o1-2/+2
I guess the message wasn't scary enough for users who are just smart enough to really get themselves in deep doo-doo. Let's make it even scarier. Addresses-Launchpad-Bug: #537483 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-03-15e2fsck: Make the -n always open the file system read-onlyTheodore Ts'o1-2/+17
A user was surprised when -n -D caused the file system to be opened read/write, and then outsmarted himself when e2fsck asked the question: WARNING!!! Running e2fsck on a mounted filesystem may cause SEVERE filesystem damage. Do you really want to continue (y/n)? This is partially our fault for not documenting the fact that -D overrode opening the filesystem read-write. But the bottom line is it much safer if -n *always* opens the file system read-only, so there can be no confusion. This means that we have to disable certain combination of options, such as "-n -c", "-n -l", and "-n -L", and "-n -D", but the utility of these combinations is pretty low, and is more than offset by making e2fsck idiot-proof. Addresses-Launchpad-Bug: #537483 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-09-07Convert uses of super->s_*_blocks_count to ext2fs_*_blocks_count()Valerie Aurora Henson1-7/+8
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-01e2fsck: Avoid scary failure messages on low-memory systemsTheodore Ts'o1-2/+7
On a very low-memory system, where ext2fs_check_desc() fails because it can't allocate a block bitmap, catch this error and report it immediate. This avoids something like this, which could scare and mislead the user: e2fsck: Group descriptors look bad... trying backup blocks... Media was not cleanly unmounted, check forced. Pass 1: Checking inodes, blocks, and sizes Error allocating block bitmap (1): Memory allocation failed e2fsck: aborted Addresses-Debian-Bug: #509529 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-09-07Merge branch 'maint' into nextTheodore Ts'o1-2/+7
2009-08-22e2fsck: Convert e2fsck to new bitmap interfaceValerie Aurora Henson1-0/+5
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-06-15e2fsck: fix miscellaneous memory leaksTheodore Ts'o1-1/+0
Fix various miscellaneous memory leaks which were discovered using valgrind. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-05-28e2fsck: Go back to the original superblock if the backup sb is invalidTheodore Ts'o1-21/+45
In the case where the block group descriptors appear corrupt, e2fsck will try to use the backup superblock. However, it could be that the backup superblock itself is completely corrupted, in which e2fsck should go back to the original superblock instead of refusing to fix the file system. Addresses-Debian-Bug: #516820 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-05-28Add empty function for init_resource_track() and print_resource_track()Ken Chen1-7/+2
in the case of ! defined RESOURCE_TRACK, so that we can clean up #ifdef throughout e2fsck source. Signed-off-by: Ken Chen <kenchen@google.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-05-17e2fsck: initialize error handling before journal replayAndreas Dilger1-2/+2
One of our customers hit a temporary IO error during an e2fsck run during the read from the journal. It seems that the read error resulted in e2fsck automatically discarding the journals and recreating them on several filesystems on this node without any prompting from the user: end_request: I/O error, dev sdg, sector 484832 Buffer I/O error on device sdg, logical block 60604 fsck-sdg[8276]: ls2-OST024c: Superblock has an invalid ext3 journal (inode 8). fsck-sdg[8276]: CLEARED. fsck-sdg[8276]: *** ext3 journal has been deleted - filesystem is now ext2 only *** fsck-sdg[8276]: ls2-OST024c was not cleanly unmounted, check forced. fsck-sdg[8276]: ls2-OST024c: Journal inode is not in use, but contains data. CLEARED. fsck-sdg[8276]: ls2-OST024c: Recreate journal to make the filesystem ext3 again? fsck-sdg[8276]: FIXED. fsck-sdg[8276]: Creating journal (32768 blocks): Done. fsck-sdg[8276]: fsck-sdg[8276]: *** journal has been re-created - filesystem is now ext3 again *** fsck-sdg[8276]: ls2-OST024c: 39818/20183248 files (8.2% non-contiguous), 222122257/779902976 blocks fsck-sdg[8276]: exit code 1 (file system errors corrected) The following patch moves the e2fsck error handler initialization earlier in the e2fsck startup code before the journal is processed, so that the user will be prompted for an action. This is the first IO that is not part of ext2fs_open() where fs->io is first initialized. It doesn't seem possible to initialize the error handlers for the initial filesystem open without changing the prototype for ext2fs_open2(). If we are getting a new ext2fs_open3() prototype for 64-bit it might make sense to add at least "read_error" as a parameter ("write_error" is not strictly necessary for the open and could be set afterward). Signed-off-by: Andreas Dilger <adilger@sun.com> Signed-off-by: Jim Garlick <garlick@llnl.gov> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-04-28e2fsck: Skip journal checks if the fs is mounted and doesn't need recoveryTheodore Ts'o1-0/+5
If we are checking a mounted filesystem (typically the root filesystem, mounted read/only) and the NEEDS_RECOVERY flag is not set, skip all of the checks associated with making sure the journal is consistent. There is the very slight possibility we could lose if the NEEDS_RECOVERY flag was somehow cleared even though there was data in the journal, but this has practically never happend in practice, and it reduces the number of reads required at boot-time, which is a big deal when trying to reduce boot times with HDD's. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-04-23e2fsck: Don't test the resize_inode if the filesystem is cleanTheodore Ts'o1-0/+1
Move check_resize_inode() out of check_super_block(), since we only need to test the resize_inode for correctness only if the filesystem requires checking. This change avoids a lot of I/O operations which slows down a 1 second boot. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-04-22e2fsck: Fix warn_unused_result warnings from gccTheodore Ts'o1-1/+1
Fixed a potential bug where by partial returns from the write(2) system call could lost characters to be sent to external progress bar display program. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-12-08e2fsck: In verbose mode, distinguish between fragmented directories/filesTheodore Ts'o1-7/+21
Track the number of non-contiguous files and directories so we can give more detailed information in verbose mode. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-09-09e2fsck: Fix e2fsck automatic blocksize detetionTheodore Ts'o1-0/+2
This fixes a regression that was introduced in commit dcc91e10 (it showed up first in e2fsprogs 1.40.7). Since we weren't freeing the filesystem handle, ext2fs_open2() was returning EBUSY, and so this caused a failure in the code that would automatically determine the filesystem block size when only the superblock number was specified by the user. This was discussed in http://ubuntuforums.org/showthread.php?t=789323, and Matthias Bannach pointed this out to me, for which I am very grateful. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-09-01Only use the test_io manager if the right environment variables are setTheodore Ts'o1-4/+5
In order to make it possible for the test_io manager to be compiled in by default, make all of the programs that might try to use it to only do so if the environment variables TEST_IO_FLAGS and TEST_IO_DEBUG are set. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-08-27Remove trailing whitespace for the entire source treeTheodore Ts'o1-44/+44
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-08-24Fix miscellaneous compile warningsAndreas Dilger1-0/+1
Signed-off-by: Andreas Dilger <adilger@sun.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-08-14e2fsck: Fix ind/dind/tind statistics and add extent depth statisticsTheodore Ts'o1-0/+15
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-08-10e2fsck: Fix check to see if an extent-based file is fragmentedTheodore Ts'o1-2/+7
Also added support for "e2fsck -E fragcheck" which issues a comprehensive report of discontiguous file extents. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>