FreeBSD/sbin/restore/dirs.c
/*
 *	Extract directory contents, building up a directory structure
 *	on disk for extraction by name.
 *	If genmode is requested, save mode, owner, and times for all
 *	directories on the tape.
 */
Extract directory contents, building up a directory structure
on disk for extraction by name.
If genmode is requested, save mode, owner, and times for all
directories on the tape.
Extract directory contents building up a directory structure on disk for extraction by name . If genmode is requested save mode owner and times for all directories on the tape .
void
extractdirs(int genmode)
{
	struct inotab *itp;
	struct direct nulldir;
	int i, fd;
	const char *tmpdir;
	vprintf(stdout, "Extract directories from tape\n");
	if ((tmpdir = getenv("TMPDIR")) == NULL || tmpdir[0] == '\0')
		tmpdir = _PATH_TMP;
	(void) sprintf(dirfile, "%s/rstdir%jd", tmpdir, (intmax_t)dumpdate);
	if (command != 'r' && command != 'R') {
		(void) strcat(dirfile, "-XXXXXX");
		fd = mkstemp(dirfile);
	} else
		fd = open(dirfile, O_RDWR|O_CREAT|O_EXCL, 0666);
	if (fd == -1 || (df = fdopen(fd, "w")) == NULL) {
		if (fd != -1)
			close(fd);
		warn("%s: cannot create directory database", dirfile);
		done(1);
	}
	if (genmode != 0) {
		(void) sprintf(modefile, "%s/rstmode%jd", tmpdir,
		    (intmax_t)dumpdate);
		if (command != 'r' && command != 'R') {
			(void) strcat(modefile, "-XXXXXX");
			fd = mkstemp(modefile);
		} else
			fd = open(modefile, O_RDWR|O_CREAT|O_EXCL, 0666);
		if (fd == -1 || (mf = fdopen(fd, "w")) == NULL) {
			if (fd != -1)
				close(fd);
			warn("%s: cannot create modefile", modefile);
			done(1);
		}
	}
	nulldir.d_ino = 0;
	nulldir.d_type = DT_DIR;
	nulldir.d_namlen = 1;
	(void) strcpy(nulldir.d_name, "/");
	nulldir.d_reclen = DIRSIZ(0, &nulldir);
	for (;;) {
		curfile.name = "<directory file - name unknown>";
		curfile.action = USING;
		if (curfile.mode == 0 || (curfile.mode & IFMT) != IFDIR)
			break;
		itp = allocinotab(&curfile, seekpt);
		getfile(putdir, putdirattrs, xtrnull);
		putent(&nulldir);
		flushent();
		itp->t_size = seekpt - itp->t_seekpt;
	}
	if (fclose(df) != 0)
		fail_dirtmp(dirfile);
	dirp = opendirfile(dirfile);
	if (dirp == NULL)
		fprintf(stderr, "opendirfile: %s\n", strerror(errno));
	if (mf != NULL && fclose(mf) != 0)
		fail_dirtmp(modefile);
	i = dirlookup(dot);
	if (i == 0)
		panic("Root directory is not on tape\n");
}
void extractdirs ( int genmode ) { struct inotab * itp ; struct direct nulldir ; int i , fd ; const char * tmpdir ; vprintf ( stdout , " \n " ) ; if ( ( tmpdir = getenv ( " " ) ) == NULL || tmpdir [ 0 ] == ' \0 ' ) tmpdir = _PATH_TMP ; ( void ) sprintf ( dirfile , " " , tmpdir , ( intmax_t ) dumpdate ) ; if ( command != ' ' && command != ' ' ) { ( void ) strcat ( dirfile , " " ) ; fd = mkstemp ( dirfile ) ; } else fd = open ( dirfile , O_RDWR | O_CREAT | O_EXCL , 0666 ) ; if ( fd == -1 || ( df = fdopen ( fd , " " ) ) == NULL ) { if ( fd != -1 ) close ( fd ) ; warn ( " " , dirfile ) ; done ( 1 ) ; } if ( genmode != 0 ) { ( void ) sprintf ( modefile , " " , tmpdir , ( intmax_t ) dumpdate ) ; if ( command != ' ' && command != ' ' ) { ( void ) strcat ( modefile , " " ) ; fd = mkstemp ( modefile ) ; } else fd = open ( modefile , O_RDWR | O_CREAT | O_EXCL , 0666 ) ; if ( fd == -1 || ( mf = fdopen ( fd , " " ) ) == NULL ) { if ( fd != -1 ) close ( fd ) ; warn ( " " , modefile ) ; done ( 1 ) ; } } nulldir . d_ino = 0 ; nulldir . d_type = DT_DIR ; nulldir . d_namlen = 1 ; ( void ) strcpy ( nulldir . d_name , " " ) ; nulldir . d_reclen = DIRSIZ ( 0 , & nulldir ) ; for ( ; ; ) { curfile . name = " " ; curfile . action = USING ; if ( curfile . mode == 0 || ( curfile . mode & IFMT ) != IFDIR ) break ; itp = allocinotab ( & curfile , seekpt ) ; getfile ( putdir , putdirattrs , xtrnull ) ; putent ( & nulldir ) ; flushent ( ) ; itp -> t_size = seekpt - itp -> t_seekpt ; } if ( fclose ( df ) != 0 ) fail_dirtmp ( dirfile ) ; dirp = opendirfile ( dirfile ) ; if ( dirp == NULL ) fprintf ( stderr , " \n " , strerror ( errno ) ) ; if ( mf != NULL && fclose ( mf ) != 0 ) fail_dirtmp ( modefile ) ; i = dirlookup ( dot ) ; if ( i == 0 ) panic ( " \n " ) ; }
Extract directory contents, building up a directory structure
      on disk for extraction by name.
Extract directory contents building up a directory structure on disk for extraction by name .