]> git.wh0rd.org - dump.git/blobdiff - restore/main.c
Added the -X option to restore (read names of files to be
[dump.git] / restore / main.c
index b3a09ff9c53237f11d1023fdafe2cff958864b20..6f9b0346e3ac07efa2e2d76b0416ae4a5698c6f8 100644 (file)
@@ -2,8 +2,7 @@
  *     Ported to Linux's Second Extended File System as part of the
  *     dump and restore backup suit
  *     Remy Card <card@Linux.EU.Org>, 1994-1997
- *      Stelian Pop <pop@cybercable.fr>, 1999 
- *
+ *     Stelian Pop <pop@cybercable.fr>, 1999-2000
  */
 
 /*
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
- *
- * $Id: main.c,v 1.5 1999/10/11 13:31:13 stelian Exp $
  */
 
+#ifndef lint
+static const char rcsid[] =
+       "$Id: main.c,v 1.10 2000/03/08 11:25:58 stelian Exp $";
+#endif /* not lint */
+
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <errno.h>
@@ -85,7 +87,7 @@ time_t        dumpdate;
 FILE   *terminal;
 char   *tmpdir;
 int    compare_ignore_not_found;
-char   *filesys = NULL;
+char   filesys[NAMELEN];
 
 #ifdef __linux__
 char   *__progname;
@@ -102,10 +104,12 @@ main(int argc, char *argv[])
        char *inputdev = _PATH_DEFTAPE;
        char *symtbl = "./restoresymtable";
        char *p, name[MAXPATHLEN];
+       FILE *filelist = NULL;
+       char fname[MAXPATHLEN];
 
        /* Temp files should *not* be readable.  We set permissions later. */
        (void) umask(077);
-
+       filesys[0] = '\0';
 #ifdef __linux__
        __progname = argv[0];
 #endif
@@ -123,9 +127,9 @@ main(int argc, char *argv[])
                ;                                                               
        obsolete(&argc, &argv);
 #ifdef KERBEROS
-#define        optlist "b:CcdD:f:hikmNRrs:tT:uvxy"
+#define        optlist "b:CcdD:f:hikmMNRrs:tT:uvxX:y"
 #else
-#define        optlist "b:CcdD:f:himNRrs:tT:uvxy"
+#define        optlist "b:CcdD:f:himMNRrs:tT:uvxX:y"
 #endif
        while ((ch = getopt(argc, argv, optlist)) != -1)
                switch(ch) {
@@ -142,7 +146,8 @@ main(int argc, char *argv[])
                        cvtflag = 1;
                        break;
                case 'D':
-                       filesys = optarg;
+                       strncpy(filesys, optarg, NAMELEN);
+                       filesys[NAMELEN - 1] = '\0';
                        break;
                case 'T':
                        tmpdir = optarg;
@@ -176,6 +181,9 @@ main(int argc, char *argv[])
                case 'm':
                        mflag = 0;
                        break;
+               case 'M':
+                       Mflag = 1;
+                       break;
                case 'N':
                        Nflag = 1;
                        break;
@@ -193,6 +201,10 @@ main(int argc, char *argv[])
                case 'v':
                        vflag = 1;
                        break;
+               case 'X':
+                       if ( !(filelist=fopen(optarg,"r")) )
+                               errx(1, "can't open file for reading -- %s", optarg);
+                       break;
                case 'y':
                        yflag = 1;
                        break;
@@ -303,6 +315,19 @@ main(int argc, char *argv[])
                checkrestore();
                dumpsymtable(symtbl, (long)1);
                break;
+               
+#define NEXTFILE(p) \
+       if (filelist) { \
+               if ((p = fgets(fname, MAXPATHLEN, filelist))) \
+                       *(p + strlen(p) - 1) = '\0'; \
+       } \
+       else { \
+               if (argc--) \
+                       p = *argv++; \
+               else \
+                       p = NULL; \
+       }
+       
        /*
         * List contents of tape.
         */
@@ -310,8 +335,11 @@ main(int argc, char *argv[])
                setup();
                extractdirs(0);
                initsymtable((char *)0);
-               while (argc--) {
-                       canon(*argv++, name, sizeof(name));
+               for (;;) {
+                       NEXTFILE(p);
+                       if (!p)
+                               break;
+                       canon(p, name, sizeof(name));
                        ino = dirlookup(name);
                        if (ino == 0)
                                continue;
@@ -325,8 +353,11 @@ main(int argc, char *argv[])
                setup();
                extractdirs(1);
                initsymtable((char *)0);
-               while (argc--) {
-                       canon(*argv++, name, sizeof(name));
+               for (;;) {
+                       NEXTFILE(p);
+                       if (!p)
+                               break;
+                       canon(p, name, sizeof(name));
                        ino = dirlookup(name);
                        if (ino == 0)
                                continue;
@@ -354,12 +385,17 @@ usage(void)
 #else
 #define kerbflag
 #endif
-       (void)fprintf(stderr, "usage:\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n",
-         "restore -i [-ch" kerbflag "muvy] [-b blocksize] [-f file] [-s fileno]",
-         "restore -r [-c" kerbflag "uvy] [-b blocksize] [-f file] [-s fileno]",
-         "restore -R [-c" kerbflag "uvy] [-b blocksize] [-f file] [-s fileno]",
-         "restore -x [-ch" kerbflag "muvy] [-b blocksize] [-f file] [-s fileno] [file ...]",
-         "restore -t [-ch" kerbflag "kuvy] [-b blocksize] [-f file] [-s fileno] [file ...]");
+       (void)fprintf(stderr, 
+         "%s %s\n", __progname, _DUMP_VERSION);
+       (void)fprintf(stderr,
+         "usage:\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n",
+         __progname, " -i [-ch" kerbflag "mMuvy] [-b blocksize] [-f file] [-s fileno]",
+         __progname, " -r [-c" kerbflag "Muvy] [-b blocksize] [-f file] [-s fileno]",
+         __progname, " -R [-c" kerbflag "Muvy] [-b blocksize] [-f file] [-s fileno]",
+         __progname, " -x [-ch" kerbflag "mMuvy] [-b blocksize] [-f file] [-s fileno] [file ...]",
+         __progname, " -x [-ch" kerbflag "mMuvy] [-b blocksize] [-f file] [-s fileno] [-X filelist]",
+         __progname, " -t [-ch" kerbflag "Muvy] [-b blocksize] [-f file] [-s fileno] [file ...]",
+         __progname, " -t [-ch" kerbflag "Muvy] [-b blocksize] [-f file] [-s fileno] [-X filelist]");
        exit(1);
 }
 
@@ -394,8 +430,11 @@ obsolete(int *argcp, char **argvp[])
        for (flags = 0; *ap; ++ap) {
                switch (*ap) {
                case 'b':
+               case 'D':
                case 'f':
                case 's':
+               case 'T':
+               case 'X':
                        if (*argv == NULL) {
                                warnx("option requires an argument -- %c", *ap);
                                usage();