diff options
author | Theodore Ts'o <tytso@mit.edu> | 2022-08-12 22:34:57 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2022-08-12 22:34:57 -0400 |
commit | d05a33bd3e255d8d279b3399eadccbcaeb3613a5 (patch) | |
tree | c1837ecd2fd4fa708e878c538a91ca7c85d74ed1 | |
parent | d5aba8e5d349272eb221e2aab3775bb942f89684 (diff) | |
parent | 18ebcf26f478702cd09dd4229320d449469f1490 (diff) | |
download | e2fsprogs-d05a33bd3e255d8d279b3399eadccbcaeb3613a5.tar.gz |
Merge branch 'maint' into next
-rw-r--r-- | debugfs/logdump.c | 18 | ||||
-rw-r--r-- | e2fsck/Makefile.in | 3 | ||||
-rw-r--r-- | e2fsck/journal.c | 14 | ||||
-rw-r--r-- | e2fsck/unix.c | 7 | ||||
-rw-r--r-- | lib/support/Makefile.in | 8 | ||||
-rw-r--r-- | lib/support/devname.c | 66 | ||||
-rw-r--r-- | lib/support/devname.h | 19 | ||||
-rw-r--r-- | misc/Makefile.in | 17 | ||||
-rw-r--r-- | misc/e2initrd_helper.c | 5 | ||||
-rw-r--r-- | misc/fsck.c | 5 | ||||
-rw-r--r-- | misc/tune2fs.c | 5 | ||||
-rw-r--r-- | misc/util.c | 3 |
12 files changed, 138 insertions, 32 deletions
diff --git a/debugfs/logdump.c b/debugfs/logdump.c index 4154ef2a5..6b0133e06 100644 --- a/debugfs/logdump.c +++ b/debugfs/logdump.c @@ -63,15 +63,15 @@ static void dump_journal(char *, FILE *, struct journal_source *); static void dump_descriptor_block(FILE *, struct journal_source *, char *, journal_superblock_t *, - unsigned int *, int, __u32, tid_t); + unsigned int *, unsigned int, __u32, tid_t); static void dump_revoke_block(FILE *, char *, journal_superblock_t *, - unsigned int, int, tid_t); + unsigned int, unsigned int, tid_t); static void dump_metadata_block(FILE *, struct journal_source *, journal_superblock_t*, unsigned int, unsigned int, unsigned int, - int, tid_t); + unsigned int, tid_t); static void dump_fc_block(FILE *out_file, char *buf, int blocksize, tid_t transaction, int *fc_done); @@ -649,11 +649,11 @@ static void dump_descriptor_block(FILE *out_file, struct journal_source *source, char *buf, journal_superblock_t *jsb, - unsigned int *blockp, int blocksize, + unsigned int *blockp, unsigned blocksize, __u32 maxlen, tid_t transaction) { - int offset, tag_size, csum_size = 0; + unsigned offset, tag_size, csum_size = 0; char *tagp; journal_block_tag_t *tag; unsigned int blocknr; @@ -709,7 +709,7 @@ static void dump_descriptor_block(FILE *out_file, static void dump_revoke_block(FILE *out_file, char *buf, journal_superblock_t *jsb EXT2FS_ATTR((unused)), unsigned int blocknr, - int blocksize EXT2FS_ATTR((unused)), + unsigned int blocksize, tid_t transaction) { unsigned int offset, max; @@ -727,10 +727,10 @@ static void dump_revoke_block(FILE *out_file, char *buf, header = (jbd2_journal_revoke_header_t *) buf; offset = sizeof(jbd2_journal_revoke_header_t); max = be32_to_cpu(header->r_count); - if (max > be32_to_cpu(jsb->s_blocksize)) { + if (max > blocksize) { fprintf(out_file, "Revoke block's r_count invalid: %u\b", max); - max = be32_to_cpu(jsb->s_blocksize); + max = blocksize; } while (offset < max) { @@ -775,7 +775,7 @@ static void dump_metadata_block(FILE *out_file, struct journal_source *source, unsigned int log_blocknr, unsigned int fs_blocknr, unsigned int log_tag_flags, - int blocksize, + unsigned int blocksize, tid_t transaction) { int retval; diff --git a/e2fsck/Makefile.in b/e2fsck/Makefile.in index 71ac3cf52..2112df57f 100644 --- a/e2fsck/Makefile.in +++ b/e2fsck/Makefile.in @@ -465,7 +465,8 @@ unix.o: $(srcdir)/unix.c $(top_builddir)/lib/config.h \ $(top_srcdir)/lib/ext2fs/fast_commit.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \ $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \ $(srcdir)/problem.h $(srcdir)/jfs_user.h \ - $(top_srcdir)/lib/ext2fs/kernel-jbd.h $(top_srcdir)/version.h + $(top_srcdir)/lib/ext2fs/kernel-jbd.h $(top_srcdir)/version.h \ + $(top_srcdir)/lib/support/devname.h dirinfo.o: $(srcdir)/dirinfo.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(srcdir)/e2fsck.h \ $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \ diff --git a/e2fsck/journal.c b/e2fsck/journal.c index 3cd3e306f..d802c5e9f 100644 --- a/e2fsck/journal.c +++ b/e2fsck/journal.c @@ -747,9 +747,19 @@ static int ext4_fc_handle_inode(e2fsck_t ctx, __u8 *val) fc_raw_inode = val + sizeof(fc_ino); ino = le32_to_cpu(fc_ino); - if (EXT2_INODE_SIZE(ctx->fs->super) > EXT2_GOOD_OLD_INODE_SIZE) - inode_len += ext2fs_le16_to_cpu( + if (EXT2_INODE_SIZE(ctx->fs->super) > EXT2_GOOD_OLD_INODE_SIZE) { + __u16 extra_isize = ext2fs_le16_to_cpu( ((struct ext2_inode_large *)fc_raw_inode)->i_extra_isize); + + if ((extra_isize < (sizeof(inode->i_extra_isize) + + sizeof(inode->i_checksum_hi))) || + (extra_isize > (EXT2_INODE_SIZE(ctx->fs->super) - + EXT2_GOOD_OLD_INODE_SIZE))) { + err = EFSCORRUPTED; + goto out; + } + inode_len += extra_isize; + } err = ext2fs_get_mem(inode_len, &inode); if (err) goto out; diff --git a/e2fsck/unix.c b/e2fsck/unix.c index 76549c407..5d924fdaa 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -52,6 +52,7 @@ extern int optind; #include "e2p/e2p.h" #include "uuid/uuid.h" #include "support/plausible.h" +#include "support/devname.h" #include "e2fsck.h" #include "problem.h" #include "jfs_user.h" @@ -943,8 +944,8 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx) goto sscanf_err; break; case 'j': - ctx->journal_name = blkid_get_devname(ctx->blkid, - optarg, NULL); + ctx->journal_name = get_devname(ctx->blkid, + optarg, NULL); if (!ctx->journal_name) { com_err(ctx->program_name, 0, _("Unable to resolve '%s'"), @@ -1023,7 +1024,7 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx) ctx->io_options = strchr(argv[optind], '?'); if (ctx->io_options) *ctx->io_options++ = 0; - ctx->filesystem_name = blkid_get_devname(ctx->blkid, argv[optind], 0); + ctx->filesystem_name = get_devname(ctx->blkid, argv[optind], 0); if (!ctx->filesystem_name) { com_err(ctx->program_name, 0, _("Unable to resolve '%s'"), argv[optind]); diff --git a/lib/support/Makefile.in b/lib/support/Makefile.in index e5600a82a..9c0d54fec 100644 --- a/lib/support/Makefile.in +++ b/lib/support/Makefile.in @@ -24,7 +24,8 @@ OBJS= cstring.o \ quotaio.o \ quotaio_v2.o \ quotaio_tree.o \ - dict.o + dict.o \ + devname.o SRCS= $(srcdir)/argv_parse.c \ $(srcdir)/cstring.c \ @@ -38,7 +39,8 @@ SRCS= $(srcdir)/argv_parse.c \ $(srcdir)/quotaio.c \ $(srcdir)/quotaio_tree.c \ $(srcdir)/quotaio_v2.c \ - $(srcdir)/dict.c + $(srcdir)/dict.c \ + $(srcdir)/devname.c LIBRARY= libsupport LIBDIR= support @@ -171,3 +173,5 @@ quotaio_v2.o: $(srcdir)/quotaio_v2.c $(top_builddir)/lib/config.h \ $(srcdir)/quotaio_tree.h dict.o: $(srcdir)/dict.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(srcdir)/dict.h +devname.o: $(srcdir)/devname.c $(top_builddir)/lib/config.h \ + $(top_builddir)/lib/dirpaths.h $(srcdir)/nls-enable.h $(srcdir)/devname.h diff --git a/lib/support/devname.c b/lib/support/devname.c new file mode 100644 index 000000000..8c2349a32 --- /dev/null +++ b/lib/support/devname.c @@ -0,0 +1,66 @@ +/* + * devname.c --- Support function to translate a user provided string + * identifying a device to an actual device path + * + * Copyright (C) 2022 Red Hat, Inc., Lukas Czerner <lczerner@redhat.com> + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Public + * License. + * %End-Header% + */ + +#include <unistd.h> +#include <string.h> +#include <stdio.h> + +#include "config.h" +#include "devname.h" +#include "nls-enable.h" + +/* + * blkid_get_devname() is primarily intended for parsing "NAME=value" + * tokens. It will return the device matching the specified token, NULL if + * nothing is found, or copy of the string if it's not in "NAME=value" + * format. + * get_devname() takes the same parameters and works the same way as + * blkid_get_devname() except it can handle '=' in the file name. + */ +char *get_devname(blkid_cache cache, const char *token, const char *value) +{ + int is_file = 0; + char *ret = NULL; + + if (!token) + goto out; + + if (value) { + ret = blkid_get_devname(cache, token, value); + goto out; + } + + if (access(token, F_OK) == 0) + is_file = 1; + + ret = blkid_get_devname(cache, token, NULL); + if (ret) { + /* + * In case of collision prefer the result from + * blkid_get_devname() to avoid a file masking file system with + * existing tag. + */ + if (is_file && (strcmp(ret, token) != 0)) { + fprintf(stderr, + _("Collision found: '%s' refers to both '%s' " + "and a file '%s'. Using '%s'!\n"), + token, ret, token, ret); + } + goto out; + } + +out_strdup: + if (is_file) + ret = strdup(token); +out: + return ret; +} diff --git a/lib/support/devname.h b/lib/support/devname.h new file mode 100644 index 000000000..cc1956122 --- /dev/null +++ b/lib/support/devname.h @@ -0,0 +1,19 @@ +/* + * devname.c --- Figure out if a pathname is ext* or something else. + * + * Copyright (C) 2022 Red Hat, Inc., Lukas Czerner <lczerner@redhat.com> + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Public + * License. + * %End-Header% + */ + +#ifndef DEVNAME_H_ +#define DEVNAME_H_ + +#include "blkid/blkid.h" + +char *get_devname(blkid_cache cache, const char *token, const char *value); + +#endif /* DEVNAME_H_ */ diff --git a/misc/Makefile.in b/misc/Makefile.in index 4db59cdf6..96e368712 100644 --- a/misc/Makefile.in +++ b/misc/Makefile.in @@ -360,15 +360,15 @@ dumpe2fs.static: $(DUMPE2FS_OBJS) $(DEPLIBS) $(DEPLIBS_E2P) $(DEPLIBUUID) $(DEPL $(STATIC_LIBS) $(STATIC_LIBE2P) $(STATIC_LIBUUID) \ $(LIBINTL) $(SYSLIBS) $(STATIC_LIBBLKID) $(LIBMAGIC) -fsck: $(FSCK_OBJS) $(DEPLIBBLKID) +fsck: $(FSCK_OBJS) $(DEPLIBBLKID) $(DEPLIBS) $(E) " LD $@" $(Q) $(CC) $(ALL_LDFLAGS) -o fsck $(FSCK_OBJS) $(LIBBLKID) \ - $(LIBINTL) $(SYSLIBS) + $(LIBINTL) $(SYSLIBS) $(LIBS) -fsck.profiled: $(FSCK_OBJS) $(PROFILED_DEPLIBBLKID) +fsck.profiled: $(FSCK_OBJS) $(PROFILED_DEPLIBBLKID) $(PROFILED_DEPLIBS) $(E) " LD $@" $(Q) $(CC) $(ALL_LDFLAGS) -g -pg -o fsck.profiled $(PROFILED_FSCK_OBJS) \ - $(PROFILED_LIBBLKID) $(LIBINTL) $(SYSLIBS) + $(PROFILED_LIBBLKID) $(LIBINTL) $(SYSLIBS) $(PROFILED_LIBS) badblocks: $(BADBLOCKS_OBJS) $(DEPLIBS) $(E) " LD $@" @@ -736,8 +736,8 @@ tune2fs.o: $(srcdir)/tune2fs.c $(top_builddir)/lib/config.h \ $(top_srcdir)/lib/ext2fs/jfs_compat.h $(top_srcdir)/lib/ext2fs/kernel-list.h \ $(top_srcdir)/lib/ext2fs/compiler.h $(top_srcdir)/lib/support/plausible.h \ $(top_srcdir)/lib/support/quotaio.h $(top_srcdir)/lib/support/dqblk_v2.h \ - $(top_srcdir)/lib/support/quotaio_tree.h $(top_srcdir)/lib/e2p/e2p.h \ - $(srcdir)/util.h $(top_srcdir)/version.h \ + $(top_srcdir)/lib/support/quotaio_tree.h $(top_srcdir)/lib/support/devname.h \ + $(top_srcdir)/lib/e2p/e2p.h $(srcdir)/util.h $(top_srcdir)/version.h \ $(top_srcdir)/lib/support/nls-enable.h mklost+found.o: $(srcdir)/mklost+found.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \ @@ -799,7 +799,8 @@ badblocks.o: $(srcdir)/badblocks.c $(top_builddir)/lib/config.h \ $(top_srcdir)/lib/ext2fs/bitops.h $(top_srcdir)/lib/support/nls-enable.h fsck.o: $(srcdir)/fsck.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(top_srcdir)/version.h \ - $(top_srcdir)/lib/support/nls-enable.h $(srcdir)/fsck.h + $(top_srcdir)/lib/support/nls-enable.h $(top_srcdir)/lib/support/devname.h \ + $(srcdir)/fsck.h util.o: $(srcdir)/util.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(top_srcdir)/lib/et/com_err.h \ $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \ @@ -808,7 +809,7 @@ util.o: $(srcdir)/util.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/ext2fs/ext2_err.h \ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/hashmap.h \ $(top_srcdir)/lib/ext2fs/bitops.h $(top_srcdir)/lib/support/nls-enable.h \ - $(srcdir)/util.h + $(srcdir)/util.h $(top_srcdir)/lib/support/devname.h uuidgen.o: $(srcdir)/uuidgen.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(top_srcdir)/lib/support/nls-enable.h blkid.o: $(srcdir)/blkid.c $(top_builddir)/lib/config.h \ diff --git a/misc/e2initrd_helper.c b/misc/e2initrd_helper.c index 436aab8c4..b39fe15d7 100644 --- a/misc/e2initrd_helper.c +++ b/misc/e2initrd_helper.c @@ -36,6 +36,7 @@ extern char *optarg; #include "ext2fs/ext2fs.h" #include "blkid/blkid.h" #include "support/nls-enable.h" +#include "support/devname.h" #include "../version.h" @@ -262,7 +263,7 @@ static int parse_fstab_line(char *line, struct fs_info *fs) parse_escape(freq); parse_escape(passno); - dev = blkid_get_devname(cache, device, NULL); + dev = get_devname(cache, device, NULL); if (dev) device = dev; @@ -325,7 +326,7 @@ static void PRS(int argc, char **argv) } if (optind < argc - 1 || optind == argc) usage(); - device_name = blkid_get_devname(NULL, argv[optind], NULL); + device_name = get_devname(NULL, argv[optind], NULL); if (!device_name) { com_err(program_name, 0, _("Unable to resolve '%s'"), argv[optind]); diff --git a/misc/fsck.c b/misc/fsck.c index 4efe10eca..1f6ec7d9b 100644 --- a/misc/fsck.c +++ b/misc/fsck.c @@ -59,6 +59,7 @@ #endif #include "../version.h" +#include "support/devname.h" #include "support/nls-enable.h" #include "fsck.h" #include "blkid/blkid.h" @@ -297,7 +298,7 @@ static int parse_fstab_line(char *line, struct fs_info **ret_fs) parse_escape(freq); parse_escape(passno); - dev = blkid_get_devname(cache, device, NULL); + dev = get_devname(cache, device, NULL); if (dev) device = dev; @@ -1128,7 +1129,7 @@ static void PRS(int argc, char *argv[]) progname); exit(EXIT_ERROR); } - dev = blkid_get_devname(cache, arg, NULL); + dev = get_devname(cache, arg, NULL); if (!dev && strchr(arg, '=')) { /* * Check to see if we failed because diff --git a/misc/tune2fs.c b/misc/tune2fs.c index 0c2ab3c3f..50bba9903 100644 --- a/misc/tune2fs.c +++ b/misc/tune2fs.c @@ -62,6 +62,7 @@ extern int optind; #include "et/com_err.h" #include "support/plausible.h" #include "support/quotaio.h" +#include "support/devname.h" #include "uuid/uuid.h" #include "e2p/e2p.h" #include "util.h" @@ -1839,7 +1840,7 @@ static void parse_e2label_options(int argc, char ** argv) io_options = strchr(argv[1], '?'); if (io_options) *io_options++ = 0; - device_name = blkid_get_devname(NULL, argv[1], NULL); + device_name = get_devname(NULL, argv[1], NULL); if (!device_name) { com_err("e2label", 0, _("Unable to resolve '%s'"), argv[1]); @@ -2139,7 +2140,7 @@ static void parse_tune2fs_options(int argc, char **argv) io_options = strchr(argv[optind], '?'); if (io_options) *io_options++ = 0; - device_name = blkid_get_devname(NULL, argv[optind], NULL); + device_name = get_devname(NULL, argv[optind], NULL); if (!device_name) { com_err(program_name, 0, _("Unable to resolve '%s'"), argv[optind]); diff --git a/misc/util.c b/misc/util.c index 48e623dcc..e84ebab5b 100644 --- a/misc/util.c +++ b/misc/util.c @@ -45,6 +45,7 @@ #include "ext2fs/ext2_fs.h" #include "ext2fs/ext2fs.h" #include "support/nls-enable.h" +#include "support/devname.h" #include "blkid/blkid.h" #include "util.h" @@ -183,7 +184,7 @@ void parse_journal_opts(const char *opts) arg ? arg : "NONE"); #endif if (strcmp(token, "device") == 0) { - journal_device = blkid_get_devname(NULL, arg, NULL); + journal_device = get_devname(NULL, arg, NULL); if (!journal_device) { if (arg) fprintf(stderr, _("\nCould not find " |