2012-05-06 01:03:02 +04:00
|
|
|
/* $NetBSD: dump.h,v 1.47 2012/05/05 21:03:02 christos Exp $ */
|
1995-03-18 17:54:19 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
1994-06-08 22:57:30 +04:00
|
|
|
* Copyright (c) 1980, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 14:04:11 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1997-09-16 10:41:19 +04:00
|
|
|
* @(#)dump.h 8.2 (Berkeley) 4/28/95
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
1999-01-15 16:32:05 +03:00
|
|
|
#include <machine/bswap.h>
|
|
|
|
|
2003-04-02 14:39:19 +04:00
|
|
|
union dinode {
|
|
|
|
struct ufs1_dinode dp1;
|
|
|
|
struct ufs2_dinode dp2;
|
|
|
|
};
|
|
|
|
#define DIP(dp, field) \
|
|
|
|
(is_ufs2 ? (dp)->dp2.di_##field : (dp)->dp1.di_##field)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2006-04-21 19:00:49 +04:00
|
|
|
#define DIP_SET(dp, field, val) do { \
|
|
|
|
if (is_ufs2) \
|
|
|
|
(dp)->dp2.di_##field = (val); \
|
|
|
|
else \
|
|
|
|
(dp)->dp1.di_##field = (val); \
|
|
|
|
} while (0)
|
|
|
|
|
1999-10-01 08:35:21 +04:00
|
|
|
/*
|
|
|
|
* Filestore-independent UFS data, so code can be more easily shared
|
|
|
|
* between ffs, lfs, and maybe ext2fs and others as well.
|
|
|
|
*/
|
|
|
|
struct ufsi {
|
2001-08-14 09:44:44 +04:00
|
|
|
int64_t ufs_dsize; /* file system size, in sectors */
|
1999-10-01 08:35:21 +04:00
|
|
|
int32_t ufs_bsize; /* block size */
|
|
|
|
int32_t ufs_bshift; /* log2(ufs_bsize) */
|
|
|
|
int32_t ufs_fsize; /* fragment size */
|
2001-12-22 11:05:24 +03:00
|
|
|
int32_t ufs_frag; /* block size / frag size */
|
1999-10-01 08:35:21 +04:00
|
|
|
int32_t ufs_fsatoda; /* disk address conversion constant */
|
|
|
|
int32_t ufs_nindir; /* disk addresses per indirect block */
|
2001-12-22 11:05:24 +03:00
|
|
|
int32_t ufs_inopb; /* inodes per block */
|
1999-10-01 08:35:21 +04:00
|
|
|
int32_t ufs_maxsymlinklen; /* max symlink length */
|
2001-12-22 11:05:24 +03:00
|
|
|
int32_t ufs_bmask; /* block mask */
|
|
|
|
int32_t ufs_fmask; /* frag mask */
|
|
|
|
int64_t ufs_qbmask; /* ~ufs_bmask */
|
|
|
|
int64_t ufs_qfmask; /* ~ufs_fmask */
|
1999-10-01 08:35:21 +04:00
|
|
|
};
|
|
|
|
#define fsatoda(u,a) ((a) << (u)->ufs_fsatoda)
|
|
|
|
#define ufs_fragroundup(u,size) /* calculates roundup(size, ufs_fsize) */ \
|
2001-12-22 11:05:24 +03:00
|
|
|
(((size) + (u)->ufs_qfmask) & (u)->ufs_fmask)
|
1999-10-01 08:35:21 +04:00
|
|
|
#define ufs_blkoff(u,loc) /* calculates (loc % u->ufs_bsize) */ \
|
2001-12-22 11:05:24 +03:00
|
|
|
((loc) & (u)->ufs_qbmask)
|
1999-10-01 08:35:21 +04:00
|
|
|
#define ufs_dblksize(u,d,b) \
|
2003-04-02 14:39:19 +04:00
|
|
|
((((b) >= NDADDR || DIP((d), size) >= ((b)+1) << (u)->ufs_bshift \
|
1999-10-01 08:35:21 +04:00
|
|
|
? (u)->ufs_bsize \
|
2003-04-02 14:39:19 +04:00
|
|
|
: (ufs_fragroundup((u), ufs_blkoff(u, DIP((d), size)))))))
|
1999-10-01 08:35:21 +04:00
|
|
|
struct ufsi *ufsib;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Dump maps used to describe what is to be dumped.
|
|
|
|
*/
|
|
|
|
int mapsize; /* size of the state maps */
|
|
|
|
char *usedinomap; /* map of allocated inodes */
|
|
|
|
char *dumpdirmap; /* map of directories to be dumped */
|
|
|
|
char *dumpinomap; /* map of files to be dumped */
|
|
|
|
/*
|
|
|
|
* Map manipulation macros.
|
|
|
|
*/
|
|
|
|
#define SETINO(ino, map) \
|
|
|
|
map[(u_int)((ino) - 1) / NBBY] |= 1 << ((u_int)((ino) - 1) % NBBY)
|
|
|
|
#define CLRINO(ino, map) \
|
|
|
|
map[(u_int)((ino) - 1) / NBBY] &= ~(1 << ((u_int)((ino) - 1) % NBBY))
|
|
|
|
#define TSTINO(ino, map) \
|
|
|
|
(map[(u_int)((ino) - 1) / NBBY] & (1 << ((u_int)((ino) - 1) % NBBY)))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All calculations done in 0.1" units!
|
|
|
|
*/
|
|
|
|
char *disk; /* name of the disk file */
|
2006-10-27 00:02:30 +04:00
|
|
|
char *disk_dev; /* name of the raw device we are dumping */
|
2005-06-27 05:37:32 +04:00
|
|
|
const char *tape; /* name of the tape file */
|
|
|
|
const char *dumpdates; /* name of the file containing dump date information*/
|
|
|
|
const char *temp; /* name of the file for doing rewrite of dumpdates */
|
1993-03-21 12:45:37 +03:00
|
|
|
char lastlevel; /* dump level of previous dump */
|
|
|
|
char level; /* dump level of this dump */
|
|
|
|
int uflag; /* update flag */
|
2001-05-08 01:17:48 +04:00
|
|
|
int eflag; /* eject flag */
|
2001-12-14 17:43:33 +03:00
|
|
|
int lflag; /* autoload flag */
|
1993-03-21 12:45:37 +03:00
|
|
|
int diskfd; /* disk file descriptor */
|
|
|
|
int tapefd; /* tape file descriptor */
|
|
|
|
int pipeout; /* true => output to standard output */
|
2010-02-26 05:11:40 +03:00
|
|
|
int trueinc; /* true => "true incremental", i.e use last 9 as ref */
|
1993-03-21 12:45:37 +03:00
|
|
|
ino_t curino; /* current inumber; used globally */
|
|
|
|
int newtape; /* new tape flag */
|
2003-04-02 14:39:19 +04:00
|
|
|
u_int64_t tapesize; /* estimated tape size, blocks */
|
1993-03-21 12:45:37 +03:00
|
|
|
long tsize; /* tape size in 0.1" units */
|
|
|
|
long asize; /* number of 0.1" units written on current tape */
|
|
|
|
int etapes; /* estimated number of tapes */
|
1994-06-08 22:57:30 +04:00
|
|
|
int nonodump; /* if set, do not honor UF_NODUMP user flags */
|
2001-12-30 07:03:16 +03:00
|
|
|
int unlimited; /* if set, write to end of medium */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2001-02-05 00:33:19 +03:00
|
|
|
extern int density; /* density in 0.1" units */
|
|
|
|
extern int notify; /* notify operator flag */
|
2001-12-22 11:05:24 +03:00
|
|
|
extern int timestamp; /* timestamp messages */
|
2001-02-05 00:33:19 +03:00
|
|
|
extern int blockswritten; /* number of blocks written on current tape */
|
|
|
|
extern int tapeno; /* current tape number */
|
2003-04-02 14:39:19 +04:00
|
|
|
extern int is_ufs2;
|
2001-02-05 00:33:19 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
time_t tstart_writing; /* when started writing the first tape block */
|
2004-03-15 04:06:06 +03:00
|
|
|
time_t tstart_volume; /* when started writing the current volume */
|
1997-04-10 09:36:23 +04:00
|
|
|
int xferrate; /* averaged transfer rate of all volumes */
|
1999-10-01 08:35:21 +04:00
|
|
|
char sblock_buf[MAXBSIZE]; /* buffer to hold the superblock */
|
2000-12-14 01:44:44 +03:00
|
|
|
extern long dev_bsize; /* block size of underlying disk device */
|
1993-03-21 12:45:37 +03:00
|
|
|
int dev_bshift; /* log2(dev_bsize) */
|
|
|
|
int tp_bshift; /* log2(TP_BSIZE) */
|
1998-03-18 19:54:56 +03:00
|
|
|
int needswap; /* file system in swapped byte order */
|
2004-03-15 04:06:06 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* some inline functions to help the byte-swapping mess */
|
2005-12-24 23:45:08 +03:00
|
|
|
static inline u_int16_t iswap16(u_int16_t);
|
|
|
|
static inline u_int32_t iswap32(u_int32_t);
|
|
|
|
static inline u_int64_t iswap64(u_int64_t);
|
2001-05-27 18:17:56 +04:00
|
|
|
|
2005-12-24 23:45:08 +03:00
|
|
|
static inline u_int16_t iswap16(u_int16_t x)
|
2001-05-27 18:17:56 +04:00
|
|
|
{
|
1998-03-18 19:54:56 +03:00
|
|
|
if (needswap)
|
|
|
|
return bswap16(x);
|
2001-05-27 18:17:56 +04:00
|
|
|
else
|
|
|
|
return x;
|
1998-03-18 19:54:56 +03:00
|
|
|
}
|
|
|
|
|
2005-12-24 23:45:08 +03:00
|
|
|
static inline u_int32_t iswap32(u_int32_t x)
|
1998-03-18 19:54:56 +03:00
|
|
|
{
|
|
|
|
if (needswap)
|
|
|
|
return bswap32(x);
|
2001-05-27 18:17:56 +04:00
|
|
|
else
|
|
|
|
return x;
|
1998-03-18 19:54:56 +03:00
|
|
|
}
|
|
|
|
|
2005-12-24 23:45:08 +03:00
|
|
|
static inline u_int64_t iswap64(u_int64_t x)
|
1998-03-18 19:54:56 +03:00
|
|
|
{
|
|
|
|
if (needswap)
|
|
|
|
return bswap64(x);
|
2001-05-27 18:17:56 +04:00
|
|
|
else
|
|
|
|
return x;
|
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
|
1999-10-01 08:35:21 +04:00
|
|
|
/* filestore-specific hooks */
|
2001-05-27 18:17:56 +04:00
|
|
|
int fs_read_sblock(char *);
|
|
|
|
struct ufsi *fs_parametrize(void);
|
|
|
|
ino_t fs_maxino(void);
|
2003-04-02 14:39:19 +04:00
|
|
|
void fs_mapinodes(ino_t, u_int64_t *, int *);
|
1999-10-01 08:35:21 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/* operator interface functions */
|
2005-06-27 05:37:32 +04:00
|
|
|
void broadcast(const char *);
|
2001-05-27 18:17:56 +04:00
|
|
|
void lastdump(char);
|
|
|
|
void msg(const char *fmt, ...) __attribute__((__format__(__printf__,1,2)));
|
|
|
|
void msgtail(const char *fmt, ...) __attribute__((__format__(__printf__,1,2)));
|
2005-06-27 05:37:32 +04:00
|
|
|
int query(const char *);
|
2001-05-27 18:17:56 +04:00
|
|
|
void quit(const char *fmt, ...) __attribute__((__format__(__printf__,1,2)));
|
|
|
|
time_t do_stats(void);
|
|
|
|
void statussig(int);
|
|
|
|
void timeest(void);
|
|
|
|
time_t unctime(char *);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-04-10 09:36:23 +04:00
|
|
|
/* mapping routines */
|
2003-04-02 14:39:19 +04:00
|
|
|
union dinode;
|
|
|
|
int64_t blockest(union dinode *);
|
|
|
|
void mapfileino(ino_t, u_int64_t *, int *);
|
|
|
|
int mapfiles(ino_t, u_int64_t *, char *, char * const *);
|
|
|
|
int mapdirs(ino_t, u_int64_t *);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/* file dumping routines */
|
2003-04-02 14:39:19 +04:00
|
|
|
void blksout32(int32_t *, int, ino_t);
|
|
|
|
void blksout64(int64_t *, int, ino_t);
|
|
|
|
void dumpino(union dinode *, ino_t);
|
2008-02-16 20:58:01 +03:00
|
|
|
#ifndef RRESTORE
|
2001-05-27 18:17:56 +04:00
|
|
|
void dumpmap(char *, int, ino_t);
|
2008-02-16 20:58:01 +03:00
|
|
|
#endif
|
2001-05-27 18:17:56 +04:00
|
|
|
void writeheader(ino_t);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1999-03-23 17:22:59 +03:00
|
|
|
/* data block caching */
|
2001-05-27 18:17:56 +04:00
|
|
|
void bread(daddr_t, char *, int);
|
|
|
|
void rawread(daddr_t, char *, int);
|
|
|
|
void initcache(int, int);
|
|
|
|
void printcachestats(void);
|
1999-03-23 17:22:59 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/* tape writing routines */
|
2001-05-27 18:17:56 +04:00
|
|
|
int alloctape(void);
|
|
|
|
void close_rewind(void);
|
|
|
|
void dumpblock(daddr_t, int);
|
|
|
|
void startnewtape(int);
|
|
|
|
void trewind(int);
|
|
|
|
void writerec(char *, int);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2001-05-27 18:17:56 +04:00
|
|
|
void Exit(int);
|
|
|
|
void dumpabort(int);
|
|
|
|
void getfstab(void);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2001-05-27 18:17:56 +04:00
|
|
|
char *rawname(char *);
|
2003-04-02 14:39:19 +04:00
|
|
|
union dinode *getino(ino_t);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2001-05-28 05:09:54 +04:00
|
|
|
void *xcalloc(size_t, size_t);
|
|
|
|
void *xmalloc(size_t);
|
|
|
|
char *xstrdup(const char *);
|
|
|
|
|
2006-06-24 09:28:54 +04:00
|
|
|
/* LFS snapshot hooks */
|
|
|
|
#ifdef DUMP_LFS
|
|
|
|
int lfs_wrap_stop(char *);
|
|
|
|
void lfs_wrap_go(void);
|
|
|
|
#endif
|
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
/* rdump routines */
|
2001-02-05 00:37:29 +03:00
|
|
|
#if defined(RDUMP) || defined(RRESTORE)
|
2001-05-27 18:17:56 +04:00
|
|
|
void rmtclose(void);
|
2005-06-27 05:37:32 +04:00
|
|
|
int rmthost(const char *);
|
|
|
|
int rmtopen(const char *, int, int);
|
|
|
|
int rmtwrite(const char *, int);
|
2001-12-14 17:43:33 +03:00
|
|
|
int rmtioctl(int, int);
|
2001-02-05 00:37:29 +03:00
|
|
|
#endif /* RDUMP || RRESTORE */
|
1994-06-08 22:57:30 +04:00
|
|
|
|
2001-05-27 18:17:56 +04:00
|
|
|
void interrupt(int); /* in case operator bangs on console */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Exit status codes
|
|
|
|
*/
|
|
|
|
#define X_FINOK 0 /* normal exit */
|
2001-12-25 15:06:26 +03:00
|
|
|
#define X_STARTUP 1 /* startup error */
|
1993-03-21 12:45:37 +03:00
|
|
|
#define X_REWRITE 2 /* restart writing from the check point */
|
1993-12-22 13:19:31 +03:00
|
|
|
#define X_ABORT 3 /* abort dump; don't attempt checkpointing */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#define OPGRENT "operator" /* group entry to notify */
|
|
|
|
#define DIALUP "ttyd" /* prefix for dialups */
|
|
|
|
|
2001-05-28 05:09:54 +04:00
|
|
|
struct fstab *fstabsearch(const char *); /* search fs_file and fs_spec */
|
2004-04-21 05:05:31 +04:00
|
|
|
struct statvfs *mntinfosearch(const char *key);
|
1993-12-22 13:19:31 +03:00
|
|
|
|
|
|
|
#ifndef NAME_MAX
|
|
|
|
#define NAME_MAX 255
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The contents of the file _PATH_DUMPDATES is maintained both on
|
|
|
|
* a linked list, and then (eventually) arrayified.
|
|
|
|
*/
|
|
|
|
struct dumpdates {
|
1993-12-22 13:19:31 +03:00
|
|
|
char dd_name[NAME_MAX+3];
|
1993-03-21 12:45:37 +03:00
|
|
|
char dd_level;
|
|
|
|
time_t dd_ddate;
|
|
|
|
};
|
2001-02-05 00:33:19 +03:00
|
|
|
|
|
|
|
extern int nddates; /* number of records (might be zero) */
|
|
|
|
extern struct dumpdates **ddatev; /* the arrayfied version */
|
|
|
|
|
2001-05-27 18:17:56 +04:00
|
|
|
void initdumptimes(void);
|
|
|
|
void getdumptime(void);
|
|
|
|
void putdumptime(void);
|
1993-03-21 12:45:37 +03:00
|
|
|
#define ITITERATE(i, ddp) \
|
2001-12-25 15:06:26 +03:00
|
|
|
if (ddatev != NULL) \
|
|
|
|
for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2001-05-27 18:17:56 +04:00
|
|
|
void sig(int signo);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
#ifndef _PATH_FSTAB
|
|
|
|
#define _PATH_FSTAB "/etc/fstab"
|
|
|
|
#endif
|