bug-coreutils
[Top][All Lists]
Advanced

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

bug#17179: [PATCH] cp: use an invalid dev_t for an unknown device


From: Eric Blake
Subject: bug#17179: [PATCH] cp: use an invalid dev_t for an unknown device
Date: Thu, 03 Apr 2014 09:54:24 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0

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

[Prev in Thread] Current Thread [Next in Thread]