@@ -3583,17 +3583,25 @@ populate_fs(filesystem *fs, struct fslayer *fslayers, int nlayers, int squash_ui
35833583 if (fs && !(nod = find_path (fs , EXT2_ROOT_INO , pdest )))
35843584 error_msg_and_die ("path %s not found in filesystem" , pdest );
35853585 }
3586+ /* do not compute stats when input is to be read from stdin */
3587+ if (stats != NULL && strcmp (fslayers [i ].path , "-" ) == 0 ) {
3588+ continue ;
3589+ }
35863590 stat (fslayers [i ].path , & st );
35873591 switch (fslayers [i ].type )
35883592 {
35893593 case FSLAYER_TABLE :
3590- if ((st .st_mode & S_IFMT ) != S_IFREG )
3594+ if (strcmp (fslayers [i ].path , "-" ) == 0 )
3595+ fh = stdin ;
3596+ else if ((st .st_mode & S_IFMT ) != S_IFREG )
35913597 error_msg_and_die ("%s should be a file" , fslayers [i ].path );
3598+ else
3599+ fh = xfopen (fslayers [i ].path , "rb" );
35923600 if (fs )
35933601 fprintf (stderr , "nodes fixup and creation from device table %s\n" , fslayers [i ].path );
3594- fh = xfopen (fslayers [i ].path , "rb" );
35953602 add2fs_from_file (fs , nod , fh , fs_timestamp , stats );
3596- fclose (fh );
3603+ if (strcmp (fslayers [i ].path , "-" ) != 0 )
3604+ fclose (fh );
35973605 break ;
35983606 case FSLAYER_DIR :
35993607 if ((st .st_mode & S_IFMT ) != S_IFDIR )
@@ -3611,13 +3619,17 @@ populate_fs(filesystem *fs, struct fslayer *fslayers, int nlayers, int squash_ui
36113619 perror_msg_and_die ("close" );
36123620 break ;
36133621 case FSLAYER_TAR :
3614- if ((st .st_mode & S_IFMT ) != S_IFREG )
3622+ if (strcmp (fslayers [i ].path , "-" ) == 0 )
3623+ fh = stdin ;
3624+ else if ((st .st_mode & S_IFMT ) != S_IFREG )
36153625 error_msg_and_die ("%s should be a file" , fslayers [i ].path );
3626+ else
3627+ fh = xfopen (fslayers [i ].path , "rb" );
36163628 if (fs )
36173629 fprintf (stderr , "copying from tar archive %s\n" , fslayers [i ].path );
3618- fh = xfopen (fslayers [i ].path , "rb" );
36193630 add2fs_from_tarball (fs , nod , fh , squash_uids , squash_perms , fs_timestamp , stats );
3620- fclose (fh );
3631+ if (strcmp (fslayers [i ].path , "-" ) != 0 )
3632+ fclose (fh );
36213633 break ;
36223634 }
36233635 }
@@ -3833,6 +3845,15 @@ main(int argc, char **argv)
38333845 if (creator_os < 0 )
38343846 error_msg_and_die ("Creator OS unknown." );
38353847
3848+ int numstdin = 0 ;
3849+ for (i = 0 ; i < nlayers ; i ++ )
3850+ if (strcmp (layers [i ].path , "-" ) == 0 )
3851+ numstdin ++ ;
3852+ if (numstdin == 1 && nbinodes == -1 && bytes_per_inode == -1 )
3853+ fprintf (stderr , "Cannot count the required inodes for input from stdin -- use the -N or -i options to set the number of inodes or work with temporary files." );
3854+ if (numstdin > 1 )
3855+ error_msg_and_die ("only one input can come from stdin" );
3856+
38363857 if (fsin )
38373858 {
38383859 fprintf (stderr , "starting from existing image %s" , fsin );
0 commit comments