Fix a few problems that Coverity picked up with error handling.
Fixes-Coverity-Bug: 1239278
Fixes-Coverity-Bug: 1239279
Fixes-Coverity-Bug: 1239280
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Extend debugfs with the ability to create transactions and replay the
journal. This will eventually be used to test kernel recovery and
metadata_csum recovery.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
The strptime() function does not update fields in struct tm that are
not specified in the input format. The glibc implementation sets the
tm_yday field (%j) when any of the year (%Y), month (%m), or day (%d)
fields are changed, but the MacOS strptime() does not set tm_yday in
this case. This caused string_to_time() to calculate the wrong Unix
epoch on MacOS. If tm_yday is unset, compute it in string_to_time().
This also fixes test regression failures for FreeBSD.
Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Fix a few minor bugs that cppcheck complained about.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
The dietlibc doesn't support the TZ environment variable, which is
required by the standard. Work around this so that we can run the
regression test suite when building with dietlibc. (This is useful
for finding problems.)
With this change, the only thing which doesn't work as far as dietlibc
is concerned is the posix_memalign test, and the MMP support tests
(because posix_memalign isn't provided by dietlibc, sigh.)
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
In response to reviewer comments, commit fe56188b07 included changes
that modified some of the code used to output error messages when
checking user-supplied block numbers. These changes converted calls
to parse_ulonglong() to calls to strtoblk(). Because strtoblk() calls
parse_ulonglong(), and both output error messages, two redundant and
relatively generic messages were output on each error.
Fix this by removing the error message output from strtoblk(), and
extending it to accept an optional error message argument that it
supplies in lieu of a default to parse_ulonglong(). Also, revert to
the more descriptive original error messages with mods per reviewer
comments, and fix an error message in do_replace_node().
Signed-off-by: Eric Whitney <enwlinux@gmail.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
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>
debugfs should use strtoull wrappers for reading block numbers from
the command line. "unsigned long" isn't wide enough to handle block
numbers on 32bit platforms.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Debugfs will now interpret date strings of the form @123 as 123
seconds after the start of the epoch. This is handy when editing an
orphan inode linked list using the inode's deletion time field.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
In the case where debugfs (or rdebugfs) is installed setgid disk, or
some such, we need to disable the use of environment variables for the
obvious reasons.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
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>
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>
Solaris's header files are very picky about which C compiler can be
used for SUSv3 conformance. Use of C99 is not compatible with SUSv2
(_XOPEN_SOURCE=500), and C89 is not compatible with SUSv3
(_XOPEN_SOURCE=600). Since we need some SUSv3 functions, consistently
use SUSv3 so that e2fsprogs will build on Solaris using c99.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
We need to set tm_isdst to -1 so that mktime will automatically
determine whether or not daylight savings time (DST) is in effect.
Previously tm_isdst was set to 0, which caused mktime to interpret the
time as if it was always not using DST.
Addresses-Debian-Bug: #471882
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
If we are redirecting the output of debugfs to a file or to another
process via a pipe, there's no point sending the output to a pager.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Fix strtoblk() to allow a block number 0, and
common_block_args_process() so it prints an error message if a block
number that can't be parsed by strtoul().
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
This fixes some (but not all) of the compatibility bugs which prevented
e2fsprogs from being compiled on a Linux 2.0.35 system. There are still
some unprotected use of long long's, and apparently some type problems
with the uuid library, but these can be fixed up later.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Generalize the time parsing code and move it to
util.c:string_to_time(). Add new command, set_current_time, which
sets the time used to set the filesystems's time fields.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
a new inode we make sure that the extra information in the inode (any extra
fields in a large inode and any ea-in-inode information) is cleared. This
can happen when e2fsck creates a new root inode or a new lost+found directory,
or when the user uses the debugfs write, mknod, or mkdir commands. Otherwise,
the newly create inode could inherit garbage (or old EA information) from
a previously deleted inode.
util.c (reset_getopt), debugfs.c (do_open_filesys,
do_show_super_stats), ls.c (do_list_dir), dump.c (do_dump),
htree.c (do_htree_dump, do_dx_hash), logdump.c (do_logdump):
Define and use a new function, reset_getopt(), which does whatever
is necessary to reset getopt() again. This is different for
different implementations, so the portabilty issues are a bit of a
nightmare. (Addresses Debian bug #192834)
mapping for a particular inode.
Fixed a bug in the libext2 library which broke ext2fs_bmap if no inode structre
was passed inside for here.
Fixed bad calling parameters to parse_ulong which broken the -b and -s
options to debugfs, as well as do_init, and the testb, setb, clearb functions.
recover deleted files. The lsdel command now takes an optional
argument which allows the user to only see the most recently
deleted files. Also added a new command, undel, which automates
undeleting a deleted inode and linking it back to a directory.
Also added an optional count argument to the testb, freeb, setb,
and find_free_block commands. The ls command now takes a new
option, -d, which lists deleted directory entries.
Factored out out commonly used code into utility subroutines
for ease of maintenance and to make the executable size smaller.
- Renamed linux/list.h to be linux/linked_list.h to work around a
problem caused by diet libc insistence to search the kernel
header files ahead of all other files in the include path,
including the user specified include files.
- Worked around a bug in diet libc which core dumps when using
putc with stderr by using fputs instead. As a bonus, this
also shaved a few bytes off of com_err.o.
- Fixed a real bug in debugfs which was detected because diet libc
was more sensitive than glibc when incorrectly using fclose()
where pclose() is required.
debugfs.c, debugfs.h, dump.c, icheck.c, ls.c, lsdel.c, ncheck.c,
setsuper.c, util.c: Change ino_t to ext2_ino_t. Fix a few minor
gcc-wall complaints while we're at it.
Fixup one more missing use of lb->f instead stdout when printing the
comma separator.
ChangeLog, util.c:
util.c (open_pager): Set SIGPIPE to be ignored, so that quitting out
of the pager doesn't blow away debugfs.
setsuper.c: New function which implements the set_super_value command.
Allows the user to set arbitrary superblock fields.
ChangeLog, util.c:
util.c (open_pager): If the PAGER environment variable is not set,
default to using "more".
Fix stupid dependency bug.
ChangeLog, debugfs.c, debugfs.h, util.c:
debugfs.c (do_testb, do_testi): Call check_fs_bitmaps to avoid
coredumping if the bitmaps aren't loaded.
util.c (check_fs_bitmaps): New function which checks whether or not
the bitmaps are loaded.