On 04/03/2014 09:03 AM, Dave Reisner wrote:
> On the initial call to copy_internal, we must use an invalid device
> number. As of linux 3.14, the mount table has shifted slightly, causing
> the initramfs filesystem to have a devno of 0. This is valid, but
> confuses cp when attempting to copy only a single filesystem (cp -x).
> Since dev_t is defined to be an integer type, we can simply use a
> negative value to identify the unknown device.

dev_t is defined as an integral type, but not necessarily a signed
integral type, and not necessarily a type as wide as int.  Using -1 as a
sentinel might be okay, but if you do, you MUST use a cast for maximum
portability.

> @@ -2434,7 +2434,7 @@ copy_internal (char const *src_name, char const 
> *dst_name,
>          }
>  
>        /* Decide whether to copy the contents of the directory.  */
> -      if (x->one_file_system && device != 0 && device != src_sb.st_dev)
> +      if (x->one_file_system && device != -1 && device != src_sb.st_dev)

For example, this comparison may fail to do what you want if dev_t is
uint16_t (it will ALWAYS be false, since ((uint16_t)-1) != -1).

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to