14 #include <sys/param.h>
18 #include <linux/types.h>
21 #include <bsdcompat.h>
22 #include <linux/fs.h> /* for definition of BLKFLSBUF */
24 #include <sys/vnode.h>
26 #include <ufs/inode.h>
29 #include <ufs/ufs/dinode.h>
30 #include <ufs/ffs/fs.h>
33 #include <protocols/dumprestore.h>
39 extern dump_ino_t volinfo[]; // TP_NINOS
42 static int Afile = -1; /* archive file descriptor */
43 static int AfileActive = 1;/* Afile flag */
49 static int GetTapePos __P((long long *));
50 static int MkTapeString __P((struct s_spcl *, long long));
51 #define FILESQFAPOS 20
54 int ntrec; /* blocking factor on tape */
55 int magtapeout; /* is output a magnetic tape? */
57 //extern int ntrec; /* blocking factor on tape */
58 //extern int magtapeout; /* is output a magnetic tape? */
60 static int gtperr = 0;
61 static int gTapeposfd;
62 static char *gTapeposfile;
63 static char gTps[255];
64 static int32_t gThisDumpDate;
67 void msg __P((const char *fmt, ...));
68 void quit __P((const char *fmt, ...));
74 * Open the indexer file.
77 legacy_open(const char *filename, int mode)
79 if (filename == NULL) {
84 if ((Afile = OPEN(filename, O_RDONLY)) < 0) {
85 msg("Cannot open %s for reading: %s\n",
86 filename, strerror(errno));
87 msg("The ENTIRE dump is aborted.\n");
90 } else if (mode == 1) {
91 if ((Afile = OPEN(filename, O_WRONLY|O_CREAT|O_TRUNC,
92 S_IRUSR | S_IWUSR | S_IRGRP |
93 S_IWGRP | S_IROTH | S_IWOTH)) < 0) {
94 msg("Cannot open %s for writing: %s\n",
95 filename, strerror(errno));
96 msg("The ENTIRE dump is aborted.\n");
105 * Close the indexer file.
111 msg("Archiving dump to %s\n", Apath);
116 * Write a record to the indexer file.
119 legacy_writerec(const void *dp, int isspcl)
121 if (! AfileActive && isspcl && (spcl.c_type == TS_END))
123 if (AfileActive && Afile >= 0 && !(spcl.c_flags & DR_EXTATTRIBUTES)) {
124 /* When we dump an inode which is not a directory,
125 * it means we ended the archive contents */
126 if (isspcl && (spcl.c_type == TS_INODE) &&
127 ((spcl.c_dinode.di_mode & S_IFMT) != IFDIR))
131 tmp = *(union u_spcl *)dp;
132 /* Write the record, _uncompressed_ */
134 tmp.s_spcl.c_flags &= ~DR_COMPRESSED;
137 if (write(Afile, &tmp, TP_BSIZE) != TP_BSIZE)
138 msg("error writing archive file: %s\n",
146 * I'm not sure what this is used for...
152 volinfo[1] = ROOTINO;
153 memcpy(spcl.c_inos, volinfo, TP_NINOS * sizeof(dump_ino_t));
154 spcl.c_flags |= DR_INODEINFO;
163 legacy_addInode(struct dinode *dp, dump_ino_t ino, int metaonly)
169 * Dump directory (dirent) entry
172 legacy_addDirEntry(struct direct *dp, dump_ino_t parent_ino)
178 #define LSEEK_GET_TAPEPOS 10
179 #define LSEEK_GO2_TAPEPOS 11
188 gThisDumpDate = spcl.c_date;
190 msg("writing QFA positions to %s\n", gTapeposfile);
191 if ((gTapeposfd = open(gTapeposfile,
192 O_WRONLY|O_CREAT|O_TRUNC,
193 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP
194 | S_IROTH | S_IWOTH)) < 0)
195 quit("can't open tapeposfile\n");
196 /* print QFA-file header */
197 snprintf(gTps, sizeof(gTps), "%s\n%s\n%ld\n\n", QFA_MAGIC, QFA_VERSION, (unsigned long)spcl.c_date);
198 gTps[sizeof(gTps) - 1] = '\0';
199 if (write(gTapeposfd, gTps, strlen(gTps)) != (ssize_t)strlen(gTps))
200 quit("can't write tapeposfile\n");
201 sprintf(gTps, "ino\ttapeno\ttapepos\n");
202 if (write(gTapeposfd, gTps, strlen(gTps)) != (ssize_t)strlen(gTps))
203 quit("can't write tapeposfile\n");
222 legacy_openQfaState(QFA_State *s)
225 s->maxntrecs = 50000; /* every 50MB */
226 s->cntntrecs = s->maxntrecs;
234 legacy_updateQfaState(QFA_State *s)
236 if (gTapeposfd >= 0) {
237 s->cntntrecs += ntrec;
248 legacy_updateQfa(QFA_State *s)
251 union u_spcl *uspclptr;
252 struct s_spcl *spclptr;
254 if (gTapeposfd >= 0) {
258 for (i = 0; (i < ntrec) && !foundone; ++i) {
259 uspclptr = (union u_spcl *)&slp->tblock[i];
260 spclptr = &uspclptr->s_spcl;
261 if ((spclptr->c_magic == NFS_MAGIC) &&
262 (spclptr->c_type == TS_INODE) &&
263 (spclptr->c_date == gThisDumpDate) &&
264 !(spclptr->c_dinode.di_mode & S_IFDIR) &&
265 !(spclptr->c_flags & DR_EXTATTRIBUTES)
268 /* if (s->cntntrecs >= s->maxntrecs) { only write every maxntrecs amount of data */
271 gtperr = GetTapePos(&s->curtapepos);
272 /* if an error occured previously don't
276 msg("inode %ld at tapepos %ld\n", spclptr->c_inumber, s->curtapepos);
278 gtperr = MkTapeString(spclptr, s->curtapepos);
290 * read the current tape position
293 GetTapePos(long long *pos)
299 *pos = (long long) rmtseek((OFF_T)0, (int)LSEEK_GET_TAPEPOS);
308 err = (ioctl(tapefd, MTIOCPOS, &mtpos) < 0);
309 *pos = (long long)mtpos;
312 *pos = LSEEK(tapefd, 0, SEEK_CUR);
318 msg("[%ld] error: %d (getting tapepos: %lld)\n", getpid(),
326 MkTapeString(struct s_spcl *spclptr, long long curtapepos)
331 msg("inode %ld at tapepos %lld\n", spclptr->c_inumber, curtapepos);
334 snprintf(gTps, sizeof(gTps), "%ld\t%d\t%lld\n",
335 (unsigned long)spclptr->c_inumber,
338 gTps[sizeof(gTps) - 1] = '\0';
339 if (write(gTapeposfd, gTps, strlen(gTps)) != (ssize_t)strlen(gTps)) {
341 warn("error writing tapepos file. (error %d)\n", errno);
347 Indexer indexer_legacy = {
358 &legacy_updateQfaState