FreeBSD/sbin/restore/dirs.c
/*
 *	Recursively find names and inumbers of all files in subtree
 *	pname and pass them off to be processed.
 */
Recursively find names and inumbers of all files in subtree
pname and pass them off to be processed.
Recursively find names and inumbers of all files in subtree pname and pass them off to be processed .
void
treescan(char *pname, ino_t ino, long (*todo)(char *, ino_t, int))
{
	struct inotab *itp;
	struct direct *dp;
	int namelen;
	long bpt;
	char locname[MAXPATHLEN];
	itp = inotablookup(ino);
	if (itp == NULL) {
		(void) (*todo)(pname, ino, LEAF);
		return;
	}
	if ((*todo)(pname, ino, NODE) == FAIL)
		return;
	(void) strlcpy(locname, pname, sizeof(locname));
	(void) strlcat(locname, "/", sizeof(locname));
	namelen = strlen(locname);
	rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt);
	dp = rst_readdir(dirp); 
	if (dp != NULL && strcmp(dp->d_name, ".") == 0)
		dp = rst_readdir(dirp); 
	else
		fprintf(stderr, "Warning: `.' missing from directory %s\n",
			pname);
	if (dp != NULL && strcmp(dp->d_name, "..") == 0)
		dp = rst_readdir(dirp); 
	else
		fprintf(stderr, "Warning: `..' missing from directory %s\n",
			pname);
	bpt = rst_telldir(dirp);
	while (dp != NULL) {
		locname[namelen] = '\0';
		if (namelen + dp->d_namlen >= sizeof(locname)) {
			fprintf(stderr, "%s%s: name exceeds %zu char\n",
			    locname, dp->d_name, sizeof(locname) - 1);
		} else {
			(void)strlcat(locname, dp->d_name, sizeof(locname));
			treescan(locname, dp->d_ino, todo);
			rst_seekdir(dirp, bpt, itp->t_seekpt);
		}
		dp = rst_readdir(dirp);
		bpt = rst_telldir(dirp);
	}
}
void treescan ( char * pname , ino_t ino , long ( * todo ) ( char * , ino_t , int ) ) { struct inotab * itp ; struct direct * dp ; int namelen ; long bpt ; char locname [ MAXPATHLEN ] ; itp = inotablookup ( ino ) ; if ( itp == NULL ) { ( void ) ( * todo ) ( pname , ino , LEAF ) ; return ; } if ( ( * todo ) ( pname , ino , NODE ) == FAIL ) return ; ( void ) strlcpy ( locname , pname , sizeof ( locname ) ) ; ( void ) strlcat ( locname , " " , sizeof ( locname ) ) ; namelen = strlen ( locname ) ; rst_seekdir ( dirp , itp -> t_seekpt , itp -> t_seekpt ) ; dp = rst_readdir ( dirp ) ; if ( dp != NULL && strcmp ( dp -> d_name , " " ) == 0 ) dp = rst_readdir ( dirp ) ; else fprintf ( stderr , " \n " , pname ) ; if ( dp != NULL && strcmp ( dp -> d_name , " " ) == 0 ) dp = rst_readdir ( dirp ) ; else fprintf ( stderr , " \n " , pname ) ; bpt = rst_telldir ( dirp ) ; while ( dp != NULL ) { locname [ namelen ] = ' \0 ' ; if ( namelen + dp -> d_namlen >= sizeof ( locname ) ) { fprintf ( stderr , " \n " , locname , dp -> d_name , sizeof ( locname ) - 1 ) ; } else { ( void ) strlcat ( locname , dp -> d_name , sizeof ( locname ) ) ; treescan ( locname , dp -> d_ino , todo ) ; rst_seekdir ( dirp , bpt , itp -> t_seekpt ) ; } dp = rst_readdir ( dirp ) ; bpt = rst_telldir ( dirp ) ; } }
Recursively find names and inumbers of all files in subtree
      pname and pass them off to be processed.
Recursively find names and inumbers of all files in subtree pname and pass them off to be processed .
/*
		 * Pname is name of a simple file or an unchanged directory.
		 */ /*
	 * Pname is a dumped directory name.
	 */ /*
	 * begin search through the directory
	 * skipping over "." and ".."
	 */ /* "." */ /* ".." */ /* first real entry */ /*
	 * a zero inode signals end of directory
	 */