]>
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, 1995, 1996
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 char sccsid
[] = "@(#)itime.c 8.1 (Berkeley) 6/5/93";
45 #include <sys/param.h>
48 #include <linux/ext2_fs.h>
49 #include <bsdcompat.h>
53 #include <sys/vnode.h>
55 #include <ufs/fsdir.h>
56 #include <ufs/inode.h>
59 #include <ufs/ufs/dinode.h>
63 #include <protocols/dumprestore.h>
75 #include <ext2fs/ext2fs.h>
80 struct dumpdates
**ddatev
= 0;
83 struct dumptime
*dthead
= 0;
85 static void dumprecout
__P((FILE *, struct dumpdates
*));
86 static int getrecord
__P((FILE *, struct dumpdates
*));
87 static int makedumpdate
__P((struct dumpdates
*, char *));
88 static void readdumptimes
__P((FILE *));
95 if ((df
= fopen(dumpdates
, "r")) == NULL
) {
96 if (errno
!= ENOENT
) {
97 quit("cannot read %s: %s\n", dumpdates
,
102 * Dumpdates does not exist, make an empty one.
104 msg("WARNING: no file `%s', making an empty one\n", dumpdates
);
105 if ((df
= fopen(dumpdates
, "w")) == NULL
) {
106 quit("cannot create %s: %s\n", dumpdates
,
111 if ((df
= fopen(dumpdates
, "r")) == NULL
) {
112 quit("cannot read %s even after creating it: %s\n",
113 dumpdates
, strerror(errno
));
117 (void) flock(fileno(df
), LOCK_SH
);
127 register struct dumptime
*dtwalk
;
130 dtwalk
= (struct dumptime
*)calloc(1, sizeof (struct dumptime
));
131 if (getrecord(df
, &(dtwalk
->dt_value
)) < 0)
134 dtwalk
->dt_next
= dthead
;
140 * arrayify the list, leaving enough room for the additional
141 * record that we may have to add to the ddate structure
143 ddatev
= (struct dumpdates
**)
144 calloc((unsigned) (nddates
+ 1), sizeof (struct dumpdates
*));
146 for (i
= nddates
- 1; i
>= 0; i
--, dtwalk
= dtwalk
->dt_next
)
147 ddatev
[i
] = &dtwalk
->dt_value
;
153 register struct dumpdates
*ddp
;
159 msg("Looking for name %s in dumpdates = %s for level = %c\n",
160 fname
, dumpdates
, level
);
167 * Go find the entry with the same name for a lower increment
171 if (strncmp(fname
, ddp
->dd_name
, sizeof (ddp
->dd_name
)) != 0)
173 if (ddp
->dd_level
>= level
)
176 if (ddp
->dd_ddate
<= (time_t)spcl
.c_ddate
)
178 if (ddp
->dd_ddate
<= spcl
.c_ddate
)
181 spcl
.c_ddate
= ddp
->dd_ddate
;
182 lastlevel
= ddp
->dd_level
;
190 register struct dumpdates
*dtwalk
;
197 if ((df
= fopen(dumpdates
, "r+")) == NULL
)
198 quit("cannot rewrite %s: %s\n", dumpdates
, strerror(errno
));
200 (void) flock(fd
, LOCK_EX
);
202 free((char *)ddatev
);
208 if (fseek(df
, 0L, 0) < 0)
209 quit("fseek: %s\n", strerror(errno
));
211 ITITERATE(i
, dtwalk
) {
212 if (strncmp(fname
, dtwalk
->dd_name
,
213 sizeof (dtwalk
->dd_name
)) != 0)
215 if (dtwalk
->dd_level
!= level
)
220 * construct the new upper bound;
221 * Enough room has been allocated.
223 dtwalk
= ddatev
[nddates
] =
224 (struct dumpdates
*)calloc(1, sizeof (struct dumpdates
));
227 (void) strncpy(dtwalk
->dd_name
, fname
, sizeof (dtwalk
->dd_name
));
228 dtwalk
->dd_level
= level
;
229 dtwalk
->dd_ddate
= spcl
.c_date
;
231 ITITERATE(i
, dtwalk
) {
232 dumprecout(df
, dtwalk
);
235 quit("%s: %s\n", dumpdates
, strerror(errno
));
236 if (ftruncate(fd
, ftell(df
)))
237 quit("ftruncate (%s): %s\n", dumpdates
, strerror(errno
));
239 msg("level %c dump on %s", level
,
241 spcl
.c_date
== 0 ? "the epoch\n" : ctime4(&spcl
.c_date
));
243 spcl
.c_date
== 0 ? "the epoch\n" : ctime(&spcl
.c_date
));
248 dumprecout(file
, what
)
250 struct dumpdates
*what
;
253 if (fprintf(file
, DUMPOUTFMT
,
256 ctime(&what
->dd_ddate
)) < 0)
257 quit("%s: %s\n", dumpdates
, strerror(errno
));
263 getrecord(df
, ddatep
)
265 struct dumpdates
*ddatep
;
270 if ( (fgets(tbuf
, sizeof (tbuf
), df
)) != tbuf
)
273 if (makedumpdate(ddatep
, tbuf
) < 0)
274 msg("Unknown intermediate format in %s, line %d\n",
278 msg("getrecord: %s %c %s", ddatep
->dd_name
, ddatep
->dd_level
,
279 ddatep
->dd_ddate
== 0 ? "the epoch\n" : ctime(&ddatep
->dd_ddate
));
285 makedumpdate(ddp
, tbuf
)
286 struct dumpdates
*ddp
;
291 (void) sscanf(tbuf
, DUMPINFMT
, ddp
->dd_name
, &ddp
->dd_level
, un_buf
);
292 ddp
->dd_ddate
= unctime(un_buf
);
293 if (ddp
->dd_ddate
< 0)