Deleted Added
full compact
dirs.c (81940) dirs.c (92806)
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 27 unchanged lines hidden (view full) ---

36 * SUCH DAMAGE.
37 */
38
39#ifndef lint
40#if 0
41static char sccsid[] = "@(#)dirs.c 8.7 (Berkeley) 5/1/95";
42#endif
43static const char rcsid[] =
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 27 unchanged lines hidden (view full) ---

36 * SUCH DAMAGE.
37 */
38
39#ifndef lint
40#if 0
41static char sccsid[] = "@(#)dirs.c 8.7 (Berkeley) 5/1/95";
42#endif
43static const char rcsid[] =
44 "$FreeBSD: head/sbin/restore/dirs.c 81940 2001-08-20 02:15:22Z dd $";
44 "$FreeBSD: head/sbin/restore/dirs.c 92806 2002-03-20 17:55:10Z obrien $";
45#endif /* not lint */
46
47#include <sys/param.h>
48#include <sys/file.h>
49#include <sys/stat.h>
50#include <sys/time.h>
51
52#include <ufs/ufs/dinode.h>

--- 83 unchanged lines hidden (view full) ---

136 * on disk for extraction by name.
137 * If genmode is requested, save mode, owner, and times for all
138 * directories on the tape.
139 */
140void
141extractdirs(genmode)
142 int genmode;
143{
45#endif /* not lint */
46
47#include <sys/param.h>
48#include <sys/file.h>
49#include <sys/stat.h>
50#include <sys/time.h>
51
52#include <ufs/ufs/dinode.h>

--- 83 unchanged lines hidden (view full) ---

136 * on disk for extraction by name.
137 * If genmode is requested, save mode, owner, and times for all
138 * directories on the tape.
139 */
140void
141extractdirs(genmode)
142 int genmode;
143{
144 register int i;
145 register struct dinode *ip;
144 int i;
145 struct dinode *ip;
146 struct inotab *itp;
147 struct direct nulldir;
148 int fd;
149 const char *tmpdir;
150
151 vprintf(stdout, "Extract directories from tape\n");
152 if ((tmpdir = getenv("TMPDIR")) == NULL || tmpdir[0] == '\0')
153 tmpdir = _PATH_TMP;

--- 70 unchanged lines hidden (view full) ---

224 * pname and pass them off to be processed.
225 */
226void
227treescan(pname, ino, todo)
228 char *pname;
229 ino_t ino;
230 long (*todo) __P((char *, ino_t, int));
231{
146 struct inotab *itp;
147 struct direct nulldir;
148 int fd;
149 const char *tmpdir;
150
151 vprintf(stdout, "Extract directories from tape\n");
152 if ((tmpdir = getenv("TMPDIR")) == NULL || tmpdir[0] == '\0')
153 tmpdir = _PATH_TMP;

--- 70 unchanged lines hidden (view full) ---

224 * pname and pass them off to be processed.
225 */
226void
227treescan(pname, ino, todo)
228 char *pname;
229 ino_t ino;
230 long (*todo) __P((char *, ino_t, int));
231{
232 register struct inotab *itp;
233 register struct direct *dp;
232 struct inotab *itp;
233 struct direct *dp;
234 int namelen;
235 long bpt;
236 char locname[MAXPATHLEN + 1];
237
238 itp = inotablookup(ino);
239 if (itp == NULL) {
240 /*
241 * Pname is name of a simple file or an unchanged directory.

--- 74 unchanged lines hidden (view full) ---

316 * Lookup the requested name in directory inum.
317 * Return its inode number if found, zero if it does not exist.
318 */
319static struct direct *
320searchdir(inum, name)
321 ino_t inum;
322 char *name;
323{
234 int namelen;
235 long bpt;
236 char locname[MAXPATHLEN + 1];
237
238 itp = inotablookup(ino);
239 if (itp == NULL) {
240 /*
241 * Pname is name of a simple file or an unchanged directory.

--- 74 unchanged lines hidden (view full) ---

316 * Lookup the requested name in directory inum.
317 * Return its inode number if found, zero if it does not exist.
318 */
319static struct direct *
320searchdir(inum, name)
321 ino_t inum;
322 char *name;
323{
324 register struct direct *dp;
325 register struct inotab *itp;
324 struct direct *dp;
325 struct inotab *itp;
326 int len;
327
328 itp = inotablookup(inum);
329 if (itp == NULL)
330 return (NULL);
331 rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt);
332 len = strlen(name);
333 do {

--- 8 unchanged lines hidden (view full) ---

342 * Put the directory entries in the directory file
343 */
344static void
345putdir(buf, size)
346 char *buf;
347 long size;
348{
349 struct direct cvtbuf;
326 int len;
327
328 itp = inotablookup(inum);
329 if (itp == NULL)
330 return (NULL);
331 rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt);
332 len = strlen(name);
333 do {

--- 8 unchanged lines hidden (view full) ---

342 * Put the directory entries in the directory file
343 */
344static void
345putdir(buf, size)
346 char *buf;
347 long size;
348{
349 struct direct cvtbuf;
350 register struct odirect *odp;
350 struct odirect *odp;
351 struct odirect *eodp;
351 struct odirect *eodp;
352 register struct direct *dp;
352 struct direct *dp;
353 long loc, i;
354
355 if (cvtflag) {
356 eodp = (struct odirect *)&buf[size];
357 for (odp = (struct odirect *)buf; odp < eodp; odp++)
358 if (odp->d_ino != 0) {
359 dcvt(odp, &cvtbuf);
360 putent(&cvtbuf);

--- 77 unchanged lines hidden (view full) ---

438 ((struct direct *)(dirbuf + prev))->d_reclen = DIRBLKSIZ - prev;
439 (void) fwrite(dirbuf, (int)dirloc, 1, df);
440 seekpt = ftell(df);
441 dirloc = 0;
442}
443
444static void
445dcvt(odp, ndp)
353 long loc, i;
354
355 if (cvtflag) {
356 eodp = (struct odirect *)&buf[size];
357 for (odp = (struct odirect *)buf; odp < eodp; odp++)
358 if (odp->d_ino != 0) {
359 dcvt(odp, &cvtbuf);
360 putent(&cvtbuf);

--- 77 unchanged lines hidden (view full) ---

438 ((struct direct *)(dirbuf + prev))->d_reclen = DIRBLKSIZ - prev;
439 (void) fwrite(dirbuf, (int)dirloc, 1, df);
440 seekpt = ftell(df);
441 dirloc = 0;
442}
443
444static void
445dcvt(odp, ndp)
446 register struct odirect *odp;
447 register struct direct *ndp;
446 struct odirect *odp;
447 struct direct *ndp;
448{
449
450 memset(ndp, 0, (long)(sizeof *ndp));
451 ndp->d_ino = odp->d_ino;
452 ndp->d_type = DT_UNKNOWN;
453 (void) strncpy(ndp->d_name, odp->d_name, ODIRSIZ);
454 ndp->d_namlen = strlen(ndp->d_name);
455 ndp->d_reclen = DIRSIZ(0, ndp);
456}
457
458/*
459 * Seek to an entry in a directory.
460 * Only values returned by rst_telldir should be passed to rst_seekdir.
461 * This routine handles many directories in a single file.
462 * It takes the base of the directory in the file, plus
463 * the desired seek offset into it.
464 */
465static void
466rst_seekdir(dirp, loc, base)
448{
449
450 memset(ndp, 0, (long)(sizeof *ndp));
451 ndp->d_ino = odp->d_ino;
452 ndp->d_type = DT_UNKNOWN;
453 (void) strncpy(ndp->d_name, odp->d_name, ODIRSIZ);
454 ndp->d_namlen = strlen(ndp->d_name);
455 ndp->d_reclen = DIRSIZ(0, ndp);
456}
457
458/*
459 * Seek to an entry in a directory.
460 * Only values returned by rst_telldir should be passed to rst_seekdir.
461 * This routine handles many directories in a single file.
462 * It takes the base of the directory in the file, plus
463 * the desired seek offset into it.
464 */
465static void
466rst_seekdir(dirp, loc, base)
467 register RST_DIR *dirp;
467 RST_DIR *dirp;
468 long loc, base;
469{
470
471 if (loc == rst_telldir(dirp))
472 return;
473 loc -= base;
474 if (loc < 0)
475 fprintf(stderr, "bad seek pointer to rst_seekdir %ld\n", loc);
476 (void) lseek(dirp->dd_fd, base + (loc & ~(DIRBLKSIZ - 1)), SEEK_SET);
477 dirp->dd_loc = loc & (DIRBLKSIZ - 1);
478 if (dirp->dd_loc != 0)
479 dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ);
480}
481
482/*
483 * get next entry in a directory.
484 */
485struct direct *
486rst_readdir(dirp)
468 long loc, base;
469{
470
471 if (loc == rst_telldir(dirp))
472 return;
473 loc -= base;
474 if (loc < 0)
475 fprintf(stderr, "bad seek pointer to rst_seekdir %ld\n", loc);
476 (void) lseek(dirp->dd_fd, base + (loc & ~(DIRBLKSIZ - 1)), SEEK_SET);
477 dirp->dd_loc = loc & (DIRBLKSIZ - 1);
478 if (dirp->dd_loc != 0)
479 dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ);
480}
481
482/*
483 * get next entry in a directory.
484 */
485struct direct *
486rst_readdir(dirp)
487 register RST_DIR *dirp;
487 RST_DIR *dirp;
488{
488{
489 register struct direct *dp;
489 struct direct *dp;
490
491 for (;;) {
492 if (dirp->dd_loc == 0) {
493 dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
494 DIRBLKSIZ);
495 if (dirp->dd_size <= 0) {
496 dprintf(stderr, "error reading directory\n");
497 return (NULL);

--- 68 unchanged lines hidden (view full) ---

566
567/*
568 * Open a directory file.
569 */
570static RST_DIR *
571opendirfile(name)
572 const char *name;
573{
490
491 for (;;) {
492 if (dirp->dd_loc == 0) {
493 dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
494 DIRBLKSIZ);
495 if (dirp->dd_size <= 0) {
496 dprintf(stderr, "error reading directory\n");
497 return (NULL);

--- 68 unchanged lines hidden (view full) ---

566
567/*
568 * Open a directory file.
569 */
570static RST_DIR *
571opendirfile(name)
572 const char *name;
573{
574 register RST_DIR *dirp;
575 register int fd;
574 RST_DIR *dirp;
575 int fd;
576
577 if ((fd = open(name, O_RDONLY)) == -1)
578 return (NULL);
579 if ((dirp = malloc(sizeof(RST_DIR))) == NULL) {
580 (void)close(fd);
581 return (NULL);
582 }
583 dirp->dd_fd = fd;

--- 69 unchanged lines hidden (view full) ---

653/*
654 * Generate a literal copy of a directory.
655 */
656int
657genliteraldir(name, ino)
658 char *name;
659 ino_t ino;
660{
576
577 if ((fd = open(name, O_RDONLY)) == -1)
578 return (NULL);
579 if ((dirp = malloc(sizeof(RST_DIR))) == NULL) {
580 (void)close(fd);
581 return (NULL);
582 }
583 dirp->dd_fd = fd;

--- 69 unchanged lines hidden (view full) ---

653/*
654 * Generate a literal copy of a directory.
655 */
656int
657genliteraldir(name, ino)
658 char *name;
659 ino_t ino;
660{
661 register struct inotab *itp;
661 struct inotab *itp;
662 int ofile, dp, i, size;
663 char buf[BUFSIZ];
664
665 itp = inotablookup(ino);
666 if (itp == NULL)
667 panic("Cannot find directory inode %d named %s\n", ino, name);
668 if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
669 fprintf(stderr, "%s: ", name);

--- 45 unchanged lines hidden (view full) ---

715 * If requested, save its pertinent mode, owner, and time info.
716 */
717static struct inotab *
718allocinotab(ino, dip, seekpt)
719 ino_t ino;
720 struct dinode *dip;
721 long seekpt;
722{
662 int ofile, dp, i, size;
663 char buf[BUFSIZ];
664
665 itp = inotablookup(ino);
666 if (itp == NULL)
667 panic("Cannot find directory inode %d named %s\n", ino, name);
668 if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
669 fprintf(stderr, "%s: ", name);

--- 45 unchanged lines hidden (view full) ---

715 * If requested, save its pertinent mode, owner, and time info.
716 */
717static struct inotab *
718allocinotab(ino, dip, seekpt)
719 ino_t ino;
720 struct dinode *dip;
721 long seekpt;
722{
723 register struct inotab *itp;
723 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;

--- 15 unchanged lines hidden (view full) ---

747
748/*
749 * Look up an inode in the table of directories
750 */
751static struct inotab *
752inotablookup(ino)
753 ino_t ino;
754{
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;

--- 15 unchanged lines hidden (view full) ---

747
748/*
749 * Look up an inode in the table of directories
750 */
751static struct inotab *
752inotablookup(ino)
753 ino_t ino;
754{
755 register struct inotab *itp;
755 struct inotab *itp;
756
757 for (itp = inotab[INOHASH(ino)]; itp != NULL; itp = itp->t_next)
758 if (itp->t_ino == ino)
759 return (itp);
760 return (NULL);
761}
762
763/*

--- 14 unchanged lines hidden ---
756
757 for (itp = inotab[INOHASH(ino)]; itp != NULL; itp = itp->t_next)
758 if (itp->t_ino == ino)
759 return (itp);
760 return (NULL);
761}
762
763/*

--- 14 unchanged lines hidden ---