X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=dump%2Fmain.c;h=7745e46c4e3cd4ad9b83fd1229b866f3ec0bf592;hb=d6967896bc4e18f9b4359a2ef5be5c0f1bcc456a;hp=61afed803398fa5e486422f35a03e80949013399;hpb=4f4eee3d2e237c2f0becd9c5ce41524f8f5bc1c1;p=dump.git diff --git a/dump/main.c b/dump/main.c index 61afed8..7745e46 100644 --- a/dump/main.c +++ b/dump/main.c @@ -2,7 +2,8 @@ * Ported to Linux's Second Extended File System as part of the * dump and restore backup suit * Remy Card , 1994-1997 - * Stelian Pop , 1999-2000 + * Stelian Pop , 1999-2000 + * Stelian Pop - AlcĂ´ve , 2000 */ /*- @@ -40,9 +41,10 @@ #ifndef lint static const char rcsid[] = - "$Id: main.c,v 1.27 2000/11/10 13:22:10 stelian Exp $"; + "$Id: main.c,v 1.32 2000/12/21 11:14:54 stelian Exp $"; #endif /* not lint */ +#include #include #include #ifdef __linux__ @@ -126,9 +128,9 @@ main(int argc, char *argv[]) char pathname[MAXPATHLEN]; #endif time_t tnow; - char labelstr[LBLSIZE]; char *diskparam; + spcl.c_label[0] = '\0'; spcl.c_date = 0; #ifdef __linux__ (void)time4(&spcl.c_date); @@ -148,7 +150,6 @@ main(int argc, char *argv[]) if ((tapeprefix = getenv("TAPE")) == NULL) tapeprefix = _PATH_DEFTAPE; dumpdates = _PATH_DUMPDATES; - strcpy(labelstr, "none"); /* XXX safe strcpy. */ if (TP_BSIZE / DEV_BSIZE == 0 || TP_BSIZE % DEV_BSIZE != 0) quit("TP_BSIZE must be a multiple of DEV_BSIZE\n"); level = '0'; @@ -243,14 +244,14 @@ main(int argc, char *argv[]) * the last must be '\0', so the limit on strlen() * is really LBLSIZE-1. */ - strncpy(labelstr, optarg, LBLSIZE); - labelstr[LBLSIZE-1] = '\0'; + strncpy(spcl.c_label, optarg, LBLSIZE); + spcl.c_label[LBLSIZE-1] = '\0'; if (strlen(optarg) > LBLSIZE-1) { msg( "WARNING Label `%s' is larger than limit of %d characters.\n", optarg, LBLSIZE-1); msg("WARNING: Using truncated label `%s'.\n", - labelstr); + spcl.c_label); } break; @@ -390,7 +391,7 @@ main(int argc, char *argv[]) * fstabsearch. */ if (strlen(disk) > 1 && disk[strlen(disk) - 1] == '/') - disk[strlen(disk) - 1] = '\0'; + disk[strlen(disk) - 1] = '\0'; /* * disk can be either the full special file name, * the suffix of the special file name, @@ -401,8 +402,8 @@ main(int argc, char *argv[]) disk = rawname(dt->fs_spec); (void)strncpy(spcl.c_dev, dt->fs_spec, NAMELEN); (void)strncpy(spcl.c_filesys, dt->fs_file, NAMELEN); -#ifdef __linux__ } else { +#ifdef __linux__ #ifdef HAVE_REALPATH if (realpath(disk, pathname) == NULL) #endif @@ -434,14 +435,12 @@ main(int argc, char *argv[]) NAMELEN); } } - } #else - } else { (void)strncpy(spcl.c_dev, disk, NAMELEN); (void)strncpy(spcl.c_filesys, "an unlisted file system", NAMELEN); - } #endif + } if (directory[0] != 0) { if (level != '0') { @@ -453,10 +452,10 @@ main(int argc, char *argv[]) exit(X_STARTUP); } } - spcl.c_dev[NAMELEN-1]='\0'; - spcl.c_filesys[NAMELEN-1]='\0'; - (void)strncpy(spcl.c_label, labelstr, sizeof(spcl.c_label) - 1); + spcl.c_dev[NAMELEN-1] = '\0'; + spcl.c_filesys[NAMELEN-1] = '\0'; (void)gethostname(spcl.c_host, NAMELEN); + spcl.c_host[NAMELEN-1] = '\0'; spcl.c_level = level - '0'; spcl.c_type = TS_TAPE; if (!Tflag) @@ -494,8 +493,6 @@ main(int argc, char *argv[]) msgtail("to %s on host %s\n", tape, host); else msgtail("to %s\n", tape); - msg("Label: %s\n", labelstr); - } /* end of size estimate */ #ifdef __linux__ @@ -515,6 +512,16 @@ main(int argc, char *argv[]) msg("Cannot open %s\n", disk); exit(X_STARTUP); } + /* if no user label specified, use ext2 filesystem label if available */ + if (spcl.c_label[0] == '\0') { + const char *lbl; + if ( (lbl = get_device_label(disk)) != NULL) { + strncpy(spcl.c_label, lbl, LBLSIZE); + spcl.c_label[LBLSIZE-1] = '\0'; + } + else + strcpy(spcl.c_label, "none"); /* safe strcpy. */ + } sync(); dev_bsize = DEV_BSIZE; dev_bshift = ffs(dev_bsize) - 1; @@ -554,10 +561,14 @@ main(int argc, char *argv[]) usedinomap = (char *)calloc((unsigned) mapsize, sizeof(char)); dumpdirmap = (char *)calloc((unsigned) mapsize, sizeof(char)); dumpinomap = (char *)calloc((unsigned) mapsize, sizeof(char)); + if (usedinomap == NULL || dumpdirmap == NULL || dumpinomap == NULL) + quit("out of memory allocating inode maps\n"); tapesize = 2 * (howmany(mapsize * sizeof(char), TP_BSIZE) + 1); nonodump = spcl.c_level < honorlevel; + msg("Label: %s\n", spcl.c_label); + #if defined(SIGINFO) (void)signal(SIGINFO, statussig); #endif