]>
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
9 * Copyright (c) 1980, 1993
10 * The Regents of the University of California. All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 static const char rcsid
[] =
43 "$Id: itime.c,v 1.9 2000/01/21 10:17:41 stelian Exp $";
46 #include <sys/param.h>
49 #include <linux/ext2_fs.h>
50 #include <bsdcompat.h>
55 #include <sys/vnode.h>
57 #include <ufs/fsdir.h>
58 #include <ufs/inode.h>
61 #include <ufs/ufs/dinode.h>
65 #include <protocols/dumprestore.h>
76 #include <ext2fs/ext2fs.h>
81 struct dumpdates
**ddatev
= 0;
84 struct dumptime
*dthead
= 0;
86 static void dumprecout
__P((FILE *, struct dumpdates
*));
87 static int getrecord
__P((FILE *, struct dumpdates
*));
88 static int makedumpdate
__P((struct dumpdates
*, char *));
89 static void readdumptimes
__P((FILE *));
92 initdumptimes(int createdumpdates
)
96 if ((df
= fopen(dumpdates
, "r")) == NULL
) {
97 if (errno
!= ENOENT
) {
98 quit("cannot read %s: %s\n", dumpdates
,
102 if (createdumpdates
) {
104 * Dumpdates does not exist, make an empty one.
106 msg("WARNING: no file `%s', making an empty one\n", dumpdates
);
107 if ((df
= fopen(dumpdates
, "w")) == NULL
) {
108 quit("cannot create %s: %s\n", dumpdates
,
113 if ((df
= fopen(dumpdates
, "r")) == NULL
) {
114 quit("cannot read %s even after creating it: %s\n",
115 dumpdates
, strerror(errno
));
120 msg("WARNING: no file `%s'\n", dumpdates
);
123 (void) flock(fileno(df
), LOCK_SH
);
130 readdumptimes(FILE *df
)
133 register struct dumptime
*dtwalk
;
136 dtwalk
= (struct dumptime
*)calloc(1, sizeof (struct dumptime
));
137 if (getrecord(df
, &(dtwalk
->dt_value
)) < 0)
140 dtwalk
->dt_next
= dthead
;
146 * arrayify the list, leaving enough room for the additional
147 * record that we may have to add to the ddate structure
149 ddatev
= (struct dumpdates
**)
150 calloc((unsigned) (nddates
+ 1), sizeof (struct dumpdates
*));
152 for (i
= nddates
- 1; i
>= 0; i
--, dtwalk
= dtwalk
->dt_next
)
153 ddatev
[i
] = &dtwalk
->dt_value
;
157 getdumptime(int createdumpdates
)
159 register struct dumpdates
*ddp
;
165 msg("Looking for name %s in dumpdates = %s for level = %c\n",
166 fname
, dumpdates
, level
);
171 /* If this is a level 0 dump, and we're not updating
172 dumpdates, there's no point in trying to read
173 dumpdates. It may not exist yet, or may not be mounted. For
174 incrementals, we *must* read dumpdates (fail if it's not there!) */
175 if ( (level
== lastlevel
) && !createdumpdates
)
177 initdumptimes(createdumpdates
);
181 * Go find the entry with the same name for a lower increment
185 if (strncmp(fname
, ddp
->dd_name
, sizeof (ddp
->dd_name
)) != 0)
187 if (ddp
->dd_level
>= level
)
190 if (ddp
->dd_ddate
<= (time_t)spcl
.c_ddate
)
192 if (ddp
->dd_ddate
<= spcl
.c_ddate
)
195 spcl
.c_ddate
= ddp
->dd_ddate
;
196 lastlevel
= ddp
->dd_level
;
204 register struct dumpdates
*dtwalk
;
211 if ((df
= fopen(dumpdates
, "r+")) == NULL
)
212 quit("cannot rewrite %s: %s\n", dumpdates
, strerror(errno
));
214 (void) flock(fd
, LOCK_EX
);
216 free((char *)ddatev
);
222 if (fseek(df
, 0L, 0) < 0)
223 quit("fseek: %s\n", strerror(errno
));
225 ITITERATE(i
, dtwalk
) {
226 if (strncmp(fname
, dtwalk
->dd_name
,
227 sizeof (dtwalk
->dd_name
)) != 0)
229 if (dtwalk
->dd_level
!= level
)
234 * construct the new upper bound;
235 * Enough room has been allocated.
237 dtwalk
= ddatev
[nddates
] =
238 (struct dumpdates
*)calloc(1, sizeof (struct dumpdates
));
241 (void) strncpy(dtwalk
->dd_name
, fname
, sizeof (dtwalk
->dd_name
));
242 dtwalk
->dd_level
= level
;
243 dtwalk
->dd_ddate
= spcl
.c_date
;
245 ITITERATE(i
, dtwalk
) {
246 dumprecout(df
, dtwalk
);
249 quit("%s: %s\n", dumpdates
, strerror(errno
));
250 if (ftruncate(fd
, ftell(df
)))
251 quit("ftruncate (%s): %s\n", dumpdates
, strerror(errno
));
253 msg("level %c dump on %s", level
,
255 spcl
.c_date
== 0 ? "the epoch\n" : ctime4(&spcl
.c_date
));
257 spcl
.c_date
== 0 ? "the epoch\n" : ctime(&spcl
.c_date
));
262 dumprecout(FILE *file
, struct dumpdates
*what
)
265 if (fprintf(file
, "%s %c %s",
268 ctime(&what
->dd_ddate
)) < 0)
269 quit("%s: %s\n", dumpdates
, strerror(errno
));
275 getrecord(FILE *df
, struct dumpdates
*ddatep
)
280 if (fgets(tbuf
, sizeof (tbuf
), df
) == NULL
)
283 if (makedumpdate(ddatep
, tbuf
) < 0)
284 msg("Unknown intermediate format in %s, line %d\n",
288 msg("getrecord: %s %c %s", ddatep
->dd_name
, ddatep
->dd_level
,
289 ddatep
->dd_ddate
== 0 ? "the epoch\n" : ctime(&ddatep
->dd_ddate
));
295 makedumpdate(struct dumpdates
*ddp
, char *tbuf
)
300 if ( NULL
== (tok
= strsep( &tbuf
, " ")) )
302 if ( strlen(tok
) > NAME_MAX
)
304 strcpy(ddp
->dd_name
, tok
);
307 for( ; *tbuf
== ' ' ; tbuf
++);
310 ddp
->dd_level
= *tbuf
;
314 for( ; *tbuf
== ' ' ; tbuf
++);
317 ddp
->dd_ddate
= unctime(tbuf
);
318 if (ddp
->dd_ddate
< 0)