+2003-03-01 Theodore Ts'o <tytso@mit.edu>
+
+ * Makefile.in, logdump.c (do_logdump): Use the blkid functions to
+ find the external journal device.
+
2003-01-21 Theodore Ts'o <tytso@mit.edu>
* dump.c (do_dump): Open the output file with O_LARGEFILE so we
$(srcdir)/dump.c $(srcdir)/setsuper.c ${srcdir}/logdump.c \
$(srcdir)/htree.c
-LIBS= $(LIBEXT2FS) $(LIBE2P) $(LIBSS) $(LIBCOM_ERR) $(LIBUUID)
-DEPLIBS= $(LIBEXT2FS) $(LIBE2P) $(LIBSS) $(LIBCOM_ERR) $(DEPLIBUUID)
+LIBS= $(LIBEXT2FS) $(LIBE2P) $(LIBSS) $(LIBCOM_ERR) $(LIBBLKID) $(LIBUUID)
+DEPLIBS= $(LIBEXT2FS) $(LIBE2P) $(LIBSS) $(LIBCOM_ERR) $(LIBBLKID) $(DEPLIBUUID)
.c.o:
$(CC) -c $(ALL_CFLAGS) $< -o $@
#endif
#include "debugfs.h"
+#include "blkid/blkid.h"
#include "jfs_user.h"
#include <uuid/uuid.h>
ext2_ino_t journal_inum;
struct ext2_inode journal_inode;
ext2_file_t journal_file;
-
char *tmp;
-
const char *logdump_usage = ("Usage: logdump "
"[-ac] [-b<block>] [-i<inode>] "
"[-f<journal_file>] [output_file]");
-
struct journal_source journal_source;
-
+ struct ext2_super_block *es = NULL;
+
optind = 0;
#ifdef HAVE_OPTRESET
optreset = 1; /* Makes BSD getopt happy */
return;
}
+ if (current_fs)
+ es = current_fs->super;
+
if (inode_spec) {
int inode_group, group_offset, inodes_per_block;
-
+
if (check_fs_open(argv[0]))
return;
return;
inode_group = ((inode_to_dump - 1)
- / current_fs->super->s_inodes_per_group);
+ / es->s_inodes_per_group);
group_offset = ((inode_to_dump - 1)
- % current_fs->super->s_inodes_per_group);
+ % es->s_inodes_per_group);
inodes_per_block = (current_fs->blocksize
/ sizeof(struct ext2_inode));
if (block_to_dump != -1 && current_fs != NULL) {
group_to_dump = ((block_to_dump -
- current_fs->super->s_first_data_block)
- / current_fs->super->s_blocks_per_group);
+ es->s_first_data_block)
+ / es->s_blocks_per_group);
bitmap_to_dump = current_fs->group_desc[group_to_dump].bg_block_bitmap;
}
journal_source.where = JOURNAL_IS_EXTERNAL;
journal_source.fd = journal_fd;
- } else if ((journal_inum = current_fs->super->s_journal_inum)) {
+ } else if ((journal_inum = es->s_journal_inum)) {
if (debugfs_read_inode(journal_inum, &journal_inode, argv[0]))
return;
}
journal_source.where = JOURNAL_IS_INTERNAL;
journal_source.file = journal_file;
- } else if ((journal_fn =
- ext2fs_find_block_device(current_fs->super->s_journal_dev))) {
+ } else {
+ char uuid[37];
+
+ uuid_unparse(es->s_journal_uuid, uuid);
+ journal_fn = blkid_get_devname(NULL, "UUID", uuid);
+ if (!journal_fn)
+ journal_fn = blkid_devno_to_devname(es->s_journal_dev);
+ if (!journal_fn) {
+ com_err(argv[0], 0, "filesystem has no journal");
+ return;
+ }
journal_fd = open(journal_fn, O_RDONLY, 0);
if (journal_fd < 0) {
com_err(argv[0], errno, "while opening %s for logdump",
free(journal_fn);
journal_source.where = JOURNAL_IS_EXTERNAL;
journal_source.fd = journal_fd;
- } else {
- com_err(argv[0], 0, "filesystem has no journal");
- return;
}
dump_journal(argv[0], out_file, &journal_source);
+2003-03-01 Theodore Ts'o <tytso@mit.edu>
+
+ * Makefile.in, journal.c, unix.c: Use blkid functions to find the
+ journal from the UUID, and to interpret the device
+ specification.
+
+ * e2fsck.c: Free the blkid_cache when releasing the e2fsck context
+ structure.
+
+ * e2fsck.h: If strnlen is not present, define it as a macro which
+ calls e2fsck_strlen(). Add prototype for string_copy().
+ Add blkid_cache to e2fsck context, and make
+ filesystem_name, device_name, and journal_name be
+ non-const variables.
+
+ * pass1.c, pass2.c: Remove static strnlen function
+
+ * util.c (string_copy, e2fsck_strnlen): New functions
+
2003-01-29 Theodore Ts'o <tytso@mit.edu>
* unix.c (usage): Make descripton -c be a bit more explicit
MANPAGES= e2fsck.8
XTRA_CFLAGS= -DRESOURCE_TRACK
-LIBS= $(LIBEXT2FS) $(LIBCOM_ERR) $(LIBUUID)
-DEPLIBS= $(LIBEXT2FS) $(LIBCOM_ERR) $(DEPLIBUUID)
+LIBS= $(LIBEXT2FS) $(LIBCOM_ERR) $(LIBBLKID) $(LIBUUID)
+DEPLIBS= $(LIBEXT2FS) $(LIBCOM_ERR) $(LIBBLKID) $(DEPLIBUUID)
-STATIC_LIBS= $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) $(STATIC_LIBUUID)
-STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) $(DEPSTATIC_LIBUUID)
+STATIC_LIBS= $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) $(STATIC_LIBBLKID) \
+ $(STATIC_LIBUUID)
+STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) $(STATIC_LIBBLKID) \
+ $(DEPSTATIC_LIBUUID)
-PROFILED_LIBS= $(PROFILED_LIBEXT2FS) $(PROFILED_LIBCOM_ERR) $(PROFILED_LIBUUID)
+PROFILED_LIBS= $(PROFILED_LIBEXT2FS) $(PROFILED_LIBCOM_ERR) \
+ $(PROFILED_BLKID) $(PROFILED_LIBUUID)
PROFILED_DEPLIBS= $(PROFILED_LIBEXT2FS) $(PROFILED_LIBCOM_ERR) \
- $(DEPPROFILED_LIBUUID)
+ $(PROFILED_BLKID) $(DEPPROFILED_LIBUUID)
.c.o:
$(CC) -c $(ALL_CFLAGS) $< -o $@
return;
e2fsck_reset_context(ctx);
-
+ if (ctx->blkid)
+ blkid_put_cache(ctx->blkid);
+
ext2fs_free_mem((void **) &ctx);
}
return (ctx->flags & E2F_FLAG_RUN_RETURN);
return 0;
}
-
-
-
-
-
-
#if EXT2_FLAT_INCLUDES
#include "ext2_fs.h"
#include "ext2fs.h"
+#include "blkid.h"
#else
#include "ext2fs/ext2_fs.h"
#include "ext2fs/ext2fs.h"
+#include "blkid/blkid.h"
#endif
#ifdef ENABLE_NLS
struct e2fsck_struct {
ext2_filsys fs;
const char *program_name;
- const char *filesystem_name;
- const char *device_name;
+ char *filesystem_name;
+ char *device_name;
int flags; /* E2fsck internal flags */
int options;
blk_t use_superblock; /* sb requested by user */
int blocksize; /* blocksize */
blk_t num_blocks; /* Total number of blocks */
int mount_flags;
+ blkid_cache blkid; /* blkid cache */
#ifdef HAVE_SETJMP_H
jmp_buf abort_loc;
* ext3 journal support
*/
io_channel journal_io;
- const char *journal_name;
+ char *journal_name;
#ifdef RESOURCE_TRACK
/*
typedef __u32 region_addr_t;
typedef struct region_struct *region_t;
+#ifndef HAVE_STRNLEN
+#define strnlen(str, x) e2fsck_strnlen((str),(x))
+extern int e2fsck_strnlen(const char * s, int count);
+#endif
+
/*
* Procedure declarations
*/
extern void e2fsck_read_bitmaps(e2fsck_t ctx);
extern void e2fsck_write_bitmaps(e2fsck_t ctx);
extern void preenhalt(e2fsck_t ctx);
+extern char *string_copy(e2fsck_t ctx, const char *str, int len);
#ifdef RESOURCE_TRACK
extern void print_resource_track(const char *desc,
struct resource_track *track);
errcode_t retval = 0;
io_manager io_ptr = 0;
unsigned long start = 0;
- int free_journal_name = 0;
int ext_journal = 0;
clear_problem_context(&pctx);
#endif
} else {
ext_journal = 1;
- journal_name = ctx->journal_name;
- if (!journal_name) {
- journal_name = ext2fs_find_block_device(sb->s_journal_dev);
- free_journal_name = 1;
+ if (!ctx->journal_name) {
+ char uuid[37];
+
+ uuid_unparse(sb->s_journal_uuid, uuid);
+ ctx->journal_name = blkid_get_devname(ctx->blkid,
+ "UUID", uuid);
+ if (!ctx->journal_name)
+ ctx->journal_name = blkid_devno_to_devname(sb->s_journal_dev);
}
+ journal_name = ctx->journal_name;
if (!journal_name) {
fix_problem(ctx, PR_0_CANT_FIND_JOURNAL, &pctx);
#endif
retval = io_ptr->open(journal_name, IO_FLAG_RW,
&ctx->journal_io);
- if (free_journal_name)
- free((void *) journal_name);
if (retval)
goto errout;
return 1;
}
-#ifndef HAVE_STRNLEN
-/*
- * Incredibly, libc5 doesn't appear to have strnlen. So we have to
- * provide our own.
- */
-static int strnlen(const char * s, int count)
-{
- const char *cp = s;
-
- while (count-- && *cp)
- cp++;
- return cp - s;
-}
-#endif
-
/*
* Check to make sure a symlink inode is real. Returns 1 if the symlink
* checks out, 0 if not.
e2fsck_t ctx;
};
-#ifndef HAVE_STRNLEN
-/*
- * Incredibly, libc5 doesn't appear to have strnlen. So we have to
- * provide our own.
- */
-static int strnlen(const char * s, int count)
-{
- const char *cp = s;
-
- while (count-- && *cp)
- cp++;
- return cp - s;
-}
-#endif
-
void e2fsck_pass2(e2fsck_t ctx)
{
struct ext2_super_block *sb = ctx->fs->super;
static void parse_extended_opts(e2fsck_t ctx, const char *opts)
{
char *buf, *token, *next, *p, *arg;
- int len, ea_ver;
+ int ea_ver;
int extended_usage = 0;
- len = strlen(opts);
- buf = malloc(len+1);
- if (!buf) {
- fprintf(stderr, _("Couldn't allocate memory to parse "
- "extended options!\n"));
- exit(1);
- }
- strcpy(buf, opts);
+ buf = string_copy(ctx, opts, 0);
for (token = buf; token && *token; token = next) {
p = strchr(token, ',');
next = 0;
setbuf(stdout, NULL);
setbuf(stderr, NULL);
initialize_ext2_error_table();
+ blkid_get_cache(&ctx->blkid, NULL);
if (argc && *argv)
ctx->program_name = *argv;
ctx->inode_buffer_blocks = atoi(optarg);
break;
case 'j':
- ctx->journal_name = optarg;
+ ctx->journal_name = string_copy(ctx, optarg, 0);
break;
case 'P':
ctx->process_inode_size = atoi(optarg);
case 'L':
replace_bad_blocks++;
case 'l':
- bad_blocks_file = (char *) malloc(strlen(optarg)+1);
- if (!bad_blocks_file)
- fatal_error(ctx,
- "Couldn't malloc bad_blocks_file");
- strcpy(bad_blocks_file, optarg);
+ bad_blocks_file = string_copy(ctx, optarg, 0);
break;
case 'd':
ctx->options |= E2F_OPT_DEBUG;
if ((ctx->options & E2F_OPT_NO) && !bad_blocks_file &&
!cflag && !swapfs && !(ctx->options & E2F_OPT_COMPRESS_DIRS))
ctx->options |= E2F_OPT_READONLY;
- ctx->filesystem_name = argv[optind];
+ ctx->filesystem_name = blkid_get_devname(ctx->blkid, argv[optind], 0);
if (extended_opts)
parse_extended_opts(ctx, extended_opts);
*/
if (ctx->device_name == 0 &&
(sb->s_volume_name[0] != 0)) {
- char *cp = malloc(sizeof(sb->s_volume_name)+1);
- if (cp) {
- strncpy(cp, sb->s_volume_name,
- sizeof(sb->s_volume_name));
- cp[sizeof(sb->s_volume_name)] = 0;
- ctx->device_name = cp;
- }
+ ctx->device_name = string_copy(ctx, sb->s_volume_name,
+ sizeof(sb->s_volume_name));
}
if (ctx->device_name == 0)
ctx->device_name = ctx->filesystem_name;
ext2fs_close(fs);
ctx->fs = NULL;
+ free(ctx->filesystem_name);
+ free(ctx->journal_name);
e2fsck_free_context(ctx);
#ifdef RESOURCE_TRACK
return ret;
}
+char *string_copy(e2fsck_t ctx, const char *str, int len)
+{
+ char *ret;
+
+ if (!str)
+ return NULL;
+ if (!len)
+ len = strlen(str);
+ ret = malloc(len+1);
+ if (ret) {
+ strncpy(ret, str, len);
+ ret[len] = 0;
+ }
+ return ret;
+}
+
+#ifndef HAVE_STRNLEN
+/*
+ * Incredibly, libc5 doesn't appear to have strnlen. So we have to
+ * provide our own.
+ */
+int e2fsck_strnlen(const char * s, int count)
+{
+ const char *cp = s;
+
+ while (count-- && *cp)
+ cp++;
+ return cp - s;
+}
+#endif
+
#ifndef HAVE_CONIO_H
static int read_a_char(void)
{