[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#244589: busybox-cvs: 'cp -a' from cramfs breaks



Package: busybox-cvs
Version: 20040408-1
Tags: patch d-i

When I create a cramfs of a debian-installer tree and try to boot from
it, the 'cp -a' in d-i's init falls over like this, which makes init
fall over in turn:

  cp: unable to link `../tmp/usr/share/discover/usb.lst': Operation not permitted
  cp: unable to link `../tmp/var/log/messages': Operation not permitted

It turns out that this is because cramfs sets the same inode (namely 1)
on empty directories and zero-length files, and busybox cp thinks that
it can hard-link together anything with the same inode. While this is a
fair assumption with more normal filesystems, it would be very useful if
it could apply more sanity checks before trying to call link(), such as
checking the link count, which on any normal filesystem will be greater
than one for each of a set of hardlink.

I've successfully booted using the following patch:

diff -u busybox-cvs-20040408/debian/changelog busybox-cvs-20040408/debian/changelog
--- busybox-cvs-20040408/debian/changelog
+++ busybox-cvs-20040408/debian/changelog
@@ -1,3 +1,11 @@
+busybox-cvs (20040408-1.1) UNRELEASED; urgency=low
+
+  * libbb/copy_file.c:
+    - Fix 'cp -a' from cramfs, where zero-length files and empty directories
+      have the same inode number. Only make hardlinks if st_nlink > 1.
+
+ -- Colin Watson <cjwatson@debian.org>  Mon, 19 Apr 2004 01:03:51 +0100
+
 busybox-cvs (20040408-1) unstable; urgency=low
 
   * New CVS version
only in patch2:
unchanged:
--- busybox-cvs-20040408.orig/libbb/copy_file.c
+++ busybox-cvs-20040408/libbb/copy_file.c
@@ -129,6 +129,7 @@
 		char *link_name;
 
 		if (!(flags & FILEUTILS_DEREFERENCE) &&
+				source_stat.st_nlink > 1 &&
 				is_in_ino_dev_hashtable(&source_stat, &link_name)) {
 			if (link(link_name, dest) < 0) {
 				bb_perror_msg("unable to link `%s'", dest);

Thanks,

-- 
Colin Watson                                  [cjwatson@flatline.org.uk]



Reply to: