X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=dump%2Fmain.c;h=876ea22e6d6b4cdee8793434901e83ad83c75667;hb=95cd88019335e29909def7e0ac8794ef01380aac;hp=c2e4eaf329c94e77e671c50915ec4e027313d792;hpb=79e318657e7faa7b2951ff554dc6f1b92624a477;p=dump.git diff --git a/dump/main.c b/dump/main.c index c2e4eaf..876ea22 100644 --- a/dump/main.c +++ b/dump/main.c @@ -40,7 +40,7 @@ #ifndef lint static const char rcsid[] = - "$Id: main.c,v 1.23 2000/08/19 23:48:10 stelian Exp $"; + "$Id: main.c,v 1.28 2000/11/10 13:52:43 stelian Exp $"; #endif /* not lint */ #include @@ -79,6 +79,7 @@ static const char rcsid[] = #include "dump.h" #include "pathnames.h" +#include "bylabel.h" #ifndef SBOFF #define SBOFF (SBLOCK * DEV_BSIZE) @@ -125,8 +126,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); @@ -141,11 +143,11 @@ main(int argc, char *argv[]) #endif tsize = 0; /* Default later, based on 'c' option for cart tapes */ + unlimited = 1; eot_script = NULL; 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'; @@ -173,6 +175,7 @@ main(int argc, char *argv[]) break; case 'B': /* blocks per output file */ + unlimited = 0; blocksperfile = numarg("number of blocks per file", 1L, 0L); break; @@ -189,10 +192,12 @@ main(int argc, char *argv[]) break; case 'c': /* Tape is cart. not 9-track */ + unlimited = 0; cartridge = 1; break; case 'd': /* density, in bits per inch */ + unlimited = 0; density = numarg("density", 10L, 327670L) / 10; if (density >= 625 && !bflag) ntrec = HIGHDENSITYTREC; @@ -200,8 +205,15 @@ main(int argc, char *argv[]) /* 04-Feb-00 ILC */ case 'e': /* exclude an inode */ - iexclude_list[iexclude_num++] = - numarg("inode to exclude",0L,0L); + if (iexclude_num == IEXCLUDE_MAXNUM) { + (void)fprintf(stderr, "Too many -e options\n"); + exit(X_STARTUP); + } + iexclude_list[iexclude_num++] = numarg("inode to exclude",0L,0L); + if (iexclude_list[iexclude_num-1] <= ROOTINO) { + (void)fprintf(stderr, "Cannot exclude inode %ld\n", iexclude_list[iexclude_num-1]); + exit(X_STARTUP); + } msg("Added %d to exclude list\n", iexclude_list[iexclude_num-1]); break; @@ -230,14 +242,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; @@ -250,6 +262,7 @@ main(int argc, char *argv[]) break; case 's': /* tape size, feet */ + unlimited = 0; tsize = numarg("tape size", 1L, 0L) * 12 * 10; break; @@ -287,9 +300,9 @@ main(int argc, char *argv[]) (void)fprintf(stderr, "Must specify disk or filesystem\n"); exit(X_STARTUP); } - disk = *argv++; - if (strlen(disk) >= MAXPATHLEN) { - (void)fprintf(stderr, "Disk or filesystem name too long: %s\n", disk); + diskparam = *argv++; + if (strlen(diskparam) >= MAXPATHLEN) { + (void)fprintf(stderr, "Disk or filesystem name too long: %s\n", diskparam); exit(X_STARTUP); } argc--; @@ -363,12 +376,20 @@ main(int argc, char *argv[]) signal(SIGINT, SIG_IGN); set_operators(); /* /etc/group snarfed */ getfstab(); /* /etc/fstab snarfed */ + + disk = get_device_name(diskparam); + if (!disk) { /* null means the disk is some form + of LABEL= or UID= but it was not + found */ + msg("Cannot find a disk having %s\n", diskparam); + exit(X_STARTUP); + } /* * disk may end in / and this can confuse * 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, @@ -379,37 +400,45 @@ 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 { - /* - * The argument was not found in the fstab - * assume that this is a subtree and search for it - */ +#ifdef __linux__ #ifdef HAVE_REALPATH if (realpath(disk, pathname) == NULL) #endif strcpy(pathname, disk); - dt = fstabsearchdir(pathname, directory); - if (dt != NULL) { - char name[MAXPATHLEN]; - (void)strncpy(spcl.c_dev, dt->fs_spec, NAMELEN); - (void)snprintf(name, sizeof(name), "%s (dir %s)", - dt->fs_file, directory); - (void)strncpy(spcl.c_filesys, name, NAMELEN); + /* + * The argument could be now a mountpoint of + * a filesystem specified in fstab. Search for it. + */ + if ((dt = fstabsearch(pathname)) != NULL) { disk = rawname(dt->fs_spec); + (void)strncpy(spcl.c_dev, dt->fs_spec, NAMELEN); + (void)strncpy(spcl.c_filesys, dt->fs_file, NAMELEN); } else { - (void)strncpy(spcl.c_dev, disk, NAMELEN); - (void)strncpy(spcl.c_filesys, "an unlisted file system", - NAMELEN); + /* + * The argument was not found in the fstab + * assume that this is a subtree and search for it + */ + dt = fstabsearchdir(pathname, directory); + if (dt != NULL) { + char name[MAXPATHLEN]; + (void)strncpy(spcl.c_dev, dt->fs_spec, NAMELEN); + (void)snprintf(name, sizeof(name), "%s (dir %s)", + dt->fs_file, directory); + (void)strncpy(spcl.c_filesys, name, NAMELEN); + disk = rawname(dt->fs_spec); + } else { + (void)strncpy(spcl.c_dev, disk, NAMELEN); + (void)strncpy(spcl.c_filesys, "an unlisted file system", + 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') { @@ -421,11 +450,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) @@ -463,8 +491,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__ @@ -484,6 +510,15 @@ 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') { + if (fs->super->s_volume_name[0] != '\0') { + strncpy(spcl.c_label, fs->super->s_volume_name,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; @@ -523,10 +558,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