summaryrefslogtreecommitdiff
path: root/e2fsck/dirinfo.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix various spelling typosSamanta Navarro2023-01-261-1/+1
| | | | | | | Typos found with codespell. Signed-off-by: Samanta Navarro <ferivoz@riseup.net> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* e2fsck: fix e2fsck_allocate_memory() overflowAndreas Dilger2020-02-291-18/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | e2fsck_allocate_memory() takes an "unsigned int size" argument, which will overflow for allocations above 4GB. This happens for dir_info and dx_dir_info arrays when there are more than 350M directories in a filesystem, and for the dblist array above 180M directories. There is also a risk of overflow during the binary search in both e2fsck_get_dir_info() and e2fsck_get_dx_dir_info() when the midpoint of the array is calculated, if there would be more than 2B directories in the filesystem and working above the half way point. Also, in some places inode numbers are "int" instead of "ext2_ino_t", which can also cause problems with the array size calculations, and makes it hard to identify where inode numbers are used. Fix e2fsck_allocate_memory() to take an "unsigned long" argument to match ext2fs_get_mem(), so that it can do single memory allocations over 4GB. Fix e2fsck_get_dir_info() and e2fsck_get_dx_dir_info() to temporarily use an unsigned long long value to calculate the midpoint (which will always fit into an ext2_ino_t again afterward). Change variables that hold inode numbers to be ext2_ino_t, and print them as unsigned values instead of printing negative inode numbers. Signed-off-by: Andreas Dilger <adilger@whamcloud.com> Reviewed-by: Shilong Wang <wshilong@ddn.com> Lustre-bug-id: https://jira.whamcloud.com/browse/LU-13197 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* e2fsck: add error-checking when unlink tdb file for dir_infoTheodore Ts'o2018-06-241-1/+3
| | | | | Fixes-Coverity-Bug: 1308365 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* Add configure --disable-tdb which disables e2fsck's scratch_files featureTheodore Ts'o2016-05-291-23/+44
| | | | | | | | | | | | | The scratch_files feature is not really needed except on 32-bit platforms, since tdb's performance is pretty awful given how we are using it. Maybe SQLite would be faster, but for 64-bit platforms, enabling swap works fairly well, especially using the rbtree for the bitmap abstraction. We leave tdb for Android since it's unlikely that someone will be trying to connect petabyte+ sized file systems to a mobile handset. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* e2fsck,misc: include ext2fs.h to avoid clang warningsTheodore Ts'o2015-05-231-0/+1
| | | | | | | e2fsck/dirinfo.c and misc/e4crypt.c use functions from libext2fs, so we need to include its header file or clang will complain. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* e2fsck: fix dangling pointer when dir_info array is resizedDarrick J. Wong2014-11-051-1/+4
| | | | | | | | | | | | e2fsck uses an array to store directory usage information during pass 3; the usage context also contains a pointer to the last directory looked up. When expanding the dir_info array, this cache pointer needs to be cleared if the array resize changed the pointer location, or else we'll later walk off the end of this dead pointer. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reported-by: Sami Liedes <sami.liedes@iki.fi> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* e2fsck: notice when the realloc of dir_info failsTheodore Ts'o2014-09-111-0/+4
| | | | | | | | | If the reallocation of dir_info fails, we will eventually cause e2fsck to fail with an internal error. So if the realloc fails, print a message and bail out with a fatal error early when at the time of the reallocation failure. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* Save and restore umask around calls to mkstemp()Theodore Ts'o2014-01-091-0/+3
| | | | | | | | | | The races would be hard to exploit, but let's close them off. Addresses-Coverity-Id: #709504 Addresses-Coverity-Id: #709505 Addresses-Coverity-Id: #709506 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* Clean up sparse warningsTheodore Ts'o2013-12-161-3/+3
| | | | | | | Mostly by adding static and removing excess extern qualifiers. Also convert a few remaining non-ANSI function declarations to ANSI. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* e2fsck: speed up runs when using tdb for large atypical filesystemsTheodore Ts'o2011-11-291-1/+5
| | | | | | | | | | | | | Optimize how the tdb library so that running with [scratch_files] in /etc/e2fsck.conf is more efficient. Use a better hash function, supplied by Rogier Wolff, and supply an estimate of the size of the hash table to tdb_open instead of using the default (which is way too small in most cases). Also, disable the tdb locking and fsync calls, since it's not necessary for our use in this case (which is essentially as cheap swap space; the tdb files do not contain persistent data.) Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* Shorten compile commands run by the build systemTheodore Ts'o2011-09-181-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>
* e2fsprogs: Don't try to close an fd which is negativeEric Sandeen2011-09-161-0/+4
| | | | | | | | | | | | | | | | | | | 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>
* e2fsck: remove extraneous memsetEric Sandeen2011-09-161-1/+0
| | | | | | | | | | e2fsck_allocate_memory() already sets allocated memory to 0, so remove the explicit memset. Especially since it was setting the wrong size (iter not *iter) Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* e2fsck: fix miscellaneous memory leaksTheodore Ts'o2009-06-151-0/+3
| | | | | | Fix various miscellaneous memory leaks which were discovered using valgrind. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* remove useless if-before-free testsJim Meyering2009-03-081-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>
* Fix e2fsck segfault on very badly damaged filesystemsTheodore Ts'o2007-07-111-1/+1
| | | | | | | | | | | | | | | | A recent change to e2fsck_add_dir_info() to use tdb files to check filesystems with a very large number of filesystems had a typo which caused us to resize the wrong data structure. This would cause a array overrun leading to malloc pointer corruptions. Since we normally can very accurately predict how big the the dirinfo array needs to be, this bug only got triggered on very badly corrupted filesystems. Thanks to Andreas Dilger for submitting the test case which discovered this problem, and to Kalpak Shah for writing a random testing script which created the test case. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* Fix gcc -Wall issues in e2fsck sourcesTheodore Ts'o2007-05-221-8/+9
| | | | | Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Signed-off-by: Andreas Dilger <adilger@clusterfs.com>
* Fix memory leaks from using the tdb libraryTheodore Ts'o2007-04-061-3/+9
| | | | | | | We weren't freeing allocated memory from calls to tdb_fetch, tdb_firstkey, and tdb_nextkey. Oops. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* Enable e2fsck to use the tdb library to store the dirinfo abstractionTheodore Ts'o2007-04-061-25/+162
| | | | | | | | | | If e2fsck.conf configures a scratch_files directory which is available, and the number of directories exceeds scratch_files.numdirs_threshold, then try to use the tdb library to store the directory information abstraction. This allows us to check very large filesystems without needing as much physical memory. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* Rework e2fsck's dirinfo abstraction to be more friendly for databasesTheodore Ts'o2007-04-041-50/+213
| | | | | | | | | | Change the iterator abstraction and replace e2fsck_get_dir_info() with e2fsck_dir_info_{set,get}_{parent,dotdot} so that we can support an on-disk dirinfo implementation. This allows e2fsck to check very large filesystems on systems with smaller amounts of memory and/or address space. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* ext2fs_getmem(), ext2fs_free_mem(), and ext2fs_resize_mem() Theodore Ts'o2003-08-011-2/+2
| | | | | | all now take a 'void *' instead of a 'void **' in order to avoid pointer aliasing problems with GCC 3.x.
* Many files:Theodore Ts'o2001-01-111-3/+3
| | | | | | | dirinfo.c, e2fsck.h, emptydir.c, iscan.c, jfs_user.h, journal.c, message.c, pass1.c, pass1b.c, pass2.c, pass3.c, pass4.c, pass5.c, problem.h, scantest.c, super.c, swapfs.c: Change ino_t to ext2_ino_t.
* Many files:Theodore Ts'o1998-04-271-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | ext2fs.h, bitops.h: Add support for the Watcom C compiler to do inline functions. ext2fs.h, dosio.c: Use asm/types.h instead of linux/types.h to evade a potential problem with glibc's header files trying to spike out linux/types.h. ext2fs.h (ext2fs_resize_mem): Change the function prototype to include the old size of the memory, which is needed for some braindamaged memory allocation systems that don't support realloc(). badblocks.c (ext2fs_badblocks_list_add): bb_inode.c (clear_bad_block_proc): dblist.c (ext2fs_add_dir_block): icount.c (insert_icount_el): irel_ma.c (ima_put): rs_bitmap.c (ext2fs_resize_generic_bitmap): Update functions to pass the old size of the memory to be resized to ext2fs_resize_mem(). ChangeLog, dirinfo.c: dirinfo.c (e2fsck_add_dir_info): Update function to pass the old size of the memory to be resized to ext2fs_resize_mem(). ChangeLog, extent.c, resize2fs.c: resize2fs.c (adjust_superblock): extent.c (ext2fs_add_extent_entry): Update functions to pass the old size of the memory to be resized to ext2fs_resize_mem().
* ChangeLog, dirinfo.c, e2fsck.c, e2fsck.h, super.c:Theodore Ts'o1998-02-011-1/+0
| | | | | | | dirinfo.c, e2fsck.c: Don't include com_err.h; it isn't needed. e2fsck.h: Include <time.h> since it is needed super.c: If EXT2_SKIP_UUID is defined, then skip the UUID processing.
* Many files:Theodore Ts'o1998-01-191-3/+4
| | | | | | | | | | | | | | e2fsck.h: If EXT2_FLAT_INCLUDES is defined, then assume all of the ext2-specific header files are in a flat directory. dirinfo.c, ehandler.c, pass1.c, pass1b.c, pass2.c, pass5.c, super.c, swapfs.c, unix.c: Explicitly cast all assignments from void * to be compatible with C++. unix.c (sync_disk): Remove sync_disk and calls to that function, since ext2fs_close() now takes care of this. pass1.c, pass1b.c, pass2.c, pass3.c, swapfs, badblocks.c, ehandler.c, unix.c: Change use of private to be priv_data, to avoid C++ reserved name clash.
* Many files:Theodore Ts'o1997-12-011-14/+5
| | | | | | | | | | | | | | | | | | | | | | | dblist.c (ext2fs_get_num_dirs): Make ext2fs_get_num_dirs more paranoid about validating the directory counts from the block group information. all files: Don't include stdlib.h anymore; include it in ext2_fs.h, since that file requires stdlib.h ChangeLog, Makefile.in, dirinfo.c: dirinfo.c (e2fsck_add_dir_info): Use ext2fs_get_num_dirs instead of e2fsck_get_num_dirs, which has been removed. Makefile.in (PROGS): Remove @EXTRA_PROGS@, since we don't want to compile and install flushb. ChangeLog, configure.in: Remove @EXTRA_PROGS@, since we aren't using it in 2fsck/Makefile.in anymore ChangeLog, Makefile.in: Install debugfs in /sbin, instead of /usr/sbin. libext2fs.texinfo: Update version string to be 1.12 Makefile.in: Fix bug in find script which made the exclusion list, where a '-' was missing from an -name option.
* Many files:Theodore Ts'o1997-11-141-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | pass1.c, pass2.c, pass3.c, pass4.c, pass5.c: Add calls to the progress indicator function. pass1.c (scan_callback): Add call to the progress feedback function (if it exists). super.c (check_super_block): Skip the device size check if the get_device_size returns EXT2_EXT_UNIMPLEMENTED. iscan.c (main): Don't use fatal_error() anymore. pass1b.c, swapfs.c, badblocks.c: Set E2F_FLAG_ABORT instead of calling fatal_error(0). problem.c, pass3.c (PR_3_ROOT_NOT_DIR_ABORT, PR_3_NO_ROOT_INODE_ABORT): New problem codes. problem.c, pass2.c (PR_2_SPLIT_DOT): New problem code. problem.c, pass1.c (PR_1_SUPPRESS_MESSAGES): New problem code. problemP.h: New file which separates out the private fix_problem data structures. util.c, dirinfo.c, pass1.c, pass1b.c, pass2.c, pass5.c, super.c, swapfs.c util.c: allocate_memory() now takes a e2fsck context as its first argument, and rename it to be e2fsck_allocate_memory(). problemP.h: New file which contains the private problem abstraction definitions. Makefile.pq: Remove include of MAKEFILE.STD, which doesn't exist at this point.
* Many files:Theodore Ts'o1997-11-031-43/+47
| | | | | | | | | | | | | | | | Change ext2fs_read_inode, ext2fs_write_inode to take the e2fsck context as their first argument. Change dir_info.c routines to take an e2fsck_context, renamed them to start with e2fsck_ to avoid namespace issues, and changed them to store the directory information inside the e2fsck context. Added e2fsck_run() which calls all of the e2fsck passes in the correct order, and which handles the return of abort codes. Added abort processing, both via setjmp/longjmp and via flags in the e2fsck context. Use a flag in the e2fsck context instead of the restart_e2fsck global variable. Change uses of free and malloc to ext2fs_free_mem and ext2fs_get_mem.
* Many files:Theodore Ts'o1997-04-291-6/+18
| | | | | Checked in e2fsprogs-1.07
* Many files:Theodore Ts'o1997-04-261-1/+1
| | | | | Checkin of e2fsprogs 0.5b
* Many files:Theodore Ts'o1997-04-261-0/+120
Checkin of e2fsprogs 0.5b