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