FreeBSD/sbin/restore/dirs.c
/*
 * get next entry in a directory.
 */
get next entry in a directory.
get next entry in a directory .
struct direct *
rst_readdir(RST_DIR *dirp)
{
	struct direct *dp;
	for (;;) {
		if (dirp->dd_loc == 0) {
			dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
			    DIRBLKSIZ);
			if (dirp->dd_size <= 0) {
				dprintf(stderr, "error reading directory\n");
				return (NULL);
			}
		}
		if (dirp->dd_loc >= dirp->dd_size) {
			dirp->dd_loc = 0;
			continue;
		}
		dp = (struct direct *)(dirp->dd_buf + dirp->dd_loc);
		if (dp->d_reclen == 0 ||
		    dp->d_reclen > DIRBLKSIZ + 1 - dirp->dd_loc) {
			dprintf(stderr, "corrupted directory: bad reclen %d\n",
				dp->d_reclen);
			return (NULL);
		}
		dirp->dd_loc += dp->d_reclen;
		if (dp->d_ino == 0 && strcmp(dp->d_name, "/") == 0)
			return (NULL);
		if (dp->d_ino >= maxino) {
			dprintf(stderr, "corrupted directory: bad inum %d\n",
				dp->d_ino);
			continue;
		}
		return (dp);
	}
}
struct direct * rst_readdir ( RST_DIR * dirp ) { struct direct * dp ; for ( ; ; ) { if ( dirp -> dd_loc == 0 ) { dirp -> dd_size = read ( dirp -> dd_fd , dirp -> dd_buf , DIRBLKSIZ ) ; if ( dirp -> dd_size <= 0 ) { dprintf ( stderr , " \n " ) ; return ( NULL ) ; } } if ( dirp -> dd_loc >= dirp -> dd_size ) { dirp -> dd_loc = 0 ; continue ; } dp = ( struct direct * ) ( dirp -> dd_buf + dirp -> dd_loc ) ; if ( dp -> d_reclen == 0 || dp -> d_reclen > DIRBLKSIZ + 1 - dirp -> dd_loc ) { dprintf ( stderr , " \n " , dp -> d_reclen ) ; return ( NULL ) ; } dirp -> dd_loc += dp -> d_reclen ; if ( dp -> d_ino == 0 && strcmp ( dp -> d_name , " " ) == 0 ) return ( NULL ) ; if ( dp -> d_ino >= maxino ) { dprintf ( stderr , " \n " , dp -> d_ino ) ; continue ; } return ( dp ) ; } }
get next entry in a directory.
get next entry in a directory .