]> git.wh0rd.org - dump.git/blobdiff - dump/itime.c
Add local EXT2_FT_* constants.
[dump.git] / dump / itime.c
index 81d8dc7e7b85b34c2594d13f24006c39070bebbe..aeaaec01f8f9ee8c92ed88d717b398956cc4cdf4 100644 (file)
@@ -2,8 +2,8 @@
  *     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@noos.fr>, 1999-2000
- *     Stelian Pop <pop@noos.fr> - Alcôve <www.alcove.fr>, 2000
+ *     Stelian Pop <stelian@popies.net>, 1999-2000
+ *     Stelian Pop <stelian@popies.net> - Alcôve <www.alcove.com>, 2000-2002
  */
 
 /*-
@@ -41,7 +41,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: itime.c,v 1.18 2001/03/21 09:37:13 stelian Exp $";
+       "$Id: itime.c,v 1.23 2002/08/01 10:23:26 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -55,10 +55,15 @@ 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>
+#else
 #include <linux/ext2_fs.h>
+#endif
 #include <ext2fs/ext2fs.h>
-#include <time.h>
 #include <bsdcompat.h>
 #include <sys/file.h>
 #include <unistd.h>
@@ -90,6 +95,7 @@ void
 initdumptimes(int createdumpdates)
 {
        FILE *df;
+       struct flock lock;
 
        if ((df = fopen(dumpdates, "r")) == NULL) {
                if (errno != ENOENT) {
@@ -118,7 +124,11 @@ initdumptimes(int createdumpdates)
                        msg("WARNING: no file `%s'\n", dumpdates);
        }
        if (df != NULL) {
-               (void) flock(fileno(df), LOCK_SH);
+               memset(&lock, 0, sizeof(lock));
+               lock.l_type = F_RDLCK;
+               if (fcntl(fileno(df), F_SETLKW, &lock) < 0)
+                       quit("cannot set read lock on %s: %s\n",
+                               dumpdates, strerror(errno));
                readdumptimes(df);
                (void) fclose(df);
        }
@@ -127,8 +137,8 @@ initdumptimes(int createdumpdates)
 static void
 readdumptimes(FILE *df)
 {
-       register int i;
-       register struct dumptime *dtwalk;
+       int i;
+       struct  dumptime *dtwalk;
 
        for (;;) {
                dtwalk = (struct dumptime *)calloc(1, sizeof (struct dumptime));
@@ -154,8 +164,8 @@ readdumptimes(FILE *df)
 void
 getdumptime(int createdumpdates)
 {
-       register struct dumpdates *ddp;
-       register int i;
+       struct dumpdates *ddp;
+       int i;
 
 #ifdef FDEBUG
        msg("Looking for name %s in dumpdates = %s for level = %c\n",
@@ -193,16 +203,20 @@ void
 putdumptime(void)
 {
        FILE *df;
-       register struct dumpdates *dtwalk;
-       register int i;
+       struct dumpdates *dtwalk;
+       int i;
        int fd;
+       struct flock lock;
 
        if(uflag == 0)
                return;
        if ((df = fopen(dumpdates, "r+")) == NULL)
                quit("cannot rewrite %s: %s\n", dumpdates, strerror(errno));
        fd = fileno(df);
-       (void) flock(fd, LOCK_EX);
+       memset(&lock, 0, sizeof(lock));
+       lock.l_type = F_WRLCK;
+       if (fcntl(fd, F_SETLKW, &lock) < 0)
+               quit("cannot set write lock on %s: %s\n", dumpdates, strerror(errno));
        free((char *)ddatev);
        ddatev = 0;
        nddates = 0;