1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * Copyright 1996-1998, 2002-2003 Sun Microsystems, Inc. All rights reserved.
3*0Sstevel@tonic-gate * Use is subject to license terms.
4*0Sstevel@tonic-gate */
5*0Sstevel@tonic-gate
6*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
7*0Sstevel@tonic-gate /* All Rights Reserved */
8*0Sstevel@tonic-gate
9*0Sstevel@tonic-gate /*
10*0Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California.
11*0Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
12*0Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
13*0Sstevel@tonic-gate */
14*0Sstevel@tonic-gate
15*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
16*0Sstevel@tonic-gate
17*0Sstevel@tonic-gate #include "dump.h"
18*0Sstevel@tonic-gate
19*0Sstevel@tonic-gate #ifndef LOCK_EX
20*0Sstevel@tonic-gate static struct flock fl;
21*0Sstevel@tonic-gate #define flock(fd, flag) (fl.l_type = (flag), fcntl(fd, F_SETLKW, &fl))
22*0Sstevel@tonic-gate #define LOCK_EX F_WRLCK
23*0Sstevel@tonic-gate #define LOCK_SH F_RDLCK
24*0Sstevel@tonic-gate #define LOCK_UN F_UNLCK
25*0Sstevel@tonic-gate #endif
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate /*
28*0Sstevel@tonic-gate * Print a date. A date of 0 is the beginning of time (the "epoch").
29*0Sstevel@tonic-gate * If the 2nd argument is non-zero, it is ok to format the date in
30*0Sstevel@tonic-gate * locale-specific form, otherwise we use ctime. We must use ctime
31*0Sstevel@tonic-gate * for dates such as those in the dumpdates file, which must be
32*0Sstevel@tonic-gate * locale-independent.
33*0Sstevel@tonic-gate */
34*0Sstevel@tonic-gate char *
prdate(d)35*0Sstevel@tonic-gate prdate(d)
36*0Sstevel@tonic-gate time_t d;
37*0Sstevel@tonic-gate {
38*0Sstevel@tonic-gate static char buf[256];
39*0Sstevel@tonic-gate struct tm *tm;
40*0Sstevel@tonic-gate char *p;
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gate if (d == 0)
43*0Sstevel@tonic-gate return (gettext("the epoch"));
44*0Sstevel@tonic-gate
45*0Sstevel@tonic-gate tm = localtime(&d);
46*0Sstevel@tonic-gate if (strftime(buf, sizeof (buf), "%c", tm) != 0) {
47*0Sstevel@tonic-gate p = buf;
48*0Sstevel@tonic-gate } else {
49*0Sstevel@tonic-gate /* Wouldn't fit in buf, fall back */
50*0Sstevel@tonic-gate p = ctime(&d);
51*0Sstevel@tonic-gate p[24] = '\0'; /* lose trailing newline */
52*0Sstevel@tonic-gate }
53*0Sstevel@tonic-gate return (p);
54*0Sstevel@tonic-gate }
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gate struct idates **idatev = 0;
57*0Sstevel@tonic-gate size_t nidates = 0;
58*0Sstevel@tonic-gate static int idates_in = 0; /* we have read the increment file */
59*0Sstevel@tonic-gate static int recno;
60*0Sstevel@tonic-gate
61*0Sstevel@tonic-gate #ifdef __STDC__
62*0Sstevel@tonic-gate static void readitimes(FILE *);
63*0Sstevel@tonic-gate static void recout(FILE *, struct idates *);
64*0Sstevel@tonic-gate static int getrecord(FILE *, struct idates *);
65*0Sstevel@tonic-gate static int makeidate(struct idates *, char *);
66*0Sstevel@tonic-gate #else
67*0Sstevel@tonic-gate static void readitimes();
68*0Sstevel@tonic-gate static void recout();
69*0Sstevel@tonic-gate static int getrecord();
70*0Sstevel@tonic-gate static int makeidate();
71*0Sstevel@tonic-gate #endif
72*0Sstevel@tonic-gate
73*0Sstevel@tonic-gate void
74*0Sstevel@tonic-gate #ifdef __STDC__
inititimes(void)75*0Sstevel@tonic-gate inititimes(void)
76*0Sstevel@tonic-gate #else
77*0Sstevel@tonic-gate inititimes()
78*0Sstevel@tonic-gate #endif
79*0Sstevel@tonic-gate {
80*0Sstevel@tonic-gate FILE *df;
81*0Sstevel@tonic-gate int saverr;
82*0Sstevel@tonic-gate
83*0Sstevel@tonic-gate if (idates_in)
84*0Sstevel@tonic-gate return;
85*0Sstevel@tonic-gate if (increm == NULL || *increm == '\0') {
86*0Sstevel@tonic-gate msg(gettext("inititimes: No dump record file name defined\n"));
87*0Sstevel@tonic-gate dumpabort();
88*0Sstevel@tonic-gate /*NOTREACHED*/
89*0Sstevel@tonic-gate }
90*0Sstevel@tonic-gate /*
91*0Sstevel@tonic-gate * No need to secure this, as increm is hard-coded to NINCREM,
92*0Sstevel@tonic-gate * and that file is in /etc. If random people have write-permission
93*0Sstevel@tonic-gate * there, then there are more problems than any degree of paranoia
94*0Sstevel@tonic-gate * on our part can fix.
95*0Sstevel@tonic-gate */
96*0Sstevel@tonic-gate if ((df = fopen(increm, "r")) == NULL) {
97*0Sstevel@tonic-gate saverr = errno;
98*0Sstevel@tonic-gate if (errno == ENOENT)
99*0Sstevel@tonic-gate msg(gettext(
100*0Sstevel@tonic-gate "Warning - dump record file `%s' does not exist\n"),
101*0Sstevel@tonic-gate increm);
102*0Sstevel@tonic-gate else {
103*0Sstevel@tonic-gate msg(gettext("Cannot open dump record file `%s': %s\n"),
104*0Sstevel@tonic-gate increm, strerror(saverr));
105*0Sstevel@tonic-gate dumpabort();
106*0Sstevel@tonic-gate /*NOTREACHED*/
107*0Sstevel@tonic-gate }
108*0Sstevel@tonic-gate return;
109*0Sstevel@tonic-gate }
110*0Sstevel@tonic-gate if (uflag && access(increm, W_OK) < 0) {
111*0Sstevel@tonic-gate msg(gettext("Cannot access dump record file `%s' for update\n"),
112*0Sstevel@tonic-gate increm);
113*0Sstevel@tonic-gate dumpabort();
114*0Sstevel@tonic-gate /*NOTREACHED*/
115*0Sstevel@tonic-gate }
116*0Sstevel@tonic-gate (void) flock(fileno(df), LOCK_SH);
117*0Sstevel@tonic-gate readitimes(df);
118*0Sstevel@tonic-gate (void) fclose(df);
119*0Sstevel@tonic-gate }
120*0Sstevel@tonic-gate
121*0Sstevel@tonic-gate static void
readitimes(df)122*0Sstevel@tonic-gate readitimes(df)
123*0Sstevel@tonic-gate FILE *df;
124*0Sstevel@tonic-gate {
125*0Sstevel@tonic-gate struct idates *idp;
126*0Sstevel@tonic-gate
127*0Sstevel@tonic-gate recno = 0;
128*0Sstevel@tonic-gate for (;;) {
129*0Sstevel@tonic-gate idp = (struct idates *)xcalloc(1, sizeof (*idp));
130*0Sstevel@tonic-gate if (getrecord(df, idp) < 0) {
131*0Sstevel@tonic-gate free((char *)idp);
132*0Sstevel@tonic-gate break;
133*0Sstevel@tonic-gate }
134*0Sstevel@tonic-gate nidates++;
135*0Sstevel@tonic-gate idatev = (struct idates **)xrealloc((void *)idatev,
136*0Sstevel@tonic-gate nidates * (size_t)sizeof (*idatev));
137*0Sstevel@tonic-gate idatev[nidates - 1] = idp;
138*0Sstevel@tonic-gate }
139*0Sstevel@tonic-gate /* LINTED: assigned value is used in inititimes */
140*0Sstevel@tonic-gate idates_in = 1;
141*0Sstevel@tonic-gate }
142*0Sstevel@tonic-gate
143*0Sstevel@tonic-gate void
144*0Sstevel@tonic-gate #ifdef __STDC__
getitime(void)145*0Sstevel@tonic-gate getitime(void)
146*0Sstevel@tonic-gate #else
147*0Sstevel@tonic-gate getitime()
148*0Sstevel@tonic-gate #endif
149*0Sstevel@tonic-gate {
150*0Sstevel@tonic-gate struct idates *ip;
151*0Sstevel@tonic-gate int i;
152*0Sstevel@tonic-gate char *fname;
153*0Sstevel@tonic-gate
154*0Sstevel@tonic-gate /*
155*0Sstevel@tonic-gate * if an alternate name was specified via the N flag, use it instead
156*0Sstevel@tonic-gate * of the disk name.
157*0Sstevel@tonic-gate */
158*0Sstevel@tonic-gate if (dname != NULL)
159*0Sstevel@tonic-gate fname = dname;
160*0Sstevel@tonic-gate else
161*0Sstevel@tonic-gate fname = disk;
162*0Sstevel@tonic-gate
163*0Sstevel@tonic-gate #ifdef FDEBUG
164*0Sstevel@tonic-gate
165*0Sstevel@tonic-gate /* XGETTEXT: #ifdef FDEBUG only */
166*0Sstevel@tonic-gate msg(gettext("Looking for name %s in increm = %s for delta = %c\n"),
167*0Sstevel@tonic-gate fname, increm, (uchar_t)incno);
168*0Sstevel@tonic-gate #endif
169*0Sstevel@tonic-gate spcl.c_ddate = 0;
170*0Sstevel@tonic-gate lastincno = '0';
171*0Sstevel@tonic-gate
172*0Sstevel@tonic-gate inititimes();
173*0Sstevel@tonic-gate if (idatev == 0)
174*0Sstevel@tonic-gate return;
175*0Sstevel@tonic-gate /*
176*0Sstevel@tonic-gate * Go find the entry with the same name for a lower increment
177*0Sstevel@tonic-gate * and older date
178*0Sstevel@tonic-gate */
179*0Sstevel@tonic-gate ITITERATE(i, ip) {
180*0Sstevel@tonic-gate if (strncmp(fname, ip->id_name, sizeof (ip->id_name)) != 0)
181*0Sstevel@tonic-gate continue;
182*0Sstevel@tonic-gate if (ip->id_incno >= incno)
183*0Sstevel@tonic-gate continue;
184*0Sstevel@tonic-gate if (ip->id_ddate <= spcl.c_ddate)
185*0Sstevel@tonic-gate continue;
186*0Sstevel@tonic-gate spcl.c_ddate = ip->id_ddate;
187*0Sstevel@tonic-gate lastincno = ip->id_incno;
188*0Sstevel@tonic-gate }
189*0Sstevel@tonic-gate }
190*0Sstevel@tonic-gate
191*0Sstevel@tonic-gate void
192*0Sstevel@tonic-gate #ifdef __STDC__
putitime(void)193*0Sstevel@tonic-gate putitime(void)
194*0Sstevel@tonic-gate #else
195*0Sstevel@tonic-gate putitime()
196*0Sstevel@tonic-gate #endif
197*0Sstevel@tonic-gate {
198*0Sstevel@tonic-gate FILE *df;
199*0Sstevel@tonic-gate struct idates *itwalk;
200*0Sstevel@tonic-gate int i;
201*0Sstevel@tonic-gate int fd, saverr;
202*0Sstevel@tonic-gate char *fname;
203*0Sstevel@tonic-gate
204*0Sstevel@tonic-gate if (uflag == 0)
205*0Sstevel@tonic-gate return;
206*0Sstevel@tonic-gate if ((df = safe_fopen(increm, "r+", 0664)) == (FILE *)NULL) {
207*0Sstevel@tonic-gate msg("%s: %s\n", increm, strerror(errno));
208*0Sstevel@tonic-gate (void) unlink(increm);
209*0Sstevel@tonic-gate dumpabort();
210*0Sstevel@tonic-gate /*NOTREACHED*/
211*0Sstevel@tonic-gate }
212*0Sstevel@tonic-gate fd = fileno(df);
213*0Sstevel@tonic-gate (void) flock(fd, LOCK_EX);
214*0Sstevel@tonic-gate
215*0Sstevel@tonic-gate /*
216*0Sstevel@tonic-gate * if an alternate name was specified via the N flag, use it instead
217*0Sstevel@tonic-gate * of the disk name.
218*0Sstevel@tonic-gate */
219*0Sstevel@tonic-gate if (dname != NULL)
220*0Sstevel@tonic-gate fname = dname;
221*0Sstevel@tonic-gate else
222*0Sstevel@tonic-gate fname = disk;
223*0Sstevel@tonic-gate
224*0Sstevel@tonic-gate if (idatev != 0) {
225*0Sstevel@tonic-gate for (i = 0; i < nidates && idatev[i] != 0; i++)
226*0Sstevel@tonic-gate free((char *)idatev[i]);
227*0Sstevel@tonic-gate free((char *)idatev);
228*0Sstevel@tonic-gate }
229*0Sstevel@tonic-gate idatev = 0;
230*0Sstevel@tonic-gate nidates = 0;
231*0Sstevel@tonic-gate readitimes(df);
232*0Sstevel@tonic-gate if (fseek(df, 0L, 0) < 0) { /* rewind() was redefined in dumptape.c */
233*0Sstevel@tonic-gate saverr = errno;
234*0Sstevel@tonic-gate msg(gettext("%s: %s error:\n"),
235*0Sstevel@tonic-gate increm, "fseek", strerror(saverr));
236*0Sstevel@tonic-gate dumpabort();
237*0Sstevel@tonic-gate /*NOTREACHED*/
238*0Sstevel@tonic-gate }
239*0Sstevel@tonic-gate spcl.c_ddate = 0;
240*0Sstevel@tonic-gate /* LINTED: won't dereference idatev if it is NULL (see readitimes) */
241*0Sstevel@tonic-gate ITITERATE(i, itwalk) {
242*0Sstevel@tonic-gate if (strncmp(fname, itwalk->id_name,
243*0Sstevel@tonic-gate sizeof (itwalk->id_name)) != 0)
244*0Sstevel@tonic-gate continue;
245*0Sstevel@tonic-gate if (itwalk->id_incno != incno)
246*0Sstevel@tonic-gate continue;
247*0Sstevel@tonic-gate goto found;
248*0Sstevel@tonic-gate }
249*0Sstevel@tonic-gate /*
250*0Sstevel@tonic-gate * Add one more entry to idatev
251*0Sstevel@tonic-gate */
252*0Sstevel@tonic-gate nidates++;
253*0Sstevel@tonic-gate idatev = (struct idates **)xrealloc((void *)idatev,
254*0Sstevel@tonic-gate nidates * (size_t)sizeof (struct idates *));
255*0Sstevel@tonic-gate itwalk = idatev[nidates - 1] =
256*0Sstevel@tonic-gate (struct idates *)xcalloc(1, sizeof (*itwalk));
257*0Sstevel@tonic-gate found:
258*0Sstevel@tonic-gate (void) strncpy(itwalk->id_name, fname, sizeof (itwalk->id_name));
259*0Sstevel@tonic-gate itwalk->id_name[sizeof (itwalk->id_name) - 1] = '\0';
260*0Sstevel@tonic-gate itwalk->id_incno = incno;
261*0Sstevel@tonic-gate itwalk->id_ddate = spcl.c_date;
262*0Sstevel@tonic-gate
263*0Sstevel@tonic-gate ITITERATE(i, itwalk) {
264*0Sstevel@tonic-gate recout(df, itwalk);
265*0Sstevel@tonic-gate }
266*0Sstevel@tonic-gate if (ftruncate64(fd, ftello64(df))) {
267*0Sstevel@tonic-gate saverr = errno;
268*0Sstevel@tonic-gate msg(gettext("%s: %s error:\n"),
269*0Sstevel@tonic-gate increm, "ftruncate64", strerror(saverr));
270*0Sstevel@tonic-gate dumpabort();
271*0Sstevel@tonic-gate /*NOTREACHED*/
272*0Sstevel@tonic-gate }
273*0Sstevel@tonic-gate (void) fclose(df);
274*0Sstevel@tonic-gate msg(gettext("Level %c dump on %s\n"),
275*0Sstevel@tonic-gate (uchar_t)incno, prdate(spcl.c_date));
276*0Sstevel@tonic-gate }
277*0Sstevel@tonic-gate
278*0Sstevel@tonic-gate static void
recout(file,what)279*0Sstevel@tonic-gate recout(file, what)
280*0Sstevel@tonic-gate FILE *file;
281*0Sstevel@tonic-gate struct idates *what;
282*0Sstevel@tonic-gate {
283*0Sstevel@tonic-gate time_t ddate = what->id_ddate;
284*0Sstevel@tonic-gate /* must use ctime, so we can later use unctime() */
285*0Sstevel@tonic-gate (void) fprintf(file, DUMPOUTFMT,
286*0Sstevel@tonic-gate what->id_name,
287*0Sstevel@tonic-gate (uchar_t)what->id_incno,
288*0Sstevel@tonic-gate ctime(&ddate));
289*0Sstevel@tonic-gate }
290*0Sstevel@tonic-gate
291*0Sstevel@tonic-gate static int
getrecord(df,idatep)292*0Sstevel@tonic-gate getrecord(df, idatep)
293*0Sstevel@tonic-gate FILE *df;
294*0Sstevel@tonic-gate struct idates *idatep;
295*0Sstevel@tonic-gate {
296*0Sstevel@tonic-gate char buf[BUFSIZ];
297*0Sstevel@tonic-gate
298*0Sstevel@tonic-gate if ((fgets(buf, BUFSIZ, df)) != buf)
299*0Sstevel@tonic-gate return (-1);
300*0Sstevel@tonic-gate recno++;
301*0Sstevel@tonic-gate if (makeidate(idatep, buf) < 0) {
302*0Sstevel@tonic-gate msg(gettext(
303*0Sstevel@tonic-gate "Malformed entry in dump record file `%s', line %d\n"),
304*0Sstevel@tonic-gate increm, recno);
305*0Sstevel@tonic-gate if (strcmp(increm, NINCREM)) {
306*0Sstevel@tonic-gate msg(gettext("`%s' not a dump record file\n"), increm);
307*0Sstevel@tonic-gate dumpabort();
308*0Sstevel@tonic-gate /*NOTREACHED*/
309*0Sstevel@tonic-gate }
310*0Sstevel@tonic-gate return (-1);
311*0Sstevel@tonic-gate }
312*0Sstevel@tonic-gate
313*0Sstevel@tonic-gate #ifdef FDEBUG
314*0Sstevel@tonic-gate msg("getrecord: %s %c %s\n",
315*0Sstevel@tonic-gate idatep->id_name,
316*0Sstevel@tonic-gate (uchar_t)idatep->id_incno,
317*0Sstevel@tonic-gate prdate(idatep->id_ddate));
318*0Sstevel@tonic-gate #endif
319*0Sstevel@tonic-gate return (0);
320*0Sstevel@tonic-gate }
321*0Sstevel@tonic-gate
322*0Sstevel@tonic-gate static int
makeidate(ip,buf)323*0Sstevel@tonic-gate makeidate(ip, buf)
324*0Sstevel@tonic-gate struct idates *ip;
325*0Sstevel@tonic-gate char *buf;
326*0Sstevel@tonic-gate {
327*0Sstevel@tonic-gate char un_buf[128]; /* size must be >= second one in DUMPINFMT */
328*0Sstevel@tonic-gate
329*0Sstevel@tonic-gate /*
330*0Sstevel@tonic-gate * MAXNAMLEN has different values in dirent.h and ufs_fsdir.h,
331*0Sstevel@tonic-gate * and we need to ensure that the length in DUMPINFMT matches
332*0Sstevel@tonic-gate * what we allow for. Can't just use MAXNAMLEN in the test,
333*0Sstevel@tonic-gate * because there's no convenient way to substitute it into
334*0Sstevel@tonic-gate * DUMPINFMT.
335*0Sstevel@tonic-gate * XXX There's got to be a better way.
336*0Sstevel@tonic-gate */
337*0Sstevel@tonic-gate /*LINTED [assertion always true]*/
338*0Sstevel@tonic-gate assert(sizeof (ip->id_name) == (255 + 3));
339*0Sstevel@tonic-gate
340*0Sstevel@tonic-gate if (sscanf(buf, DUMPINFMT, ip->id_name, &ip->id_incno, un_buf) != 3)
341*0Sstevel@tonic-gate return (-1);
342*0Sstevel@tonic-gate /* LINTED casting from 64-bit to 32-bit time */
343*0Sstevel@tonic-gate ip->id_ddate = (time32_t)unctime(un_buf);
344*0Sstevel@tonic-gate if (ip->id_ddate < 0)
345*0Sstevel@tonic-gate return (-1);
346*0Sstevel@tonic-gate return (0);
347*0Sstevel@tonic-gate }
348*0Sstevel@tonic-gate
349*0Sstevel@tonic-gate /*
350*0Sstevel@tonic-gate * This is an estimation of the number of tp_bsize blocks in the file.
351*0Sstevel@tonic-gate * It estimates the number of blocks in files with holes by assuming
352*0Sstevel@tonic-gate * that all of the blocks accounted for by di_blocks are data blocks
353*0Sstevel@tonic-gate * (when some of the blocks are usually used for indirect pointers);
354*0Sstevel@tonic-gate * hence the estimate may be high.
355*0Sstevel@tonic-gate */
356*0Sstevel@tonic-gate void
est(ip)357*0Sstevel@tonic-gate est(ip)
358*0Sstevel@tonic-gate struct dinode *ip;
359*0Sstevel@tonic-gate {
360*0Sstevel@tonic-gate u_offset_t s, t;
361*0Sstevel@tonic-gate
362*0Sstevel@tonic-gate /*
363*0Sstevel@tonic-gate * ip->di_size is the size of the file in bytes.
364*0Sstevel@tonic-gate * ip->di_blocks stores the number of sectors actually in the file.
365*0Sstevel@tonic-gate * If there are more sectors than the size would indicate, this just
366*0Sstevel@tonic-gate * means that there are indirect blocks in the file or unused
367*0Sstevel@tonic-gate * sectors in the last file block; we can safely ignore these
368*0Sstevel@tonic-gate * (s = t below).
369*0Sstevel@tonic-gate * If the file is bigger than the number of sectors would indicate,
370*0Sstevel@tonic-gate * then the file has holes in it. In this case we must use the
371*0Sstevel@tonic-gate * block count to estimate the number of data blocks used, but
372*0Sstevel@tonic-gate * we use the actual size for estimating the number of indirect
373*0Sstevel@tonic-gate * dump blocks (t vs. s in the indirect block calculation).
374*0Sstevel@tonic-gate */
375*0Sstevel@tonic-gate o_esize++;
376*0Sstevel@tonic-gate s = (unsigned)(ip->di_blocks) / (unsigned)(tp_bsize / DEV_BSIZE);
377*0Sstevel@tonic-gate /* LINTED: spurious complaint about sign-extending 32 to 64 bits */
378*0Sstevel@tonic-gate t = d_howmany(ip->di_size, (unsigned)tp_bsize);
379*0Sstevel@tonic-gate if (s > t)
380*0Sstevel@tonic-gate s = t;
381*0Sstevel@tonic-gate if (ip->di_size > (u_offset_t)((unsigned)(sblock->fs_bsize) * NDADDR)) {
382*0Sstevel@tonic-gate /* calculate the number of indirect blocks on the dump tape */
383*0Sstevel@tonic-gate /* LINTED: spurious complaint sign-extending 32 to 64 bits */
384*0Sstevel@tonic-gate s += d_howmany(t -
385*0Sstevel@tonic-gate (unsigned)(NDADDR * sblock->fs_bsize / tp_bsize),
386*0Sstevel@tonic-gate (unsigned)TP_NINDIR);
387*0Sstevel@tonic-gate }
388*0Sstevel@tonic-gate f_esize += s;
389*0Sstevel@tonic-gate }
390*0Sstevel@tonic-gate
391*0Sstevel@tonic-gate /*ARGSUSED*/
392*0Sstevel@tonic-gate void
bmapest(map)393*0Sstevel@tonic-gate bmapest(map)
394*0Sstevel@tonic-gate uchar_t *map;
395*0Sstevel@tonic-gate {
396*0Sstevel@tonic-gate o_esize++;
397*0Sstevel@tonic-gate /* LINTED: spurious complaint sign-extending 32 to 64 bits */
398*0Sstevel@tonic-gate f_esize += d_howmany(msiz * sizeof (map[0]), (unsigned)tp_bsize);
399*0Sstevel@tonic-gate }
400*0Sstevel@tonic-gate
401*0Sstevel@tonic-gate
402*0Sstevel@tonic-gate /*
403*0Sstevel@tonic-gate * Check to see if what we are trying to dump is a fs snapshot
404*0Sstevel@tonic-gate * If so, we can use the snapshot's create time to populate
405*0Sstevel@tonic-gate * the dumpdates file, instead of the time of the dump.
406*0Sstevel@tonic-gate */
407*0Sstevel@tonic-gate time32_t
is_fssnap_dump(char * disk)408*0Sstevel@tonic-gate is_fssnap_dump(char *disk)
409*0Sstevel@tonic-gate {
410*0Sstevel@tonic-gate struct stat st;
411*0Sstevel@tonic-gate char *last;
412*0Sstevel@tonic-gate int snapnum;
413*0Sstevel@tonic-gate kstat_ctl_t *kslib;
414*0Sstevel@tonic-gate kstat_t *ksnum;
415*0Sstevel@tonic-gate kstat_named_t *numval;
416*0Sstevel@tonic-gate
417*0Sstevel@tonic-gate last = basename(disk);
418*0Sstevel@tonic-gate if ((strstr(disk, SNAP_NAME) == NULL) || (stat(disk, &st) == -1) ||
419*0Sstevel@tonic-gate (isdigit(last[0]) == 0))
420*0Sstevel@tonic-gate return (0);
421*0Sstevel@tonic-gate
422*0Sstevel@tonic-gate snapnum = atoi(last);
423*0Sstevel@tonic-gate
424*0Sstevel@tonic-gate if ((kslib = kstat_open()) == NULL)
425*0Sstevel@tonic-gate return (0);
426*0Sstevel@tonic-gate
427*0Sstevel@tonic-gate ksnum = kstat_lookup(kslib, SNAP_NAME, snapnum, FSSNAP_KSTAT_NUM);
428*0Sstevel@tonic-gate if (ksnum == NULL) {
429*0Sstevel@tonic-gate (void) kstat_close(kslib);
430*0Sstevel@tonic-gate return (0);
431*0Sstevel@tonic-gate }
432*0Sstevel@tonic-gate
433*0Sstevel@tonic-gate if (kstat_read(kslib, ksnum, NULL) == -1) {
434*0Sstevel@tonic-gate (void) kstat_close(kslib);
435*0Sstevel@tonic-gate return (0);
436*0Sstevel@tonic-gate }
437*0Sstevel@tonic-gate
438*0Sstevel@tonic-gate numval = kstat_data_lookup(ksnum, FSSNAP_KSTAT_NUM_CREATETIME);
439*0Sstevel@tonic-gate if (numval == NULL) {
440*0Sstevel@tonic-gate (void) kstat_close(kslib);
441*0Sstevel@tonic-gate return (0);
442*0Sstevel@tonic-gate }
443*0Sstevel@tonic-gate
444*0Sstevel@tonic-gate (void) kstat_close(kslib);
445*0Sstevel@tonic-gate /* LINTED casting from long to 32-bit time */
446*0Sstevel@tonic-gate return (time32_t)(numval->value.l & INT_MAX);
447*0Sstevel@tonic-gate }
448