FreeBSD/sbin/restore/dirs.c
/*
 * Generate a literal copy of a directory.
 */
Generate a literal copy of a directory.
Generate a literal copy of a directory .
int
genliteraldir(char *name, ino_t ino)
{
	struct inotab *itp;
	int ofile, dp, i, size;
	char buf[BUFSIZ];
	itp = inotablookup(ino);
	if (itp == NULL)
		panic("Cannot find directory inode %ju named %s\n",
		    (uintmax_t)ino, name);
	if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
		fprintf(stderr, "%s: ", name);
		(void) fflush(stderr);
		fprintf(stderr, "cannot create file: %s\n", strerror(errno));
		return (FAIL);
	}
	rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt);
	dp = dup(dirp->dd_fd);
	for (i = itp->t_size; i > 0; i -= BUFSIZ) {
		size = MIN(i, BUFSIZ);
		if (read(dp, buf, (int) size) == -1) {
			fprintf(stderr,
			    "write error extracting inode %ju, name %s\n",
			    (uintmax_t)curfile.ino, curfile.name);
			fprintf(stderr, "read: %s\n", strerror(errno));
			done(1);
		}
		if (!Nflag && write(ofile, buf, (int) size) == -1) {
			fprintf(stderr,
			    "write error extracting inode %ju, name %s\n",
			    (uintmax_t)curfile.ino, curfile.name);
			fprintf(stderr, "write: %s\n", strerror(errno));
			done(1);
		}
	}
	(void) close(dp);
	(void) close(ofile);
	return (GOOD);
}
int genliteraldir ( char * name , ino_t ino ) { struct inotab * itp ; int ofile , dp , i , size ; char buf [ BUFSIZ ] ; itp = inotablookup ( ino ) ; if ( itp == NULL ) panic ( " \n " , ( uintmax_t ) ino , name ) ; if ( ( ofile = open ( name , O_WRONLY | O_CREAT | O_TRUNC , 0666 ) ) < 0 ) { fprintf ( stderr , " " , name ) ; ( void ) fflush ( stderr ) ; fprintf ( stderr , " \n " , strerror ( errno ) ) ; return ( FAIL ) ; } rst_seekdir ( dirp , itp -> t_seekpt , itp -> t_seekpt ) ; dp = dup ( dirp -> dd_fd ) ; for ( i = itp -> t_size ; i > 0 ; i -= BUFSIZ ) { size = MIN ( i , BUFSIZ ) ; if ( read ( dp , buf , ( int ) size ) == -1 ) { fprintf ( stderr , " \n " , ( uintmax_t ) curfile . ino , curfile . name ) ; fprintf ( stderr , " \n " , strerror ( errno ) ) ; done ( 1 ) ; } if ( ! Nflag && write ( ofile , buf , ( int ) size ) == -1 ) { fprintf ( stderr , " \n " , ( uintmax_t ) curfile . ino , curfile . name ) ; fprintf ( stderr , " \n " , strerror ( errno ) ) ; done ( 1 ) ; } } ( void ) close ( dp ) ; ( void ) close ( ofile ) ; return ( GOOD ) ; }
Generate a literal copy of a directory.
Generate a literal copy of a directory .