Merge branch 'vendor/ELFTOOLCHAIN'
[dragonfly.git] / sbin / dump / dump.h
1 /*-
2  * Copyright (c) 1980, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by the University of
16  *      California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *      @(#)dump.h      8.2 (Berkeley) 4/28/95
34  *
35  * $FreeBSD: src/sbin/dump/dump.h,v 1.7.6.4 2003/01/25 18:54:59 dillon Exp $
36  */
37
38 #include <sys/param.h>
39
40 #define MAXINOPB        (MAXBSIZE / sizeof(struct ufs1_dinode))
41 #define MAXNINDIR       (MAXBSIZE / sizeof(daddr_t))
42
43 /*
44  * Dump maps used to describe what is to be dumped.
45  */
46 int     mapsize;        /* size of the state maps */
47 char    *usedinomap;    /* map of allocated inodes */
48 char    *dumpdirmap;    /* map of directories to be dumped */
49 char    *dumpinomap;    /* map of files to be dumped */
50 /*
51  * Map manipulation macros.
52  */
53 #define SETINO(ino, map) \
54         map[(u_int)((ino) - 1) / NBBY] |=  1 << ((u_int)((ino) - 1) % NBBY)
55 #define CLRINO(ino, map) \
56         map[(u_int)((ino) - 1) / NBBY] &=  ~(1 << ((u_int)((ino) - 1) % NBBY))
57 #define TSTINO(ino, map) \
58         (map[(u_int)((ino) - 1) / NBBY] &  (1 << ((u_int)((ino) - 1) % NBBY)))
59
60 /*
61  *      All calculations done in 0.1" units!
62  */
63 char    *disk;          /* name of the disk file */
64 const char      *tape;          /* name of the tape file */
65 extern const char *dumpdates;   /* name of the file containing dump date information*/
66 extern const char *temp;                /* name of the file for doing rewrite of dumpdates */
67 char    lastlevel;      /* dump level of previous dump */
68 char    level;          /* dump level of this dump */
69 int     uflag;          /* update flag */
70 int     diskfd;         /* disk file descriptor */
71 int     tapefd;         /* tape file descriptor */
72 int     pipeout;        /* true => output to standard output */
73 ufs1_ino_t curino;      /* current inumber; used globally */
74 int     newtape;        /* new tape flag */
75 long    tapesize;       /* estimated tape size, blocks */
76 long    tsize;          /* tape size in 0.1" units */
77 long    asize;          /* number of 0.1" units written on current tape */
78 int     etapes;         /* estimated number of tapes */
79 int     nonodump;       /* if set, do not honor UF_NODUMP user flags */
80 int     unlimited;      /* if set, write to end of medium */
81
82 extern int      cachesize;      /* size of block cache */
83 extern int      density;        /* density in 0.1" units */
84 extern int      dokerberos;
85 extern int      ntrec;          /* blocking factor on tape */
86 extern int      cartridge;
87 extern const char *host;
88 extern long     blocksperfile;  /* number of blocks per output file */
89 extern int      notify;         /* notify operator flag */
90 extern int      blockswritten;  /* number of blocks written on current tape */
91 extern long     dev_bsize;      /* block size of underlying disk device */
92
93 time_t  tstart_writing; /* when started writing the first tape block */
94 time_t  tend_writing;   /* after writing the last tape block */
95 int     passno;         /* current dump pass number */
96 struct  fs *sblock;     /* the file system super block */
97 char    sblock_buf[MAXBSIZE];
98 int     dev_bshift;     /* log2(dev_bsize) */
99 int     tp_bshift;      /* log2(TP_BSIZE) */
100
101 /* operator interface functions */
102 void    broadcast(const char *);
103 void    infosch(int);
104 void    lastdump(int);          /* int should be char */
105 void    msg(const char *, ...) __printflike(1, 2);
106 void    msgtail(const char *, ...) __printflike(1, 2);
107 int     query(const char *);
108 void    quit(const char *, ...) __printflike(1, 2);
109 void    timeest(void);
110 time_t  unctime(const char *);
111
112 /* mapping rouintes */
113 struct  ufs1_dinode;
114 long    blockest(struct ufs1_dinode *);
115 int     mapfiles(ufs1_ino_t maxino, long *);
116 int     mapdirs(ufs1_ino_t maxino, long *);
117
118 /* file dumping routines */
119 void    blksout(daddr_t *, int, ufs1_ino_t);
120 void    bread(daddr_t, char *, int);
121 ssize_t cread(int, void *, size_t, off_t);
122 void    dumpino(struct ufs1_dinode *, ufs1_ino_t);
123 void    dumpmap(const char *, int, ufs1_ino_t);
124 void    writeheader(ufs1_ino_t);
125
126 /* tape writing routines */
127 int     alloctape(void);
128 void    close_rewind(void);
129 void    dumpblock(daddr_t, int);
130 void    startnewtape(int);
131 void    trewind(void);
132 void    writerec(const void *, int);
133
134 void    Exit(int) __dead2;
135 void    dumpabort(int);
136 void    dump_getfstab(void);
137
138 char    *rawname(char *);
139 struct  ufs1_dinode *getino(ufs1_ino_t);
140
141 /* rdump routines */
142 #if defined(RDUMP) || defined(RRESTORE)
143 void    rmtclose(void);
144 int     rmthost(const char *);
145 int     rmtopen(const char *, int);
146 int     rmtwrite(const void *, int);
147 #endif /* RDUMP || RRESTORE */
148
149 /* rrestore routines */
150 #ifdef RRESTORE
151 int     rmtread(char *, int);
152 int     rmtseek(int, int);
153 int     rmtioctl(int, int);
154 #endif /* RRESTORE */
155
156 void    interrupt(int);         /* in case operator bangs on console */
157
158 /*
159  *      Exit status codes
160  */
161 #define X_FINOK         0       /* normal exit */
162 #define X_STARTUP       1       /* startup error */
163 #define X_REWRITE       2       /* restart writing from the check point */
164 #define X_ABORT         3       /* abort dump; don't attempt checkpointing */
165
166 #define OPGRENT "operator"              /* group entry to notify */
167
168 struct  fstab *fstabsearch(const char *);       /* search fs_file and fs_spec */
169
170 #ifndef NAME_MAX
171 #define NAME_MAX 255
172 #endif
173
174 /*
175  *      The contents of the file _PATH_DUMPDATES is maintained both on
176  *      a linked list, and then (eventually) arrayified.
177  */
178 struct dumpdates {
179         char    dd_name[NAME_MAX+3];
180         char    dd_level;
181         time_t  dd_ddate;
182 };
183 extern int      nddates;                /* number of records (might be zero) */
184 extern struct   dumpdates **ddatev;     /* the arrayfied version */
185 void    initdumptimes(void);
186 void    getdumptime(void);
187 void    putdumptime(void);
188 #define ITITERATE(i, ddp)       \
189         if (ddatev != NULL)     \
190                 for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
191
192 void    sig(int);
193
194 #ifndef _PATH_UTMP
195 #define _PATH_UTMP      "/etc/utmp"
196 #endif
197 #ifndef _PATH_FSTAB
198 #define _PATH_FSTAB     "/etc/fstab"
199 #endif