Add getfstab(3) and setfstab(3).
[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  * $DragonFly: src/sbin/dump/dump.h,v 1.12 2006/04/03 01:58:48 dillon Exp $
37  */
38
39 #include <sys/param.h>
40
41 #define MAXINOPB        (MAXBSIZE / sizeof(struct ufs1_dinode))
42 #define MAXNINDIR       (MAXBSIZE / sizeof(daddr_t))
43
44 /*
45  * Dump maps used to describe what is to be dumped.
46  */
47 int     mapsize;        /* size of the state maps */
48 char    *usedinomap;    /* map of allocated inodes */
49 char    *dumpdirmap;    /* map of directories to be dumped */
50 char    *dumpinomap;    /* map of files to be dumped */
51 /*
52  * Map manipulation macros.
53  */
54 #define SETINO(ino, map) \
55         map[(u_int)((ino) - 1) / NBBY] |=  1 << ((u_int)((ino) - 1) % NBBY)
56 #define CLRINO(ino, map) \
57         map[(u_int)((ino) - 1) / NBBY] &=  ~(1 << ((u_int)((ino) - 1) % NBBY))
58 #define TSTINO(ino, map) \
59         (map[(u_int)((ino) - 1) / NBBY] &  (1 << ((u_int)((ino) - 1) % NBBY)))
60
61 /*
62  *      All calculations done in 0.1" units!
63  */
64 char    *disk;          /* name of the disk file */
65 const char      *tape;          /* name of the tape file */
66 extern const char *dumpdates;   /* name of the file containing dump date information*/
67 extern const char *temp;                /* name of the file for doing rewrite of dumpdates */
68 char    lastlevel;      /* dump level of previous dump */
69 char    level;          /* dump level of this dump */
70 int     uflag;          /* update flag */
71 int     diskfd;         /* disk file descriptor */
72 int     tapefd;         /* tape file descriptor */
73 int     pipeout;        /* true => output to standard output */
74 ufs1_ino_t curino;      /* current inumber; used globally */
75 int     newtape;        /* new tape flag */
76 long    tapesize;       /* estimated tape size, blocks */
77 long    tsize;          /* tape size in 0.1" units */
78 long    asize;          /* number of 0.1" units written on current tape */
79 int     etapes;         /* estimated number of tapes */
80 int     nonodump;       /* if set, do not honor UF_NODUMP user flags */
81 int     unlimited;      /* if set, write to end of medium */
82
83 extern int      cachesize;      /* size of block cache */
84 extern int      density;        /* density in 0.1" units */
85 extern int      dokerberos;
86 extern int      ntrec;          /* blocking factor on tape */
87 extern int      cartridge;
88 extern const char *host;
89 extern long     blocksperfile;  /* number of blocks per output file */
90 extern int      notify;         /* notify operator flag */
91 extern int      blockswritten;  /* number of blocks written on current tape */
92 extern long     dev_bsize;      /* block size of underlying disk device */
93
94 time_t  tstart_writing; /* when started writing the first tape block */
95 time_t  tend_writing;   /* after writing the last tape block */
96 int     passno;         /* current dump pass number */
97 struct  fs *sblock;     /* the file system super block */
98 char    sblock_buf[MAXBSIZE];
99 int     dev_bshift;     /* log2(dev_bsize) */
100 int     tp_bshift;      /* log2(TP_BSIZE) */
101
102 /* operator interface functions */
103 void    broadcast(const char *);
104 void    infosch(int);
105 void    lastdump(int);          /* int should be char */
106 void    msg(const char *, ...) __printflike(1, 2);
107 void    msgtail(const char *, ...) __printflike(1, 2);
108 int     query(const char *);
109 void    quit(const char *, ...) __printflike(1, 2);
110 void    timeest(void);
111 time_t  unctime(const char *);
112
113 /* mapping rouintes */
114 struct  ufs1_dinode;
115 long    blockest(struct ufs1_dinode *);
116 int     mapfiles(ufs1_ino_t maxino, long *);
117 int     mapdirs(ufs1_ino_t maxino, long *);
118
119 /* file dumping routines */
120 void    blksout(daddr_t *, int, ufs1_ino_t);
121 void    bread(daddr_t, char *, int);
122 ssize_t cread(int, void *, size_t, off_t);
123 void    dumpino(struct ufs1_dinode *, ufs1_ino_t);
124 void    dumpmap(const char *, int, ufs1_ino_t);
125 void    writeheader(ufs1_ino_t);
126
127 /* tape writing routines */
128 int     alloctape(void);
129 void    close_rewind(void);
130 void    dumpblock(daddr_t, int);
131 void    startnewtape(int);
132 void    trewind(void);
133 void    writerec(const void *, int);
134
135 void    Exit(int) __dead2;
136 void    dumpabort(int);
137 void    dump_getfstab(void);
138
139 char    *rawname(char *);
140 struct  ufs1_dinode *getino(ufs1_ino_t);
141
142 /* rdump routines */
143 #if defined(RDUMP) || defined(RRESTORE)
144 void    rmtclose(void);
145 int     rmthost(const char *);
146 int     rmtopen(const char *, int);
147 int     rmtwrite(const void *, int);
148 #endif /* RDUMP || RRESTORE */
149
150 /* rrestore routines */
151 #ifdef RRESTORE
152 int     rmtread(char *, int);
153 int     rmtseek(int, int);
154 int     rmtioctl(int, int);
155 #endif /* RRESTORE */
156
157 void    interrupt(int);         /* in case operator bangs on console */
158
159 /*
160  *      Exit status codes
161  */
162 #define X_FINOK         0       /* normal exit */
163 #define X_STARTUP       1       /* startup error */
164 #define X_REWRITE       2       /* restart writing from the check point */
165 #define X_ABORT         3       /* abort dump; don't attempt checkpointing */
166
167 #define OPGRENT "operator"              /* group entry to notify */
168
169 struct  fstab *fstabsearch(const char *);       /* search fs_file and fs_spec */
170
171 #ifndef NAME_MAX
172 #define NAME_MAX 255
173 #endif
174
175 /*
176  *      The contents of the file _PATH_DUMPDATES is maintained both on
177  *      a linked list, and then (eventually) arrayified.
178  */
179 struct dumpdates {
180         char    dd_name[NAME_MAX+3];
181         char    dd_level;
182         time_t  dd_ddate;
183 };
184 extern int      nddates;                /* number of records (might be zero) */
185 extern struct   dumpdates **ddatev;     /* the arrayfied version */
186 void    initdumptimes(void);
187 void    getdumptime(void);
188 void    putdumptime(void);
189 #define ITITERATE(i, ddp)       \
190         if (ddatev != NULL)     \
191                 for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
192
193 void    sig(int);
194
195 /*
196  * Compatibility with old systems.
197  */
198 #ifdef COMPAT
199 #include <sys/file.h>
200 #define strchr(a,b)     index(a,b)
201 #define strrchr(a,b)    rindex(a,b)
202 extern char *strdup(), *ctime();
203 extern int read(), write();
204 extern int errno;
205 #endif
206
207 #ifndef _PATH_UTMP
208 #define _PATH_UTMP      "/etc/utmp"
209 #endif
210 #ifndef _PATH_FSTAB
211 #define _PATH_FSTAB     "/etc/fstab"
212 #endif
213
214 #ifdef sunos
215 extern char *calloc();
216 extern char *malloc();
217 extern long atol();
218 extern char *strcpy();
219 extern char *strncpy();
220 extern char *strcat();
221 extern time_t time();
222 extern void endgrent();
223 extern void exit();
224 extern off_t lseek();
225 extern const char *strerror();
226 #endif