Commit Graph

613 Commits

Author SHA1 Message Date
Theodore Ts'o
cecc2bc78b debugfs: fix printing of xattrs with ea_in_inode values
Due to a missing "else" debugfs was printing (garbage) from the xattr
buffer which could potentially overrun the end of the buffer.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2019-03-26 09:36:53 -04:00
Theodore Ts'o
a935b93dca Merge branch 'maint' into next 2019-02-10 21:50:26 -05:00
Artem Blagodarenko
453a2f6175 debugfs: output large directory size
large_dir option allows to create directory with size > 2GB.
debugfs utility outputs negative size value for large directories
and ignores high part of directory size.

Fix debugfs to use high part of directory size in debugfs output
and use appropriate output format.

Signed-off-by: Artem Blagodarenko <artem.blagodarenko@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2019-02-05 17:11:26 -05:00
Theodore Ts'o
32917350a4 debugfs: fix set_inode_field so it can set the checksum field
Previously, setting the inode field was a no-op, since the library
function ext2fs_write_inode_full() would override whatever value was
set by debugfs.  Use the new ext2fs_write_inode2() interface so we can
in fact set the checksum to a potentially wrong value.  Also, ignore
the inode checksum failures if we are setting the checksum, and if the
checksum value is "calc", set the inode checksum to the correct value.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-12-15 18:31:40 -05:00
Gabriel Krisman Bertazi
ef733f1a97 debugfs: support encoding when printing the file hash
Implement two parameters -e and -c, to specify encoding and casefold
when printing the hash of a given file.

Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.co.uk>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-12-02 23:59:12 -05:00
Theodore Ts'o
29d78e01ef Merge branch 'maint' into next 2018-10-14 12:31:06 -04:00
David Anderson
c4ef5b4f6b AOSP: Fix debugfs clang build.
Signed-off-by: Theodore Ts'o <tytso@mit.edu>

Change-Id: Ic4de282039524e1858bbd288e2b85be30d843f40
From AOSP commit: 7e9e2ca4b08aab41b28e57d0c9b840b8b9e6466d
2018-10-12 22:55:57 -04:00
Theodore Ts'o
f7260c1974 debugfs: fix missing variable rename in debugfs.h
This should have been part of commit 2fcbcb1b9e: "Fix function
declarations for ss commands to fix LTO warnings".

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-08-15 22:06:16 -04:00
Theodore Ts'o
2ca70c2253 Merge branch 'maint' into next 2018-08-13 22:40:15 -04:00
Ross Burton
5abc041492 build: use MKDIR_P instead of MKINSTALLDIRS
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-08-11 15:29:48 -04:00
Theodore Ts'o
2fcbcb1b9e Fix function declarations for ss commands to fix LTO warnings
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-08-08 19:59:40 -04:00
David Anderson
0958bc6327 AOSP: Update Android.bp files.
debugfs now links to a new libext2_support library, which only includes
cstring.c (Android separates other pieces of libsupport into separate
libraries).

e2fsck now builds with -Wno-unused-variable to work around an unused
variable introduced by cabde4999d.

libext_e2p builds the new ljs.c file, and links to ws2_32 on Windows for
ntohl().

Signed-off-by: Theodore Ts'o <tytso@mit.edu>

Change-Id: I42edce0478f1529f44acdbef1495ec5270e3a61e
From AOSP commit: af14814afe0cb3389ecc4b9e9422bd7e8962e0ed
2018-08-05 13:54:26 -04:00
Jaco Kroon
4a30e2ae7c debugfs: fix ncheck so it handles hard links correctly
Due to hard links inodes can have multiple names (except for folders),
ncheck should find all of the names (equal to the number of links to the
inodes, directories excepted), not names to the count of the provided
inodes.

Signed-off-by: Jaco Kroon <jaco@uls.co.za>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-08-05 12:07:20 -04:00
Li Dongyang
fddc423dc6 Fix compile error and warnings for old gcc versions
-Wimplicit-fallthrough option was added in gcc7 and
-Wpedantic was added in gcc4.8, while #pragma GCC diagnostic
support was not available until gcc4.6

We got following warnings:
../lib/ext2fs/fiemap.h:35: warning: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’
../lib/ext2fs/fiemap.h:36: warning: unknown option after ‘#pragma GCC diagnostic’ kind
../lib/ext2fs/fiemap.h:38: warning: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’

and error:
filefrag.c: In function ‘main’:
filefrag.c:577: error: #pragma GCC diagnostic not allowed inside functions
filefrag.c:578: error: #pragma GCC diagnostic not allowed inside functions
filefrag.c:595: error: #pragma GCC diagnostic not allowed inside functions

when compiling latest e2fsprogs with a gcc older than 4.6
e.g. on CentOS 6.9

Signed-off-by: Li Dongyang <dongyangli@ddn.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-07-14 20:46:30 -04:00
Theodore Ts'o
8cec4acdc0 tests, mke2fs: add option to suppress xattr copying to fix f_extent_htree
If the developer is running with SELinux enabled on /tmp, the
f_extent_htree regression test will fail because mke2fs by default
copies the extended attributes into the newly created file system (if
a directory hierarchy is specified via the -d option).

Fix this by adding a new extended option to mke2fs, -E no_copy_xattrs
and using it in f_extent_htree's test script.

Reported-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-06-26 15:21:28 -04:00
Theodore Ts'o
47e6105264 debugfs: fix mknod command on some 32-bit platforms due to LFS
On some platforms the layout of struct stat changes if
_FILE_OFFSET_BITS is set to 64 (which force the use of 64-bit types
and 64-bit variants for system calls such as stat, lseek, etc.)

This is not true (mercifully) on i386, but it is true for the 32-bit
mips platform on Linux.  This caused debugfs's mknod command to fail,
since it used struct stat to pass the desired st_mode and st_rdev
fields for the to-be-created device file or FIFO, and this would be
different for create_inode.c and debugfs.c.

Linking together different object files together compiled with
different values of _FILE_OFFSET_BITS is perilous, but for now, let's
fix the specific problem by passing the two fields in the stat
structure that we really care about.  This fixes two regression tests
on the 32-bit MIPS platform: d_special_files and r_move_itable.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-06-26 09:02:46 -04:00
Theodore Ts'o
574b714d58 Update Makefile.in files using "make depend"
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-06-25 10:10:39 -04:00
Theodore Ts'o
5f63e5c4f9 debugfs: suppress spurious "checksum errors" message for unrelated failures
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-06-24 21:21:49 -04:00
Theodore Ts'o
366d526f15 debugfs: avoid undefined bit shift in parse_uint()
The case is one that should never happen (and indicates a bug if it
does), but in that case, we should still avoid an undefiniced C
expression.

Fixes-Coverity-Bug: 1297494
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-06-24 00:39:37 -04:00
Theodore Ts'o
ac3256fd31 Fix gcc and clang warnings
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-06-23 23:00:50 -04:00
Andreas Dilger
b7454eb8ee tests: remove redundant sed filtering
Now that the majority of device name filtering is in filter.sed,
it does not need to be specified explicitly for every test.

Fix the error message printed in debugfs when opening the device
to match that used in other tools.  This simplifies the filtering,
and will be helpful if debugfs messages are internationalized.

[ Fixed up some test failures in m_hugefile t_uninit_bg_rm --tytso ]

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-06-22 14:06:53 -04:00
Jan Kara
d194a08083 debugfs: allow fixing superblock errors in catastrophic mode
Open filesystem with EXT2_FLAG_IGNORE_SB_ERRORS flag in catastrophic
mode so that superblock errors can be fixed in debugfs.

Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-06-19 11:27:51 -04:00
Jan Kara
d338544de1 debugfs: allow read-write opening in catastrophic mode
Allow filesystem to be open read-write in catastrophic mode so that one
can fixup e.g. superblock breakage. The CHECK_FS_BITMAPS flag to
common_args_process() still guards us from doing operations on bitmaps
which we don't load in this mode.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-06-19 11:27:51 -04:00
Theodore Ts'o
c7c99af6bd debugfs: add support to display details of extended attribute structures
Teach the inode_dump and block_dump commands the -x option, which
tries to interpret the data structures as xattr data strucgtures.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-06-13 18:41:45 -04:00
Theodore Ts'o
dd1543dba4 debugfs: add -b and -e options to the inode_dump command
Teach the inode_dump command to dump out just the i_block array and
the extra space in the inode, as a convenience to someone
investigating a corrupted inode.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-05-26 23:11:18 -04:00
harshads
7cc4cf5c7c debugfs: release clusters only once in release_blocks_proc
While killing file by inode in debugfs (kill_file_by_inode), if
bigalloc feature is turned on, release clusters only once. We do it by
remembering the last released cluster while releasing blocks. We
release a cluster only if it is not already released.

Signed-off-by: Harshad Shirwadkar <harshads@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-03-24 11:14:06 -04:00
Theodore Ts'o
6a6393964f debugfs: read allocation bitmaps more efficiently
It is more efficient to use ext2fs_read_bitmaps() than to read the
inode and block bitmaps separately, since extra seeks.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-03-20 22:10:09 -04:00
Theodore Ts'o
c19b18f84b AOSP: use e2fsprogs-defaults for ccflags
From AOSP commit: 2002d7f1fc: Use -Werror in external/e2fsprogs

... which got reverted and reapplied in a confusing way.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-02-26 13:54:20 -05:00
Jeff Gaston
33b80078db AOSP: Revert "Add "libc" to soong static_executable targets."
This reverts commit b799ad178fa18c2925a283206496d3f5d6e87f35.
It's no longer needed after https://android-review.googlesource.com/c/329298/

Bug: 34722432
Test: lunch aosp_arm-eng && mmma external/e2fsprogs
Change-Id: I4115fe89ef7751364053223be24e7682e66b6b67
From AOSP commit: 34115ec38e86ba3cc17ae7a866e891abf7bd3aeb
2018-02-26 13:53:35 -05:00
Pavlin Radoslavov
88ca49f99b AOSP: Add missing libdl dependencies
Bug: 62815515
Test: lunch full-eng; make checkbuild
Change-Id: I1751669c4ed046c22587938e04eb76abe8553a8d
From AOSP commit: a24084ceb74c84b0943c86deb5cb99a63d3c46d7
2018-02-26 12:23:11 -05:00
Theodore Ts'o
1ad400d380 Merge branch 'maint' into next 2018-02-26 11:13:35 -05:00
Theodore Ts'o
60f032bbc1 tune2fs/fuse2fs/debugfs: after replaying the journal, fix up s_lastcheck
If the file system needs to have the journal replayed, but definition
it can't be freshly checked.  So if the time when the file system was
last checked (s_lastcheck) is before the time it was last mounted
(s_mtime), force s_lastcheck to be before s_mtime.

This is necessary to make sure some of tune2fs's safety checks work
correctly after replaying the journal, since some of tune2fs's
operations really require that the file system be self-consistent or
grave damage can result.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-02-24 18:11:19 -05:00
Theodore Ts'o
604075a0ad v1.43.9
-----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCAAdFiEEK2m5VNv+CHkogTfJ8vlZVpUNgaMFAlp9KFYACgkQ8vlZVpUN
 gaNEdwgAgstbkq3T7E16dIbW+f7/U7JbF8ugvZh/OnXp0OunmrkP+N2T9ZHriG8k
 f0eb2Polp25lC2U3tHGUs4gRsTaZPKmxMQVwY8/cLs556+zlmItZpDdaT7Hu5zPH
 ReL/s0k9SjF9Cv75YAu8m6ygtkyiy+36HD50EFNAmZoWLQa2xHx/df+HXAXVVz5D
 ujzQ/W899RXdOBERzbvfYpblA/VoYPZaaPf6ctZMtBZfzWUcn+PLljmxPgZEJWNn
 KO/e0cftfulmD12G3OgLsge6hbOyJSN3SEHW5EBy87y3sR1EjJnrHADUxaaXDYrD
 9znRtY0LKqQfIX103Jlm82pigq+adA==
 =5ztX
 -----END PGP SIGNATURE-----

Merge tag 'v1.43.9' into next

v1.43.9
2018-02-09 00:29:10 -05:00
Tyson Nottingham
f54f08bd0b debugfs: remove misplaced "MMP is unsupported" message
This message was inadvertently copied from the version of do_dump_mmp
that is used when CONFIG_MMP is disabled.

Signed-off-by: Tyson Nottingham <tgnottingham@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
2018-02-07 23:28:17 -05:00
Theodore Ts'o
df22ead1ba Merge branch 'maint' into next 2018-01-02 00:53:10 -05:00
Shen-Ta Hsieh
88580763fc debugfs: fix printf format %d on ext2_ino_t
Signed-off-by: Shen-Ta Hsieh <ibmibmibm.tw@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2018-01-01 23:51:36 -05:00
Tyson Nottingham
7600aa0f06 Add missing information to debugfs man pages and usage texts
Add descriptions for dump_unused, get_quota, list_quota,
set_current_time, show_debugfs_params, and supported_features
commands to debugfs man page. Add various missing command
arguments and correct a few typos in man page and usage texts.

Signed-off-by: Tyson Nottingham <tgnottingham@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2017-12-15 00:28:58 -05:00
Qian Yingjin
07b11a7ba3 debugfs: fix ncheck program output
Fix the bug that print the inode number not the program name
when reporting bad inode name during checking in ncheck.
Minor bug fix: it should reduce iw->inodes_left when found
matched inode number.

Signed-off-by: Qian Yingjin <qian@ddn.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2017-12-13 10:59:39 -05:00
Theodore Ts'o
69ab815dbe Merge branch 'maint' into next 2017-10-15 23:20:53 -04:00
Sebastian Rasmussen
055866d84d Fix typos in code comments and developer docs
Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
2017-10-15 23:00:11 -04:00
Sebastian Rasmussen
ce20096fc6 Fix typos in error messages and documentation
Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
2017-10-15 23:00:03 -04:00
Andreas Dilger
8dca24c3cb debugfs: print "Xst" bits of file mode via stat
Currently, debugfs does not print the Xst high-order mode bits
in the "stat" output.  While "ls -l" shows these bits are set:

  # ls -il /mnt/tmp/O/0/d2/406306
  1588 0 -rwSrwSrw- 1 root root 0 Dec 31  1969 /mnt/tmp/O/0/d2/406306

debugfs currently only prints the low nine "ugo" mode bits:

  # debugfs -c -R "stat O/0/d2/406306" /dev/vgmyth/lvmythost4
  Inode: 1588   Type: regular    Mode:  0666   Flags: 0x80000

Fix debugfs so that the high-order mode bits are also printed,
if available, otherwise only print the standard low mode bits.

  # debugfs -c -R "stat O/0/d2/406306" /dev/vgmyth/lvmythost4
  Inode: 1588   Type: regular    Mode:  06666   Flags: 0x80000

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2017-10-15 22:27:40 -04:00
Theodore Ts'o
21f685b6c1 Merge branch 'maint' into next 2017-10-15 16:37:10 -04:00
Theodore Ts'o
6ae16a6814 misc: clean up error handling for ext2fs_run_ext3_journal()
The ext2fs_run_ext3_journal() function is in debugfs/journal.c, and in
some error conditions cases may close the passed-in file system handle.

Clean up the both the function so that it reliably clears the file
system handle if it has been freed, and its callers so that they do
not crash by dereferencing a null pointer if it has been freed.

Reported-by: Erkki Ruohtula <eru@netti.fi>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2017-10-15 00:22:20 -04:00
Theodore Ts'o
fed2dbdc64 Merge branch 'maint' into next 2017-07-27 20:07:22 -04:00
Theodore Ts'o
b55571cdf7 debugfs: fix "ls -p" to avoid printing garbage after the file name
In commit 68a1de3df3 (debugfs: pretty print encrypted filenames in the
ls command), a change was introduced in debugfs/ls.c which instead of
copying dirent->name and 0-terminating it, dirent->name is used
directly in printf.

However, instead of using the precision to limit the number of
characters output, the code uses the field width. As a result,
characters are output until a 0 is read, which results in garbage
after the file name.

Also fix two other instances of this in debugging messages that aren't
used, but fixing them will avoid potential future copypasta bugs.

Reported-by: Christian Gabriel <ch_gabriel@web.de>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2017-07-24 13:11:16 -04:00
Tahsin Erdogan
50d0998cfe libext2fs: add ea_inode support to set xattr
This patch is a major update to how we decide where to put extended
attributes.  The main motivation is to enable creating values in
extended attribute inodes.  While doing this, we want to implement a
behavior that is as close to kernel as possible.

Existing set ea code deviates from kernel behavior which makes it harder
to implement ea_inode feature:

 - kernel only sorts ea entries in xattr block, e2fsprogs implementation
   sorts all entries on every update.

 - e2fsprogs implementation shuffled things on every update so the order
   of updates does not matter. Kernel does not reshuffle things.

 - e2fsprogs could evacuate entries from inode body to xattr block and
   vice versa. This behavior does not exist in kernel.

Such differences could lead to inconsistent behavior between fuse2fs and
a kernel mount.

With ea_inode feature, we also need to decide whether to put a value
in an inode or keep it 'inline'.  In kernel implementation this
depends on current placement of entries.

To close the behavioral gap, ext2fs_xattr_set() now takes over the
decision about where to place ea values.  This also allows it to raise
errors early instead of delaying them to a separate
ext2fs_xattrs_write() call later.

Signed-off-by: Tahsin Erdogan <tahsin@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2017-07-23 23:15:08 -04:00
Theodore Ts'o
393df14769 debugfs: add sanity checking to the string_to_inode() utility function
Otherwise it's possible for a corrupt file system or bad user input to
cause debugfs to crash if the resulting inode number is insanely
large.

This problem was found using American Fuzzy Lop.

Reported-by: Adam Buchbinder <abuchbinder@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2017-07-23 00:45:05 -04:00
Tahsin Erdogan
cf0be23436 Use i_size to determine whether a symlink is a fast symlink
Current way of determining whether a symlink is in fast symlink
format is to call ext2fs_inode_data_blocks2(). If number of data
blocks is zero and EXT4_INLINE_DATA_FL flag is not set, then symlink
data must be in inode->i_block.

This heuristic is becoming increasingly hard to maintain because
inode->i_blocks count can also be incremented for blocks used by
extended attributes. Before ea_inode feature, extra block could come
from xattr block, now more blocks can be added because of xattr
inodes.

To address the issue, add a ext2fs_is_fast_symlink() function that
gives a direct answer based on inode->i_size field. This is
equivalent to kernel's ext4_inode_is_fast_symlink() function.

This patch also fixes a few issues related to fast symlink handling:

  - Both rdump_symlink() and follow_link() interpreted symlinks with
    0 data blocks to always mean fast symlinks. This is incorrect
    because symlinks that are stored as inline data also have
    0 data blocks. Thus, they try to read everything from
    inode->i_block and miss the symlink suffix in inode extra area.

  - e2fsck_pass1_check_symlink() had code to handle inode with
    EXT4_INLINE_DATA_FL flag twice. The first if block always returns
    from the function so the second one is unreachable code.

Signed-off-by: Tahsin Erdogan <tahsin@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2017-07-05 00:06:30 -04:00
Elliott Hughes
7701f128ae AOSP: Define HAVE_SYS_SYSMACROS_H for Android.
Also remove a duplicate copy of misc/create_inode.c that isn't upstream.

Bug: https://github.com/android-ndk/ndk/issues/398
Test: builds
Change-Id: Ibc475c82aa21f063673cb68bcf6e41ad9d821cd3
From AOSP commit: 37f805a9571cf33c95080c3dbd65c7a4e46fcd71

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2017-05-23 23:18:28 -04:00