]> git.wh0rd.org - dump.git/blobdiff - dump/itime.c
Added EA/ACL support in dump and restore.
[dump.git] / dump / itime.c
index aeaaec01f8f9ee8c92ed88d717b398956cc4cdf4..f2cc76307eaf68d3e15b6569fc5760ba76598864 100644 (file)
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
@@ -41,7 +37,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: itime.c,v 1.23 2002/08/01 10:23:26 stelian Exp $";
+       "$Id: itime.c,v 1.28 2004/06/17 09:01:15 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -56,7 +52,6 @@ static const char rcsid[] =
 #include <sys/param.h>
 #include <sys/time.h>
 #include <time.h>
-#include <fcntl.h>
 #ifdef __linux__
 #ifdef HAVE_EXT2FS_EXT2_FS_H
 #include <ext2fs/ext2_fs.h>
@@ -168,17 +163,17 @@ getdumptime(int createdumpdates)
        int i;
 
 #ifdef FDEBUG
-       msg("Looking for name %s in dumpdates = %s for level = %c\n",
+       msg("Looking for name %s in dumpdates = %s for level = %s\n",
                disk, dumpdates, level);
 #endif
        spcl.c_ddate = 0;
-       lastlevel = '0';
+       memset(&lastlevel, 0, NUM_STR_SIZE);
 
        /* If this is a level 0 dump, and we're not updating 
           dumpdates, there's no point in trying to read
           dumpdates.  It may not exist yet, or may not be mounted.  For
           incrementals, we *must* read dumpdates (fail if it's not there!) */
-       if ( (level == lastlevel) && !createdumpdates)
+       if ( (!strcmp(level, lastlevel)) && !createdumpdates)
                return;
        initdumptimes(createdumpdates);
        if (ddatev == NULL)
@@ -190,12 +185,12 @@ getdumptime(int createdumpdates)
        ITITERATE(i, ddp) {
                if (strncmp(disk, ddp->dd_name, sizeof (ddp->dd_name)) != 0)
                        continue;
-               if (ddp->dd_level >= level)
+               if (ddp->dd_level >= atoi(level))
                        continue;
                if (ddp->dd_ddate <= (time_t)spcl.c_ddate)
                        continue;
                spcl.c_ddate = ddp->dd_ddate;
-               lastlevel = ddp->dd_level;
+               snprintf(lastlevel, NUM_STR_SIZE, "%d", ddp->dd_level);
        }
 }
 
@@ -230,7 +225,7 @@ putdumptime(void)
                if (strncmp(disk, dtwalk->dd_name,
                                sizeof (dtwalk->dd_name)) != 0)
                        continue;
-               if (dtwalk->dd_level != level)
+               if (dtwalk->dd_level != atoi(level))
                        continue;
                goto found;
        }
@@ -243,7 +238,7 @@ putdumptime(void)
        nddates += 1;
   found:
        (void) strncpy(dtwalk->dd_name, disk, sizeof (dtwalk->dd_name));
-       dtwalk->dd_level = level;
+       dtwalk->dd_level = atoi(level);
        dtwalk->dd_ddate = spcl.c_date;
 
        ITITERATE(i, dtwalk) {
@@ -259,11 +254,21 @@ putdumptime(void)
 static void
 dumprecout(FILE *file, struct dumpdates *what)
 {
+       char buf[26];
+       struct tm *tms;
 
-       if (fprintf(file, "%s %c %s",
+       tms = localtime(&what->dd_ddate);
+       strncpy(buf, asctime(tms), sizeof(buf));
+       if (buf[24] != '\n' || buf[25] != '\0')
+               quit("asctime returned an unexpected string\n");
+       buf[24] = 0;
+       if (fprintf(file, "%s %d %s %c%2.2d%2.2d\n",
                    what->dd_name,
                    what->dd_level,
-                   ctime(&what->dd_ddate)) < 0)
+                   buf,
+                   (tms->tm_gmtoff < 0 ? '-' : '+'),
+                   abs(tms->tm_gmtoff) / 3600,
+                   abs(tms->tm_gmtoff) % 3600 / 60) < 0)
                quit("%s: %s\n", dumpdates, strerror(errno));
 }
 
@@ -278,12 +283,14 @@ getrecord(FILE *df, struct dumpdates *ddatep)
        if (fgets(tbuf, sizeof (tbuf), df) == NULL)
                return(-1);
        recno++;
-       if (makedumpdate(ddatep, tbuf) < 0)
-               msg("Unknown intermediate format in %s, line %d\n",
+       if (makedumpdate(ddatep, tbuf) < 0) {
+               msg("Unknown format in %s, line %d\n",
                        dumpdates, recno);
+               return(-1);
+       }
 
 #ifdef FDEBUG
-       msg("getrecord: %s %c %s", ddatep->dd_name, ddatep->dd_level,
+       msg("getrecord: %s %d %s", ddatep->dd_name, ddatep->dd_level,
            ddatep->dd_ddate == 0 ? "the epoch\n" : ctime(&ddatep->dd_ddate));
 #endif
        return(0);
@@ -293,11 +300,10 @@ static int
 makedumpdate(struct dumpdates *ddp, char *tbuf)
 {
        char *tok;
-       
        /* device name */
        if ( NULL == (tok = strsep( &tbuf, " ")) )
                return(-1);
-       if ( strlen(tok) >  MAXPATHLEN )
+       if ( !tbuf || strlen(tok) >  MAXPATHLEN )
                return(-1);
        strcpy(ddp->dd_name, tok);
 
@@ -305,8 +311,9 @@ makedumpdate(struct dumpdates *ddp, char *tbuf)
        for( ; *tbuf == ' ' ; tbuf++);
 
        /* dump level */
-       ddp->dd_level = *tbuf;
-       ++tbuf;
+       ddp->dd_level = atoi(tbuf);
+       /* eat the rest of the numbers*/
+       for( ; *tbuf >= '0' && *tbuf <= '9' ; tbuf++);
 
        /* eat whitespace */
        for( ; *tbuf == ' ' ; tbuf++);