Description: Better handle device nodes from cramfs.
Author: Carl Miller <chaz@energoncube.net> 

--- cpio-2.11.orig/src/copyout.c
+++ cpio-2.11/src/copyout.c
@@ -232,7 +232,8 @@ writeout_defered_file (struct cpio_file_
 			   header->c_name);
   warn_if_file_changed(header->c_name, file_hdr.c_filesize, file_hdr.c_mtime);
 
-  if (archive_format == arf_tar || archive_format == arf_ustar)
+  if ((archive_format == arf_tar || archive_format == arf_ustar)
+      && (file_hdr.c_nlink > 1))
     add_inode (file_hdr.c_ino, file_hdr.c_name, file_hdr.c_dev_maj,
 	       file_hdr.c_dev_min);
 
@@ -651,7 +652,7 @@ process_copy_out ()
 	  
 	  if (archive_format == arf_tar || archive_format == arf_ustar)
 	    {
-	      if (file_hdr.c_mode & CP_IFDIR)
+             if ((file_hdr.c_mode & CP_IFMT) == CP_IFDIR)
 		{
 		  int len = strlen (input_name.ds_string);
 		  /* Make sure the name ends with a slash */
@@ -695,7 +696,8 @@ process_copy_out ()
 	  switch (file_hdr.c_mode & CP_IFMT)
 	    {
 	    case CP_IFREG:
-	      if (archive_format == arf_tar || archive_format == arf_ustar)
+             if ((archive_format == arf_tar || archive_format == arf_ustar)
+                 && (file_hdr.c_nlink > 1))
 		{
 		  char *otherfile;
 		  if ((otherfile = find_inode_file (file_hdr.c_ino,
@@ -742,7 +744,8 @@ process_copy_out ()
 	      warn_if_file_changed(orig_file_name, file_hdr.c_filesize,
                                    file_hdr.c_mtime);
 
-	      if (archive_format == arf_tar || archive_format == arf_ustar)
+             if ((archive_format == arf_tar || archive_format == arf_ustar)
+                 && (file_hdr.c_nlink > 1))
 		add_inode (file_hdr.c_ino, orig_file_name, file_hdr.c_dev_maj,
 			   file_hdr.c_dev_min);
 
@@ -776,7 +779,7 @@ process_copy_out ()
 			 orig_file_name);
 		  continue;
 		}
-	      else if (archive_format == arf_ustar)
+             else if ((archive_format == arf_ustar) && (file_hdr.c_nlink > 1))
 		{
 		  char *otherfile;
 		  if ((otherfile = find_inode_file (file_hdr.c_ino,

