diff options
author | Andreas Dilger <adilger@clusterfs.com> | 2001-08-17 03:48:11 -0600 |
---|---|---|
committer | Andreas Dilger <adilger@clusterfs.com> | 2001-08-17 03:48:11 -0600 |
commit | 2d15576dfe8ffd8521a6f4211cef3d2a663dc379 (patch) | |
tree | 926780492e8c88d8fcef4379135c2dc1bbe0faac | |
parent | f27728adac8c8332313d84110f50c3568093b4a8 (diff) | |
download | e2fsprogs-2d15576dfe8ffd8521a6f4211cef3d2a663dc379.tar.gz |
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.
-rw-r--r-- | misc/ChangeLog | 15 | ||||
-rw-r--r-- | misc/Makefile.in | 7 | ||||
-rw-r--r-- | misc/fsck.c | 34 | ||||
-rw-r--r-- | misc/get_device_by_label.c | 33 | ||||
-rw-r--r-- | misc/get_device_by_label.h | 1 | ||||
-rw-r--r-- | misc/mke2fs.8.in | 21 | ||||
-rw-r--r-- | misc/mke2fs.c | 1 | ||||
-rw-r--r-- | misc/tune2fs.8.in | 35 | ||||
-rw-r--r-- | misc/tune2fs.c | 39 | ||||
-rw-r--r-- | misc/util.c | 5 |
10 files changed, 147 insertions, 44 deletions
diff --git a/misc/ChangeLog b/misc/ChangeLog index a8108c8d..8cf5339b 100644 --- a/misc/ChangeLog +++ b/misc/ChangeLog @@ -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 diff --git a/misc/Makefile.in b/misc/Makefile.in index d4421fc0..ec2396ff 100644 --- a/misc/Makefile.in +++ b/misc/Makefile.in @@ -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 diff --git a/misc/fsck.c b/misc/fsck.c index f0f05b4b..05c69cbc 100644 --- a/misc/fsck.c +++ b/misc/fsck.c @@ -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); } diff --git a/misc/get_device_by_label.c b/misc/get_device_by_label.c index 6691ab39..69750d4f 100644 --- a/misc/get_device_by_label.c +++ b/misc/get_device_by_label.c @@ -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; +} diff --git a/misc/get_device_by_label.h b/misc/get_device_by_label.h index 2385c142..79b14996 100644 --- a/misc/get_device_by_label.h +++ b/misc/get_device_by_label.h @@ -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); diff --git a/misc/mke2fs.8.in b/misc/mke2fs.8.in index 46d7c1ec..32de8670 100644 --- a/misc/mke2fs.8.in +++ b/misc/mke2fs.8.in @@ -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 diff --git a/misc/mke2fs.c b/misc/mke2fs.c index 22770631..a09326a3 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -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); diff --git a/misc/tune2fs.8.in b/misc/tune2fs.8.in index 060e87c9..4da05eb5 100644 --- a/misc/tune2fs.8.in +++ b/misc/tune2fs.8.in @@ -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. diff --git a/misc/tune2fs.c b/misc/tune2fs.c index e96f55a9..1acb4634 100644 --- a/misc/tune2fs.c +++ b/misc/tune2fs.c @@ -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(); diff --git a/misc/util.c b/misc/util.c index b05a2f1a..98ad0b25 100644 --- a/misc/util.c +++ b/misc/util.c @@ -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++; |