]>
git.wh0rd.org - dump.git/blob - dump/itime.c
2 * Ported to Linux's Second Extended File System as part of the
3 * dump and restore backup suit
4 * Remy Card <card@Linux.EU.Org>, 1994-1997
5 * Stelian Pop <pop@cybercable.fr>, 1999-2000
6 * Stelian Pop <pop@cybercable.fr> - Alcôve <www.alcove.fr>, 2000
10 * Copyright (c) 1980, 1993
11 * The Regents of the University of California. All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement:
23 * This product includes software developed by the University of
24 * California, Berkeley and its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 static const char rcsid
[] =
44 "$Id: itime.c,v 1.12 2000/11/10 14:42:25 stelian Exp $";
47 #include <sys/param.h>
50 #include <linux/ext2_fs.h>
51 #include <bsdcompat.h>
56 #include <sys/vnode.h>
58 #include <ufs/fsdir.h>
59 #include <ufs/inode.h>
62 #include <ufs/ufs/dinode.h>
66 #include <protocols/dumprestore.h>
77 #include <ext2fs/ext2fs.h>
82 struct dumpdates
**ddatev
;
85 struct dumptime
*dthead
;
87 static void dumprecout
__P((FILE *, struct dumpdates
*));
88 static int getrecord
__P((FILE *, struct dumpdates
*));
89 static int makedumpdate
__P((struct dumpdates
*, char *));
90 static void readdumptimes
__P((FILE *));
93 initdumptimes(int createdumpdates
)
97 if ((df
= fopen(dumpdates
, "r")) == NULL
) {
98 if (errno
!= ENOENT
) {
99 quit("cannot read %s: %s\n", dumpdates
,
103 if (createdumpdates
) {
105 * Dumpdates does not exist, make an empty one.
107 msg("WARNING: no file `%s', making an empty one\n", dumpdates
);
108 if ((df
= fopen(dumpdates
, "w")) == NULL
) {
109 quit("cannot create %s: %s\n", dumpdates
,
114 if ((df
= fopen(dumpdates
, "r")) == NULL
) {
115 quit("cannot read %s even after creating it: %s\n",
116 dumpdates
, strerror(errno
));
121 msg("WARNING: no file `%s'\n", dumpdates
);
124 (void) flock(fileno(df
), LOCK_SH
);
131 readdumptimes(FILE *df
)
134 register struct dumptime
*dtwalk
;
137 dtwalk
= (struct dumptime
*)calloc(1, sizeof (struct dumptime
));
138 if (getrecord(df
, &(dtwalk
->dt_value
)) < 0)
141 dtwalk
->dt_next
= dthead
;
147 * arrayify the list, leaving enough room for the additional
148 * record that we may have to add to the ddate structure
150 ddatev
= (struct dumpdates
**)
151 calloc((unsigned) (nddates
+ 1), sizeof (struct dumpdates
*));
153 for (i
= nddates
- 1; i
>= 0; i
--, dtwalk
= dtwalk
->dt_next
)
154 ddatev
[i
] = &dtwalk
->dt_value
;
158 getdumptime(int createdumpdates
)
160 register struct dumpdates
*ddp
;
166 msg("Looking for name %s in dumpdates = %s for level = %c\n",
167 fname
, dumpdates
, level
);
172 /* If this is a level 0 dump, and we're not updating
173 dumpdates, there's no point in trying to read
174 dumpdates. It may not exist yet, or may not be mounted. For
175 incrementals, we *must* read dumpdates (fail if it's not there!) */
176 if ( (level
== lastlevel
) && !createdumpdates
)
178 initdumptimes(createdumpdates
);
182 * Go find the entry with the same name for a lower increment
186 if (strncmp(fname
, ddp
->dd_name
, sizeof (ddp
->dd_name
)) != 0)
188 if (ddp
->dd_level
>= level
)
191 if (ddp
->dd_ddate
<= (time_t)spcl
.c_ddate
)
193 if (ddp
->dd_ddate
<= spcl
.c_ddate
)
196 spcl
.c_ddate
= ddp
->dd_ddate
;
197 lastlevel
= ddp
->dd_level
;
205 register struct dumpdates
*dtwalk
;
212 if ((df
= fopen(dumpdates
, "r+")) == NULL
)
213 quit("cannot rewrite %s: %s\n", dumpdates
, strerror(errno
));
215 (void) flock(fd
, LOCK_EX
);
217 free((char *)ddatev
);
223 if (fseek(df
, 0L, 0) < 0)
224 quit("fseek: %s\n", strerror(errno
));
226 ITITERATE(i
, dtwalk
) {
227 if (strncmp(fname
, dtwalk
->dd_name
,
228 sizeof (dtwalk
->dd_name
)) != 0)
230 if (dtwalk
->dd_level
!= level
)
235 * construct the new upper bound;
236 * Enough room has been allocated.
238 dtwalk
= ddatev
[nddates
] =
239 (struct dumpdates
*)calloc(1, sizeof (struct dumpdates
));
242 (void) strncpy(dtwalk
->dd_name
, fname
, sizeof (dtwalk
->dd_name
));
243 dtwalk
->dd_level
= level
;
244 dtwalk
->dd_ddate
= spcl
.c_date
;
246 ITITERATE(i
, dtwalk
) {
247 dumprecout(df
, dtwalk
);
250 quit("%s: %s\n", dumpdates
, strerror(errno
));
251 if (ftruncate(fd
, ftell(df
)))
252 quit("ftruncate (%s): %s\n", dumpdates
, strerror(errno
));
254 msg("level %c dump on %s", level
,
256 spcl
.c_date
== 0 ? "the epoch\n" : ctime4(&spcl
.c_date
));
258 spcl
.c_date
== 0 ? "the epoch\n" : ctime(&spcl
.c_date
));
263 dumprecout(FILE *file
, struct dumpdates
*what
)
266 if (fprintf(file
, "%s %c %s",
269 ctime(&what
->dd_ddate
)) < 0)
270 quit("%s: %s\n", dumpdates
, strerror(errno
));
276 getrecord(FILE *df
, struct dumpdates
*ddatep
)
281 if (fgets(tbuf
, sizeof (tbuf
), df
) == NULL
)
284 if (makedumpdate(ddatep
, tbuf
) < 0)
285 msg("Unknown intermediate format in %s, line %d\n",
289 msg("getrecord: %s %c %s", ddatep
->dd_name
, ddatep
->dd_level
,
290 ddatep
->dd_ddate
== 0 ? "the epoch\n" : ctime(&ddatep
->dd_ddate
));
296 makedumpdate(struct dumpdates
*ddp
, char *tbuf
)
301 if ( NULL
== (tok
= strsep( &tbuf
, " ")) )
303 if ( strlen(tok
) > MAXPATHLEN
)
305 strcpy(ddp
->dd_name
, tok
);
308 for( ; *tbuf
== ' ' ; tbuf
++);
311 ddp
->dd_level
= *tbuf
;
315 for( ; *tbuf
== ' ' ; tbuf
++);
318 ddp
->dd_ddate
= unctime(tbuf
);
319 if (ddp
->dd_ddate
< 0)
322 ddp
->dd_fstab
= fstabsearch(ddp
->dd_name
);