]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
get_device_by_label.[ch], fsck.c, util.c: New interpret_spec()
authorAndreas Dilger <adilger@clusterfs.com>
Fri, 17 Aug 2001 09:48:11 +0000 (03:48 -0600)
committerAndreas Dilger <adilger@clusterfs.com>
Fri, 17 Aug 2001 09:48:11 +0000 (03:48 -0600)
        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.

misc/ChangeLog
misc/Makefile.in
misc/fsck.c
misc/get_device_by_label.c
misc/get_device_by_label.h
misc/mke2fs.8.in
misc/mke2fs.c
misc/tune2fs.8.in
misc/tune2fs.c
misc/util.c

index a8108c8d85d716e76d48fd0758546bba95792c3d..8cf5339be8cacd0f3875cf57465dd69a2791f148 100644 (file)
@@ -1,3 +1,18 @@
+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
index d4421fc091738053997e9de4a4f7073038428305..ec2396ffbfe56bd45a058b59f50a179d3ffdd6a6 100644 (file)
@@ -22,9 +22,9 @@ SMANPAGES=    tune2fs.8 mklost+found.8 mke2fs.8 dumpe2fs.8 badblocks.8 \
 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
@@ -235,6 +235,7 @@ util.o: $(srcdir)/util.c $(top_srcdir)/lib/et/com_err.h \
  $(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
index f0f05b4bad6791af9b66083052a2059a1446e8b7..05c69cbc3b6aef67422ebe6472f0021582ab1dfa 100644 (file)
@@ -106,16 +106,6 @@ const char *fsck_prefix_path = "/sbin:/sbin/fs.d:/sbin/fs:/etc/fs:/etc";
 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))
@@ -217,18 +207,11 @@ static int parse_fstab_line(char *line, struct fs_info **ret_fs)
  */
 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.
@@ -243,10 +226,11 @@ static char *interpret_device(char *spec)
         * 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);
 }
index 6691ab392cad925a4af92b5500fd678b4b0120c3..69750d4f300d856550625fb84cb34fde775b99cc 100644 (file)
@@ -64,6 +64,16 @@ static struct uuidCache_s {
        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) {
@@ -204,6 +214,9 @@ get_spec_by_x(int n, const char *t) {
        uuidcache_init();
        uc = uuidCache;
 
+       if (t == NULL)
+               return NULL;
+
        while(uc) {
                switch (n) {
                case UUID:
@@ -272,3 +285,23 @@ get_volume_label_by_spec(const char *spec) {
        }
        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;
+}
index 2385c142aaa3d767bff26b5ae28a2b757d773452..79b14996b8c95b3258370976a2824dda7f45835e 100644 (file)
@@ -11,3 +11,4 @@
 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);
index 46d7c1ecccc124513e411b0fa85529524ed5055a..32de86702e27a68b40e17f2cd195607c18759c9a 100644 (file)
@@ -115,6 +115,9 @@ mke2fs \- create a Linux second extended file system
 @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
@@ -193,13 +196,27 @@ The journal must fit within the newly created filesystem.
 @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
index 2277063107388ed1c2f0befb8daefc4ab3e3aa49..a09326a375165287396da57c9be45f29c28b05f1 100644 (file)
@@ -1280,6 +1280,7 @@ int main (int argc, char *argv[])
                if (!quiet)
                        printf(_("done\n"));
                ext2fs_close(jfs);
+               free(journal_device);
        } else if (journal_size) {
                journal_blocks = figure_journal_size(journal_size, fs);
 
index 060e87c9218ccfa801be73bbefd32e1108c68389..4da05eb592566cc71bae6c64cd51c46e14716cec 100644 (file)
@@ -189,6 +189,20 @@ that size.
 @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
@@ -204,7 +218,16 @@ Ext2 filesystem labels can be at most 16 characters long; if
 .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.
@@ -290,6 +313,16 @@ generate a new randomly-generated UUID
 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.
index e96f55a9547e84c79a33096277aac5370b32fd05..1acb463492af8b22e13a78b04991d3fd2c0f5057 100644 (file)
@@ -48,6 +48,7 @@ extern int optind;
 #include "e2p/e2p.h"
 #include "jfs_user.h"
 #include "util.h"
+#include "get_device_by_label.h"
 
 #include "../version.h"
 #include "nls-enable.h"
@@ -101,13 +102,20 @@ static void remove_journal_device(ext2_filsys fs)
        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,
@@ -174,6 +182,7 @@ no_valid_journal:
               sizeof(fs->super->s_journal_uuid));
        ext2fs_mark_super_dirty(fs);
        printf(_("Journal removed\n"));
+       free(journal_device);
 }
 
 /* Helper function for remove_journal_inode */
@@ -327,7 +336,7 @@ static void add_journal(ext2_filsys fs)
        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);
@@ -339,21 +348,21 @@ static void add_journal(ext2_filsys fs)
                        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);
@@ -376,6 +385,12 @@ static void add_journal(ext2_filsys fs)
                        fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
        }
        print_check_message(fs);
+       return;
+
+err:
+       if (journal_device)
+               free(journal_device);
+       exit(1);
 }
 
 /*
@@ -401,7 +416,7 @@ static void parse_e2label_options(int argc, char ** argv)
        }
        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 
@@ -532,7 +547,8 @@ static void parse_tune2fs_options(int argc, char **argv)
                        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);
@@ -597,7 +613,8 @@ static void parse_tune2fs_options(int argc, char **argv)
                        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();
index b05a2f1a81799972a36e6146aeb9507a2b2d2d21..98ad0b25a73f25a6dda072c8264f1ac461edd060 100644 (file)
@@ -26,6 +26,7 @@
 #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
@@ -154,11 +155,11 @@ void parse_journal_opts(const char *opts)
                       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++;