+2001-08-17 Andreas Dilger <adilger@turbolinux.com>
+
+ * get_device_by_label.[ch], fsck.c, util.c: New interpret_spec()
+ function in get_device_by_label.c to allow the use of
+ UUID= or LABEL= when creating filesystems which use external
+ journal dev (e.g. mke2fs -J device=LABEL=<journal_label>).
+
+ * tune2fs.c: Use superblock s_journal_uuid to locate an external
+ journal device instead of s_journal_dev when removing it.
+ Allow opening journal devices to set the label and UUID
+ in the ext2 superblock.
+
+ * mke2fs.c, tune2fs.c: Free journal_device after use, as it is
+ malloc'd in interpret spec.
+
2001-08-15 Theodore Tso <tytso@valinux.com>
* tune2fs.c: Make sure that error messages are sent to stderr, and
UPROGS= chattr lsattr uuidgen
UMANPAGES= chattr.1 lsattr.1 uuidgen.1
-TUNE2FS_OBJS= tune2fs.o util.o
+TUNE2FS_OBJS= tune2fs.o util.o get_device_by_label.o
MKLPF_OBJS= mklost+found.o
-MKE2FS_OBJS= mke2fs.o util.o
+MKE2FS_OBJS= mke2fs.o util.o get_device_by_label.o
CHATTR_OBJS= chattr.o
LSATTR_OBJS= lsattr.o
UUIDGEN_OBJS= uuidgen.o
$(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
$(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
$(top_srcdir)/lib/ext2fs/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
- $(top_srcdir)/lib/ext2fs/bitops.h $(srcdir)/nls-enable.h $(srcdir)/util.h
+ $(top_srcdir)/lib/ext2fs/bitops.h $(srcdir)/nls-enable.h $(srcdir)/util.h \
+ $(srcdir)/get_device_by_label.h
uuidgen.o: $(srcdir)/uuidgen.c $(top_srcdir)/lib/uuid/uuid.h \
$(srcdir)/nls-enable.h
char *fsck_path = 0;
static int ignore(struct fs_info *);
-char *string_copy(const char *s)
-{
- char *ret;
-
- ret = malloc(strlen(s)+1);
- if (ret)
- strcpy(ret, s);
- return ret;
-}
-
static char *skip_over_blank(char *cp)
{
while (*cp && isspace(*cp))
*/
static char *interpret_device(char *spec)
{
- char *dev = NULL;
-
- if (!strncmp(spec, "UUID=", 5))
- dev = get_spec_by_uuid(spec+5);
- else if (!strncmp(spec, "LABEL=", 6))
- dev = get_spec_by_volume_label(spec+6);
- else
- return spec;
- if (dev) {
- free(spec);
- return (dev);
- }
+ char *dev = interpret_spec(spec);
+
+ if (dev)
+ return dev;
+
/*
* Check to see if this was because /proc/partitions isn't
* found.
* Check to see if this is because we're not running as root
*/
if (geteuid())
- fprintf(stderr, "Must be root to scan for matching "
- "filesystems: %s\n", spec);
+ fprintf(stderr,
+ "Must be root to scan for matching filesystems: %s\n",
+ spec);
else
- fprintf(stderr, "Couldn't find matching filesystem: %s\n",
+ fprintf(stderr, "Couldn't find matching filesystem: %s\n",
spec);
exit(EXIT_ERROR);
}
char *device;
} *uuidCache = NULL;
+char *string_copy(const char *s)
+{
+ char *ret;
+
+ ret = malloc(strlen(s)+1);
+ if (ret)
+ strcpy(ret, s);
+ return ret;
+}
+
/* for now, only ext2 and xfs are supported */
static int
get_label_uuid(const char *device, char **label, char *uuid) {
uuidcache_init();
uc = uuidCache;
+ if (t == NULL)
+ return NULL;
+
while(uc) {
switch (n) {
case UUID:
}
return NULL;
}
+
+/*
+ * Interpret the device name if necessary.
+ * Frees the pointer passed to it if we return a different device string.
+ */
+char *interpret_spec(char *spec)
+{
+ char *dev = NULL;
+
+ if (!spec)
+ return NULL;
+
+ if (!strncmp(spec, "UUID=", 5))
+ dev = get_spec_by_uuid(spec+5);
+ else if (!strncmp(spec, "LABEL=", 6))
+ dev = get_spec_by_volume_label(spec+6);
+ else
+ dev = string_copy(spec);
+ return dev;
+}
extern char *get_spec_by_uuid(const char *uuid);
extern char *get_spec_by_volume_label(const char *volumelabel);
extern const char *get_volume_label_by_spec(const char *spec);
+extern char *interpret_spec(char *spec);
@JDEV@.B \-v
@JDEV@]
@JDEV@.I external-journal
+@JDEV@[
+@JDEV@.I blocks-count
+@JDEV@]
.SH DESCRIPTION
.B mke2fs
is used to create a Linux second extended file system on a device (usually
@JDEV@The external
@JDEV@journal must already have been created using the command
@JDEV@.IP
-@JDEV@.B mke2fs -O journal_dev
-@JDEV@.IR external-journal
+@JDEV@.B mke2fs -O journal_dev
+@JDEV@.I external-journal
@JDEV@.IP
@JDEV@Note that
@JDEV@.I external-journal
@JDEV@must have been created with the
@JDEV@same block size as the new filesystem.
+@JDEV@.IP
+@JDEV@Instead of specifying a device name directly,
+@JDEV@.I external-journal
+@JDEV@can also be specified by either
+@JDEV@.BI LABEL= label
+@JDEV@or
+@JDEV@.BI UUID= UUID
+@JDEV@to locate the external journal by either the volume label or UUID
+@JDEV@stored in the ext2 superblock at the start of the journal. Use
+@JDEV@.BR dumpe2fs (8)
+@JDEV@to display a journal device's volume label and UUID. See also the
+@JDEV@.B -L
+@JDEV@option of
+@JDEV@.BR tune2fs (8).
.RE
@JDEV@.IP
@JDEV@Only one of the
if (!quiet)
printf(_("done\n"));
ext2fs_close(jfs);
+ free(journal_device);
} else if (journal_size) {
journal_blocks = figure_journal_size(journal_size, fs);
@JDEV@.I external-journal
@JDEV@must be formatted with the same block
@JDEV@size as filesystems which will be using it.
+@JDEV@.IP
+@JDEV@Instead of specifying a device name directly,
+@JDEV@.I external-journal
+@JDEV@can also be specified by either
+@JDEV@.BI LABEL= label
+@JDEV@or
+@JDEV@.BI UUID= UUID
+@JDEV@to locate the external journal by either the volume label or UUID
+@JDEV@stored in the ext2 superblock at the start of the journal. Use
+@JDEV@.BR dumpe2fs (8)
+@JDEV@to display a journal device's volume label and UUID. See also the
+@JDEV@.B -L
+@JDEV@option of
+@JDEV@.BR tune2fs (8).
.RE
@JDEV@.IP
@JDEV@Only one of the
.I volume-label
is longer than 16 characters,
.B tune2fs
-will truncate it and print a warning.
+will truncate it and print a warning. The volume label can be used
+by
+.BR mount (8),
+.BR fsck (8),
+and
+.BR /etc/fstab (5)
+(and possibly others) by specifying
+.BI LABEL= volume_label
+instead of a block special device name like
+.BR /dev/hda5 .
.TP
.BI \-m " reserved-blocks-percentage"
Set the percentage of reserved filesystem blocks.
generate a new time-based UUID
.RE
.IP
+The UUID may be used by
+.BR mount (8),
+.BR fsck (8),
+and
+.BR /etc/fstab (5)
+(and possibly others) by specifying
+.BI UUID= uuid
+instead of a block special device name like
+.BR /dev/hda1 .
+.IP
See
.BR uuidgen (8)
for more information.
#include "e2p/e2p.h"
#include "jfs_user.h"
#include "util.h"
+#include "get_device_by_label.h"
#include "../version.h"
#include "nls-enable.h"
int i, nr_users;
errcode_t retval;
int commit_remove_journal = 0;
+ int check_uuid = 1;
if (f_flag)
commit_remove_journal = 1; /* force removal even if error */
- journal_device = ext2fs_find_block_device(fs->super->s_journal_dev);
- if (!journal_device)
- return;
+ uuid_unparse(fs->super->s_journal_uuid, buf);
+ journal_device = get_spec_by_uuid(buf);
+
+ if (!journal_device) {
+ journal_device =
+ ext2fs_find_block_device(fs->super->s_journal_dev);
+ if (!journal_device)
+ return;
+ }
retval = ext2fs_open(journal_device, EXT2_FLAG_RW|
EXT2_FLAG_JOURNAL_DEV_OK, 0,
sizeof(fs->super->s_journal_uuid));
ext2fs_mark_super_dirty(fs);
printf(_("Journal removed\n"));
+ free(journal_device);
}
/* Helper function for remove_journal_inode */
if (fs->super->s_feature_compat &
EXT3_FEATURE_COMPAT_HAS_JOURNAL) {
fprintf(stderr, _("The filesystem already has a journal.\n"));
- exit(1);
+ goto err;
}
if (journal_device) {
check_plausibility(journal_device);
com_err(program_name, retval,
_("\n\twhile trying to open journal on %s\n"),
journal_device);
- exit(1);
+ goto err;
}
printf(_("Creating journal on device %s: "),
journal_device);
fflush(stdout);
-
+
retval = ext2fs_add_journal_device(fs, jfs);
+ ext2fs_close(jfs);
if (retval) {
com_err (program_name, retval,
_("while adding filesystem to journal on %s"),
journal_device);
- exit(1);
+ goto err;
}
printf(_("done\n"));
- ext2fs_close(jfs);
} else if (journal_size) {
printf(_("Creating journal inode: "));
fflush(stdout);
fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
}
print_check_message(fs);
+ return;
+
+err:
+ if (journal_device)
+ free(journal_device);
+ exit(1);
}
/*
}
device_name = argv[1];
if (argc == 3) {
- open_flag = EXT2_FLAG_RW;
+ open_flag = EXT2_FLAG_RW | EXT2_FLAG_JOURNAL_DEV_OK;
L_flag = 1;
new_label = argv[2];
} else
case 'L':
new_label = optarg;
L_flag = 1;
- open_flag = EXT2_FLAG_RW;
+ open_flag = EXT2_FLAG_RW |
+ EXT2_FLAG_JOURNAL_DEV_OK;
break;
case 'm':
reserved_ratio = strtoul (optarg, &tmp, 0);
case 'U':
new_UUID = optarg;
U_flag = 1;
- open_flag = EXT2_FLAG_RW;
+ open_flag = EXT2_FLAG_RW |
+ EXT2_FLAG_JOURNAL_DEV_OK;
break;
default:
usage();
#include "ext2fs/ext2_fs.h"
#include "ext2fs/ext2fs.h"
#include "nls-enable.h"
+#include "get_device_by_label.h"
#include "util.h"
#ifndef HAVE_STRCASECMP
arg ? arg : "NONE");
#endif
if (strcmp(token, "device") == 0) {
- if (!arg) {
+ journal_device = interpret_spec(arg);
+ if (!journal_device) {
journal_usage++;
continue;
}
- journal_device = arg;
} else if (strcmp(token, "size") == 0) {
if (!arg) {
journal_usage++;