]> git.wh0rd.org - dump.git/blob - restore/dirs.c
cybercable -> noos.
[dump.git] / restore / dirs.c
1 /*
2 * Ported to Linux's Second Extended File System as part of the
3 * dump and restore backup suit
4 * Remy Card <card@Linux.EU.Org>, 1994-1997
5 * Stelian Pop <pop@noos.fr>, 1999-2000
6 * Stelian Pop <pop@noos.fr> - AlcĂ´ve <www.alcove.fr>, 2000
7 */
8
9 /*
10 * Copyright (c) 1983, 1993
11 * The Regents of the University of California. All rights reserved.
12 * (c) UNIX System Laboratories, Inc.
13 * All or some portions of this file are derived from material licensed
14 * to the University of California by American Telephone and Telegraph
15 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
16 * the permission of UNIX System Laboratories, Inc.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
26 * 3. All advertising materials mentioning features or use of this software
27 * must display the following acknowledgement:
28 * This product includes software developed by the University of
29 * California, Berkeley and its contributors.
30 * 4. Neither the name of the University nor the names of its contributors
31 * may be used to endorse or promote products derived from this software
32 * without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
35 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
38 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 * SUCH DAMAGE.
45 */
46
47 #ifndef lint
48 static const char rcsid[] =
49 "$Id: dirs.c,v 1.11 2000/12/04 15:43:17 stelian Exp $";
50 #endif /* not lint */
51
52 #include <sys/param.h>
53 #include <sys/file.h>
54 #include <sys/stat.h>
55
56 #ifdef __linux__
57 #include <linux/ext2_fs.h>
58 #include <bsdcompat.h>
59 #else /* __linux__ */
60 #include <ufs/ufs/dinode.h>
61 #include <ufs/ufs/dir.h>
62 #endif /* __linux__ */
63 #include <protocols/dumprestore.h>
64
65 #include <compaterr.h>
66 #include <errno.h>
67 #include <stdio.h>
68 #include <stdlib.h>
69 #include <string.h>
70 #include <unistd.h>
71
72 #ifdef __linux__
73 #include <endian.h>
74 #else
75 #include <machine/endian.h>
76 #endif
77
78 #include "pathnames.h"
79 #include "restore.h"
80 #include "extern.h"
81
82 /*
83 * Symbol table of directories read from tape.
84 */
85 #define HASHSIZE 1000
86 #define INOHASH(val) (val % HASHSIZE)
87 struct inotab {
88 struct inotab *t_next;
89 ino_t t_ino;
90 int32_t t_seekpt;
91 int32_t t_size;
92 };
93 static struct inotab *inotab[HASHSIZE];
94
95 /*
96 * Information retained about directories.
97 */
98 struct modeinfo {
99 ino_t ino;
100 struct timeval timep[2];
101 mode_t mode;
102 uid_t uid;
103 gid_t gid;
104 unsigned int flags;
105 };
106
107 /*
108 * Definitions for library routines operating on directories.
109 */
110 #undef DIRBLKSIZ
111 #define DIRBLKSIZ 1024
112 struct rstdirdesc {
113 int dd_fd;
114 int32_t dd_loc;
115 int32_t dd_size;
116 char dd_buf[DIRBLKSIZ];
117 };
118
119 /*
120 * Global variables for this file.
121 */
122 static long seekpt;
123 static FILE *df, *mf;
124 static RST_DIR *dirp;
125 static char dirfile[MAXPATHLEN] = "#"; /* No file */
126 static char modefile[MAXPATHLEN] = "#"; /* No file */
127 static char dot[2] = "."; /* So it can be modified */
128
129 /*
130 * Format of old style directories.
131 */
132 #define ODIRSIZ 14
133 struct odirect {
134 u_short d_ino;
135 char d_name[ODIRSIZ];
136 };
137
138 #ifdef __linux__
139 static struct inotab *allocinotab __P((ino_t, struct new_bsd_inode *, long));
140 #else
141 static struct inotab *allocinotab __P((ino_t, struct dinode *, long));
142 #endif
143 static void dcvt __P((struct odirect *, struct direct *));
144 static void flushent __P((void));
145 static struct inotab *inotablookup __P((ino_t));
146 static RST_DIR *opendirfile __P((const char *));
147 static void putdir __P((char *, size_t));
148 static void putent __P((struct direct *));
149 static void rst_seekdir __P((RST_DIR *, long, long));
150 static long rst_telldir __P((RST_DIR *));
151 static struct direct *searchdir __P((ino_t, char *));
152
153 /*
154 * Extract directory contents, building up a directory structure
155 * on disk for extraction by name.
156 * If genmode is requested, save mode, owner, and times for all
157 * directories on the tape.
158 */
159 void
160 extractdirs(int genmode)
161 {
162 register int i;
163 #ifdef __linux__
164 register struct new_bsd_inode *ip;
165 #else
166 register struct dinode *ip;
167 #endif
168 struct inotab *itp;
169 struct direct nulldir;
170 int fd;
171
172 Vprintf(stdout, "Extract directories from tape\n");
173 (void) snprintf(dirfile, sizeof(dirfile), "%s/rstdir%ld", tmpdir,
174 (long)dumpdate);
175 if (command != 'r' && command != 'R') {
176 (void) strncat(dirfile, "-XXXXXX",
177 sizeof(dirfile) - strlen(dirfile));
178 fd = mkstemp(dirfile);
179 } else
180 fd = open(dirfile, O_RDWR|O_CREAT|O_EXCL, 0666);
181 if (fd == -1 || (df = fdopen(fd, "w")) == NULL) {
182 if (fd != -1)
183 close(fd);
184 err(1, "cannot create directory temporary %s", dirfile);
185 }
186 if (genmode != 0) {
187 (void) snprintf(modefile, sizeof(modefile), "%s/rstmode%ld", tmpdir, (long)dumpdate);
188 if (command != 'r' && command != 'R') {
189 (void) strncat(modefile, "-XXXXXX",
190 sizeof(modefile) - strlen(modefile));
191 fd = mkstemp(modefile);
192 } else
193 fd = open(modefile, O_RDWR|O_CREAT|O_EXCL, 0666);
194 if (fd == -1 || (mf = fdopen(fd, "w")) == NULL) {
195 if (fd != -1)
196 close(fd);
197 err(1, "cannot create modefile %s", modefile);
198 }
199 }
200 nulldir.d_ino = 0;
201 nulldir.d_type = DT_DIR;
202 nulldir.d_namlen = 1;
203 nulldir.d_name[0] = '/';
204 nulldir.d_name[1] = '\0';
205 nulldir.d_reclen = DIRSIZ(0, &nulldir);
206 for (;;) {
207 curfile.name = "<directory file - name unknown>";
208 curfile.action = USING;
209 ip = curfile.dip;
210 if (ip == NULL || (ip->di_mode & IFMT) != IFDIR) {
211 (void) fclose(df);
212 dirp = opendirfile(dirfile);
213 if (dirp == NULL)
214 warn("opendirfile");
215 if (mf != NULL)
216 (void) fclose(mf);
217 i = dirlookup(dot);
218 if (i == 0)
219 panic("Root directory is not on tape\n");
220 return;
221 }
222 itp = allocinotab(curfile.ino, ip, seekpt);
223 getfile(putdir, xtrnull);
224 putent(&nulldir);
225 flushent();
226 itp->t_size = seekpt - itp->t_seekpt;
227 }
228 }
229
230 /*
231 * skip over all the directories on the tape
232 */
233 void
234 skipdirs(void)
235 {
236
237 while (curfile.dip && (curfile.dip->di_mode & IFMT) == IFDIR) {
238 skipfile();
239 }
240 }
241
242 /*
243 * Recursively find names and inumbers of all files in subtree
244 * pname and pass them off to be processed.
245 */
246 void
247 treescan(char *pname, ino_t ino, long (*todo) __P((char *, ino_t, int)))
248 {
249 register struct inotab *itp;
250 register struct direct *dp;
251 int namelen;
252 long bpt;
253 char locname[MAXPATHLEN + 1];
254
255 itp = inotablookup(ino);
256 if (itp == NULL) {
257 /*
258 * Pname is name of a simple file or an unchanged directory.
259 */
260 (void) (*todo)(pname, ino, LEAF);
261 return;
262 }
263 /*
264 * Pname is a dumped directory name.
265 */
266 if ((*todo)(pname, ino, NODE) == FAIL)
267 return;
268 /*
269 * begin search through the directory
270 * skipping over "." and ".."
271 */
272 namelen = snprintf(locname, sizeof(locname), "%s/", pname);
273 if (namelen >= sizeof(locname))
274 namelen = sizeof(locname) - 1;
275 rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt);
276 dp = rst_readdir(dirp); /* "." */
277 if (dp != NULL && strcmp(dp->d_name, ".") == 0)
278 dp = rst_readdir(dirp); /* ".." */
279 else
280 fprintf(stderr, "Warning: `.' missing from directory %s\n",
281 pname);
282 if (dp != NULL && strcmp(dp->d_name, "..") == 0)
283 dp = rst_readdir(dirp); /* first real entry */
284 else
285 fprintf(stderr, "Warning: `..' missing from directory %s\n",
286 pname);
287 bpt = rst_telldir(dirp);
288 /*
289 * a zero inode signals end of directory
290 */
291 while (dp != NULL) {
292 locname[namelen] = '\0';
293 if (namelen + dp->d_namlen >= sizeof(locname)) {
294 fprintf(stderr, "%s%s: name exceeds %ld char\n",
295 locname, dp->d_name, (long)sizeof(locname) - 1);
296 } else {
297 (void) strncat(locname, dp->d_name, (int)dp->d_namlen);
298 treescan(locname, dp->d_ino, todo);
299 rst_seekdir(dirp, bpt, itp->t_seekpt);
300 }
301 dp = rst_readdir(dirp);
302 bpt = rst_telldir(dirp);
303 }
304 }
305
306 /*
307 * Lookup a pathname which is always assumed to start from the ROOTINO.
308 */
309 struct direct *
310 pathsearch(const char *pathname)
311 {
312 ino_t ino;
313 struct direct *dp;
314 char *path, *name, buffer[MAXPATHLEN];
315
316 strcpy(buffer, pathname);
317 path = buffer;
318 ino = ROOTINO;
319 while (*path == '/')
320 path++;
321 dp = NULL;
322 while ((name = strsep(&path, "/")) != NULL && *name /* != NULL */) {
323 if ((dp = searchdir(ino, name)) == NULL)
324 return (NULL);
325 ino = dp->d_ino;
326 }
327 return (dp);
328 }
329
330 /*
331 * Lookup the requested name in directory inum.
332 * Return its inode number if found, zero if it does not exist.
333 */
334 static struct direct *
335 searchdir(ino_t inum, char *name)
336 {
337 register struct direct *dp;
338 register struct inotab *itp;
339 int len;
340
341 itp = inotablookup(inum);
342 if (itp == NULL)
343 return (NULL);
344 rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt);
345 len = strlen(name);
346 do {
347 dp = rst_readdir(dirp);
348 if (dp == NULL)
349 return (NULL);
350 } while (dp->d_namlen != len || strncmp(dp->d_name, name, len) != 0);
351 return (dp);
352 }
353
354 /*
355 * Put the directory entries in the directory file
356 */
357 static void
358 putdir(char *buf, size_t size)
359 {
360 struct direct cvtbuf;
361 register struct odirect *odp;
362 struct odirect *eodp;
363 register struct direct *dp;
364 long loc, i;
365
366 if (cvtflag) {
367 eodp = (struct odirect *)&buf[size];
368 for (odp = (struct odirect *)buf; odp < eodp; odp++)
369 if (odp->d_ino != 0) {
370 dcvt(odp, &cvtbuf);
371 putent(&cvtbuf);
372 }
373 } else {
374 for (loc = 0; loc < size; ) {
375 dp = (struct direct *)(buf + loc);
376 #ifdef DIRDEBUG
377 printf ("reclen = %d, namlen = %d, type = %d\n",
378 dp->d_reclen, dp->d_namlen, dp->d_type);
379 #endif
380 if (Bcvt)
381 swabst((u_char *)"is", (u_char *) dp);
382 if (oldinofmt && dp->d_ino != 0) {
383 # if BYTE_ORDER == BIG_ENDIAN
384 if (Bcvt)
385 dp->d_namlen = dp->d_type;
386 # else
387 if (!Bcvt)
388 dp->d_namlen = dp->d_type;
389 # endif
390 dp->d_type = DT_UNKNOWN;
391 }
392 #ifdef DIRDEBUG
393 printf ("reclen = %d, namlen = %d, type = %d\n",
394 dp->d_reclen, dp->d_namlen, dp->d_type);
395 #endif
396 i = DIRBLKSIZ - (loc & (DIRBLKSIZ - 1));
397 if ((dp->d_reclen & 0x3) != 0 ||
398 dp->d_reclen > i ||
399 dp->d_reclen < DIRSIZ(0, dp) ||
400 dp->d_namlen > MAXNAMLEN) {
401 Vprintf(stdout, "Mangled directory: ");
402 if ((dp->d_reclen & 0x3) != 0)
403 Vprintf(stdout,
404 "reclen not multiple of 4 ");
405 if (dp->d_reclen < DIRSIZ(0, dp))
406 Vprintf(stdout,
407 "reclen less than DIRSIZ (%d < %d) ",
408 dp->d_reclen, DIRSIZ(0, dp));
409 if (dp->d_namlen > MAXNAMLEN)
410 Vprintf(stdout,
411 "reclen name too big (%d > %d) ",
412 dp->d_namlen, MAXNAMLEN);
413 Vprintf(stdout, "\n");
414 loc += i;
415 continue;
416 }
417 loc += dp->d_reclen;
418 if (dp->d_ino != 0) {
419 putent(dp);
420 }
421 }
422 }
423 }
424
425 /*
426 * These variables are "local" to the following two functions.
427 */
428 char dirbuf[DIRBLKSIZ];
429 long dirloc = 0;
430 long prev = 0;
431
432 /*
433 * add a new directory entry to a file.
434 */
435 static void
436 putent(struct direct *dp)
437 {
438 dp->d_reclen = DIRSIZ(0, dp);
439 if (dirloc + dp->d_reclen > DIRBLKSIZ) {
440 ((struct direct *)(dirbuf + prev))->d_reclen =
441 DIRBLKSIZ - prev;
442 (void) fwrite(dirbuf, 1, DIRBLKSIZ, df);
443 dirloc = 0;
444 }
445 memmove(dirbuf + dirloc, dp, (size_t)dp->d_reclen);
446 prev = dirloc;
447 dirloc += dp->d_reclen;
448 }
449
450 /*
451 * flush out a directory that is finished.
452 */
453 static void
454 flushent(void)
455 {
456 ((struct direct *)(dirbuf + prev))->d_reclen = DIRBLKSIZ - prev;
457 (void) fwrite(dirbuf, (int)dirloc, 1, df);
458 seekpt = ftell(df);
459 dirloc = 0;
460 }
461
462 static void
463 dcvt(struct odirect *odp, struct direct *ndp)
464 {
465
466 memset(ndp, 0, (size_t)(sizeof *ndp));
467 ndp->d_ino = odp->d_ino;
468 ndp->d_type = DT_UNKNOWN;
469 (void) strncpy(ndp->d_name, odp->d_name, ODIRSIZ);
470 ndp->d_namlen = strlen(ndp->d_name);
471 ndp->d_reclen = DIRSIZ(0, ndp);
472 }
473
474 /*
475 * Seek to an entry in a directory.
476 * Only values returned by rst_telldir should be passed to rst_seekdir.
477 * This routine handles many directories in a single file.
478 * It takes the base of the directory in the file, plus
479 * the desired seek offset into it.
480 */
481 static void
482 rst_seekdir(RST_DIR *dirp, long loc, long base)
483 {
484
485 if (loc == rst_telldir(dirp))
486 return;
487 loc -= base;
488 if (loc < 0)
489 fprintf(stderr, "bad seek pointer to rst_seekdir %ld\n", loc);
490 (void) lseek(dirp->dd_fd, base + (loc & ~(DIRBLKSIZ - 1)), SEEK_SET);
491 dirp->dd_loc = loc & (DIRBLKSIZ - 1);
492 if (dirp->dd_loc != 0)
493 dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ);
494 }
495
496 /*
497 * get next entry in a directory.
498 */
499 struct direct *
500 rst_readdir(RST_DIR *dirp)
501 {
502 register struct direct *dp;
503
504 for (;;) {
505 if (dirp->dd_loc == 0) {
506 dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
507 DIRBLKSIZ);
508 if (dirp->dd_size <= 0) {
509 Dprintf(stderr, "error reading directory\n");
510 return (NULL);
511 }
512 }
513 if (dirp->dd_loc >= dirp->dd_size) {
514 dirp->dd_loc = 0;
515 continue;
516 }
517 dp = (struct direct *)(dirp->dd_buf + dirp->dd_loc);
518 if (dp->d_reclen == 0 ||
519 dp->d_reclen > DIRBLKSIZ + 1 - dirp->dd_loc) {
520 Dprintf(stderr, "corrupted directory: bad reclen %d\n",
521 dp->d_reclen);
522 return (NULL);
523 }
524 dirp->dd_loc += dp->d_reclen;
525 if (dp->d_ino == 0 && strcmp(dp->d_name, "/") == 0)
526 return (NULL);
527 if (dp->d_ino >= maxino) {
528 Dprintf(stderr, "corrupted directory: bad inum %d\n",
529 dp->d_ino);
530 continue;
531 }
532 return (dp);
533 }
534 }
535
536 /*
537 * Simulate the opening of a directory
538 */
539 RST_DIR *
540 rst_opendir(const char *name)
541 {
542 struct inotab *itp;
543 RST_DIR *dirp;
544 ino_t ino;
545
546 if ((ino = dirlookup(name)) > 0 &&
547 (itp = inotablookup(ino)) != NULL) {
548 dirp = opendirfile(dirfile);
549 rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt);
550 return (dirp);
551 }
552 return (NULL);
553 }
554
555 /*
556 * In our case, there is nothing to do when closing a directory.
557 */
558 void
559 rst_closedir(RST_DIR *dirp)
560 {
561
562 (void)close(dirp->dd_fd);
563 free(dirp);
564 return;
565 }
566
567 /*
568 * Simulate finding the current offset in the directory.
569 */
570 static long
571 rst_telldir(RST_DIR *dirp)
572 {
573 return ((long)lseek(dirp->dd_fd,
574 (off_t)0, SEEK_CUR) - dirp->dd_size + dirp->dd_loc);
575 }
576
577 /*
578 * Open a directory file.
579 */
580 static RST_DIR *
581 opendirfile(const char *name)
582 {
583 register RST_DIR *dirp;
584 register int fd;
585
586 if ((fd = open(name, O_RDONLY)) == -1)
587 return (NULL);
588 if ((dirp = malloc(sizeof(RST_DIR))) == NULL) {
589 (void)close(fd);
590 return (NULL);
591 }
592 dirp->dd_fd = fd;
593 dirp->dd_loc = 0;
594 return (dirp);
595 }
596
597 /*
598 * Set the mode, owner, and times for all new or changed directories
599 */
600 void
601 setdirmodes(int flags)
602 {
603 FILE *mf;
604 struct modeinfo node;
605 struct entry *ep;
606 char *cp;
607
608 Vprintf(stdout, "Set directory mode, owner, and times.\n");
609 if (command == 'r' || command == 'R')
610 (void) snprintf(modefile, sizeof(modefile), "%s/rstmode%lu", tmpdir, (long)dumpdate);
611 if (modefile[0] == '#') {
612 panic("modefile not defined\n");
613 fprintf(stderr, "directory mode, owner, and times not set\n");
614 return;
615 }
616 mf = fopen(modefile, "r");
617 if (mf == NULL) {
618 warn("fopen");
619 fprintf(stderr, "cannot open mode file %s\n", modefile);
620 fprintf(stderr, "directory mode, owner, and times not set\n");
621 return;
622 }
623 clearerr(mf);
624 for (;;) {
625 (void) fread((char *)&node, 1, sizeof(struct modeinfo), mf);
626 if (feof(mf))
627 break;
628 ep = lookupino(node.ino);
629 if (command == 'i' || command == 'x') {
630 if (ep == NULL)
631 continue;
632 if ((flags & FORCE) == 0 && ep->e_flags & EXISTED) {
633 ep->e_flags &= ~NEW;
634 continue;
635 }
636 if (node.ino == ROOTINO &&
637 reply("set owner/mode for '.'") == FAIL)
638 continue;
639 }
640 if (ep == NULL) {
641 panic("cannot find directory inode %d\n", node.ino);
642 } else {
643 cp = myname(ep);
644 (void) chown(cp, node.uid, node.gid);
645 (void) chmod(cp, node.mode);
646 if (node.flags)
647 #ifdef __linux__
648 (void) fsetflags(cp, node.flags);
649 #else
650 (void) chflags(cp, node.flags);
651 #endif
652 utimes(cp, node.timep);
653 ep->e_flags &= ~NEW;
654 }
655 }
656 if (ferror(mf))
657 panic("error setting directory modes\n");
658 (void) fclose(mf);
659 }
660
661 /*
662 * Generate a literal copy of a directory.
663 */
664 int
665 genliteraldir(char *name, ino_t ino)
666 {
667 register struct inotab *itp;
668 int ofile, dp, i, size;
669 char buf[BUFSIZ];
670
671 itp = inotablookup(ino);
672 if (itp == NULL)
673 panic("Cannot find directory inode %d named %s\n", ino, name);
674 if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
675 warn("%s: cannot create file\n", name);
676 return (FAIL);
677 }
678 rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt);
679 dp = dup(dirp->dd_fd);
680 for (i = itp->t_size; i > 0; i -= BUFSIZ) {
681 size = i < BUFSIZ ? i : BUFSIZ;
682 if (read(dp, buf, (int) size) == -1) {
683 warnx("write error extracting inode %lu, name %s\n",
684 (unsigned long)curfile.ino, curfile.name);
685 err(1, "read");
686 }
687 if (!Nflag && write(ofile, buf, (int) size) == -1) {
688 warnx("write error extracting inode %lu, name %s\n",
689 (unsigned long)curfile.ino, curfile.name);
690 err(1, "write");
691 }
692 }
693 (void) close(dp);
694 (void) close(ofile);
695 return (GOOD);
696 }
697
698 /*
699 * Determine the type of an inode
700 */
701 int
702 inodetype(ino_t ino)
703 {
704 struct inotab *itp;
705
706 itp = inotablookup(ino);
707 if (itp == NULL)
708 return (LEAF);
709 return (NODE);
710 }
711
712 /*
713 * Allocate and initialize a directory inode entry.
714 * If requested, save its pertinent mode, owner, and time info.
715 */
716 static struct inotab *
717 #ifdef __linux__
718 allocinotab(ino_t ino, struct new_bsd_inode *dip, long seekpt)
719 #else
720 allocinotab(ino_t ino, struct dinode *dip, long seekpt)
721 #endif
722 {
723 register struct inotab *itp;
724 struct modeinfo node;
725
726 itp = calloc(1, sizeof(struct inotab));
727 if (itp == NULL)
728 panic("no memory directory table\n");
729 itp->t_next = inotab[INOHASH(ino)];
730 inotab[INOHASH(ino)] = itp;
731 itp->t_ino = ino;
732 itp->t_seekpt = seekpt;
733 if (mf == NULL)
734 return (itp);
735 node.ino = ino;
736 #ifdef __linux__
737 node.timep[0].tv_sec = dip->di_atime.tv_sec;
738 node.timep[0].tv_usec = dip->di_atime.tv_usec;
739 node.timep[1].tv_sec = dip->di_mtime.tv_sec;
740 node.timep[1].tv_usec = dip->di_mtime.tv_usec;
741 #else /* __linux__ */
742 node.timep[0].tv_sec = dip->di_atime;
743 node.timep[0].tv_usec = dip->di_atimensec / 1000;
744 node.timep[1].tv_sec = dip->di_mtime;
745 node.timep[1].tv_usec = dip->di_mtimensec / 1000;
746 #endif /* __linux__ */
747 node.mode = dip->di_mode;
748 node.flags = dip->di_flags;
749 node.uid = dip->di_uid;
750 node.gid = dip->di_gid;
751 (void) fwrite((char *)&node, 1, sizeof(struct modeinfo), mf);
752 return (itp);
753 }
754
755 /*
756 * Look up an inode in the table of directories
757 */
758 static struct inotab *
759 inotablookup(ino_t ino)
760 {
761 register struct inotab *itp;
762
763 for (itp = inotab[INOHASH(ino)]; itp != NULL; itp = itp->t_next)
764 if (itp->t_ino == ino)
765 return (itp);
766 return (NULL);
767 }
768
769 /*
770 * Clean up and exit
771 */
772 void
773 cleanup(void)
774 {
775 closemt();
776 if (modefile[0] != '#')
777 (void) unlink(modefile);
778 if (dirfile[0] != '#')
779 (void) unlink(dirfile);
780 }